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>
25 #include "gvolumeprivate.h"
26 #include "gsimpleasyncresult.h"
33 * @short_description: mounted volume management
35 * Class for managing mounted volumes.
37 * Unmounting volumes is an asynchronous operation. For more information about
38 * asynchronous operations, see #GAsyncReady and #GSimpleAsyncReady. To unmount a volume,
39 * first call g_volume_unmount() with (at least) the volume and a #GAsyncReadyCallback.
40 * The callback will be fired when the operation has resolved (either with success or failure),
41 * and a #GAsyncReady structure will be passed to the callback.
42 * That callback should then call g_volume_unmount_finish() with
43 * the volume and the #GAsyncReady data to see if the operation was completed successfully.
44 * If an @error is present when g_volume_unmount_finish() is called, then it will
45 * be filled with any error information.
47 * Ejecting volumes is also an asynchronous operation.
48 * To eject a volume, call g_volume_eject() with (at least) the volume to eject
49 * and a #GAsyncReadyCallback. The callback will be fired when the eject operation
50 * has resolved (either with success or failure), and a #GAsyncReady structure will
51 * be passed to the callback. That callback should then call g_volume_eject_finish()
52 * with the volume and the #GAsyncReady data to determine if the operation was completed
53 * successfully. If an @error is present when g_volume_eject_finish() is called, then
54 * it will be filled with any error information.
58 static void g_volume_base_init (gpointer g_class);
59 static void g_volume_class_init (gpointer g_class,
63 g_volume_get_type (void)
65 static GType volume_type = 0;
69 static const GTypeInfo volume_info =
71 sizeof (GVolumeIface), /* class_size */
72 g_volume_base_init, /* base_init */
73 NULL, /* base_finalize */
75 NULL, /* class_finalize */
76 NULL, /* class_data */
83 g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
86 g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
93 g_volume_class_init (gpointer g_class,
99 g_volume_base_init (gpointer g_class)
101 static gboolean initialized = FALSE;
108 * Emitted when the volume has been changed.
110 g_signal_new (I_("changed"),
113 G_STRUCT_OFFSET (GVolumeIface, changed),
115 g_cclosure_marshal_VOID__VOID,
124 * @volume: a #GVolume.
126 * Gets the root directory on @volume.
131 g_volume_get_root (GVolume *volume)
135 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
137 iface = G_VOLUME_GET_IFACE (volume);
139 return (* iface->get_root) (volume);
144 * @volume: a #GVolume.
146 * Gets the name of @volume.
148 * Returns: the name for the given @volume. The returned string should
149 * be freed when no longer needed.
152 g_volume_get_name (GVolume *volume)
156 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
158 iface = G_VOLUME_GET_IFACE (volume);
160 return (* iface->get_name) (volume);
165 * @volume: a #GVolume.
167 * Gets the icon for @volume.
172 g_volume_get_icon (GVolume *volume)
176 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
178 iface = G_VOLUME_GET_IFACE (volume);
180 return (* iface->get_icon) (volume);
184 * g_volume_get_drive:
185 * @volume: a #GVolume.
187 * Gets the drive for the @volume.
189 * Returns: a #GDrive.
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_can_unmount:
205 * @volume: a #GVolume.
207 * Checks if @volume can be mounted.
209 * Returns: %TRUE if the @volume can be unmounted.
212 g_volume_can_unmount (GVolume *volume)
216 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
218 iface = G_VOLUME_GET_IFACE (volume);
220 return (* iface->can_unmount) (volume);
224 * g_volume_can_eject:
225 * @volume: a #GVolume.
227 * Checks if @volume can be ejected.
229 * Returns: %TRUE if the @volume can be ejected.
232 g_volume_can_eject (GVolume *volume)
236 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
238 iface = G_VOLUME_GET_IFACE (volume);
240 return (* iface->can_eject) (volume);
245 * @volume: a #GVolume.
246 * @cancellable: optional #GCancellable object, %NULL to ignore.
247 * @callback: a #GAsyncReadyCallback.
248 * @user_data: user data passed to @callback.
250 * Unmounts a volume. This is an asynchronous operation, and is
251 * finished by calling g_volume_unmount_finish() with the @volume
252 * and #GAsyncResults data returned in the @callback.
255 g_volume_unmount (GVolume *volume,
256 GCancellable *cancellable,
257 GAsyncReadyCallback callback,
262 g_return_if_fail (G_IS_VOLUME (volume));
264 iface = G_VOLUME_GET_IFACE (volume);
266 if (iface->unmount == NULL)
268 g_simple_async_report_error_in_idle (G_OBJECT (volume),
270 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
271 _("volume doesn't implement unmount"));
276 (* iface->unmount) (volume, cancellable, callback, user_data);
280 * g_volume_unmount_finish:
281 * @volume: a #GVolume.
282 * @result: a #GAsyncResult.
283 * @error: a #GError location to store the error occuring, or %NULL to
286 * Finishes unmounting a volume. If any errors occured during the operation,
287 * @error will be set to contain the errors and %FALSE will be returned.
289 * Returns: %TRUE if the volume was successfully unmounted. %FALSE otherwise.
292 g_volume_unmount_finish (GVolume *volume,
293 GAsyncResult *result,
298 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
299 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
301 if (G_IS_SIMPLE_ASYNC_RESULT (result))
303 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
304 if (g_simple_async_result_propagate_error (simple, error))
308 iface = G_VOLUME_GET_IFACE (volume);
309 return (* iface->unmount_finish) (volume, result, error);
314 * @volume: a #GVolume.
315 * @cancellable: optional #GCancellable object, %NULL to ignore.
316 * @callback: a #GAsyncReadyCallback.
317 * @user_data: user data passed to @callback.
319 * Ejects a volume. This is an asynchronous operation, and is
320 * finished by calling g_volume_eject_finish() from the @callback
321 * with the @volume and #GAsyncResults returned in the callback.
324 g_volume_eject (GVolume *volume,
325 GCancellable *cancellable,
326 GAsyncReadyCallback callback,
331 g_return_if_fail (G_IS_VOLUME (volume));
333 iface = G_VOLUME_GET_IFACE (volume);
335 if (iface->eject == NULL)
337 g_simple_async_report_error_in_idle (G_OBJECT (volume),
339 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
340 _("volume doesn't implement eject"));
345 (* iface->eject) (volume, cancellable, callback, user_data);
349 * g_volume_eject_finish:
350 * @volume: a #GVolume.
351 * @result: a #GAsyncResult.
352 * @error: a #GError location to store the error occuring, or %NULL to
355 * Finishes ejecting the volume. If any errors occured during the operation,
356 * @error will be set to contain the errors and %FALSE will be returned.
358 * Returns: %TRUE if the volume was successfully ejected. %FALSE otherwise.
361 g_volume_eject_finish (GVolume *volume,
362 GAsyncResult *result,
367 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
368 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
370 if (G_IS_SIMPLE_ASYNC_RESULT (result))
372 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
373 if (g_simple_async_result_propagate_error (simple, error))
377 iface = G_VOLUME_GET_IFACE (volume);
378 return (* iface->eject_finish) (volume, result, error);
381 #define __G_VOLUME_C__
382 #include "gioaliasdef.c"