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 "gsimpleasyncresult.h"
30 * @short_description: Virtual File System drive management
31 * @include: gio/gdrive.h
33 * #GDrive manages drive operations from GVFS, including volume mounting
34 * and ejecting, and getting the drive's name and icon.
38 static void g_drive_base_init (gpointer g_class);
39 static void g_drive_class_init (gpointer g_class,
43 g_drive_get_type (void)
45 static GType drive_type = 0;
49 static const GTypeInfo drive_info =
51 sizeof (GDriveIface), /* class_size */
52 g_drive_base_init, /* base_init */
53 NULL, /* base_finalize */
55 NULL, /* class_finalize */
56 NULL, /* class_data */
63 g_type_register_static (G_TYPE_INTERFACE, I_("GDrive"),
66 g_type_interface_add_prerequisite (drive_type, G_TYPE_OBJECT);
73 g_drive_class_init (gpointer g_class,
79 g_drive_base_init (gpointer g_class)
81 static gboolean initialized = FALSE;
87 * @volume: a #GVolume.
89 * Emitted when the drive's state has changed.
92 g_signal_new (I_("changed"),
95 G_STRUCT_OFFSET (GDriveIface, changed),
97 g_cclosure_marshal_VOID__VOID,
108 * Gets the name of @drive.
110 * Returns: a string containing @drive's name. The returned
111 * string should be freed when no longer needed.
114 g_drive_get_name (GDrive *drive)
118 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
120 iface = G_DRIVE_GET_IFACE (drive);
122 return (* iface->get_name) (drive);
129 * Gets the icon for @drive.
131 * Returns: #GIcon for the @drive.
134 g_drive_get_icon (GDrive *drive)
138 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
140 iface = G_DRIVE_GET_IFACE (drive);
142 return (* iface->get_icon) (drive);
146 * g_drive_has_volumes:
149 * Checks if a drive has any volumes.
151 * Returns: %TRUE if @drive contains volumes, %FALSE otherwise.
154 g_drive_has_volumes (GDrive *drive)
158 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
160 iface = G_DRIVE_GET_IFACE (drive);
162 return (* iface->has_volumes) (drive);
166 * g_drive_get_volumes:
169 * Gets a list of volumes for a drive.
171 * Returns: #GList containing any #GVolume<!---->s on the given @drive.
172 * NOTE: Fact-check this.
175 g_drive_get_volumes (GDrive *drive)
179 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
181 iface = G_DRIVE_GET_IFACE (drive);
183 return (* iface->get_volumes) (drive);
187 * g_drive_is_automounted:
190 * Checks if a drive was automatically mounted, e.g. by HAL.
192 * Returns: %TRUE if the drive was automounted. %FALSE otherwise.
195 g_drive_is_automounted (GDrive *drive)
199 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
201 iface = G_DRIVE_GET_IFACE (drive);
203 return (* iface->is_automounted) (drive);
210 * Checks if a drive can be mounted.
212 * Returns: %TRUE if the @drive can be mounted. %FALSE otherwise.
215 g_drive_can_mount (GDrive *drive)
219 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
221 iface = G_DRIVE_GET_IFACE (drive);
223 if (iface->can_mount == NULL)
226 return (* iface->can_mount) (drive);
231 * @drive: pointer to a #GDrive.
233 * Checks if a drive can be ejected.
235 * Returns: %TRUE if the @drive can be ejected. %FALSE otherwise.
238 g_drive_can_eject (GDrive *drive)
242 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
244 iface = G_DRIVE_GET_IFACE (drive);
246 if (iface->can_eject == NULL)
249 return (* iface->can_eject) (drive);
255 * @mount_operation: a #GMountOperation.
256 * @cancellable: optional #GCancellable object, %NULL to ignore.
257 * @callback: a #GAsyncReadyCallback.
258 * @user_data: a #gpointer.
264 g_drive_mount (GDrive *drive,
265 GMountOperation *mount_operation,
266 GCancellable *cancellable,
267 GAsyncReadyCallback callback,
272 g_return_if_fail (G_IS_DRIVE (drive));
273 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
275 iface = G_DRIVE_GET_IFACE (drive);
277 if (iface->mount == NULL)
279 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
280 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
281 _("drive doesn't implement mount"));
286 (* iface->mount) (drive, mount_operation, cancellable, callback, user_data);
290 * g_drive_mount_finish:
291 * @drive: pointer to a #GDrive.
292 * @result: a #GAsyncResult.
295 * Finishes mounting a drive.
297 * Returns: %TRUE, %FALSE if operation failed.
300 g_drive_mount_finish (GDrive *drive,
301 GAsyncResult *result,
306 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
307 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
309 if (G_IS_SIMPLE_ASYNC_RESULT (result))
311 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
312 if (g_simple_async_result_propagate_error (simple, error))
316 iface = G_DRIVE_GET_IFACE (drive);
317 return (* iface->mount_finish) (drive, result, error);
323 * @cancellable: optional #GCancellable object, %NULL to ignore.
324 * @callback: a #GAsyncReadyCallback.
325 * @user_data: a #gpointer.
331 g_drive_eject (GDrive *drive,
332 GCancellable *cancellable,
333 GAsyncReadyCallback callback,
338 g_return_if_fail (G_IS_DRIVE (drive));
340 iface = G_DRIVE_GET_IFACE (drive);
342 if (iface->eject == NULL)
344 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
345 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
346 _("drive doesn't implement eject"));
351 (* iface->eject) (drive, cancellable, callback, user_data);
355 * g_drive_eject_finish
357 * @result: a #GAsyncResult.
360 * Finishes ejecting a drive.
362 * Returns: %TRUE if the drive has been ejected successfully,
366 g_drive_eject_finish (GDrive *drive,
367 GAsyncResult *result,
372 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
373 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
375 if (G_IS_SIMPLE_ASYNC_RESULT (result))
377 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
378 if (g_simple_async_result_propagate_error (simple, error))
382 iface = G_DRIVE_GET_IFACE (drive);
384 return (* iface->mount_finish) (drive, result, error);