Implement this function by moving bits from glocalfileinfo.c
[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.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   if (G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize)
70     (*G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize) (object);
71 }
72
73 static void
74 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
75 {
76   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
77   
78   gobject_class->finalize = g_volume_monitor_finalize;
79
80   /**
81    * GVolumeMonitor::volume-added:
82    * @volume_monitor: The volume monitor emitting the signal.
83    * @volume: a #GVolume that was added.
84    * 
85    * Emitted when a mountable volume is added to the system.
86    **/
87   signals[VOLUME_ADDED] = g_signal_new (I_("volume_added"),
88                                         G_TYPE_VOLUME_MONITOR,
89                                         G_SIGNAL_RUN_LAST,
90                                         G_STRUCT_OFFSET (GVolumeMonitorClass, volume_added),
91                                         NULL, NULL,
92                                         g_cclosure_marshal_VOID__OBJECT,
93                                         G_TYPE_NONE, 1, G_TYPE_VOLUME);
94   
95   /**
96    * GVolumeMonitor::volume-removed:
97    * @volume_monitor: The volume monitor emitting the signal.
98    * @volume: a #GVolume that was removed.
99    * 
100    * Emitted when a mountable volume is removed from the system.
101    **/  
102   signals[VOLUME_REMOVED] = g_signal_new (I_("volume_removed"),
103                                           G_TYPE_VOLUME_MONITOR,
104                                           G_SIGNAL_RUN_LAST,
105                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_removed),
106                                           NULL, NULL,
107                                           g_cclosure_marshal_VOID__OBJECT,
108                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
109   
110   /**
111    * GVolumeMonitor::volume-changed:
112    * @volume_monitor: The volume monitor emitting the signal.
113    * @volume: a #GVolume that changed.
114    * 
115    * Emitted when mountable volume is changed.
116    **/  
117   signals[VOLUME_CHANGED] = g_signal_new (I_("volume_changed"),
118                                           G_TYPE_VOLUME_MONITOR,
119                                           G_SIGNAL_RUN_LAST,
120                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_changed),
121                                           NULL, NULL,
122                                           g_cclosure_marshal_VOID__OBJECT,
123                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
124
125   /**
126    * GVolumeMonitor::mount-added:
127    * @volume_monitor: The volume monitor emitting the signal.
128    * @mount: a #GMount that was added.
129    * 
130    * Emitted when a mount is added.
131    **/
132   signals[MOUNT_ADDED] = g_signal_new (I_("mount_added"),
133                                        G_TYPE_VOLUME_MONITOR,
134                                        G_SIGNAL_RUN_LAST,
135                                        G_STRUCT_OFFSET (GVolumeMonitorClass, mount_added),
136                                        NULL, NULL,
137                                        g_cclosure_marshal_VOID__OBJECT,
138                                        G_TYPE_NONE, 1, G_TYPE_MOUNT);
139
140   /**
141    * GVolumeMonitor::mount-removed:
142    * @volume_monitor: The volume monitor emitting the signal.
143    * @mount: a #GMount that was removed.
144    * 
145    * Emitted when a mount is removed.
146    **/
147   signals[MOUNT_REMOVED] = g_signal_new (I_("mount_removed"),
148                                          G_TYPE_VOLUME_MONITOR,
149                                          G_SIGNAL_RUN_LAST,
150                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_removed),
151                                          NULL, NULL,
152                                          g_cclosure_marshal_VOID__OBJECT,
153                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
154
155   /**
156    * GVolumeMonitor::mount-pre-unmount:
157    * @volume_monitor: The volume monitor emitting the signal.
158    * @mount: a #GMount that is being unmounted.
159    *
160    * Emitted when a mount is about to be removed.
161    **/ 
162   signals[MOUNT_PRE_UNMOUNT] = g_signal_new (I_("mount_pre_unmount"),
163                                              G_TYPE_VOLUME_MONITOR,
164                                              G_SIGNAL_RUN_LAST,
165                                              G_STRUCT_OFFSET (GVolumeMonitorClass, mount_pre_unmount),
166                                              NULL, NULL,
167                                              g_cclosure_marshal_VOID__OBJECT,
168                                              G_TYPE_NONE, 1, G_TYPE_MOUNT);
169
170   /**
171    * GVolumeMonitor::mount-changed:
172    * @volume_monitor: The volume monitor emitting the signal.
173    * @mount: a #GMount that changed.
174    *
175    * Emitted when a mount changes.
176    **/ 
177   signals[MOUNT_CHANGED] = g_signal_new (I_("mount_changed"),
178                                          G_TYPE_VOLUME_MONITOR,
179                                          G_SIGNAL_RUN_LAST,
180                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_changed),
181                                          NULL, NULL,
182                                          g_cclosure_marshal_VOID__OBJECT,
183                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
184
185   /**
186    * GVolumeMonitor::drive-connected:
187    * @volume_monitor: The volume monitor emitting the signal.
188    * @drive: a #GDrive that was connected.
189    * 
190    * Emitted when a drive is connected to the system.
191    **/
192   signals[DRIVE_CONNECTED] = g_signal_new (I_("drive_connected"),
193                                            G_TYPE_VOLUME_MONITOR,
194                                            G_SIGNAL_RUN_LAST,
195                                            G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
196                                            NULL, NULL,
197                                            g_cclosure_marshal_VOID__OBJECT,
198                                            G_TYPE_NONE, 1, G_TYPE_DRIVE);
199   
200   /**
201    * GVolumeMonitor::drive-disconnected:
202    * @volume_monitor: The volume monitor emitting the signal.
203    * @drive: a #GDrive that was disconnected.
204    * 
205    * Emitted when a drive is disconnected from the system.
206    **/  
207   signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive_disconnected"),
208                                               G_TYPE_VOLUME_MONITOR,
209                                               G_SIGNAL_RUN_LAST,
210                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
211                                               NULL, NULL,
212                                               g_cclosure_marshal_VOID__OBJECT,
213                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
214
215   /**
216    * GVolumeMonitor::drive-changed:
217    * @volume_monitor: The volume monitor emitting the signal.
218    * @drive: the drive that changed
219    *
220    * Emitted when a drive changes.
221    **/ 
222   signals[DRIVE_CHANGED] = g_signal_new (I_("drive_changed"),
223                                          G_TYPE_VOLUME_MONITOR,
224                                          G_SIGNAL_RUN_LAST,
225                                          G_STRUCT_OFFSET (GVolumeMonitorClass, drive_changed),
226                                          NULL, NULL,
227                                          g_cclosure_marshal_VOID__OBJECT,
228                                          G_TYPE_NONE, 1, G_TYPE_DRIVE);
229
230 }
231
232 static void
233 g_volume_monitor_init (GVolumeMonitor *monitor)
234 {
235 }
236
237
238 /**
239  * g_volume_monitor_get_connected_drives:
240  * @volume_monitor: a #GVolumeMonitor.
241  * 
242  * Gets a list of drives connected to the system.
243  * 
244  * The returned list should be freed with g_list_free(), after
245  * its elements have been unreffed with g_object_unref().
246  *
247  * Returns: a #GList of connected #GDrive<!-- -->s
248  **/
249 GList *
250 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
251 {
252   GVolumeMonitorClass *class;
253
254   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
255
256   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
257
258   return class->get_connected_drives (volume_monitor);
259 }
260
261 /**
262  * g_volume_monitor_get_volumes:
263  * @volume_monitor: a #GVolumeMonitor.
264  * 
265  * Gets a list of the volumes on the system.
266  * 
267  * The returned list should be freed with g_list_free(), after
268  * its elements have been unreffed with g_object_unref().
269  *
270  * Returns: a #GList of #GVolume<!-- -->s.
271  **/
272 GList *
273 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
274 {
275   GVolumeMonitorClass *class;
276
277   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
278
279   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
280
281   return class->get_volumes (volume_monitor);
282 }
283
284 /**
285  * g_volume_monitor_get_mounts:
286  * @volume_monitor: a #GVolumeMonitor.
287  * 
288  * Gets a list of the mounts on the system.
289  *
290  * The returned list should be freed with g_list_free(), after
291  * its elements have been unreffed with g_object_unref().
292  * 
293  * Returns: a #GList of #GMount<!-- -->s
294  **/
295 GList *
296 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
297 {
298   GVolumeMonitorClass *class;
299
300   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
301
302   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
303
304   return class->get_mounts (volume_monitor);
305 }
306
307 /**
308  * g_volume_monitor_get_volume_for_uuid:
309  * @volume_monitor: a #GVolumeMonitor.
310  * @uuid: the UUID to look for
311  * 
312  * Finds a #GVolume object by it's UUID (see g_volume_get_uuid())
313  * 
314  * Returns: a #GVolume or %NULL if no such volume is available.
315  **/
316 GVolume *
317 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor, 
318                                       const char     *uuid)
319 {
320   GVolumeMonitorClass *class;
321
322   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
323   g_return_val_if_fail (uuid != NULL, NULL);
324
325   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
326
327   return class->get_volume_for_uuid (volume_monitor, uuid);
328 }
329
330 /**
331  * g_volume_monitor_get_mount_for_uuid:
332  * @volume_monitor: a #GVolumeMonitor.
333  * @uuid: the UUID to look for
334  * 
335  * Finds a #GMount object by it's UUID (see g_mount_get_uuid())
336  * 
337  * Returns: a #GMount or %NULL if no such mount is available.
338  **/
339 GMount *
340 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor, 
341                                      const char     *uuid)
342 {
343   GVolumeMonitorClass *class;
344
345   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
346   g_return_val_if_fail (uuid != NULL, NULL);
347
348   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
349
350   return class->get_mount_for_uuid (volume_monitor, uuid);
351 }
352
353
354 #define __G_VOLUME_MONITOR_C__
355 #include "gioaliasdef.c"