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