Add Friulian translation
[glib.git] / gio / gvolumemonitor.c
blob441afc66719237284bff8cb1961c9fe2e2e04a63
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 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 * 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);
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.
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);
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,
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);
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.
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);
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.
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);
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.
239 * Since: 2.18
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);
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.
256 * Since: 2.22
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);
268 static void
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.
285 GList *
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.
308 GList *
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.
331 GList *
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().
353 GVolume *
354 g_volume_monitor_get_volume_for_uuid (GVolumeMonitor *volume_monitor,
355 const char *uuid)
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().
377 GMount *
378 g_volume_monitor_get_mount_for_uuid (GVolumeMonitor *volume_monitor,
379 const char *uuid)
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);