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