1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
21 * David Zeuthen <davidz@redhat.com>
27 #include "gsimpleasyncresult.h"
34 * @short_description: volume management
36 * The #GVolume interface represents user-visible objects that can be
37 * mounted. Note, when porting from GnomeVFS, #GVolume is the moral
38 * equivalent of #GnomeVFSDrive.
40 * Mounting a #GVolume instance is an asynchronous operation. For more
41 * information about asynchronous operations, see #GAsyncReady and
42 * #GSimpleAsyncReady. To mount a #GVolume, first call
43 * g_volume_mount() with (at least) the #GVolume instane, a
44 * #GMountOperation object and a #GAsyncReadyCallback. The callback
45 * will be fired when the operation has resolved (either with success
46 * or failure), and a #GAsyncReady structure will be passed to the
47 * callback. That callback should then call g_volume_mount_finish()
48 * with the #GVolume instance and the #GAsyncReady data to see if the
49 * operation was completed successfully. If an @error is present when
50 * g_volume_mount_finish() is called, then it will be filled with any
54 static void g_volume_base_init (gpointer g_class);
55 static void g_volume_class_init (gpointer g_class,
59 g_volume_get_type (void)
61 static GType volume_type = 0;
65 static const GTypeInfo volume_info =
67 sizeof (GVolumeIface), /* class_size */
68 g_volume_base_init, /* base_init */
69 NULL, /* base_finalize */
71 NULL, /* class_finalize */
72 NULL, /* class_data */
79 g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
82 g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
89 g_volume_class_init (gpointer g_class,
95 g_volume_base_init (gpointer g_class)
97 static gboolean initialized = FALSE;
104 * Emitted when the volume has been changed.
106 g_signal_new (I_("changed"),
109 G_STRUCT_OFFSET (GVolumeIface, changed),
111 g_cclosure_marshal_VOID__VOID,
120 * @volume: a #GVolume.
122 * Gets the name of @volume.
124 * Returns: the name for the given @volume. The returned string should
125 * be freed when no longer needed.
128 g_volume_get_name (GVolume *volume)
132 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
134 iface = G_VOLUME_GET_IFACE (volume);
136 return (* iface->get_name) (volume);
141 * @volume: a #GVolume.
143 * Gets the icon for @volume.
148 g_volume_get_icon (GVolume *volume)
152 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
154 iface = G_VOLUME_GET_IFACE (volume);
156 return (* iface->get_icon) (volume);
161 * @volume: a #GVolume.
163 * Gets the UUID for the @volume. The reference is typically based on
164 * the file system UUID for the volume in question and should be
165 * considered an opaque string. Returns %NULL if there is no UUID
168 * Returns: the UUID for @volume or %NULL if no UUID can be computed.
171 g_volume_get_uuid (GVolume *volume)
175 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
177 iface = G_VOLUME_GET_IFACE (volume);
179 return (* iface->get_uuid) (volume);
183 * g_volume_get_drive:
184 * @volume: a #GVolume.
186 * Gets the drive for the @volume.
188 * Returns: a #GDrive or %NULL if @volume is not associated with a drive.
191 g_volume_get_drive (GVolume *volume)
195 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
197 iface = G_VOLUME_GET_IFACE (volume);
199 return (* iface->get_drive) (volume);
203 * g_volume_get_mount:
204 * @volume: a #GVolume.
206 * Gets the mount for the @volume.
208 * Returns: a #GMount or %NULL if @volume isn't mounted.
211 g_volume_get_mount (GVolume *volume)
215 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
217 iface = G_VOLUME_GET_IFACE (volume);
219 return (* iface->get_mount) (volume);
224 * g_volume_can_mount:
225 * @volume: a #GVolume.
227 * Checks if a volume can be mounted.
229 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise.
232 g_volume_can_mount (GVolume *volume)
236 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
238 iface = G_VOLUME_GET_IFACE (volume);
240 if (iface->can_mount == NULL)
243 return (* iface->can_mount) (volume);
247 * g_volume_can_eject:
248 * @volume: a #GVolume.
250 * Checks if a volume can be ejected.
252 * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise.
255 g_volume_can_eject (GVolume *volume)
259 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
261 iface = G_VOLUME_GET_IFACE (volume);
263 if (iface->can_eject == NULL)
266 return (* iface->can_eject) (volume);
271 * @volume: a #GVolume.
272 * @mount_operation: a #GMountOperation.
273 * @cancellable: optional #GCancellable object, %NULL to ignore.
274 * @callback: a #GAsyncReadyCallback.
275 * @user_data: a #gpointer.
280 g_volume_mount (GVolume *volume,
281 GMountOperation *mount_operation,
282 GCancellable *cancellable,
283 GAsyncReadyCallback callback,
288 g_return_if_fail (G_IS_VOLUME (volume));
289 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
291 iface = G_VOLUME_GET_IFACE (volume);
293 if (iface->mount_fn == NULL)
295 g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
296 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
297 _("volume doesn't implement mount"));
302 (* iface->mount_fn) (volume, mount_operation, cancellable, callback, user_data);
306 * g_volume_mount_finish:
307 * @volume: pointer to a #GVolume.
308 * @result: a #GAsyncResult.
311 * Finishes mounting a volume.
313 * Returns: %TRUE, %FALSE if operation failed.
316 g_volume_mount_finish (GVolume *volume,
317 GAsyncResult *result,
322 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
323 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
325 if (G_IS_SIMPLE_ASYNC_RESULT (result))
327 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
328 if (g_simple_async_result_propagate_error (simple, error))
332 iface = G_VOLUME_GET_IFACE (volume);
333 return (* iface->mount_finish) (volume, result, error);
338 * @volume: a #GVolume.
339 * @cancellable: optional #GCancellable object, %NULL to ignore.
340 * @callback: a #GAsyncReadyCallback.
341 * @user_data: a #gpointer.
346 g_volume_eject (GVolume *volume,
347 GCancellable *cancellable,
348 GAsyncReadyCallback callback,
353 g_return_if_fail (G_IS_VOLUME (volume));
355 iface = G_VOLUME_GET_IFACE (volume);
357 if (iface->eject == NULL)
359 g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
360 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
361 _("volume doesn't implement eject"));
366 (* iface->eject) (volume, cancellable, callback, user_data);
370 * g_volume_eject_finish:
371 * @volume: pointer to a #GVolume.
372 * @result: a #GAsyncResult.
375 * Finishes ejecting a volume.
377 * Returns: %TRUE, %FALSE if operation failed.
380 g_volume_eject_finish (GVolume *volume,
381 GAsyncResult *result,
386 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
387 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
389 if (G_IS_SIMPLE_ASYNC_RESULT (result))
391 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
392 if (g_simple_async_result_propagate_error (simple, error))
396 iface = G_VOLUME_GET_IFACE (volume);
397 return (* iface->eject_finish) (volume, result, error);
400 #define __G_VOLUME_C__
401 #include "gioaliasdef.c"