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, see <http://www.gnu.org/licenses/>.
20 * Author: Alexander Larsson <alexl@redhat.com>
21 * David Zeuthen <davidz@redhat.com>
25 #include "gvolumemonitor.h"
33 * SECTION:gvolumemonitor
34 * @short_description: Volume Monitor
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.
48 G_DEFINE_TYPE (GVolumeMonitor
, g_volume_monitor
, G_TYPE_OBJECT
);
66 static guint signals
[LAST_SIGNAL
] = { 0 };
70 g_volume_monitor_finalize (GObject
*object
)
72 G_OBJECT_CLASS (g_volume_monitor_parent_class
)->finalize (object
);
76 g_volume_monitor_class_init (GVolumeMonitorClass
*klass
)
78 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
80 gobject_class
->finalize
= g_volume_monitor_finalize
;
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.
89 signals
[VOLUME_ADDED
] = g_signal_new (I_("volume-added"),
90 G_TYPE_VOLUME_MONITOR
,
92 G_STRUCT_OFFSET (GVolumeMonitorClass
, volume_added
),
94 g_cclosure_marshal_VOID__OBJECT
,
95 G_TYPE_NONE
, 1, G_TYPE_VOLUME
);
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.
104 signals
[VOLUME_REMOVED
] = g_signal_new (I_("volume-removed"),
105 G_TYPE_VOLUME_MONITOR
,
107 G_STRUCT_OFFSET (GVolumeMonitorClass
, volume_removed
),
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.
119 signals
[VOLUME_CHANGED
] = g_signal_new (I_("volume-changed"),
120 G_TYPE_VOLUME_MONITOR
,
122 G_STRUCT_OFFSET (GVolumeMonitorClass
, volume_changed
),
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
,
137 G_STRUCT_OFFSET (GVolumeMonitorClass
, mount_added
),
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
,
152 G_STRUCT_OFFSET (GVolumeMonitorClass
, mount_removed
),
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 * Emitted when a mount is about to be removed.
164 signals
[MOUNT_PRE_UNMOUNT
] = g_signal_new (I_("mount-pre-unmount"),
165 G_TYPE_VOLUME_MONITOR
,
167 G_STRUCT_OFFSET (GVolumeMonitorClass
, mount_pre_unmount
),
169 g_cclosure_marshal_VOID__OBJECT
,
170 G_TYPE_NONE
, 1, G_TYPE_MOUNT
);
173 * GVolumeMonitor::mount-changed:
174 * @volume_monitor: The volume monitor emitting the signal.
175 * @mount: a #GMount that changed.
177 * Emitted when a mount changes.
179 signals
[MOUNT_CHANGED
] = g_signal_new (I_("mount-changed"),
180 G_TYPE_VOLUME_MONITOR
,
182 G_STRUCT_OFFSET (GVolumeMonitorClass
, mount_changed
),
184 g_cclosure_marshal_VOID__OBJECT
,
185 G_TYPE_NONE
, 1, G_TYPE_MOUNT
);
188 * GVolumeMonitor::drive-connected:
189 * @volume_monitor: The volume monitor emitting the signal.
190 * @drive: a #GDrive that was connected.
192 * Emitted when a drive is connected to the system.
194 signals
[DRIVE_CONNECTED
] = g_signal_new (I_("drive-connected"),
195 G_TYPE_VOLUME_MONITOR
,
197 G_STRUCT_OFFSET (GVolumeMonitorClass
, drive_connected
),
199 g_cclosure_marshal_VOID__OBJECT
,
200 G_TYPE_NONE
, 1, G_TYPE_DRIVE
);
203 * GVolumeMonitor::drive-disconnected:
204 * @volume_monitor: The volume monitor emitting the signal.
205 * @drive: a #GDrive that was disconnected.
207 * Emitted when a drive is disconnected from the system.
209 signals
[DRIVE_DISCONNECTED
] = g_signal_new (I_("drive-disconnected"),
210 G_TYPE_VOLUME_MONITOR
,
212 G_STRUCT_OFFSET (GVolumeMonitorClass
, drive_disconnected
),
214 g_cclosure_marshal_VOID__OBJECT
,
215 G_TYPE_NONE
, 1, G_TYPE_DRIVE
);
218 * GVolumeMonitor::drive-changed:
219 * @volume_monitor: The volume monitor emitting the signal.
220 * @drive: the drive that changed
222 * Emitted when a drive changes.
224 signals
[DRIVE_CHANGED
] = g_signal_new (I_("drive-changed"),
225 G_TYPE_VOLUME_MONITOR
,
227 G_STRUCT_OFFSET (GVolumeMonitorClass
, drive_changed
),
229 g_cclosure_marshal_VOID__OBJECT
,
230 G_TYPE_NONE
, 1, G_TYPE_DRIVE
);
233 * GVolumeMonitor::drive-eject-button:
234 * @volume_monitor: The volume monitor emitting the signal.
235 * @drive: the drive where the eject button was pressed
237 * Emitted when the eject button is pressed on @drive.
241 signals
[DRIVE_EJECT_BUTTON
] = g_signal_new (I_("drive-eject-button"),
242 G_TYPE_VOLUME_MONITOR
,
244 G_STRUCT_OFFSET (GVolumeMonitorClass
, drive_eject_button
),
246 g_cclosure_marshal_VOID__OBJECT
,
247 G_TYPE_NONE
, 1, G_TYPE_DRIVE
);
250 * GVolumeMonitor::drive-stop-button:
251 * @volume_monitor: The volume monitor emitting the signal.
252 * @drive: the drive where the stop button was pressed
254 * Emitted when the stop button is pressed on @drive.
258 signals
[DRIVE_STOP_BUTTON
] = g_signal_new (I_("drive-stop-button"),
259 G_TYPE_VOLUME_MONITOR
,
261 G_STRUCT_OFFSET (GVolumeMonitorClass
, drive_stop_button
),
263 g_cclosure_marshal_VOID__OBJECT
,
264 G_TYPE_NONE
, 1, G_TYPE_DRIVE
);
269 g_volume_monitor_init (GVolumeMonitor
*monitor
)
275 * g_volume_monitor_get_connected_drives:
276 * @volume_monitor: a #GVolumeMonitor.
278 * Gets a list of drives connected to the system.
280 * The returned list should be freed with g_list_free(), after
281 * its elements have been unreffed with g_object_unref().
283 * Returns: (element-type GDrive) (transfer full): a #GList of connected #GDrive objects.
286 g_volume_monitor_get_connected_drives (GVolumeMonitor
*volume_monitor
)
288 GVolumeMonitorClass
*class;
290 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor
), NULL
);
292 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor
);
294 return class->get_connected_drives (volume_monitor
);
298 * g_volume_monitor_get_volumes:
299 * @volume_monitor: a #GVolumeMonitor.
301 * Gets a list of the volumes on the system.
303 * The returned list should be freed with g_list_free(), after
304 * its elements have been unreffed with g_object_unref().
306 * Returns: (element-type GVolume) (transfer full): a #GList of #GVolume objects.
309 g_volume_monitor_get_volumes (GVolumeMonitor
*volume_monitor
)
311 GVolumeMonitorClass
*class;
313 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor
), NULL
);
315 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor
);
317 return class->get_volumes (volume_monitor
);
321 * g_volume_monitor_get_mounts:
322 * @volume_monitor: a #GVolumeMonitor.
324 * Gets a list of the mounts on the system.
326 * The returned list should be freed with g_list_free(), after
327 * its elements have been unreffed with g_object_unref().
329 * Returns: (element-type GMount) (transfer full): a #GList of #GMount objects.
332 g_volume_monitor_get_mounts (GVolumeMonitor
*volume_monitor
)
334 GVolumeMonitorClass
*class;
336 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor
), NULL
);
338 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor
);
340 return class->get_mounts (volume_monitor
);
344 * g_volume_monitor_get_volume_for_uuid:
345 * @volume_monitor: a #GVolumeMonitor.
346 * @uuid: the UUID to look for
348 * Finds a #GVolume object by its UUID (see g_volume_get_uuid())
350 * Returns: (transfer full): a #GVolume or %NULL if no such volume is available.
351 * Free the returned object with g_object_unref().
354 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor
*volume_monitor
,
357 GVolumeMonitorClass
*class;
359 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor
), NULL
);
360 g_return_val_if_fail (uuid
!= NULL
, NULL
);
362 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor
);
364 return class->get_volume_for_uuid (volume_monitor
, uuid
);
368 * g_volume_monitor_get_mount_for_uuid:
369 * @volume_monitor: a #GVolumeMonitor.
370 * @uuid: the UUID to look for
372 * Finds a #GMount object by its UUID (see g_mount_get_uuid())
374 * Returns: (transfer full): a #GMount or %NULL if no such mount is available.
375 * Free the returned object with g_object_unref().
378 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor
*volume_monitor
,
381 GVolumeMonitorClass
*class;
383 g_return_val_if_fail (G_IS_VOLUME_MONITOR (volume_monitor
), NULL
);
384 g_return_val_if_fail (uuid
!= NULL
, NULL
);
386 class = G_VOLUME_MONITOR_GET_CLASS (volume_monitor
);
388 return class->get_mount_for_uuid (volume_monitor
, uuid
);