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"
32 * @short_description: Virtual File System drive management
33 * @include: gio/gdrive.h
35 * #GDrive manages drive operations from GVFS, including volume mounting
36 * and ejecting, and getting the drive's name and icon.
40 static void g_drive_base_init (gpointer g_class);
41 static void g_drive_class_init (gpointer g_class,
45 g_drive_get_type (void)
47 static GType drive_type = 0;
51 static const GTypeInfo drive_info =
53 sizeof (GDriveIface), /* class_size */
54 g_drive_base_init, /* base_init */
55 NULL, /* base_finalize */
57 NULL, /* class_finalize */
58 NULL, /* class_data */
65 g_type_register_static (G_TYPE_INTERFACE, I_("GDrive"),
68 g_type_interface_add_prerequisite (drive_type, G_TYPE_OBJECT);
75 g_drive_class_init (gpointer g_class,
81 g_drive_base_init (gpointer g_class)
83 static gboolean initialized = FALSE;
89 * @volume: a #GVolume.
91 * Emitted when the drive's state has changed.
94 g_signal_new (I_("changed"),
97 G_STRUCT_OFFSET (GDriveIface, changed),
99 g_cclosure_marshal_VOID__VOID,
110 * Gets the name of @drive.
112 * Returns: a string containing @drive's name. The returned
113 * string should be freed when no longer needed.
116 g_drive_get_name (GDrive *drive)
120 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
122 iface = G_DRIVE_GET_IFACE (drive);
124 return (* iface->get_name) (drive);
131 * Gets the icon for @drive.
133 * Returns: #GIcon for the @drive.
136 g_drive_get_icon (GDrive *drive)
140 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
142 iface = G_DRIVE_GET_IFACE (drive);
144 return (* iface->get_icon) (drive);
148 * g_drive_has_volumes:
151 * Checks if a drive has any volumes.
153 * Returns: %TRUE if @drive contains volumes, %FALSE otherwise.
156 g_drive_has_volumes (GDrive *drive)
160 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
162 iface = G_DRIVE_GET_IFACE (drive);
164 return (* iface->has_volumes) (drive);
168 * g_drive_get_volumes:
171 * Gets a list of volumes for a drive.
173 * Returns: #GList containing any #GVolume<!---->s on the given @drive.
174 * NOTE: Fact-check this.
177 g_drive_get_volumes (GDrive *drive)
181 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
183 iface = G_DRIVE_GET_IFACE (drive);
185 return (* iface->get_volumes) (drive);
189 * g_drive_is_automounted:
192 * Checks if a drive was automatically mounted, e.g. by HAL.
194 * Returns: %TRUE if the drive was automounted. %FALSE otherwise.
197 g_drive_is_automounted (GDrive *drive)
201 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
203 iface = G_DRIVE_GET_IFACE (drive);
205 return (* iface->is_automounted) (drive);
212 * Checks if a drive can be mounted.
214 * Returns: %TRUE if the @drive can be mounted. %FALSE otherwise.
217 g_drive_can_mount (GDrive *drive)
221 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
223 iface = G_DRIVE_GET_IFACE (drive);
225 if (iface->can_mount == NULL)
228 return (* iface->can_mount) (drive);
233 * @drive: pointer to a #GDrive.
235 * Checks if a drive can be ejected.
237 * Returns: %TRUE if the @drive can be ejected. %FALSE otherwise.
240 g_drive_can_eject (GDrive *drive)
244 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
246 iface = G_DRIVE_GET_IFACE (drive);
248 if (iface->can_eject == NULL)
251 return (* iface->can_eject) (drive);
257 * @mount_operation: a #GMountOperation.
258 * @cancellable: optional #GCancellable object, %NULL to ignore.
259 * @callback: a #GAsyncReadyCallback.
260 * @user_data: a #gpointer.
266 g_drive_mount (GDrive *drive,
267 GMountOperation *mount_operation,
268 GCancellable *cancellable,
269 GAsyncReadyCallback callback,
274 g_return_if_fail (G_IS_DRIVE (drive));
275 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
277 iface = G_DRIVE_GET_IFACE (drive);
279 if (iface->mount == NULL)
281 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
282 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
283 _("drive doesn't implement mount"));
288 (* iface->mount) (drive, mount_operation, cancellable, callback, user_data);
292 * g_drive_mount_finish:
293 * @drive: pointer to a #GDrive.
294 * @result: a #GAsyncResult.
297 * Finishes mounting a drive.
299 * Returns: %TRUE, %FALSE if operation failed.
302 g_drive_mount_finish (GDrive *drive,
303 GAsyncResult *result,
308 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
309 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
311 if (G_IS_SIMPLE_ASYNC_RESULT (result))
313 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
314 if (g_simple_async_result_propagate_error (simple, error))
318 iface = G_DRIVE_GET_IFACE (drive);
319 return (* iface->mount_finish) (drive, result, error);
325 * @cancellable: optional #GCancellable object, %NULL to ignore.
326 * @callback: a #GAsyncReadyCallback.
327 * @user_data: a #gpointer.
333 g_drive_eject (GDrive *drive,
334 GCancellable *cancellable,
335 GAsyncReadyCallback callback,
340 g_return_if_fail (G_IS_DRIVE (drive));
342 iface = G_DRIVE_GET_IFACE (drive);
344 if (iface->eject == NULL)
346 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
347 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
348 _("drive doesn't implement eject"));
353 (* iface->eject) (drive, cancellable, callback, user_data);
357 * g_drive_eject_finish
359 * @result: a #GAsyncResult.
362 * Finishes ejecting a drive.
364 * Returns: %TRUE if the drive has been ejected successfully,
368 g_drive_eject_finish (GDrive *drive,
369 GAsyncResult *result,
374 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
375 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
377 if (G_IS_SIMPLE_ASYNC_RESULT (result))
379 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
380 if (g_simple_async_result_propagate_error (simple, error))
384 iface = G_DRIVE_GET_IFACE (drive);
386 return (* iface->mount_finish) (drive, result, error);
389 #define __G_DRIVE_C__
390 #include "gioaliasdef.c"