Initialize variable
[glib.git] / gio / gvolumemonitor.c
blobcb22f8927070a95ffa1faca448e3ee4b86e3c6bc
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
4 *
5 * Copyright (C) 2006-2007 Red Hat, Inc.
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.1 of the License, or (at your option) any later version.
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.
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/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
21 * David Zeuthen <davidz@redhat.com>
24 #include "config.h"
25 #include "gvolumemonitor.h"
26 #include "gvolume.h"
27 #include "gmount.h"
28 #include "gdrive.h"
29 #include "glibintl.h"
32 /**
33 * SECTION:gvolumemonitor
34 * @short_description: Volume Monitor
35 * @include: gio/gio.h
36 * @see_also: #GFileMonitor
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.
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 **/
48 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT)
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
66 static guint signals[LAST_SIGNAL] = { 0 };
69 static void
70 g_volume_monitor_finalize (GObject *object)
72 G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize (object);
75 static void
76 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
78 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
80 gobject_class->finalize = g_volume_monitor_finalize;
82 /**
83 * GVolumeMonitor::volume-added:
84 * @volume_monitor: The volume monitor emitting the signal.
85 * @volume: a #GVolume that was added.
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);
97 /**
98 * GVolumeMonitor::volume-removed:
99 * @volume_monitor: The volume monitor emitting the signal.
100 * @volume: a #GVolume that was removed.
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);
113 * GVolumeMonitor::volume-changed:
114 * @volume_monitor: The volume monitor emitting the signal.
115 * @volume: a #GVolume that changed.
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);
128 * GVolumeMonitor::mount-added:
129 * @volume_monitor: The volume monitor emitting the signal.
130 * @mount: a #GMount that was added.
132 * Emitted when a mount is added.
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);
143 * GVolumeMonitor::mount-removed:
144 * @volume_monitor: The volume monitor emitting the signal.
145 * @mount: a #GMount that was removed.
147 * Emitted when a mount is removed.
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);
158 * GVolumeMonitor::mount-pre-unmount:
159 * @volume_monitor: The volume monitor emitting the signal.
160 * @mount: a #GMount that is being unmounted.
162 * May be emitted when a mount is about to be removed.
164 * This signal depends on the backend and is only emitted if
165 * GIO was used to unmount.
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);
176 * GVolumeMonitor::mount-changed:
177 * @volume_monitor: The volume monitor emitting the signal.
178 * @mount: a #GMount that changed.
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);
191 * GVolumeMonitor::drive-connected:
192 * @volume_monitor: The volume monitor emitting the signal.
193 * @drive: a #GDrive that was connected.
195 * Emitted when a drive is connected to the system.
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);
206 * GVolumeMonitor::drive-disconnected:
207 * @volume_monitor: The volume monitor emitting the signal.
208 * @drive: a #GDrive that was disconnected.
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);
221 * GVolumeMonitor::drive-changed:
222 * @volume_monitor: The volume monitor emitting the signal.
223 * @drive: the drive that changed
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);
236 * GVolumeMonitor::drive-eject-button:
237 * @volume_monitor: The volume monitor emitting the signal.
238 * @drive: the drive where the eject button was pressed
240 * Emitted when the eject button is pressed on @drive.
242 * Since: 2.18
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);
253 * GVolumeMonitor::drive-stop-button:
254 * @volume_monitor: The volume monitor emitting the signal.
255 * @drive: the drive where the stop button was pressed
257 * Emitted when the stop button is pressed on @drive.
259 * Since: 2.22
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);
271 static void
272 g_volume_monitor_init (GVolumeMonitor *monitor)
278 * g_volume_monitor_get_connected_drives:
279 * @volume_monitor: a #GVolumeMonitor.
281 * Gets a list of drives connected to the system.
283 * The returned list should be freed with g_list_free(), after
284 * its elements have been unreffed with g_object_unref().
286 * Returns: (element-type GDrive) (transfer full): a #GList of connected #GDrive objects.
288 GList *
289 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
291 GVolumeMonitorClass *class;
293 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
295 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
297 return class->get_connected_drives (volume_monitor);
301 * g_volume_monitor_get_volumes:
302 * @volume_monitor: a #GVolumeMonitor.
304 * Gets a list of the volumes on the system.
306 * The returned list should be freed with g_list_free(), after
307 * its elements have been unreffed with g_object_unref().
309 * Returns: (element-type GVolume) (transfer full): a #GList of #GVolume objects.
311 GList *
312 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
314 GVolumeMonitorClass *class;
316 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
318 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
320 return class->get_volumes (volume_monitor);
324 * g_volume_monitor_get_mounts:
325 * @volume_monitor: a #GVolumeMonitor.
327 * Gets a list of the mounts on the system.
329 * The returned list should be freed with g_list_free(), after
330 * its elements have been unreffed with g_object_unref().
332 * Returns: (element-type GMount) (transfer full): a #GList of #GMount objects.
334 GList *
335 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
337 GVolumeMonitorClass *class;
339 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
341 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
343 return class->get_mounts (volume_monitor);
347 * g_volume_monitor_get_volume_for_uuid:
348 * @volume_monitor: a #GVolumeMonitor.
349 * @uuid: the UUID to look for
351 * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
353 * Returns: (transfer full): a #GVolume or %NULL if no such volume is available.
354 * Free the returned object with g_object_unref().
356 GVolume *
357 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor,
358 const char *uuid)
360 GVolumeMonitorClass *class;
362 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
363 g_return_val_if_fail (uuid != NULL, NULL);
365 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
367 return class->get_volume_for_uuid (volume_monitor, uuid);
371 * g_volume_monitor_get_mount_for_uuid:
372 * @volume_monitor: a #GVolumeMonitor.
373 * @uuid: the UUID to look for
375 * Finds a #GMount object by its UUID (see g_mount_get_uuid())
377 * Returns: (transfer full): a #GMount or %NULL if no such mount is available.
378 * Free the returned object with g_object_unref().
380 GMount *
381 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor,
382 const char *uuid)
384 GVolumeMonitorClass *class;
386 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
387 g_return_val_if_fail (uuid != NULL, NULL);
389 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
391 return class->get_mount_for_uuid (volume_monitor, uuid);