const GValue *value,
GParamSpec *pspec)
{
+ GLocalDirectoryMonitor *local_monitor = G_LOCAL_DIRECTORY_MONITOR (object);
+
switch (property_id)
- {
+ {
case PROP_DIRNAME:
- /* Do nothing */
+ local_monitor->dirname = g_value_dup_string (value);
break;
+
case PROP_FLAGS:
- /* Do nothing */
+ local_monitor->flags = g_value_get_flags (value);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
-static GObject *
-g_local_directory_monitor_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
+void
+g_local_directory_monitor_start (GLocalDirectoryMonitor *local_monitor)
{
- GObject *obj;
- GLocalDirectoryMonitorClass *klass;
- GObjectClass *parent_class;
- GLocalDirectoryMonitor *local_monitor;
- GFileMonitorFlags flags = 0;
- const gchar *dirname = NULL;
- gint i;
-
- klass = G_LOCAL_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_DIRECTORY_MONITOR));
- parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
- obj = parent_class->constructor (type,
- n_construct_properties,
- construct_properties);
-
- local_monitor = G_LOCAL_DIRECTORY_MONITOR (obj);
-
- for (i = 0; i < n_construct_properties; i++)
- {
- if (strcmp ("dirname", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
- {
- g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
- dirname = g_value_get_string (construct_properties[i].value);
- }
- if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
- {
- g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
- flags = g_value_get_flags (construct_properties[i].value);
- }
- }
+ GLocalDirectoryMonitorClass *class;
- local_monitor->dirname = g_strdup (dirname);
- local_monitor->flags = flags;
+ class = G_LOCAL_DIRECTORY_MONITOR_GET_CLASS (local_monitor);
- if (!G_LOCAL_DIRECTORY_MONITOR_GET_CLASS (local_monitor)->mount_notify &&
- (flags & G_FILE_MONITOR_WATCH_MOUNTS))
+ if (!class->mount_notify && (local_monitor->flags & G_FILE_MONITOR_WATCH_MOUNTS))
{
#ifdef G_OS_WIN32
/*claim everything was mounted */
local_monitor->was_mounted = TRUE;
#else
GUnixMountEntry *mount;
-
+
/* Emulate unmount detection */
-
+
mount = g_unix_mount_at (local_monitor->dirname, NULL);
-
+
local_monitor->was_mounted = mount != NULL;
-
+
if (mount)
g_unix_mount_free (mount);
local_monitor->mount_monitor = g_unix_mount_monitor_new ();
g_signal_connect_object (local_monitor->mount_monitor, "mounts-changed",
- G_CALLBACK (mounts_changed), local_monitor, 0);
+ G_CALLBACK (mounts_changed), local_monitor, 0);
#endif
}
- return obj;
+ if (class->start)
+ class->start (local_monitor);
}
static void
{
GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
GFileMonitorClass *file_monitor_class = G_FILE_MONITOR_CLASS (klass);
-
+
gobject_class->finalize = g_local_directory_monitor_finalize;
gobject_class->set_property = g_local_directory_monitor_set_property;
- gobject_class->constructor = g_local_directory_monitor_constructor;
file_monitor_class->cancel = g_local_directory_monitor_cancel;
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Unable to find default local directory monitor type"));
+ if (monitor)
+ g_local_directory_monitor_start (G_LOCAL_DIRECTORY_MONITOR (monitor));
+
return monitor;
}
gboolean mount_notify;
gboolean (* is_supported) (void);
+ void (* start) (GLocalDirectoryMonitor *local_monitor);
};
#ifdef G_OS_UNIX
GFileMonitorFlags flags,
gboolean is_remote_fs,
GError **error);
+void g_local_directory_monitor_start (GLocalDirectoryMonitor *local_monitor);
G_END_DECLS
const GValue *value,
GParamSpec *pspec)
{
+ GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
+
switch (property_id)
- {
+ {
case PROP_FILENAME:
- /* Do nothing */
+ local_monitor->filename = g_value_dup_string (value);
break;
+
case PROP_FLAGS:
- /* Do nothing as well */
+ local_monitor->flags = g_value_get_flags (value);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
- }
+ }
}
-static GObject *
-g_local_file_monitor_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
+void
+g_local_file_monitor_start (GLocalFileMonitor *local_monitor)
{
- GObject *obj;
- GLocalFileMonitorClass *klass;
- GObjectClass *parent_class;
- GLocalFileMonitor *local_monitor;
- const gchar *filename = NULL;
- GFileMonitorFlags flags = 0;
- gint i;
-
- klass = G_LOCAL_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_FILE_MONITOR));
- parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
- obj = parent_class->constructor (type,
- n_construct_properties,
- construct_properties);
-
- local_monitor = G_LOCAL_FILE_MONITOR (obj);
-
- for (i = 0; i < n_construct_properties; i++)
- {
- if (strcmp ("filename", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
- {
- g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
- filename = g_value_get_string (construct_properties[i].value);
- }
- else if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
- {
- g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
- flags = g_value_get_flags (construct_properties[i].value);
- }
- }
+ GLocalFileMonitorClass *class;
- g_warn_if_fail (filename != NULL);
+ class = G_LOCAL_FILE_MONITOR_GET_CLASS (local_monitor);
- local_monitor->filename = g_strdup (filename);
- local_monitor->flags = flags;
- return obj;
+ if (class->start)
+ class->start (local_monitor);
}
static void
g_local_file_monitor_finalize (GObject *object)
{
GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
- if (local_monitor->filename)
- {
- g_free (local_monitor->filename);
- local_monitor->filename = NULL;
- }
+
+ g_free (local_monitor->filename);
G_OBJECT_CLASS (g_local_file_monitor_parent_class)->finalize (object);
}
gobject_class->set_property = g_local_file_monitor_set_property;
gobject_class->finalize = g_local_file_monitor_finalize;
- gobject_class->constructor = g_local_file_monitor_constructor;
g_object_class_install_property (gobject_class,
PROP_FILENAME,
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Unable to find default local file monitor type"));
+ if (monitor)
+ g_local_file_monitor_start (G_LOCAL_FILE_MONITOR (monitor));
+
return monitor;
}
#define G_LOCAL_FILE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_LOCAL_FILE_MONITOR, GLocalFileMonitorClass))
#define G_IS_LOCAL_FILE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_LOCAL_FILE_MONITOR))
#define G_IS_LOCAL_FILE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_LOCAL_FILE_MONITOR))
+#define G_LOCAL_FILE_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_LOCAL_FILE_MONITOR, GLocalFileMonitorClass))
#define G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME "gio-local-file-monitor"
#define G_NFS_FILE_MONITOR_EXTENSION_POINT_NAME "gio-nfs-file-monitor"
GFileMonitorClass parent_class;
gboolean (* is_supported) (void);
+ void (* start) (GLocalFileMonitor *local_monitor);
};
#ifdef G_OS_UNIX
GFileMonitorFlags flags,
gboolean is_remote_fs,
GError **error);
+void g_local_file_monitor_start (GLocalFileMonitor *local_monitor);
G_END_DECLS