1 /* GIO - GLib Input, Output and Streaming Library
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>
25 #include "gioenumtypes.h"
26 #include "glocalfilemonitor.h"
27 #include "giomodule-priv.h"
41 G_DEFINE_ABSTRACT_TYPE (GLocalFileMonitor, g_local_file_monitor, G_TYPE_FILE_MONITOR)
44 g_local_file_monitor_init (GLocalFileMonitor* local_monitor)
49 g_local_file_monitor_set_property (GObject *object,
60 /* Do nothing as well */
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
69 g_local_file_monitor_constructor (GType type,
70 guint n_construct_properties,
71 GObjectConstructParam *construct_properties)
74 GLocalFileMonitorClass *klass;
75 GObjectClass *parent_class;
76 GLocalFileMonitor *local_monitor;
77 const gchar *filename = NULL;
78 GFileMonitorFlags flags = 0;
81 klass = G_LOCAL_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_LOCAL_FILE_MONITOR));
82 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
83 obj = parent_class->constructor (type,
84 n_construct_properties,
85 construct_properties);
87 local_monitor = G_LOCAL_FILE_MONITOR (obj);
89 for (i = 0; i < n_construct_properties; i++)
91 if (strcmp ("filename", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
93 g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
94 filename = g_value_get_string (construct_properties[i].value);
96 else if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
98 g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
99 flags = g_value_get_flags (construct_properties[i].value);
103 g_warn_if_fail (filename != NULL);
105 local_monitor->filename = g_strdup (filename);
106 local_monitor->flags = flags;
111 g_local_file_monitor_finalize (GObject *object)
113 GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
114 if (local_monitor->filename)
116 g_free (local_monitor->filename);
117 local_monitor->filename = NULL;
120 G_OBJECT_CLASS (g_local_file_monitor_parent_class)->finalize (object);
123 static void g_local_file_monitor_class_init (GLocalFileMonitorClass *klass)
125 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
127 gobject_class->set_property = g_local_file_monitor_set_property;
128 gobject_class->finalize = g_local_file_monitor_finalize;
129 gobject_class->constructor = g_local_file_monitor_constructor;
131 g_object_class_install_property (gobject_class,
133 g_param_spec_string ("filename",
135 P_("File name to monitor"),
137 G_PARAM_CONSTRUCT_ONLY|
139 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
141 g_object_class_install_property (gobject_class,
143 g_param_spec_flags ("flags",
146 G_TYPE_FILE_MONITOR_FLAGS,
148 G_PARAM_CONSTRUCT_ONLY|
150 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
154 _g_local_file_monitor_new (const char *pathname,
155 GFileMonitorFlags flags,
156 gboolean is_remote_fs,
159 GFileMonitor *monitor = NULL;
160 GType type = G_TYPE_INVALID;
163 type = _g_io_module_get_default_type (G_NFS_FILE_MONITOR_EXTENSION_POINT_NAME,
164 "GIO_USE_FILE_MONITOR",
165 G_STRUCT_OFFSET (GLocalFileMonitorClass, is_supported));
167 if (type == G_TYPE_INVALID)
168 type = _g_io_module_get_default_type (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
169 "GIO_USE_FILE_MONITOR",
170 G_STRUCT_OFFSET (GLocalFileMonitorClass, is_supported));
172 if (type != G_TYPE_INVALID)
173 monitor = G_FILE_MONITOR (g_object_new (type, "filename", pathname, "flags", flags, NULL));
175 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
176 _("Unable to find default local file monitor type"));