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 * Returns: string containing @drive's name.
110 * The returned string should be freed when no longer needed.
113 g_drive_get_name (GDrive *drive)
117 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
119 iface = G_DRIVE_GET_IFACE (drive);
121 return (* iface->get_name) (drive);
128 * Gets the icon for @drive.
130 * Returns: #GIcon for the @drive.
133 g_drive_get_icon (GDrive *drive)
137 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
139 iface = G_DRIVE_GET_IFACE (drive);
141 return (* iface->get_icon) (drive);
145 * g_drive_has_volumes:
148 * Checks if a drive has any volumes.
150 * Returns: %TRUE if @drive contains volumes, %FALSE otherwise.
153 g_drive_has_volumes (GDrive *drive)
157 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
159 iface = G_DRIVE_GET_IFACE (drive);
161 return (* iface->has_volumes) (drive);
165 * g_drive_get_volumes:
168 * Gets a list of volumes for a drive.
170 * Returns: #GList containing any #GVolume<!---->s on the given @drive.
171 * NOTE: Fact-check this.
174 g_drive_get_volumes (GDrive *drive)
178 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
180 iface = G_DRIVE_GET_IFACE (drive);
182 return (* iface->get_volumes) (drive);
186 * g_drive_is_automounted:
189 * Checks if a drive was automatically mounted, e.g. by HAL.
191 * Returns: %TRUE if the drive was automounted. %FALSE otherwise.
194 g_drive_is_automounted (GDrive *drive)
198 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
200 iface = G_DRIVE_GET_IFACE (drive);
202 return (* iface->is_automounted) (drive);
209 * Checks if a drive can be mounted.
211 * Returns: %TRUE if the @drive can be mounted. %FALSE otherwise.
214 g_drive_can_mount (GDrive *drive)
218 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
220 iface = G_DRIVE_GET_IFACE (drive);
222 if (iface->can_mount == NULL)
225 return (* iface->can_mount) (drive);
230 * @drive: pointer to a #GDrive.
232 * Checks if a drive can be ejected.
234 * Returns: %TRUE if the @drive can be ejected. %FALSE otherwise.
237 g_drive_can_eject (GDrive *drive)
241 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
243 iface = G_DRIVE_GET_IFACE (drive);
245 if (iface->can_eject == NULL)
248 return (* iface->can_eject) (drive);
254 * @mount_operation: a #GMountOperation.
255 * @cancellable: optional #GCancellable object, %NULL to ignore.
256 * @callback: a #GAsyncReadyCallback.
257 * @user_data: a #gpointer.
263 g_drive_mount (GDrive *drive,
264 GMountOperation *mount_operation,
265 GCancellable *cancellable,
266 GAsyncReadyCallback callback,
271 g_return_if_fail (G_IS_DRIVE (drive));
272 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
274 iface = G_DRIVE_GET_IFACE (drive);
276 if (iface->mount == NULL)
278 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
279 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
280 _("drive doesn't implement mount"));
285 (* iface->mount) (drive, mount_operation, cancellable, callback, user_data);
289 * g_drive_mount_finish:
290 * @drive: pointer to a #GDrive.
291 * @result: a #GAsyncResult.
294 * Finishes mounting a drive.
296 * Returns: %TRUE, %FALSE if operation failed.
299 g_drive_mount_finish (GDrive *drive,
300 GAsyncResult *result,
305 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
306 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
308 if (G_IS_SIMPLE_ASYNC_RESULT (result))
310 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
311 if (g_simple_async_result_propagate_error (simple, error))
315 iface = G_DRIVE_GET_IFACE (drive);
316 return (* iface->mount_finish) (drive, result, error);
322 * @cancellable: optional #GCancellable object, %NULL to ignore.
323 * @callback: a #GAsyncReadyCallback.
324 * @user_data: a #gpointer.
330 g_drive_eject (GDrive *drive,
331 GCancellable *cancellable,
332 GAsyncReadyCallback callback,
337 g_return_if_fail (G_IS_DRIVE (drive));
339 iface = G_DRIVE_GET_IFACE (drive);
341 if (iface->eject == NULL)
343 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
344 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
345 _("drive doesn't implement eject"));
350 (* iface->eject) (drive, cancellable, callback, user_data);
354 * g_drive_eject_finish
356 * @result: a #GAsyncResult.
359 * Finishes ejecting a drive.
361 * Returns: %TRUE if the drive has been ejected successfully,
365 g_drive_eject_finish (GDrive *drive,
366 GAsyncResult *result,
371 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
372 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
374 if (G_IS_SIMPLE_ASYNC_RESULT (result))
376 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
377 if (g_simple_async_result_propagate_error (simple, error))
381 iface = G_DRIVE_GET_IFACE (drive);
383 return (* iface->mount_finish) (drive, result, error);