gio: Clean up trashinfo file if trashing fails
[glib.git] / gio / glocalfilemonitor.c
bloba4cbeae0b207b09723cc2dac6a42c2a873e75f93
1 /* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
23 #include "config.h"
25 #include "gioenumtypes.h"
26 #include "glocalfilemonitor.h"
27 #include "giomodule-priv.h"
28 #include "gioerror.h"
29 #include "glibintl.h"
31 #include <string.h>
34 enum
36 PROP_0,
37 PROP_FILENAME,
38 PROP_FLAGS
41 G_DEFINE_ABSTRACT_TYPE (GLocalFileMonitor, g_local_file_monitor, G_TYPE_FILE_MONITOR)
43 static void
44 g_local_file_monitor_init (GLocalFileMonitor* local_monitor)
48 static void
49 g_local_file_monitor_set_property (GObject *object,
50 guint property_id,
51 const GValue *value,
52 GParamSpec *pspec)
54 GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
56 switch (property_id)
58 case PROP_FILENAME:
59 local_monitor->filename = g_value_dup_string (value);
60 break;
62 case PROP_FLAGS:
63 local_monitor->flags = g_value_get_flags (value);
64 break;
66 default:
67 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 break;
72 void
73 g_local_file_monitor_start (GLocalFileMonitor *local_monitor)
75 GLocalFileMonitorClass *class;
77 class = G_LOCAL_FILE_MONITOR_GET_CLASS (local_monitor);
79 if (class->start)
80 class->start (local_monitor);
83 static void
84 g_local_file_monitor_finalize (GObject *object)
86 GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
88 g_free (local_monitor->filename);
90 G_OBJECT_CLASS (g_local_file_monitor_parent_class)->finalize (object);
93 static void g_local_file_monitor_class_init (GLocalFileMonitorClass *klass)
95 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
97 gobject_class->set_property = g_local_file_monitor_set_property;
98 gobject_class->finalize = g_local_file_monitor_finalize;
100 g_object_class_install_property (gobject_class,
101 PROP_FILENAME,
102 g_param_spec_string ("filename",
103 P_("File name"),
104 P_("File name to monitor"),
105 NULL,
106 G_PARAM_CONSTRUCT_ONLY|
107 G_PARAM_WRITABLE|
108 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
110 g_object_class_install_property (gobject_class,
111 PROP_FLAGS,
112 g_param_spec_flags ("flags",
113 P_("Monitor flags"),
114 P_("Monitor flags"),
115 G_TYPE_FILE_MONITOR_FLAGS,
117 G_PARAM_CONSTRUCT_ONLY|
118 G_PARAM_WRITABLE|
119 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
122 GFileMonitor*
123 _g_local_file_monitor_new (const char *pathname,
124 GFileMonitorFlags flags,
125 GMainContext *context,
126 gboolean is_remote_fs,
127 gboolean do_start,
128 GError **error)
130 GFileMonitor *monitor = NULL;
131 GType type = G_TYPE_INVALID;
133 if (is_remote_fs)
134 type = _g_io_module_get_default_type (G_NFS_FILE_MONITOR_EXTENSION_POINT_NAME,
135 "GIO_USE_FILE_MONITOR",
136 G_STRUCT_OFFSET (GLocalFileMonitorClass, is_supported));
138 if (type == G_TYPE_INVALID)
139 type = _g_io_module_get_default_type (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
140 "GIO_USE_FILE_MONITOR",
141 G_STRUCT_OFFSET (GLocalFileMonitorClass, is_supported));
143 if (type != G_TYPE_INVALID)
144 monitor = G_FILE_MONITOR (g_object_new (type, "filename", pathname, "flags", flags, "context", context, NULL));
145 else
146 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
147 _("Unable to find default local file monitor type"));
149 if (monitor && do_start)
150 g_local_file_monitor_start (G_LOCAL_FILE_MONITOR (monitor));
152 return monitor;