gcredentials: add Solaris support
[platform/upstream/glib.git] / gio / glocalfilemonitor.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include "config.h"
24
25 #include "gioenumtypes.h"
26 #include "glocalfilemonitor.h"
27 #include "giomodule-priv.h"
28 #include "gioerror.h"
29 #include "glibintl.h"
30
31 #include <string.h>
32
33
34 enum
35 {
36   PROP_0,
37   PROP_FILENAME,
38   PROP_FLAGS
39 };
40
41 G_DEFINE_ABSTRACT_TYPE (GLocalFileMonitor, g_local_file_monitor, G_TYPE_FILE_MONITOR)
42
43 static void
44 g_local_file_monitor_init (GLocalFileMonitor* local_monitor)
45 {
46 }
47
48 static void
49 g_local_file_monitor_set_property (GObject      *object,
50                                    guint         property_id,
51                                    const GValue *value,
52                                    GParamSpec   *pspec)
53 {
54   GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
55
56   switch (property_id)
57     {
58     case PROP_FILENAME:
59       local_monitor->filename = g_value_dup_string (value);
60       break;
61
62     case PROP_FLAGS:
63       local_monitor->flags = g_value_get_flags (value);
64       break;
65
66     default:
67       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68       break;
69     }
70 }
71
72 void
73 g_local_file_monitor_start (GLocalFileMonitor *local_monitor)
74 {
75   GLocalFileMonitorClass *class;
76
77   class = G_LOCAL_FILE_MONITOR_GET_CLASS (local_monitor);
78
79   if (class->start)
80     class->start (local_monitor);
81 }
82
83 static void
84 g_local_file_monitor_finalize (GObject *object)
85 {
86   GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (object);
87
88   g_free (local_monitor->filename);
89
90   G_OBJECT_CLASS (g_local_file_monitor_parent_class)->finalize (object);
91 }
92
93 static void g_local_file_monitor_class_init (GLocalFileMonitorClass *klass)
94 {
95   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
96
97   gobject_class->set_property = g_local_file_monitor_set_property;
98   gobject_class->finalize = g_local_file_monitor_finalize;
99
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));
109
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,
116                                                        0,
117                                                        G_PARAM_CONSTRUCT_ONLY|
118                                                        G_PARAM_WRITABLE|
119                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
120 }
121
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)
129 {
130   GFileMonitor *monitor = NULL;
131   GType type = G_TYPE_INVALID;
132
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));
137
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));
142
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"));
148
149   if (monitor && do_start)
150     g_local_file_monitor_start (G_LOCAL_FILE_MONITOR (monitor));
151
152   return monitor;
153 }