Rework how volumes, drives and volume monitoring is done. Previosly the
[platform/upstream/glib.git] / gio / gvolumemonitor.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  *         David Zeuthen <davidz@redhat.com>
22  */
23
24 #include <config.h>
25 #include "gvolumemonitor.h"
26 #include "glibintl.h"
27
28 #include "gioalias.h"
29
30 /**
31  * SECTION:gvolumemonitor
32  * @short_description: Volume Monitor
33  * @see_also: #GDirectoryMonitor, #GFileMonitor
34  * 
35  * Monitors a mounted volume for changes.
36  **/
37
38 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT);
39
40 enum {
41   VOLUME_ADDED,
42   VOLUME_REMOVED,
43   VOLUME_CHANGED,
44   MOUNT_ADDED,
45   MOUNT_REMOVED,
46   MOUNT_PRE_UNMOUNT,
47   MOUNT_CHANGED,
48   DRIVE_CONNECTED,
49   DRIVE_DISCONNECTED,
50   DRIVE_CHANGED,
51   LAST_SIGNAL
52 };
53
54 static guint signals[LAST_SIGNAL] = { 0 };
55
56
57 static void
58 g_volume_monitor_finalize (GObject *object)
59 {
60   GVolumeMonitor *monitor;
61
62   monitor = G_VOLUME_MONITOR (object);
63
64   if (G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize)
65     (*G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize) (object);
66 }
67
68 static void
69 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
70 {
71   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
72   
73   gobject_class->finalize = g_volume_monitor_finalize;
74
75   /**
76    * GVolumeMonitor::volume-added:
77    * @volume_monitor: The volume monitor emitting the signal.
78    * @volume: a #GVolume that was added.
79    * 
80    * Emitted when a mountable volume is added to the system.
81    **/
82   signals[VOLUME_ADDED] = g_signal_new (I_("volume_added"),
83                                         G_TYPE_VOLUME_MONITOR,
84                                         G_SIGNAL_RUN_LAST,
85                                         G_STRUCT_OFFSET (GVolumeMonitorClass, volume_added),
86                                         NULL, NULL,
87                                         g_cclosure_marshal_VOID__OBJECT,
88                                         G_TYPE_NONE, 1, G_TYPE_VOLUME);
89   
90   /**
91    * GVolumeMonitor::volume-removed:
92    * @volume_monitor: The volume monitor emitting the signal.
93    * @volume: a #GVolume that was removed.
94    * 
95    * Emitted when a mountable volume is removed from the system.
96    **/  
97   signals[VOLUME_REMOVED] = g_signal_new (I_("volume_removed"),
98                                           G_TYPE_VOLUME_MONITOR,
99                                           G_SIGNAL_RUN_LAST,
100                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_removed),
101                                           NULL, NULL,
102                                           g_cclosure_marshal_VOID__OBJECT,
103                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
104   
105   /**
106    * GVolumeMonitor::volume-changed:
107    * @volume_monitor: The volume monitor emitting the signal.
108    * @volume: a #GVolume that changed.
109    * 
110    * Emitted when mountable volume is changed.
111    **/  
112   signals[VOLUME_CHANGED] = g_signal_new (I_("volume_changed"),
113                                           G_TYPE_VOLUME_MONITOR,
114                                           G_SIGNAL_RUN_LAST,
115                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_changed),
116                                           NULL, NULL,
117                                           g_cclosure_marshal_VOID__OBJECT,
118                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
119
120   /**
121    * GVolumeMonitor::mount-added:
122    * @volume_monitor: The volume monitor emitting the signal.
123    * @mount: a #GMount that was added.
124    * 
125    * Emitted when a mount is added.
126    **/
127   signals[MOUNT_ADDED] = g_signal_new (I_("mount_added"),
128                                        G_TYPE_VOLUME_MONITOR,
129                                        G_SIGNAL_RUN_LAST,
130                                        G_STRUCT_OFFSET (GVolumeMonitorClass, mount_added),
131                                        NULL, NULL,
132                                        g_cclosure_marshal_VOID__OBJECT,
133                                        G_TYPE_NONE, 1, G_TYPE_MOUNT);
134
135   /**
136    * GVolumeMonitor::mount-removed:
137    * @volume_monitor: The volume monitor emitting the signal.
138    * @mount: a #GMount that was removed.
139    * 
140    * Emitted when a mount is removed.
141    **/
142   signals[MOUNT_REMOVED] = g_signal_new (I_("mount_removed"),
143                                          G_TYPE_VOLUME_MONITOR,
144                                          G_SIGNAL_RUN_LAST,
145                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_removed),
146                                          NULL, NULL,
147                                          g_cclosure_marshal_VOID__OBJECT,
148                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
149
150   /**
151    * GVolumeMonitor::mount-pre-unmount:
152    * @volume_monitor: The volume monitor emitting the signal.
153    * @mount: a #GMount that is being unmounted.
154    *
155    * Emitted when a mount is about to be removed.
156    **/ 
157   signals[MOUNT_PRE_UNMOUNT] = g_signal_new (I_("mount_pre_unmount"),
158                                              G_TYPE_VOLUME_MONITOR,
159                                              G_SIGNAL_RUN_LAST,
160                                              G_STRUCT_OFFSET (GVolumeMonitorClass, mount_pre_unmount),
161                                              NULL, NULL,
162                                              g_cclosure_marshal_VOID__OBJECT,
163                                              G_TYPE_NONE, 1, G_TYPE_MOUNT);
164
165   /**
166    * GVolumeMonitor::mount-changed:
167    * @volume_monitor: The volume monitor emitting the signal.
168    * @mount: a #GMount that changed.
169    *
170    * Emitted when a mount changes.
171    **/ 
172   signals[MOUNT_CHANGED] = g_signal_new (I_("mount_changed"),
173                                          G_TYPE_VOLUME_MONITOR,
174                                          G_SIGNAL_RUN_LAST,
175                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_changed),
176                                          NULL, NULL,
177                                          g_cclosure_marshal_VOID__OBJECT,
178                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
179
180   /**
181    * GVolumeMonitor::drive-connected:
182    * @volume_monitor: The volume monitor emitting the signal.
183    * @drive: a #GDrive that was connected.
184    * 
185    * Emitted when a drive is connected to the system.
186    **/
187   signals[DRIVE_CONNECTED] = g_signal_new (I_("drive_connected"),
188                                            G_TYPE_VOLUME_MONITOR,
189                                            G_SIGNAL_RUN_LAST,
190                                            G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
191                                            NULL, NULL,
192                                            g_cclosure_marshal_VOID__OBJECT,
193                                            G_TYPE_NONE, 1, G_TYPE_DRIVE);
194   
195   /**
196    * GVolumeMonitor::drive-disconnected:
197    * @volume_monitor: The volume monitor emitting the signal.
198    * @drive: a #GDrive that was disconnected.
199    * 
200    * Emitted when a drive is disconnected from the system.
201    **/  
202   signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive_disconnected"),
203                                               G_TYPE_VOLUME_MONITOR,
204                                               G_SIGNAL_RUN_LAST,
205                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
206                                               NULL, NULL,
207                                               g_cclosure_marshal_VOID__OBJECT,
208                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
209
210   /**
211    * GVolumeMonitor::drive-changed:
212    * @volume_monitor: The volume monitor emitting the signal.
213    * @drive: the drive that changed
214    *
215    * Emitted when a drive changes.
216    **/ 
217   signals[DRIVE_CHANGED] = g_signal_new (I_("drive_changed"),
218                                          G_TYPE_VOLUME_MONITOR,
219                                          G_SIGNAL_RUN_LAST,
220                                          G_STRUCT_OFFSET (GVolumeMonitorClass, drive_changed),
221                                          NULL, NULL,
222                                          g_cclosure_marshal_VOID__OBJECT,
223                                          G_TYPE_NONE, 1, G_TYPE_DRIVE);
224
225 }
226
227 static void
228 g_volume_monitor_init (GVolumeMonitor *monitor)
229 {
230 }
231
232
233 /**
234  * g_volume_monitor_get_drives:
235  * @volume_monitor: a #GVolumeMonitor.
236  * 
237  * Gets a list of drives connected to the system.
238  * 
239  * Returns: a #GList of connected #GDrives. 
240  **/
241 GList *
242 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
243 {
244   GVolumeMonitorClass *class;
245
246   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
247
248   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
249
250   return class->get_connected_drives (volume_monitor);
251 }
252
253 /**
254  * g_volume_monitor_get_volumes:
255  * @volume_monitor: a #GVolumeMonitor.
256  * 
257  * Gets a list of the volumes on the system.
258  * 
259  * Returns: a #GList of #GVolume.
260  **/
261 GList *
262 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
263 {
264   GVolumeMonitorClass *class;
265
266   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
267
268   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
269
270   return class->get_volumes (volume_monitor);
271 }
272
273 /**
274  * g_volume_monitor_get_mounts:
275  * @volume_monitor: a #GVolumeMonitor.
276  * 
277  * Gets a list of the mounts on the system.
278  * 
279  * Returns: a #GList of #GMount.
280  **/
281 GList *
282 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
283 {
284   GVolumeMonitorClass *class;
285
286   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
287
288   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
289
290   return class->get_mounts (volume_monitor);
291 }
292
293 #define __G_VOLUME_MONITOR_C__
294 #include "gioaliasdef.c"