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);
160 * g_volume_get_drive:
161 * @volume: a #GVolume.
163 * Gets the drive for the @volume.
165 * Returns: a #GDrive or %NULL if @volume is not associated with a drive.
168 g_volume_get_drive (GVolume *volume)
172 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
174 iface = G_VOLUME_GET_IFACE (volume);
176 return (* iface->get_drive) (volume);
180 * g_volume_get_mount:
181 * @volume: a #GVolume.
183 * Gets the mount for the @volume.
185 * Returns: a #GMount or %NULL if @volume isn't mounted.
188 g_volume_get_mount (GVolume *volume)
192 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
194 iface = G_VOLUME_GET_IFACE (volume);
196 return (* iface->get_mount) (volume);
201 * g_volume_can_mount:
202 * @volume: a #GVolume.
204 * Checks if a volume can be mounted.
206 * Returns: %TRUE if the @volume can be mounted. %FALSE otherwise.
209 g_volume_can_mount (GVolume *volume)
213 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
215 iface = G_VOLUME_GET_IFACE (volume);
217 if (iface->can_mount == NULL)
220 return (* iface->can_mount) (volume);
225 * @volume: a #GVolume.
226 * @mount_operation: a #GMountOperation.
227 * @cancellable: optional #GCancellable object, %NULL to ignore.
228 * @callback: a #GAsyncReadyCallback.
229 * @user_data: a #gpointer.
234 g_volume_mount (GVolume *volume,
235 GMountOperation *mount_operation,
236 GCancellable *cancellable,
237 GAsyncReadyCallback callback,
242 g_return_if_fail (G_IS_VOLUME (volume));
243 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
245 iface = G_VOLUME_GET_IFACE (volume);
247 if (iface->mount_fn == NULL)
249 g_simple_async_report_error_in_idle (G_OBJECT (volume), callback, user_data,
250 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
251 _("volume doesn't implement mount"));
256 (* iface->mount_fn) (volume, mount_operation, cancellable, callback, user_data);
260 * g_volume_mount_finish:
261 * @volume: pointer to a #GVolume.
262 * @result: a #GAsyncResult.
265 * Finishes mounting a volume.
267 * Returns: %TRUE, %FALSE if operation failed.
270 g_volume_mount_finish (GVolume *volume,
271 GAsyncResult *result,
276 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
277 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
279 if (G_IS_SIMPLE_ASYNC_RESULT (result))
281 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
282 if (g_simple_async_result_propagate_error (simple, error))
286 iface = G_VOLUME_GET_IFACE (volume);
287 return (* iface->mount_finish) (volume, result, error);
290 #define __G_VOLUME_C__
291 #include "gioaliasdef.c"