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"
28 static void g_drive_base_init (gpointer g_class);
29 static void g_drive_class_init (gpointer g_class,
33 g_drive_get_type (void)
35 static GType drive_type = 0;
39 static const GTypeInfo drive_info =
41 sizeof (GDriveIface), /* class_size */
42 g_drive_base_init, /* base_init */
43 NULL, /* base_finalize */
45 NULL, /* class_finalize */
46 NULL, /* class_data */
53 g_type_register_static (G_TYPE_INTERFACE, I_("GDrive"),
56 g_type_interface_add_prerequisite (drive_type, G_TYPE_OBJECT);
63 g_drive_class_init (gpointer g_class,
69 g_drive_base_init (gpointer g_class)
71 static gboolean initialized = FALSE;
75 g_signal_new (I_("changed"),
78 G_STRUCT_OFFSET (GDriveIface, changed),
80 g_cclosure_marshal_VOID__VOID,
91 * Returns: string containing @drive's name.
93 * The returned string should be freed when no longer needed
96 g_drive_get_name (GDrive *drive)
100 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
102 iface = G_DRIVE_GET_IFACE (drive);
104 return (* iface->get_name) (drive);
111 * Gets the icon for @drive.
113 * Returns: #GIcon for the @drive.
116 g_drive_get_icon (GDrive *drive)
120 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
122 iface = G_DRIVE_GET_IFACE (drive);
124 return (* iface->get_icon) (drive);
128 * g_drive_has_volumes:
131 * Returns: %TRUE if @drive contains volumes, %FALSE otherwise.
134 g_drive_has_volumes (GDrive *drive)
138 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
140 iface = G_DRIVE_GET_IFACE (drive);
142 return (* iface->has_volumes) (drive);
146 * g_drive_get_volumes:
149 * Returns: #GList containing any #GVolume s on the given @drive.
150 * NOTE: Fact-check this.
153 g_drive_get_volumes (GDrive *drive)
157 g_return_val_if_fail (G_IS_DRIVE (drive), NULL);
159 iface = G_DRIVE_GET_IFACE (drive);
161 return (* iface->get_volumes) (drive);
165 * g_drive_is_automounted:
168 * Returns: %TRUE if the drive was automounted. %FALSE otherwise.
171 g_drive_is_automounted (GDrive *drive)
175 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
177 iface = G_DRIVE_GET_IFACE (drive);
179 return (* iface->is_automounted) (drive);
186 * Returns: %TRUE if the @drive can be mounted. %FALSE otherwise.
189 g_drive_can_mount (GDrive *drive)
193 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
195 iface = G_DRIVE_GET_IFACE (drive);
197 if (iface->can_mount == NULL)
200 return (* iface->can_mount) (drive);
205 * @drive: pointer to a #GDrive.
207 * Returns: %TRUE if the @drive can be ejected. %FALSE otherwise.
210 g_drive_can_eject (GDrive *drive)
214 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
216 iface = G_DRIVE_GET_IFACE (drive);
218 if (iface->can_eject == NULL)
221 return (* iface->can_eject) (drive);
227 * @mount_operation: a #GMountOperation.
228 * @callback: a #GAsyncReadyCallback.
229 * @user_data: a #gpointer.
234 g_drive_mount (GDrive *drive,
235 GMountOperation *mount_operation,
236 GCancellable *cancellable,
237 GAsyncReadyCallback callback,
242 g_return_if_fail (G_IS_DRIVE (drive));
243 g_return_if_fail (G_IS_MOUNT_OPERATION (mount_operation));
245 iface = G_DRIVE_GET_IFACE (drive);
247 if (iface->mount == NULL)
249 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
250 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
251 _("drive doesn't implement mount"));
256 (* iface->mount) (drive, mount_operation, cancellable, callback, user_data);
260 * g_drive_mount_finish:
261 * @drive: pointer to a #GDrive.
262 * @result: a #GAsyncResult.
265 * Returns: %TRUE, %FALSE if operation failed.
268 g_drive_mount_finish (GDrive *drive,
269 GAsyncResult *result,
274 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
275 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
277 if (G_IS_SIMPLE_ASYNC_RESULT (result))
279 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
280 if (g_simple_async_result_propagate_error (simple, error))
284 iface = G_DRIVE_GET_IFACE (drive);
285 return (* iface->mount_finish) (drive, result, error);
291 * @callback: a #GAsyncReadyCallback.
292 * @user_data: a #gpointer.
296 g_drive_eject (GDrive *drive,
297 GCancellable *cancellable,
298 GAsyncReadyCallback callback,
303 g_return_if_fail (G_IS_DRIVE (drive));
305 iface = G_DRIVE_GET_IFACE (drive);
307 if (iface->eject == NULL)
309 g_simple_async_report_error_in_idle (G_OBJECT (drive), callback, user_data,
310 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
311 _("drive doesn't implement eject"));
316 (* iface->eject) (drive, cancellable, callback, user_data);
320 * g_drive_eject_finish
322 * @result: a #GAsyncResult.
325 * Returns: %TRUE if the drive has been ejected successfully,
329 g_drive_eject_finish (GDrive *drive,
330 GAsyncResult *result,
335 g_return_val_if_fail (G_IS_DRIVE (drive), FALSE);
336 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
338 if (G_IS_SIMPLE_ASYNC_RESULT (result))
340 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
341 if (g_simple_async_result_propagate_error (simple, error))
345 iface = G_DRIVE_GET_IFACE (drive);
347 return (* iface->mount_finish) (drive, result, error);