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"
31 * @short_description: mounted volume management
33 * Class for managing mounted volumes.
35 * Unmounting volumes is an asynchronous operation. For more information about
36 * asynchronous operations, see #GAsyncReady and #GSimpleAsyncReady. To unmount a volume,
37 * first call g_volume_unmount() with (at least) the volume and a #GAsyncReadyCallback.
38 * The callback will be fired when the operation has resolved (either with success or failure),
39 * and a #GAsyncReady structure will be passed to the callback.
40 * That callback should then call g_volume_unmount_finish() with
41 * the volume and the #GAsyncReady data to see if the operation was completed successfully.
42 * If an @error is present when g_volume_unmount_finish() is called, then it will
43 * be filled with any error information.
45 * Ejecting volumes is also an asynchronous operation.
46 * To eject a volume, call g_volume_eject() with (at least) the volume to eject
47 * and a #GAsyncReadyCallback. The callback will be fired when the eject operation
48 * has resolved (either with success or failure), and a #GAsyncReady structure will
49 * be passed to the callback. That callback should then call g_volume_eject_finish()
50 * with the volume and the #GAsyncReady data to determine if the operation was completed
51 * successfully. If an @error is present when g_volume_eject_finish() is called, then
52 * it will be filled with any error information.
56 static void g_volume_base_init (gpointer g_class);
57 static void g_volume_class_init (gpointer g_class,
61 g_volume_get_type (void)
63 static GType volume_type = 0;
67 static const GTypeInfo volume_info =
69 sizeof (GVolumeIface), /* class_size */
70 g_volume_base_init, /* base_init */
71 NULL, /* base_finalize */
73 NULL, /* class_finalize */
74 NULL, /* class_data */
81 g_type_register_static (G_TYPE_INTERFACE, I_("GVolume"),
84 g_type_interface_add_prerequisite (volume_type, G_TYPE_OBJECT);
91 g_volume_class_init (gpointer g_class,
97 g_volume_base_init (gpointer g_class)
99 static gboolean initialized = FALSE;
106 * Emitted when the volume has been changed.
108 g_signal_new (I_("changed"),
111 G_STRUCT_OFFSET (GVolumeIface, changed),
113 g_cclosure_marshal_VOID__VOID,
122 * @volume: a #GVolume.
124 * Gets the root directory on @volume.
129 g_volume_get_root (GVolume *volume)
133 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
135 iface = G_VOLUME_GET_IFACE (volume);
137 return (* iface->get_root) (volume);
142 * @volume: a #GVolume.
144 * Gets the name of @volume.
146 * Returns: the name for the given @volume. The returned string should
147 * be freed when no longer needed.
150 g_volume_get_name (GVolume *volume)
154 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
156 iface = G_VOLUME_GET_IFACE (volume);
158 return (* iface->get_name) (volume);
163 * @volume: a #GVolume.
165 * Gets the icon for @volume.
170 g_volume_get_icon (GVolume *volume)
174 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
176 iface = G_VOLUME_GET_IFACE (volume);
178 return (* iface->get_icon) (volume);
182 * g_volume_get_drive:
183 * @volume: a #GVolume.
185 * Gets the drive for the @volume.
187 * Returns: a #GDrive.
190 g_volume_get_drive (GVolume *volume)
194 g_return_val_if_fail (G_IS_VOLUME (volume), NULL);
196 iface = G_VOLUME_GET_IFACE (volume);
198 return (* iface->get_drive) (volume);
202 * g_volume_can_unmount:
203 * @volume: a #GVolume.
205 * Checks if @volume can be mounted.
207 * Returns: %TRUE if the @volume can be unmounted.
210 g_volume_can_unmount (GVolume *volume)
214 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
216 iface = G_VOLUME_GET_IFACE (volume);
218 return (* iface->can_unmount) (volume);
222 * g_volume_can_eject:
223 * @volume: a #GVolume.
225 * Checks if @volume can be ejected.
227 * Returns: %TRUE if the @volume can be ejected.
230 g_volume_can_eject (GVolume *volume)
234 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
236 iface = G_VOLUME_GET_IFACE (volume);
238 return (* iface->can_eject) (volume);
243 * @volume: a #GVolume.
244 * @cancellable: optional #GCancellable object, %NULL to ignore.
245 * @callback: a #GAsyncReadyCallback.
246 * @user_data: user data passed to @callback.
248 * Unmounts a volume. This is an asynchronous operation, and is finished by calling
249 * g_volume_unmount_finish() with the @volume and #GAsyncResults data returned in the
254 g_volume_unmount (GVolume *volume,
255 GCancellable *cancellable,
256 GAsyncReadyCallback callback,
261 g_return_if_fail (G_IS_VOLUME (volume));
263 iface = G_VOLUME_GET_IFACE (volume);
265 if (iface->unmount == NULL)
267 g_simple_async_report_error_in_idle (G_OBJECT (volume),
269 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
270 _("volume doesn't implement unmount"));
275 (* iface->unmount) (volume, cancellable, callback, user_data);
279 * g_volume_unmount_finish:
280 * @volume: a #GVolume.
281 * @result: a #GAsyncResult.
282 * @error: a #GError location to store the error occuring, or %NULL to
285 * Finishes unmounting a volume. If any errors occured during the operation,
286 * @error will be set to contain the errors and %FALSE will be returned.
288 * Returns: %TRUE if the volume was successfully unmounted. %FALSE otherwise.
291 g_volume_unmount_finish (GVolume *volume,
292 GAsyncResult *result,
297 g_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
298 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
300 if (G_IS_SIMPLE_ASYNC_RESULT (result))
302 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
303 if (g_simple_async_result_propagate_error (simple, error))
307 iface = G_VOLUME_GET_IFACE (volume);
308 return (* iface->unmount_finish) (volume, result, error);
313 * @volume: a #GVolume.
314 * @cancellable: optional #GCancellable object, %NULL to ignore.
315 * @callback: a #GAsyncReadyCallback.
316 * @user_data: user data passed to @callback.
318 * Ejects a volume. This is an asynchronous operation, and is finished
319 * by calling g_volume_eject_finish() from the @callback with the @volume and
320 * #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);