1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
23 * David Zeuthen <davidz@redhat.com>
31 #include "gmountprivate.h"
32 #include "gsimpleasyncresult.h"
39 * @short_description: Mount management
42 * The #GMount interface represents user-visible mounts. Note, when
43 * porting from GnomeVFS, #GMount is the moral equivalent of #GnomeVFSVolume.
45 * Unmounting a #GMount instance is an asynchronous operation. For
46 * more information about asynchronous operations, see #GAsyncReady
47 * and #GSimpleAsyncReady. To unmount a #GMount instance, first call
48 * g_mount_unmount() with (at least) the #GMount instance and a
49 * #GAsyncReadyCallback. The callback will be fired when the
50 * operation has resolved (either with success or failure), and a
51 * #GAsyncReady structure will be passed to the callback. That
52 * callback should then call g_mount_unmount_finish() with the #GMount
53 * and the #GAsyncReady data to see if the operation was completed
54 * successfully. If an @error is present when g_mount_unmount_finish()
55 * is called, then it will be filled with any error information.
58 static void g_mount_base_init (gpointer g_class);
59 static void g_mount_class_init (gpointer g_class,
63 g_mount_get_type (void)
65 static GType mount_type = 0;
69 static const GTypeInfo mount_info =
71 sizeof (GMountIface), /* class_size */
72 g_mount_base_init, /* base_init */
73 NULL, /* base_finalize */
75 NULL, /* class_finalize */
76 NULL, /* class_data */
83 g_type_register_static (G_TYPE_INTERFACE, I_("GMount"),
86 g_type_interface_add_prerequisite (mount_type, G_TYPE_OBJECT);
93 g_mount_class_init (gpointer g_class,
99 g_mount_base_init (gpointer g_class)
101 static gboolean initialized = FALSE;
108 * Emitted when the mount has been changed.
110 g_signal_new (I_("changed"),
113 G_STRUCT_OFFSET (GMountIface, changed),
115 g_cclosure_marshal_VOID__VOID,
126 * Gets the root directory on @mount.
131 g_mount_get_root (GMount *mount)
135 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
137 iface = G_MOUNT_GET_IFACE (mount);
139 return (* iface->get_root) (mount);
146 * Gets the name of @mount.
148 * Returns: the name for the given @mount. The returned string should
149 * be freed when no longer needed.
152 g_mount_get_name (GMount *mount)
156 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
158 iface = G_MOUNT_GET_IFACE (mount);
160 return (* iface->get_name) (mount);
167 * Gets the icon for @mount.
172 g_mount_get_icon (GMount *mount)
176 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
178 iface = G_MOUNT_GET_IFACE (mount);
180 return (* iface->get_icon) (mount);
187 * Gets the UUID for the @mount. The reference is typically based on
188 * the file system UUID for the mount in question and should be
189 * considered an opaque string. Returns %NULL if there is no UUID
192 * Returns: the UUID for @mount or %NULL if no UUID can be computed.
195 g_mount_get_uuid (GMount *mount)
199 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
201 iface = G_MOUNT_GET_IFACE (mount);
203 return (* iface->get_uuid) (mount);
207 * g_mount_get_volume:
210 * Gets the volume for the @mount.
212 * Returns: a #GVolume or %NULL if @mount is not associated with a volume.
215 g_mount_get_volume (GMount *mount)
219 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
221 iface = G_MOUNT_GET_IFACE (mount);
223 return (* iface->get_volume) (mount);
230 * Gets the drive for the @mount.
232 * This is a convenience method for getting the #GVolume and then
233 * using that object to get the #GDrive.
235 * Returns: a #GDrive or %NULL if @mount is not associated with a volume or a drive.
238 g_mount_get_drive (GMount *mount)
242 g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
244 iface = G_MOUNT_GET_IFACE (mount);
246 return (* iface->get_drive) (mount);
250 * g_mount_can_unmount:
253 * Checks if @mount can be mounted.
255 * Returns: %TRUE if the @mount can be unmounted.
258 g_mount_can_unmount (GMount *mount)
262 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
264 iface = G_MOUNT_GET_IFACE (mount);
266 return (* iface->can_unmount) (mount);
273 * Checks if @mount can be eject.
275 * Returns: %TRUE if the @mount can be ejected.
278 g_mount_can_eject (GMount *mount)
282 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
284 iface = G_MOUNT_GET_IFACE (mount);
286 return (* iface->can_eject) (mount);
292 * @cancellable: optional #GCancellable object, %NULL to ignore.
293 * @callback: a #GAsyncReadyCallback.
294 * @user_data: user data passed to @callback.
296 * Unmounts a mount. This is an asynchronous operation, and is
297 * finished by calling g_mount_unmount_finish() with the @mount
298 * and #GAsyncResults data returned in the @callback.
301 g_mount_unmount (GMount *mount,
302 GCancellable *cancellable,
303 GAsyncReadyCallback callback,
308 g_return_if_fail (G_IS_MOUNT (mount));
310 iface = G_MOUNT_GET_IFACE (mount);
312 if (iface->unmount == NULL)
314 g_simple_async_report_error_in_idle (G_OBJECT (mount),
316 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
317 _("mount doesn't implement unmount"));
322 (* iface->unmount) (mount, cancellable, callback, user_data);
326 * g_mount_unmount_finish:
328 * @result: a #GAsyncResult.
329 * @error: a #GError location to store the error occuring, or %NULL to
332 * Finishes unmounting a mount. If any errors occured during the operation,
333 * @error will be set to contain the errors and %FALSE will be returned.
335 * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
338 g_mount_unmount_finish (GMount *mount,
339 GAsyncResult *result,
344 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
345 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
347 if (G_IS_SIMPLE_ASYNC_RESULT (result))
349 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
350 if (g_simple_async_result_propagate_error (simple, error))
354 iface = G_MOUNT_GET_IFACE (mount);
355 return (* iface->unmount_finish) (mount, result, error);
362 * @cancellable: optional #GCancellable object, %NULL to ignore.
363 * @callback: a #GAsyncReadyCallback.
364 * @user_data: user data passed to @callback.
366 * Ejects a mount. This is an asynchronous operation, and is
367 * finished by calling g_mount_eject_finish() with the @mount
368 * and #GAsyncResults data returned in the @callback.
371 g_mount_eject (GMount *mount,
372 GCancellable *cancellable,
373 GAsyncReadyCallback callback,
378 g_return_if_fail (G_IS_MOUNT (mount));
380 iface = G_MOUNT_GET_IFACE (mount);
382 if (iface->eject == NULL)
384 g_simple_async_report_error_in_idle (G_OBJECT (mount),
386 G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
387 _("mount doesn't implement eject"));
392 (* iface->eject) (mount, cancellable, callback, user_data);
396 * g_mount_eject_finish:
398 * @result: a #GAsyncResult.
399 * @error: a #GError location to store the error occuring, or %NULL to
402 * Finishes ejecting a mount. If any errors occured during the operation,
403 * @error will be set to contain the errors and %FALSE will be returned.
405 * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
408 g_mount_eject_finish (GMount *mount,
409 GAsyncResult *result,
414 g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
415 g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
417 if (G_IS_SIMPLE_ASYNC_RESULT (result))
419 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
420 if (g_simple_async_result_propagate_error (simple, error))
424 iface = G_MOUNT_GET_IFACE (mount);
425 return (* iface->eject_finish) (mount, result, error);
428 #define __G_MOUNT_C__
429 #include "gioaliasdef.c"