summaryrefslogtreecommitdiff
path: root/gio/gmount.c
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-07-05 21:59:38 -0400
committerMatthias Clasen <mclasen@redhat.com>2009-07-05 21:59:38 -0400
commit99a1c47343d09ab0485c2377e5c8c53e847d84dd (patch)
tree93dba99fbd34d3780945eec38207273fd529d3dc /gio/gmount.c
parentc85ff0c75004736d5c8798e3b47a47e0fc67ac70 (diff)
downloadglib-99a1c47343d09ab0485c2377e5c8c53e847d84dd.tar.gz
Allow interaction when unmounting mounts
For details, see bug 587482. The new api: - Provide new _with_operation() variants of all unmount and eject methods - Add GMountOperation::show-processes signal - this can be used to show processes blocking an unmount operation - Deprecate all unmount and eject methods - Add g_drive_can_start_degraded() method - this is to avoid auto-starting degraded drives - Make g_drive_stop() resp. g_file_stop_mountable() take a GMountOperation - these ops were recently added and not yet public API so it's fine to change how they work - Provide a way to poll mountable files, e.g. g_file_poll_mountable() - Add some missing file attributes for mountable files - G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE_FILE - needed for the GDU Nautilus extensions to format a volume - G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START_DEGRADED: - mimics g_drive_can_start_degraded() - G_FILE_ATTRIBUTE_MOUNTABLE_CAN_POLL: - mimics g_drive_can_poll_for_media() - G_FILE_ATTRIBUTE_MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC - mimics g_drive_is_media_check_automatic()
Diffstat (limited to 'gio/gmount.c')
-rw-r--r--gio/gmount.c186
1 files changed, 183 insertions, 3 deletions
diff --git a/gio/gmount.c b/gio/gmount.c
index e4753c422..124583c51 100644
--- a/gio/gmount.c
+++ b/gio/gmount.c
@@ -53,13 +53,13 @@
* Unmounting a #GMount instance is an asynchronous operation. For
* more information about asynchronous operations, see #GAsyncReady
* and #GSimpleAsyncReady. To unmount a #GMount instance, first call
- * g_mount_unmount() with (at least) the #GMount instance and a
+ * g_mount_unmount_with_operation() with (at least) the #GMount instance and a
* #GAsyncReadyCallback. The callback will be fired when the
* operation has resolved (either with success or failure), and a
* #GAsyncReady structure will be passed to the callback. That
- * callback should then call g_mount_unmount_finish() with the #GMount
+ * callback should then call g_mount_unmount_with_operation_finish() with the #GMount
* and the #GAsyncReady data to see if the operation was completed
- * successfully. If an @error is present when g_mount_unmount_finish()
+ * successfully. If an @error is present when g_mount_unmount_with_operation_finish()
* is called, then it will be filled with any error information.
**/
@@ -351,6 +351,8 @@ g_mount_can_eject (GMount *mount)
* Unmounts a mount. This is an asynchronous operation, and is
* finished by calling g_mount_unmount_finish() with the @mount
* and #GAsyncResult data returned in the @callback.
+ *
+ * Deprecated: 2.22: Use g_mount_unmount_with_operation() instead.
**/
void
g_mount_unmount (GMount *mount,
@@ -392,6 +394,8 @@ g_mount_unmount (GMount *mount,
* @error will be set to contain the errors and %FALSE will be returned.
*
* Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
+ *
+ * Deprecated: 2.22: Use g_mount_unmount_with_operation_finish() instead.
**/
gboolean
g_mount_unmount_finish (GMount *mount,
@@ -426,6 +430,8 @@ g_mount_unmount_finish (GMount *mount,
* Ejects a mount. This is an asynchronous operation, and is
* finished by calling g_mount_eject_finish() with the @mount
* and #GAsyncResult data returned in the @callback.
+ *
+ * Deprecated: 2.22: Use g_mount_eject_with_operation() instead.
**/
void
g_mount_eject (GMount *mount,
@@ -467,6 +473,8 @@ g_mount_eject (GMount *mount,
* @error will be set to contain the errors and %FALSE will be returned.
*
* Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
+ *
+ * Deprecated: 2.22: Use g_mount_eject_with_operation_finish() instead.
**/
gboolean
g_mount_eject_finish (GMount *mount,
@@ -490,6 +498,178 @@ g_mount_eject_finish (GMount *mount,
}
/**
+ * g_mount_unmount_with_operation:
+ * @mount: a #GMount.
+ * @flags: flags affecting the operation
+ * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
+ * @cancellable: optional #GCancellable object, %NULL to ignore.
+ * @callback: a #GAsyncReadyCallback, or %NULL.
+ * @user_data: user data passed to @callback.
+ *
+ * Unmounts a mount. This is an asynchronous operation, and is
+ * finished by calling g_mount_unmount_with_operation_finish() with the @mount
+ * and #GAsyncResult data returned in the @callback.
+ *
+ * Since: 2.22
+ **/
+void
+g_mount_unmount_with_operation (GMount *mount,
+ GMountUnmountFlags flags,
+ GMountOperation *mount_operation,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GMountIface *iface;
+
+ g_return_if_fail (G_IS_MOUNT (mount));
+
+ iface = G_MOUNT_GET_IFACE (mount);
+
+ if (iface->unmount == NULL && iface->unmount_with_operation == NULL)
+ {
+ g_simple_async_report_error_in_idle (G_OBJECT (mount),
+ callback, user_data,
+ G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ /* Translators: This is an error
+ * message for mount objects that
+ * don't implement any of unmount or unmount_with_operation. */
+ _("mount doesn't implement unmount or unmount_with_operation"));
+
+ return;
+ }
+
+ if (iface->unmount_with_operation != NULL)
+ (* iface->unmount_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
+ else
+ (* iface->unmount) (mount, flags, cancellable, callback, user_data);
+}
+
+/**
+ * g_mount_unmount_with_operation_finish:
+ * @mount: a #GMount.
+ * @result: a #GAsyncResult.
+ * @error: a #GError location to store the error occuring, or %NULL to
+ * ignore.
+ *
+ * Finishes unmounting a mount. If any errors occurred during the operation,
+ * @error will be set to contain the errors and %FALSE will be returned.
+ *
+ * Returns: %TRUE if the mount was successfully unmounted. %FALSE otherwise.
+ *
+ * Since: 2.22
+ **/
+gboolean
+g_mount_unmount_with_operation_finish (GMount *mount,
+ GAsyncResult *result,
+ GError **error)
+{
+ GMountIface *iface;
+
+ g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+ if (G_IS_SIMPLE_ASYNC_RESULT (result))
+ {
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+ }
+
+ iface = G_MOUNT_GET_IFACE (mount);
+ if (iface->unmount_with_operation_finish != NULL)
+ return (* iface->unmount_with_operation_finish) (mount, result, error);
+ else
+ return (* iface->unmount_finish) (mount, result, error);
+}
+
+
+/**
+ * g_mount_eject_with_operation:
+ * @mount: a #GMount.
+ * @flags: flags affecting the unmount if required for eject
+ * @mount_operation: a #GMountOperation or %NULL to avoid user interaction.
+ * @cancellable: optional #GCancellable object, %NULL to ignore.
+ * @callback: a #GAsyncReadyCallback, or %NULL.
+ * @user_data: user data passed to @callback.
+ *
+ * Ejects a mount. This is an asynchronous operation, and is
+ * finished by calling g_mount_eject_with_operation_finish() with the @mount
+ * and #GAsyncResult data returned in the @callback.
+ *
+ * Since: 2.22
+ **/
+void
+g_mount_eject_with_operation (GMount *mount,
+ GMountUnmountFlags flags,
+ GMountOperation *mount_operation,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GMountIface *iface;
+
+ g_return_if_fail (G_IS_MOUNT (mount));
+
+ iface = G_MOUNT_GET_IFACE (mount);
+
+ if (iface->eject == NULL && iface->eject_with_operation == NULL)
+ {
+ g_simple_async_report_error_in_idle (G_OBJECT (mount),
+ callback, user_data,
+ G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ /* Translators: This is an error
+ * message for mount objects that
+ * don't implement any of eject or eject_with_operation. */
+ _("mount doesn't implement eject or eject_with_operation"));
+ return;
+ }
+
+ if (iface->eject_with_operation != NULL)
+ (* iface->eject_with_operation) (mount, flags, mount_operation, cancellable, callback, user_data);
+ else
+ (* iface->eject) (mount, flags, cancellable, callback, user_data);
+}
+
+/**
+ * g_mount_eject_with_operation_finish:
+ * @mount: a #GMount.
+ * @result: a #GAsyncResult.
+ * @error: a #GError location to store the error occuring, or %NULL to
+ * ignore.
+ *
+ * Finishes ejecting a mount. If any errors occurred during the operation,
+ * @error will be set to contain the errors and %FALSE will be returned.
+ *
+ * Returns: %TRUE if the mount was successfully ejected. %FALSE otherwise.
+ *
+ * Since: 2.22
+ **/
+gboolean
+g_mount_eject_with_operation_finish (GMount *mount,
+ GAsyncResult *result,
+ GError **error)
+{
+ GMountIface *iface;
+
+ g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+ if (G_IS_SIMPLE_ASYNC_RESULT (result))
+ {
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+ }
+
+ iface = G_MOUNT_GET_IFACE (mount);
+ if (iface->eject_with_operation_finish != NULL)
+ return (* iface->eject_with_operation_finish) (mount, result, error);
+ else
+ return (* iface->eject_finish) (mount, result, error);
+}
+
+/**
* g_mount_remount:
* @mount: a #GMount.
* @flags: flags affecting the operation