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>
21 * David Zeuthen <davidz@redhat.com>
26 #include "gmountprivate.h"
27 #include "gsimpleasyncresult.h"
34 * @short_description: mount management
36 * The #GMount interface represents user-visible mounts. Note, when
37 * porting from GnomeVFS, #GMount is the moral equivalent of
40 * Unmounting a #GMount instance is an asynchronous operation. For
41 * more information about asynchronous operations, see #GAsyncReady
42 * and #GSimpleAsyncReady. To unmount a #GMount instance, first call
43 * g_mount_unmount() with (at least) the #GMount instance and a
44 * #GAsyncReadyCallback. The callback will be fired when the
45 * operation has resolved (either with success or failure), and a
46 * #GAsyncReady structure will be passed to the callback. That
47 * callback should then call g_mount_unmount_finish() with the #GMount
48 * and the #GAsyncReady data to see if the operation was completed
49 * successfully. If an @error is present when
50 * g_mount_unmount_finish() is called, then it will be filled with any
54 static void g_mount_base_init (gpointer g_class);
55 static void g_mount_class_init (gpointer g_class,
59 g_mount_get_type (void)
61 static GType mount_type = 0;
65 static const GTypeInfo mount_info =
67 sizeof (GMountIface), /* class_size */
68 g_mount_base_init, /* base_init */
69 NULL, /* base_finalize */
71 NULL, /* class_finalize */
72 NULL, /* class_data */
79 g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
82 g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
89 g_mount_class_init (gpointer g_class,
95 g_mount_base_init (gpointer g_class)
97 static gboolean initialized = FALSE;
104 * Emitted when the mount has been changed.
106 g_signal_new (I_("changed"),
109 G_STRUCT_OFFSET (GMountIface, changed),
111 g_cclosure_marshal_VOID__VOID,
122 * Gets the root directory on @mount.
127 g_mount_get_root (GMount *mount)
131 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
133 iface = G_MOUNT_GET_IFACE (mount);
135 return (* iface->get_root) (mount);
142 * Gets the name of @mount.
144 * Returns: the name for the given @mount. The returned string should
145 * be freed when no longer needed.
148 g_mount_get_name (GMount *mount)
152 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
154 iface = G_MOUNT_GET_IFACE (mount);
156 return (* iface->get_name) (mount);
163 * Gets the icon for @mount.
168 g_mount_get_icon (GMount *mount)
172 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
174 iface = G_MOUNT_GET_IFACE (mount);
176 return (* iface->get_icon) (mount);
180 * g_mount_get_volume:
183 * Gets the volume for the @mount.
185 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
188 g_mount_get_volume (GMount *mount)
192 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
194 iface = G_MOUNT_GET_IFACE (mount);
196 return (* iface->get_volume) (mount);
203 * Gets the drive for the @mount.
205 * This is a convenience method for getting the #GVolume and then
206 * using that object to get the #GDrive.
208 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
211 g_mount_get_drive (GMount *mount)
215 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
217 iface = G_MOUNT_GET_IFACE (mount);
219 return (* iface->get_drive) (mount);
223 * g_mount_can_unmount:
226 * Checks if @mount can be mounted.
228 * Returns: %TRUE if the @mount can be unmounted.
231 g_mount_can_unmount (GMount *mount)
235 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
237 iface = G_MOUNT_GET_IFACE (mount);
239 return (* iface->can_unmount) (mount);
245 * @cancellable: optional #GCancellable object, %NULL to ignore.
246 * @callback: a #GAsyncReadyCallback.
247 * @user_data: user data passed to @callback.
249 * Unmounts a mount. This is an asynchronous operation, and is
250 * finished by calling g_mount_unmount_finish() with the @mount
251 * and #GAsyncResults data returned in the @callback.
254 g_mount_unmount (GMount *mount,
255 GCancellable *cancellable,
256 GAsyncReadyCallback callback,
261 g_return_if_fail (G_IS_MOUNT (mount));
263 iface = G_MOUNT_GET_IFACE (mount);
265 if (iface->unmount == NULL)
267 g_simple_async_report_error_in_idle (G_OBJECT (mount),
269 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
270 _("mount doesn't implement unmount"));
275 (* iface->unmount) (mount, cancellable, callback, user_data);
279 * g_mount_unmount_finish:
281 * @result: a #GAsyncResult.
282 * @error: a #GError location to store the error occuring, or %NULL to
285 * Finishes unmounting a mount. 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 mount was successfully unmounted. %FALSE otherwise.
291 g_mount_unmount_finish (GMount *mount,
292 GAsyncResult *result,
297 g_return_val_if_fail (G_IS_MOUNT (mount), 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_MOUNT_GET_IFACE (mount);
308 return (* iface->unmount_finish) (mount, result, error);
311 #define __G_MOUNT_C__
312 #include "gioaliasdef.c"