[gvfs] common: add support show-unmount-progress signal to GMountOperationDBus



commit 69bdea2a55b976322c9583eafcd51468ef953a30
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jul 9 21:12:13 2012 -0400

    common: add support show-unmount-progress signal to GMountOperationDBus
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676111

 common/gmountoperationdbus.c |   49 +++++++++++++++++++++++++++++++++
 common/gmountsource.c        |   61 ++++++++++++++++++++++++++++++++++++++++++
 common/gmountsource.h        |    5 +++
 common/gvfsdaemonprotocol.h  |    1 +
 4 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/common/gmountoperationdbus.c b/common/gmountoperationdbus.c
index b192b7e..c5e251e 100644
--- a/common/gmountoperationdbus.c
+++ b/common/gmountoperationdbus.c
@@ -53,6 +53,8 @@ static void              mount_op_ask_question        (GMountOperationDBus *op_d
 						       DBusMessage         *message);
 static void              mount_op_show_processes      (GMountOperationDBus *op_dbus,
 						       DBusMessage         *message);
+static void              mount_op_show_unmount_progress (GMountOperationDBus *op_dbus,
+                                                         DBusMessage         *message);
 static void              mount_op_aborted             (GMountOperationDBus *op_dbus,
 						       DBusMessage         *message);
 
@@ -140,6 +142,10 @@ mount_op_message_function (DBusConnection  *connection,
 					G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_PROCESSES))
     mount_op_show_processes (op_dbus, message);
   else if (dbus_message_is_method_call (message,
+                                        G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
+                                        G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_UNMOUNT_PROGRESS))
+    mount_op_show_unmount_progress (op_dbus, message);
+  else if (dbus_message_is_method_call (message,
 					G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
 					G_VFS_DBUS_MOUNT_OPERATION_OP_ABORTED))
     mount_op_aborted (op_dbus, message);
@@ -407,6 +413,49 @@ mount_op_show_processes (GMountOperationDBus *op_dbus,
 }
 
 static void
+mount_op_show_unmount_progress (GMountOperationDBus *op_dbus,
+                                DBusMessage *message)
+{
+  const gchar *message_string;
+  guint64 time_left, bytes_left;
+  DBusMessage *reply;
+  DBusMessageIter iter;
+  DBusError error;
+
+  reply = NULL;
+
+  dbus_message_iter_init (message, &iter);
+  dbus_error_init (&error);
+  if (!_g_dbus_message_iter_get_args (&iter,
+                                      &error,
+                                      DBUS_TYPE_STRING, &message_string,
+                                      DBUS_TYPE_UINT64, &time_left,
+                                      DBUS_TYPE_UINT64, &bytes_left,
+                                      0))
+    {
+      reply = dbus_message_new_error (message, error.name, error.message);
+      if (reply == NULL)
+        _g_dbus_oom ();
+      if (!dbus_connection_send (op_dbus->connection, reply, NULL))
+        _g_dbus_oom ();
+      dbus_message_unref (reply);
+      dbus_error_free (&error);
+      return;
+    }
+
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    _g_dbus_oom ();
+
+  g_signal_emit_by_name (op_dbus->op, "show-unmount-progress",
+                         message_string,
+                         time_left,
+                         bytes_left);
+
+  mount_op_send_reply (op_dbus, reply);
+}
+
+static void
 mount_op_aborted (GMountOperationDBus *op_dbus,
 		  DBusMessage         *message)
 {
diff --git a/common/gmountsource.c b/common/gmountsource.c
index cf567fc..da1b1c7 100644
--- a/common/gmountsource.c
+++ b/common/gmountsource.c
@@ -931,6 +931,66 @@ op_show_processes (GMountOperation *op,
   return TRUE;
 }
 
+/* the callback from dbus -> main thread */
+static void
+show_unmount_progress_reply (DBusMessage *reply,
+                             GError      *error,
+                             gpointer     _data)
+{
+  if (error != NULL)
+    g_warning ("ShowUnmountProgress request failed: %s", error->message);
+}
+
+void
+g_mount_source_show_unmount_progress (GMountSource        *source,
+                                      const char          *message_string,
+                                      guint64              time_left,
+                                      guint64              bytes_left)
+{
+  DBusMessage *message;
+
+  /* If no dbus id specified, warn and return */
+  if (source->dbus_id[0] == 0)
+    {
+      g_warning ("No dbus id specified in the mount source, "
+                 "ignoring show-unmount-progress request");
+      return;
+    }
+
+  if (message_string == NULL)
+    message_string = "";
+
+  message = dbus_message_new_method_call (source->dbus_id,
+					  source->obj_path,
+					  G_VFS_DBUS_MOUNT_OPERATION_INTERFACE,
+					  G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_UNMOUNT_PROGRESS);
+
+  _g_dbus_message_append_args (message,
+			       DBUS_TYPE_STRING, &message_string,
+                               DBUS_TYPE_UINT64, &time_left,
+                               DBUS_TYPE_UINT64, &bytes_left,
+			       0);
+
+  /* 30 minute timeout */
+  _g_dbus_connection_call_async (NULL, message, 1000 * 60 * 30,
+				 show_unmount_progress_reply, NULL);
+  dbus_message_unref (message);
+}
+
+static void
+op_show_unmount_progress (GMountOperation *op,
+                          const char      *message,
+                          guint64          time_left,
+                          guint64          bytes_left,
+                          GMountSource    *mount_source)
+{
+  g_mount_source_show_unmount_progress (mount_source,
+                                        message,
+                                        time_left,
+                                        bytes_left);
+  g_signal_stop_emission_by_name (op, "show_unmount_progress");
+}
+
 gboolean
 g_mount_source_abort (GMountSource *source)
 {
@@ -993,6 +1053,7 @@ g_mount_source_get_operation (GMountSource *mount_source)
   g_signal_connect (op, "ask_password", (GCallback)op_ask_password, mount_source);
   g_signal_connect (op, "ask_question", (GCallback)op_ask_question, mount_source);
   g_signal_connect (op, "show_processes", (GCallback)op_show_processes, mount_source);
+  g_signal_connect (op, "show_unmount_progress", (GCallback)op_show_unmount_progress, mount_source);
   g_signal_connect (op, "aborted", (GCallback)op_aborted, mount_source);
 
   return op;
diff --git a/common/gmountsource.h b/common/gmountsource.h
index 1f973a1..6a1d2e0 100644
--- a/common/gmountsource.h
+++ b/common/gmountsource.h
@@ -125,6 +125,11 @@ gboolean     g_mount_source_show_processes_finish     (GMountSource
                                                        gboolean                  *aborted,
                                                        gint                      *choice_out);
 
+void         g_mount_source_show_unmount_progress     (GMountSource              *mount_source,
+						       const char                *message,
+                                                       guint64                    time_left,
+                                                       guint64                    bytes_left);
+
 gboolean     g_mount_source_abort                     (GMountSource              *source);
 
 gboolean     g_mount_source_is_dummy                  (GMountSource              *source);
diff --git a/common/gvfsdaemonprotocol.h b/common/gvfsdaemonprotocol.h
index 98779f7..b5d4720 100644
--- a/common/gvfsdaemonprotocol.h
+++ b/common/gvfsdaemonprotocol.h
@@ -77,6 +77,7 @@ G_BEGIN_DECLS
 #define G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_PASSWORD "askPassword"
 #define G_VFS_DBUS_MOUNT_OPERATION_OP_ASK_QUESTION "askQuestion"
 #define G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_PROCESSES "showProcesses"
+#define G_VFS_DBUS_MOUNT_OPERATION_OP_SHOW_UNMOUNT_PROGRESS "showUnmountProgress"
 #define G_VFS_DBUS_MOUNT_OPERATION_OP_ABORTED "aborted"
 
 /* Implemented by the spawner of a process, the spawned process sends the



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]