1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
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 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, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
23 * David Zeuthen <davidz@redhat.com>
27 #include "gvolumemonitor.h"
35 * SECTION:gvolumemonitor
36 * @short_description: Volume Monitor
38 * @see_also: #GFileMonitor
40 * #GVolumeMonitor is for listing the user interesting devices and volumes
41 * on the computer. In other words, what a file selector or file manager
42 * would show in a sidebar.
44 * #GVolumeMonitor is not <link
45 * linkend="g-main-context-push-thread-default">thread-default-context
46 * aware</link>, and so should not be used other than from the main
47 * thread, with no thread-default-context active.
50 G_DEFINE_TYPE (GVolumeMonitor, g_volume_monitor, G_TYPE_OBJECT);
68 static guint signals[LAST_SIGNAL] = { 0 };
72 g_volume_monitor_finalize (GObject *object)
74 G_OBJECT_CLASS (g_volume_monitor_parent_class)->finalize (object);
78 g_volume_monitor_class_init (GVolumeMonitorClass *klass)
80 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
82 gobject_class->finalize = g_volume_monitor_finalize;
85 * GVolumeMonitor::volume-added:
86 * @volume_monitor: The volume monitor emitting the signal.
87 * @volume: a #GVolume that was added.
89 * Emitted when a mountable volume is added to the system.
91 signals[VOLUME_ADDED] = g_signal_new (I_("volume-added"),
92 G_TYPE_VOLUME_MONITOR,
94 G_STRUCT_OFFSET (GVolumeMonitorClass, volume_added),
96 g_cclosure_marshal_VOID__OBJECT,
97 G_TYPE_NONE, 1, G_TYPE_VOLUME);
100 * GVolumeMonitor::volume-removed:
101 * @volume_monitor: The volume monitor emitting the signal.
102 * @volume: a #GVolume that was removed.
104 * Emitted when a mountable volume is removed from the system.
106 signals[VOLUME_REMOVED] = g_signal_new (I_("volume-removed"),
107 G_TYPE_VOLUME_MONITOR,
109 G_STRUCT_OFFSET (GVolumeMonitorClass, volume_removed),
111 g_cclosure_marshal_VOID__OBJECT,
112 G_TYPE_NONE, 1, G_TYPE_VOLUME);
115 * GVolumeMonitor::volume-changed:
116 * @volume_monitor: The volume monitor emitting the signal.
117 * @volume: a #GVolume that changed.
119 * Emitted when mountable volume is changed.
121 signals[VOLUME_CHANGED] = g_signal_new (I_("volume-changed"),
122 G_TYPE_VOLUME_MONITOR,
124 G_STRUCT_OFFSET (GVolumeMonitorClass, volume_changed),
126 g_cclosure_marshal_VOID__OBJECT,
127 G_TYPE_NONE, 1, G_TYPE_VOLUME);
130 * GVolumeMonitor::mount-added:
131 * @volume_monitor: The volume monitor emitting the signal.
132 * @mount: a #GMount that was added.
134 * Emitted when a mount is added.
136 signals[MOUNT_ADDED] = g_signal_new (I_("mount-added"),
137 G_TYPE_VOLUME_MONITOR,
139 G_STRUCT_OFFSET (GVolumeMonitorClass, mount_added),
141 g_cclosure_marshal_VOID__OBJECT,
142 G_TYPE_NONE, 1, G_TYPE_MOUNT);
145 * GVolumeMonitor::mount-removed:
146 * @volume_monitor: The volume monitor emitting the signal.
147 * @mount: a #GMount that was removed.
149 * Emitted when a mount is removed.
151 signals[MOUNT_REMOVED] = g_signal_new (I_("mount-removed"),
152 G_TYPE_VOLUME_MONITOR,
154 G_STRUCT_OFFSET (GVolumeMonitorClass, mount_removed),
156 g_cclosure_marshal_VOID__OBJECT,
157 G_TYPE_NONE, 1, G_TYPE_MOUNT);
160 * GVolumeMonitor::mount-pre-unmount:
161 * @volume_monitor: The volume monitor emitting the signal.
162 * @mount: a #GMount that is being unmounted.
164 * Emitted when a mount is about to be removed.
166 signals[MOUNT_PRE_UNMOUNT] = g_signal_new (I_("mount-pre-unmount"),
167 G_TYPE_VOLUME_MONITOR,
169 G_STRUCT_OFFSET (GVolumeMonitorClass, mount_pre_unmount),
171 g_cclosure_marshal_VOID__OBJECT,
172 G_TYPE_NONE, 1, G_TYPE_MOUNT);
175 * GVolumeMonitor::mount-changed:
176 * @volume_monitor: The volume monitor emitting the signal.
177 * @mount: a #GMount that changed.
179 * Emitted when a mount changes.
181 signals[MOUNT_CHANGED] = g_signal_new (I_("mount-changed"),
182 G_TYPE_VOLUME_MONITOR,
184 G_STRUCT_OFFSET (GVolumeMonitorClass, mount_changed),
186 g_cclosure_marshal_VOID__OBJECT,
187 G_TYPE_NONE, 1, G_TYPE_MOUNT);
190 * GVolumeMonitor::drive-connected:
191 * @volume_monitor: The volume monitor emitting the signal.
192 * @drive: a #GDrive that was connected.
194 * Emitted when a drive is connected to the system.
196 signals[DRIVE_CONNECTED] = g_signal_new (I_("drive-connected"),
197 G_TYPE_VOLUME_MONITOR,
199 G_STRUCT_OFFSET (GVolumeMonitorClass, drive_connected),
201 g_cclosure_marshal_VOID__OBJECT,
202 G_TYPE_NONE, 1, G_TYPE_DRIVE);
205 * GVolumeMonitor::drive-disconnected:
206 * @volume_monitor: The volume monitor emitting the signal.
207 * @drive: a #GDrive that was disconnected.
209 * Emitted when a drive is disconnected from the system.
211 signals[DRIVE_DISCONNECTED] = g_signal_new (I_("drive-disconnected"),
212 G_TYPE_VOLUME_MONITOR,
214 G_STRUCT_OFFSET (GVolumeMonitorClass, drive_disconnected),
216 g_cclosure_marshal_VOID__OBJECT,
217 G_TYPE_NONE, 1, G_TYPE_DRIVE);
220 * GVolumeMonitor::drive-changed:
221 * @volume_monitor: The volume monitor emitting the signal.
222 * @drive: the drive that changed
224 * Emitted when a drive changes.
226 signals[DRIVE_CHANGED] = g_signal_new (I_("drive-changed"),
227 G_TYPE_VOLUME_MONITOR,
229 G_STRUCT_OFFSET (GVolumeMonitorClass, drive_changed),
231 g_cclosure_marshal_VOID__OBJECT,
232 G_TYPE_NONE, 1, G_TYPE_DRIVE);
235 * GVolumeMonitor::drive-eject-button:
236 * @volume_monitor: The volume monitor emitting the signal.
237 * @drive: the drive where the eject button was pressed
239 * Emitted when the eject button is pressed on @drive.
243 signals[DRIVE_EJECT_BUTTON] = g_signal_new (I_("drive-eject-button"),
244 G_TYPE_VOLUME_MONITOR,
246 G_STRUCT_OFFSET (GVolumeMonitorClass, drive_eject_button),
248 g_cclosure_marshal_VOID__OBJECT,
249 G_TYPE_NONE, 1, G_TYPE_DRIVE);
252 * GVolumeMonitor::drive-stop-button:
253 * @volume_monitor: The volume monitor emitting the signal.
254 * @drive: the drive where the stop button was pressed
256 * Emitted when the stop button is pressed on @drive.
260 signals[DRIVE_STOP_BUTTON] = g_signal_new (I_("drive-stop-button"),
261 G_TYPE_VOLUME_MONITOR,
263 G_STRUCT_OFFSET (GVolumeMonitorClass, drive_stop_button),
265 g_cclosure_marshal_VOID__OBJECT,
266 G_TYPE_NONE, 1, G_TYPE_DRIVE);
271 g_volume_monitor_init (GVolumeMonitor *monitor)
277 * g_volume_monitor_get_connected_drives:
278 * @volume_monitor: a #GVolumeMonitor.
280 * Gets a list of drives connected to the system.
282 * The returned list should be freed with g_list_free(), after
283 * its elements have been unreffed with g_object_unref().
285 * Returns: (element-type GDrive) (transfer full): a #GList of connected #GDrive objects.
288 g_volume_monitor_get_connected_drives (GVolumeMonitor *volume_monitor)
290 GVolumeMonitorClass *class;
292 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
294 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
296 return class->get_connected_drives (volume_monitor);
300 * g_volume_monitor_get_volumes:
301 * @volume_monitor: a #GVolumeMonitor.
303 * Gets a list of the volumes on the system.
305 * The returned list should be freed with g_list_free(), after
306 * its elements have been unreffed with g_object_unref().
308 * Returns: (element-type GVolume) (transfer full): a #GList of #GVolume objects.
311 g_volume_monitor_get_volumes (GVolumeMonitor *volume_monitor)
313 GVolumeMonitorClass *class;
315 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
317 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
319 return class->get_volumes (volume_monitor);
323 * g_volume_monitor_get_mounts:
324 * @volume_monitor: a #GVolumeMonitor.
326 * Gets a list of the mounts on the system.
328 * The returned list should be freed with g_list_free(), after
329 * its elements have been unreffed with g_object_unref().
331 * Returns: (element-type GMount) (transfer full): a #GList of #GMount objects.
334 g_volume_monitor_get_mounts (GVolumeMonitor *volume_monitor)
336 GVolumeMonitorClass *class;
338 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
340 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
342 return class->get_mounts (volume_monitor);
346 * g_volume_monitor_get_volume_for_uuid:
347 * @volume_monitor: a #GVolumeMonitor.
348 * @uuid: the UUID to look for
350 * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
352 * Returns: (transfer full): a #GVolume or %NULL if no such volume is available.
353 * Free the returned object with g_object_unref().
356 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor,
359 GVolumeMonitorClass *class;
361 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
362 g_return_val_if_fail (uuid != NULL, NULL);
364 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
366 return class->get_volume_for_uuid (volume_monitor, uuid);
370 * g_volume_monitor_get_mount_for_uuid:
371 * @volume_monitor: a #GVolumeMonitor.
372 * @uuid: the UUID to look for
374 * Finds a #GMount object by its UUID (see g_mount_get_uuid())
376 * Returns: (transfer full): a #GMount or %NULL if no such mount is available.
377 * Free the returned object with g_object_unref().
380 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor,
383 GVolumeMonitorClass *class;
385 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor), NULL);
386 g_return_val_if_fail (uuid != NULL, NULL);
388 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor);
390 return class->get_mount_for_uuid (volume_monitor, uuid);