Merge remote branch 'gvdb/master'
[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 "gvolume.h"
29 #include "gmount.h"
30 #include "gdrive.h"
31 #include "glibintl.h"
32
33 #include "gioalias.h"
34
35 /**
36  * SECTION:gvolumemonitor
37  * @short_description: Volume Monitor
38  * @include: gio/gio.h
39  * @see_also: #GFileMonitor
40  * 
41  * #GVolumeMonitor is for listing the user interesting devices and volumes
42  * on the computer. In other words, what a file selector or file manager
43  * would show in a sidebar. 
44  *
45  * #GVolumeMonitor is not <link
46  * linkend="g-main-context-push-thread-default">thread-default-context
47  * aware</link>, and so should not be used other than from the main
48  * thread, with no thread-default-context active.
49  **/
50
51 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT);
52
53 enum {
54   VOLUME_ADDED,
55   VOLUME_REMOVED,
56   VOLUME_CHANGED,
57   MOUNT_ADDED,
58   MOUNT_REMOVED,
59   MOUNT_PRE_UNMOUNT,
60   MOUNT_CHANGED,
61   DRIVE_CONNECTED,
62   DRIVE_DISCONNECTED,
63   DRIVE_CHANGED,
64   DRIVE_EJECT_BUTTON,
65   DRIVE_STOP_BUTTON,
66   LAST_SIGNAL
67 };
68
69 static guint signals[LAST_SIGNAL] = { 0 };
70
71
72 static void
73 g_volume_monitor_finalize (GObject *object)
74 {
75   G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize (object);
76 }
77
78 static void
79 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
80 {
81   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
82   
83   gobject_class->finalize = g_volume_monitor_finalize;
84
85   /**
86    * GVolumeMonitor::volume-added:
87    * @volume_monitor: The volume monitor emitting the signal.
88    * @volume: a #GVolume that was added.
89    * 
90    * Emitted when a mountable volume is added to the system.
91    **/
92   signals[VOLUME_ADDED] = g_signal_new (I_("volume-added"),
93                                         G_TYPE_VOLUME_MONITOR,
94                                         G_SIGNAL_RUN_LAST,
95                                         G_STRUCT_OFFSET (GVolumeMonitorClass, volume_added),
96                                         NULL, NULL,
97                                         g_cclosure_marshal_VOID__OBJECT,
98                                         G_TYPE_NONE, 1, G_TYPE_VOLUME);
99   
100   /**
101    * GVolumeMonitor::volume-removed:
102    * @volume_monitor: The volume monitor emitting the signal.
103    * @volume: a #GVolume that was removed.
104    * 
105    * Emitted when a mountable volume is removed from the system.
106    **/  
107   signals[VOLUME_REMOVED] = g_signal_new (I_("volume-removed"),
108                                           G_TYPE_VOLUME_MONITOR,
109                                           G_SIGNAL_RUN_LAST,
110                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_removed),
111                                           NULL, NULL,
112                                           g_cclosure_marshal_VOID__OBJECT,
113                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
114   
115   /**
116    * GVolumeMonitor::volume-changed:
117    * @volume_monitor: The volume monitor emitting the signal.
118    * @volume: a #GVolume that changed.
119    * 
120    * Emitted when mountable volume is changed.
121    **/  
122   signals[VOLUME_CHANGED] = g_signal_new (I_("volume-changed"),
123                                           G_TYPE_VOLUME_MONITOR,
124                                           G_SIGNAL_RUN_LAST,
125                                           G_STRUCT_OFFSET (GVolumeMonitorClass, volume_changed),
126                                           NULL, NULL,
127                                           g_cclosure_marshal_VOID__OBJECT,
128                                           G_TYPE_NONE, 1, G_TYPE_VOLUME);
129
130   /**
131    * GVolumeMonitor::mount-added:
132    * @volume_monitor: The volume monitor emitting the signal.
133    * @mount: a #GMount that was added.
134    * 
135    * Emitted when a mount is added.
136    **/
137   signals[MOUNT_ADDED] = g_signal_new (I_("mount-added"),
138                                        G_TYPE_VOLUME_MONITOR,
139                                        G_SIGNAL_RUN_LAST,
140                                        G_STRUCT_OFFSET (GVolumeMonitorClass, mount_added),
141                                        NULL, NULL,
142                                        g_cclosure_marshal_VOID__OBJECT,
143                                        G_TYPE_NONE, 1, G_TYPE_MOUNT);
144
145   /**
146    * GVolumeMonitor::mount-removed:
147    * @volume_monitor: The volume monitor emitting the signal.
148    * @mount: a #GMount that was removed.
149    * 
150    * Emitted when a mount is removed.
151    **/
152   signals[MOUNT_REMOVED] = g_signal_new (I_("mount-removed"),
153                                          G_TYPE_VOLUME_MONITOR,
154                                          G_SIGNAL_RUN_LAST,
155                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_removed),
156                                          NULL, NULL,
157                                          g_cclosure_marshal_VOID__OBJECT,
158                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
159
160   /**
161    * GVolumeMonitor::mount-pre-unmount:
162    * @volume_monitor: The volume monitor emitting the signal.
163    * @mount: a #GMount that is being unmounted.
164    *
165    * Emitted when a mount is about to be removed.
166    **/ 
167   signals[MOUNT_PRE_UNMOUNT] = g_signal_new (I_("mount-pre-unmount"),
168                                              G_TYPE_VOLUME_MONITOR,
169                                              G_SIGNAL_RUN_LAST,
170                                              G_STRUCT_OFFSET (GVolumeMonitorClass, mount_pre_unmount),
171                                              NULL, NULL,
172                                              g_cclosure_marshal_VOID__OBJECT,
173                                              G_TYPE_NONE, 1, G_TYPE_MOUNT);
174
175   /**
176    * GVolumeMonitor::mount-changed:
177    * @volume_monitor: The volume monitor emitting the signal.
178    * @mount: a #GMount that changed.
179    *
180    * Emitted when a mount changes.
181    **/ 
182   signals[MOUNT_CHANGED] = g_signal_new (I_("mount-changed"),
183                                          G_TYPE_VOLUME_MONITOR,
184                                          G_SIGNAL_RUN_LAST,
185                                          G_STRUCT_OFFSET (GVolumeMonitorClass, mount_changed),
186                                          NULL, NULL,
187                                          g_cclosure_marshal_VOID__OBJECT,
188                                          G_TYPE_NONE, 1, G_TYPE_MOUNT);
189
190   /**
191    * GVolumeMonitor::drive-connected:
192    * @volume_monitor: The volume monitor emitting the signal.
193    * @drive: a #GDrive that was connected.
194    * 
195    * Emitted when a drive is connected to the system.
196    **/
197   signals[DRIVE_CONNECTED] = g_signal_new (I_("drive-connected"),
198                                            G_TYPE_VOLUME_MONITOR,
199                                            G_SIGNAL_RUN_LAST,
200                                            G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
201                                            NULL, NULL,
202                                            g_cclosure_marshal_VOID__OBJECT,
203                                            G_TYPE_NONE, 1, G_TYPE_DRIVE);
204   
205   /**
206    * GVolumeMonitor::drive-disconnected:
207    * @volume_monitor: The volume monitor emitting the signal.
208    * @drive: a #GDrive that was disconnected.
209    * 
210    * Emitted when a drive is disconnected from the system.
211    **/  
212   signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive-disconnected"),
213                                               G_TYPE_VOLUME_MONITOR,
214                                               G_SIGNAL_RUN_LAST,
215                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
216                                               NULL, NULL,
217                                               g_cclosure_marshal_VOID__OBJECT,
218                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
219
220   /**
221    * GVolumeMonitor::drive-changed:
222    * @volume_monitor: The volume monitor emitting the signal.
223    * @drive: the drive that changed
224    *
225    * Emitted when a drive changes.
226    **/ 
227   signals[DRIVE_CHANGED] = g_signal_new (I_("drive-changed"),
228                                          G_TYPE_VOLUME_MONITOR,
229                                          G_SIGNAL_RUN_LAST,
230                                          G_STRUCT_OFFSET (GVolumeMonitorClass, drive_changed),
231                                          NULL, NULL,
232                                          g_cclosure_marshal_VOID__OBJECT,
233                                          G_TYPE_NONE, 1, G_TYPE_DRIVE);
234
235   /**
236    * GVolumeMonitor::drive-eject-button:
237    * @volume_monitor: The volume monitor emitting the signal.
238    * @drive: the drive where the eject button was pressed
239    *
240    * Emitted when the eject button is pressed on @drive.
241    *
242    * Since: 2.18
243    **/
244   signals[DRIVE_EJECT_BUTTON] = g_signal_new (I_("drive-eject-button"),
245                                               G_TYPE_VOLUME_MONITOR,
246                                               G_SIGNAL_RUN_LAST,
247                                               G_STRUCT_OFFSET (GVolumeMonitorClass, drive_eject_button),
248                                               NULL, NULL,
249                                               g_cclosure_marshal_VOID__OBJECT,
250                                               G_TYPE_NONE, 1, G_TYPE_DRIVE);
251
252   /**
253    * GVolumeMonitor::drive-stop-button:
254    * @volume_monitor: The volume monitor emitting the signal.
255    * @drive: the drive where the stop button was pressed
256    *
257    * Emitted when the stop button is pressed on @drive.
258    *
259    * Since: 2.22
260    **/
261   signals[DRIVE_STOP_BUTTON] = g_signal_new (I_("drive-stop-button"),
262                                              G_TYPE_VOLUME_MONITOR,
263                                              G_SIGNAL_RUN_LAST,
264                                              G_STRUCT_OFFSET (GVolumeMonitorClass, drive_stop_button),
265                                              NULL, NULL,
266                                              g_cclosure_marshal_VOID__OBJECT,
267                                              G_TYPE_NONE, 1, G_TYPE_DRIVE);
268
269 }
270
271 static void
272 g_volume_monitor_init (GVolumeMonitor *monitor)
273 {
274 }
275
276
277 /**
278  * g_volume_monitor_get_connected_drives:
279  * @volume_monitor: a #GVolumeMonitor.
280  * 
281  * Gets a list of drives connected to the system.
282  * 
283  * The returned list should be freed with g_list_free(), after
284  * its elements have been unreffed with g_object_unref().
285  *
286  * Returns: a #GList of connected #GDrive objects.
287  **/
288 GList *
289 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
290 {
291   GVolumeMonitorClass *class;
292
293   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
294
295   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
296
297   return class->get_connected_drives (volume_monitor);
298 }
299
300 /**
301  * g_volume_monitor_get_volumes:
302  * @volume_monitor: a #GVolumeMonitor.
303  * 
304  * Gets a list of the volumes on the system.
305  * 
306  * The returned list should be freed with g_list_free(), after
307  * its elements have been unreffed with g_object_unref().
308  *
309  * Returns: a #GList of #GVolume objects.
310  **/
311 GList *
312 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
313 {
314   GVolumeMonitorClass *class;
315
316   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
317
318   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
319
320   return class->get_volumes (volume_monitor);
321 }
322
323 /**
324  * g_volume_monitor_get_mounts:
325  * @volume_monitor: a #GVolumeMonitor.
326  * 
327  * Gets a list of the mounts on the system.
328  *
329  * The returned list should be freed with g_list_free(), after
330  * its elements have been unreffed with g_object_unref().
331  * 
332  * Returns: a #GList of #GMount objects.
333  **/
334 GList *
335 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
336 {
337   GVolumeMonitorClass *class;
338
339   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
340
341   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
342
343   return class->get_mounts (volume_monitor);
344 }
345
346 /**
347  * g_volume_monitor_get_volume_for_uuid:
348  * @volume_monitor: a #GVolumeMonitor.
349  * @uuid: the UUID to look for
350  * 
351  * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
352  * 
353  * Returns: a #GVolume or %NULL if no such volume is available.
354  *     Free the returned object with g_object_unref().
355  **/
356 GVolume *
357 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor, 
358                                       const char     *uuid)
359 {
360   GVolumeMonitorClass *class;
361
362   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
363   g_return_val_if_fail (uuid != NULL, NULL);
364
365   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
366
367   return class->get_volume_for_uuid (volume_monitor, uuid);
368 }
369
370 /**
371  * g_volume_monitor_get_mount_for_uuid:
372  * @volume_monitor: a #GVolumeMonitor.
373  * @uuid: the UUID to look for
374  * 
375  * Finds a #GMount object by its UUID (see g_mount_get_uuid())
376  * 
377  * Returns: a #GMount or %NULL if no such mount is available.
378  *     Free the returned object with g_object_unref().
379  **/
380 GMount *
381 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor, 
382                                      const char     *uuid)
383 {
384   GVolumeMonitorClass *class;
385
386   g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
387   g_return_val_if_fail (uuid != NULL, NULL);
388
389   class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
390
391   return class->get_mount_for_uuid (volume_monitor, uuid);
392 }
393
394
395 #define __G_VOLUME_MONITOR_C__
396 #include "gioaliasdef.c"