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
37 * The #GVolume interface represents user-visible objects that can be
38 * mounted. Note, when porting from GnomeVFS, #GVolume is the moral
39 * equivalent of #GnomeVFSDrive.
41 * Mounting a #GVolume instance is an asynchronous operation. For more
42 * information about asynchronous operations, see #GAsyncReady and
43 * #GSimpleAsyncReady. To mount a #GVolume, first call
44 * g_volume_mount() with (at least) the #GVolume instane, a
45 * #GMountOperation object and a #GAsyncReadyCallback. The callback
46 * will be fired when the operation has resolved (either with success
47 * or failure), and a #GAsyncReady structure will be passed to the
48 * callback. That callback should then call g_volume_mount_finish()
49 * with the #GVolume instance and the #GAsyncReady data to see if the
50 * operation was completed successfully. If an @error is present when
51 * g_volume_mount_finish() is called, then it will be filled with any
55 static void g_volume_base_init (gpointer g_class);
56 static void g_volume_class_init (gpointer g_class,
60 g_volume_get_type (void)
62 static GType volume_type = 0;
66 static const GTypeInfo volume_info =
68 sizeof (GVolumeIface), /* class_size */
69 g_volume_base_init, /* base_init */
70 NULL, /* base_finalize */
72 NULL, /* class_finalize */
73 NULL, /* class_data */
80 g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
83 g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
90 g_volume_class_init (gpointer g_class,
96 g_volume_base_init (gpointer g_class)
98 static gboolean initialized = FALSE;
105 * Emitted when the volume has been changed.
107 g_signal_new (I_("changed"),
110 G_STRUCT_OFFSET (GVolumeIface, changed),
112 g_cclosure_marshal_VOID__VOID,
121 * @volume: a #GVolume.
123 * Gets the name of @volume.
125 * Returns: the name for the given @volume. The returned string should
126 * be freed when no longer needed.
129 g_volume_get_name (GVolume *volume)
133 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
135 iface = G_VOLUME_GET_IFACE (volume);
137 return (* iface->get_name) (volume);
142 * @volume: a #GVolume.
144 * Gets the icon for @volume.
149 g_volume_get_icon (GVolume *volume)
153 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
155 iface = G_VOLUME_GET_IFACE (volume);
157 return (* iface->get_icon) (volume);
162 * @volume: a #GVolume.
164 * Gets the UUID for the @volume. The reference is typically based on
165 * the file system UUID for the volume in question and should be
166 * considered an opaque string. Returns %NULL if there is no UUID
169 * Returns: the UUID for @volume or %NULL if no UUID can be computed.
172 g_volume_get_uuid (GVolume *volume)
176 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
178 iface = G_VOLUME_GET_IFACE (volume);
180 return (* iface->get_uuid) (volume);
184 * g_volume_get_drive:
185 * @volume: a #GVolume.
187 * Gets the drive for the @volume.
189 * Returns: a #GDrive or %NULL if @volume is not associated with a drive.
192 g_volume_get_drive (GVolume *volume)
196 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
198 iface = G_VOLUME_GET_IFACE (volume);
200 return (* iface->get_drive) (volume);
204 * g_volume_get_mount:
205 * @volume: a #GVolume.
207 * Gets the mount for the @volume.
209 * Returns: a #GMount or %NULL if @volume isn't mounted.
212 g_volume_get_mount (GVolume *volume)
216 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
218 iface = G_VOLUME_GET_IFACE (volume);
220 return (* iface->get_mount) (volume);
225 * g_volume_can_mount:
226 * @volume: a #GVolume.
228 * Checks if a volume can be mounted.
230 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise.
233 g_volume_can_mount (GVolume *volume)
237 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
239 iface = G_VOLUME_GET_IFACE (volume);
241 if (iface->can_mount == NULL)
244 return (* iface->can_mount) (volume);
248 * g_volume_can_eject:
249 * @volume: a #GVolume.
251 * Checks if a volume can be ejected.
253 * Returns: %TRUE if the @volume can be ejected. %FALSE otherwise.
256 g_volume_can_eject (GVolume *volume)
260 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
262 iface = G_VOLUME_GET_IFACE (volume);
264 if (iface->can_eject == NULL)
267 return (* iface->can_eject) (volume);
272 * @volume: a #GVolume.
273 * @mount_operation: a #GMountOperation.
274 * @cancellable: optional #GCancellable object, %NULL to ignore.
275 * @callback: a #GAsyncReadyCallback.
276 * @user_data: a #gpointer.
281 g_volume_mount (GVolume *volume,
282 GMountOperation *mount_operation,
283 GCancellable *cancellable,
284 GAsyncReadyCallback callback,
289 g_return_if_fail (G_IS_VOLUME (volume));
290 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
292 iface = G_VOLUME_GET_IFACE (volume);
294 if (iface->mount_fn == NULL)
296 g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
297 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
298 _("volume doesn't implement mount"));
303 (* iface->mount_fn) (volume, mount_operation, cancellable, callback, user_data);
307 * g_volume_mount_finish:
308 * @volume: pointer to a #GVolume.
309 * @result: a #GAsyncResult.
312 * Finishes mounting a volume.
314 * Returns: %TRUE, %FALSE if operation failed.
317 g_volume_mount_finish (GVolume *volume,
318 GAsyncResult *result,
323 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
324 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
326 if (G_IS_SIMPLE_ASYNC_RESULT (result))
328 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
329 if (g_simple_async_result_propagate_error (simple, error))
333 iface = G_VOLUME_GET_IFACE (volume);
334 return (* iface->mount_finish) (volume, result, error);
339 * @volume: a #GVolume.
340 * @cancellable: optional #GCancellable object, %NULL to ignore.
341 * @callback: a #GAsyncReadyCallback.
342 * @user_data: a #gpointer.
347 g_volume_eject (GVolume *volume,
348 GCancellable *cancellable,
349 GAsyncReadyCallback callback,
354 g_return_if_fail (G_IS_VOLUME (volume));
356 iface = G_VOLUME_GET_IFACE (volume);
358 if (iface->eject == NULL)
360 g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
361 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
362 _("volume doesn't implement eject"));
367 (* iface->eject) (volume, cancellable, callback, user_data);
371 * g_volume_eject_finish:
372 * @volume: pointer to a #GVolume.
373 * @result: a #GAsyncResult.
376 * Finishes ejecting a volume.
378 * Returns: %TRUE, %FALSE if operation failed.
381 g_volume_eject_finish (GVolume *volume,
382 GAsyncResult *result,
387 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
388 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
390 if (G_IS_SIMPLE_ASYNC_RESULT (result))
392 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
393 if (g_simple_async_result_propagate_error (simple, error))
397 iface = G_VOLUME_GET_IFACE (volume);
398 return (* iface->eject_finish) (volume, result, error);
401 #define __G_VOLUME_C__
402 #include "gioaliasdef.c"