[empathy] chat-mgr: Use GDBus client side API



commit b941bce456bf366afcaf3304d13b9d797770b5b5
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Thu Feb 6 12:08:45 2014 +0100

    chat-mgr: Use GDBus client side API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723766

 src/Makefile.am            |    2 +
 src/empathy-chat-manager.c |   66 +++++++++++++++++++++++++++++++++----------
 2 files changed, 52 insertions(+), 16 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6f96880..25e0239 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -86,6 +86,7 @@ empathy_auth_client_SOURCES =                                         \
        $(NULL)
 
 empathy_chat_SOURCES =                                         \
+       chat-manager-interface.c chat-manager-interface.h \
        empathy-about-dialog.c empathy-about-dialog.h                   \
        empathy-chat-manager.c empathy-chat-manager.h           \
        empathy-chat-window.c empathy-chat-window.h             \
@@ -154,6 +155,7 @@ empathy_handwritten_source = \
 
 empathy_SOURCES =                                                      \
        $(empathy_handwritten_source)                                   \
+       chat-manager-interface.c chat-manager-interface.h \
        $(NULL)
 
 empathy_LDADD =                                                                \
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index b3b02c5..3e6404d 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -28,6 +28,7 @@
 #include "empathy-request-util.h"
 #include "empathy-ui-utils.h"
 #include "extensions.h"
+#include "chat-manager-interface.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include "empathy-debug.h"
@@ -535,27 +536,60 @@ svc_iface_init (gpointer g_iface,
 #undef IMPLEMENT
 }
 
-void
-empathy_chat_manager_call_undo_closed_chat (void)
+static void
+undo_closed_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
-  TpDBusDaemon *dbus_daemon = tp_dbus_daemon_dup (NULL);
-  TpProxy *proxy;
+  GError *error = NULL;
 
-  if (dbus_daemon == NULL)
-    return;
+  if (!empathy_gen_chat_manager_call_undo_closed_chat_finish (
+        EMPATHY_GEN_CHAT_MANAGER (source), result,
+        &error))
+    {
+      DEBUG ("UndoClosedChat failed: %s", error->message);
+      g_error_free (error);
+    }
+}
 
-  proxy = g_object_new (TP_TYPE_PROXY,
-      "dbus-daemon", dbus_daemon,
-      "dbus-connection", tp_proxy_get_dbus_connection (TP_PROXY (dbus_daemon)),
-      "bus-name", EMPATHY_CHAT_TP_BUS_NAME,
-      "object-path", CHAT_MANAGER_PATH,
-      NULL);
+static void
+chat_mgr_proxy_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  EmpathyGenChatManager *proxy;
+  GError *error = NULL;
+  GVariant *action_time = user_data;
 
-  tp_proxy_add_interface_by_id (proxy, EMP_IFACE_QUARK_CHAT_MANAGER);
+  proxy = empathy_gen_chat_manager_proxy_new_for_bus_finish (result, &error);
+  if (proxy == NULL)
+    {
+      DEBUG ("Failed to create ChatManager proxy: %s", error->message);
+      g_error_free (error);
+      goto finally;
+    }
 
-  emp_cli_chat_manager_call_undo_closed_chat (proxy, -1, empathy_get_current_action_time (),
-      NULL, NULL, NULL, NULL);
+  empathy_gen_chat_manager_call_undo_closed_chat (proxy,
+      g_variant_get_int64 (action_time), NULL, undo_closed_cb, NULL);
 
   g_object_unref (proxy);
-  g_object_unref (dbus_daemon);
+
+finally:
+  g_variant_unref (action_time);
+}
+
+void
+empathy_chat_manager_call_undo_closed_chat (void)
+{
+  gint64 action_time;
+
+  action_time = empathy_get_current_action_time ();
+
+  empathy_gen_chat_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+      G_DBUS_PROXY_FLAGS_NONE, EMPATHY_CHAT_TP_BUS_NAME, CHAT_MANAGER_PATH,
+      NULL, chat_mgr_proxy_cb,
+      /* We can't use GINT_TO_POINTER as we won't be able to store a 64 bits
+       * integer on a 32 bits plateform. Use a GVariant for its convenient
+       * API. */
+      g_variant_new_int64 (action_time));
 }


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