Include "config.h" instead of <config.h> Command used: find -name
[platform/upstream/glib.git] / gio / gvolumemonitor.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
3 /* GIO - GLib Input, Output and Streaming Library
4  * 
5  * Copyright (C) 2006-2007 Red Hat, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General
18  * Public License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * Author: Alexander Larsson <alexl@redhat.com>
23  *         David Zeuthen <davidz@redhat.com>
24  */
25
26 #include "config.h"
27 #include "gvolumemonitor.h"
28 #include "glibintl.h"
29
30 #include "gioalias.h"
31
32 /**
33  * SECTION:gvolumemonitor
34  * @short_description: Volume Monitor
35  * @include: gio/gio.h
36  * @see_also: #GFileMonitor
37  * 
38  * #GVolumeMonitor is for listing the user interesting devices and volumes
39  * on the computer. In other words, what a file selector or file manager
40  * would show in a sidebar. 
41 **/
42
43 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT);
44
45 enum {
46   VOLUME_ADDED,
47   VOLUME_REMOVED,
48   VOLUME_CHANGED,
49   MOUNT_ADDED,
50   MOUNT_REMOVED,
51   MOUNT_PRE_UNMOUNT,
52   MOUNT_CHANGED,
53   DRIVE_CONNECTED,
54   DRIVE_DISCONNECTED,
55   DRIVE_CHANGED,
56   LAST_SIGNAL
57 };
58
59 static guint signals[LAST_SIGNAL] = { 0 };
60
61
62 static void
63 g_volume_monitor_finalize (GObject *object)
64 {
65   GVolumeMonitor *monitor;
66
67   monitor = G_VOLUME_MONITOR (object);
68
69   G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize (object);
70 }
71
72 static void
73 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
74 {
75   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
76   
77   gobject_class->finalize = g_volume_monitor_finalize;
78
79   /**
80    * GVolumeMonitor::volume-added:
81    * @volume_monitor: The volume monitor emitting the signal.
82    * @volume: a #GVolume that was added.
83    * 
84    * Emitted when a mountable volume is added to the system.
85    **/
86   signals[VOLUME_ADDED] = g_signal_new (I_("volume_added"),
87                                         G_TYPE_VOLUME_MONITOR,
88                                         G_SIGNAL_RUN_LAST,
89                                         G_STRUCT_OFFSET (GVolumeMonitorClass, volume_added),
90                                         NULL, NULL,
91                                         g_cclosure_marshal_VOID__OBJECT,
92                                         G_TYPE_NONE, 1, G_TYPE_VOLUME);
93   
94   /**
95    * GVolumeMonitor::volume-removed:
96    * @volume_monitor: The volume monitor emitting the signal.
97    * @volume: a #GVolume that was removed.
98    * 
99    * Emitted when a mountable volume is removed from the system.
100    **/  
101   signals[VOLUME_REMOVED] = g_signal_new (I_("volume_removed"),
102                                           G_TYPE_VOLUME_MONITOR,
103                                           G_SIGNAL_RUN_LAST,
104                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_removed),
105                                           NULL, NULL,
106                                           g_cclosure_marshal_VOID__OBJECT,
107                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
108   
109   /**
110    * GVolumeMonitor::volume-changed:
111    * @volume_monitor: The volume monitor emitting the signal.
112    * @volume: a #GVolume that changed.
113    * 
114    * Emitted when mountable volume is changed.
115    **/  
116   signals[VOLUME_CHANGED] = g_signal_new (I_("volume_changed"),
117                                           G_TYPE_VOLUME_MONITOR,
118                                           G_SIGNAL_RUN_LAST,
119                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_changed),
120                                           NULL, NULL,
121                                           g_cclosure_marshal_VOID__OBJECT,
122                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
123
124   /**
125    * GVolumeMonitor::mount-added:
126    * @volume_monitor: The volume monitor emitting the signal.
127    * @mount: a #GMount that was added.
128    * 
129    * Emitted when a mount is added.
130    **/
131   signals[MOUNT_ADDED] = g_signal_new (I_("mount_added"),
132                                        G_TYPE_VOLUME_MONITOR,
133                                        G_SIGNAL_RUN_LAST,
134                                        G_STRUCT_OFFSET (GVolumeMonitorClass, mount_added),
135                                        NULL, NULL,
136                                        g_cclosure_marshal_VOID__OBJECT,
137                                        G_TYPE_NONE, 1, G_TYPE_MOUNT);
138
139   /**
140    * GVolumeMonitor::mount-removed:
141    * @volume_monitor: The volume monitor emitting the signal.
142    * @mount: a #GMount that was removed.
143    * 
144    * Emitted when a mount is removed.
145    **/
146   signals[MOUNT_REMOVED] = g_signal_new (I_("mount_removed"),
147                                          G_TYPE_VOLUME_MONITOR,
148                                          G_SIGNAL_RUN_LAST,
149                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_removed),
150                                          NULL, NULL,
151                                          g_cclosure_marshal_VOID__OBJECT,
152                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
153
154   /**
155    * GVolumeMonitor::mount-pre-unmount:
156    * @volume_monitor: The volume monitor emitting the signal.
157    * @mount: a #GMount that is being unmounted.
158    *
159    * Emitted when a mount is about to be removed.
160    **/ 
161   signals[MOUNT_PRE_UNMOUNT] = g_signal_new (I_("mount_pre_unmount"),
162                                              G_TYPE_VOLUME_MONITOR,
163                                              G_SIGNAL_RUN_LAST,
164                                              G_STRUCT_OFFSET (GVolumeMonitorClass, mount_pre_unmount),
165                                              NULL, NULL,
166                                              g_cclosure_marshal_VOID__OBJECT,
167                                              G_TYPE_NONE, 1, G_TYPE_MOUNT);
168
169   /**
170    * GVolumeMonitor::mount-changed:
171    * @volume_monitor: The volume monitor emitting the signal.
172    * @mount: a #GMount that changed.
173    *
174    * Emitted when a mount changes.
175    **/ 
176   signals[MOUNT_CHANGED] = g_signal_new (I_("mount_changed"),
177                                          G_TYPE_VOLUME_MONITOR,
178                                          G_SIGNAL_RUN_LAST,
179                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_changed),
180                                          NULL, NULL,
181                                          g_cclosure_marshal_VOID__OBJECT,
182                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
183
184   /**
185    * GVolumeMonitor::drive-connected:
186    * @volume_monitor: The volume monitor emitting the signal.
187    * @drive: a #GDrive that was connected.
188    * 
189    * Emitted when a drive is connected to the system.
190    **/
191   signals[DRIVE_CONNECTED] = g_signal_new (I_("drive_connected"),
192                                            G_TYPE_VOLUME_MONITOR,
193                                            G_SIGNAL_RUN_LAST,
194                                            G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
195                                            NULL, NULL,
196                                            g_cclosure_marshal_VOID__OBJECT,
197                                            G_TYPE_NONE, 1, G_TYPE_DRIVE);
198   
199   /**
200    * GVolumeMonitor::drive-disconnected:
201    * @volume_monitor: The volume monitor emitting the signal.
202    * @drive: a #GDrive that was disconnected.
203    * 
204    * Emitted when a drive is disconnected from the system.
205    **/  
206   signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive_disconnected"),
207                                               G_TYPE_VOLUME_MONITOR,
208                                               G_SIGNAL_RUN_LAST,
209                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
210                                               NULL, NULL,
211                                               g_cclosure_marshal_VOID__OBJECT,
212                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
213
214   /**
215    * GVolumeMonitor::drive-changed:
216    * @volume_monitor: The volume monitor emitting the signal.
217    * @drive: the drive that changed
218    *
219    * Emitted when a drive changes.
220    **/ 
221   signals[DRIVE_CHANGED] = g_signal_new (I_("drive_changed"),
222                                          G_TYPE_VOLUME_MONITOR,
223                                          G_SIGNAL_RUN_LAST,
224                                          G_STRUCT_OFFSET (GVolumeMonitorClass, drive_changed),
225                                          NULL, NULL,
226                                          g_cclosure_marshal_VOID__OBJECT,
227                                          G_TYPE_NONE, 1, G_TYPE_DRIVE);
228
229 }
230
231 static void
232 g_volume_monitor_init (GVolumeMonitor *monitor)
233 {
234 }
235
236
237 /**
238  * g_volume_monitor_get_connected_drives:
239  * @volume_monitor: a #GVolumeMonitor.
240  * 
241  * Gets a list of drives connected to the system.
242  * 
243  * The returned list should be freed with g_list_free(), after
244  * its elements have been unreffed with g_object_unref().
245  *
246  * Returns: a #GList of connected #GDrive<!-- -->s
247  **/
248 GList *
249 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
250 {
251   GVolumeMonitorClass *class;
252
253   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
254
255   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
256
257   return class->get_connected_drives (volume_monitor);
258 }
259
260 /**
261  * g_volume_monitor_get_volumes:
262  * @volume_monitor: a #GVolumeMonitor.
263  * 
264  * Gets a list of the volumes on the system.
265  * 
266  * The returned list should be freed with g_list_free(), after
267  * its elements have been unreffed with g_object_unref().
268  *
269  * Returns: a #GList of #GVolume<!-- -->s.
270  **/
271 GList *
272 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
273 {
274   GVolumeMonitorClass *class;
275
276   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
277
278   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
279
280   return class->get_volumes (volume_monitor);
281 }
282
283 /**
284  * g_volume_monitor_get_mounts:
285  * @volume_monitor: a #GVolumeMonitor.
286  * 
287  * Gets a list of the mounts on the system.
288  *
289  * The returned list should be freed with g_list_free(), after
290  * its elements have been unreffed with g_object_unref().
291  * 
292  * Returns: a #GList of #GMount<!-- -->s
293  **/
294 GList *
295 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
296 {
297   GVolumeMonitorClass *class;
298
299   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
300
301   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
302
303   return class->get_mounts (volume_monitor);
304 }
305
306 /**
307  * g_volume_monitor_get_volume_for_uuid:
308  * @volume_monitor: a #GVolumeMonitor.
309  * @uuid: the UUID to look for
310  * 
311  * Finds a #GVolume object by it's UUID (see g_volume_get_uuid())
312  * 
313  * Returns: a #GVolume or %NULL if no such volume is available.
314  **/
315 GVolume *
316 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor, 
317                                       const char     *uuid)
318 {
319   GVolumeMonitorClass *class;
320
321   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
322   g_return_val_if_fail (uuid != NULL, NULL);
323
324   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
325
326   return class->get_volume_for_uuid (volume_monitor, uuid);
327 }
328
329 /**
330  * g_volume_monitor_get_mount_for_uuid:
331  * @volume_monitor: a #GVolumeMonitor.
332  * @uuid: the UUID to look for
333  * 
334  * Finds a #GMount object by it's UUID (see g_mount_get_uuid())
335  * 
336  * Returns: a #GMount or %NULL if no such mount is available.
337  **/
338 GMount *
339 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor, 
340                                      const char     *uuid)
341 {
342   GVolumeMonitorClass *class;
343
344   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
345   g_return_val_if_fail (uuid != NULL, NULL);
346
347   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
348
349   return class->get_mount_for_uuid (volume_monitor, uuid);
350 }
351
352
353 #define __G_VOLUME_MONITOR_C__
354 #include "gioaliasdef.c"