]> git.0d.be Git - empathy.git/commitdiff
Make the set_enabled API async
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 6 Aug 2009 19:13:09 +0000 (21:13 +0200)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>
Sat, 22 Aug 2009 13:21:07 +0000 (14:21 +0100)
libempathy/empathy-account.c
libempathy/empathy-account.h

index 5a6b31f0a83fb74a738d80f604fc19be1960806f..2dd662874064d4f5a9bdeb21af63483e1392d70a 100644 (file)
@@ -132,7 +132,8 @@ empathy_account_set_property (GObject *object,
   switch (prop_id)
     {
       case PROP_ENABLED:
-        empathy_account_set_enabled (account, g_value_get_boolean (value));
+        empathy_account_set_enabled_async (account,
+            g_value_get_boolean (value), NULL, NULL);
         break;
       case PROP_UNIQUE_NAME:
         priv->unique_name = g_value_dup_string (value);
@@ -915,30 +916,58 @@ _empathy_account_set_connection (EmpathyAccount *account,
    g_object_notify (G_OBJECT (account), "connection");
 }
 
+static void
+account_enabled_set_cb (TpProxy *proxy,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  GSimpleAsyncResult *result = user_data;
+
+  if (error != NULL)
+    g_simple_async_result_set_from_error (result, (GError *) error);
+
+  g_simple_async_result_complete (result);
+  g_object_unref (result);
+}
+
+gboolean
+empathy_account_set_enabled_finish (EmpathyAccount *account,
+    GAsyncResult *result,
+    GError **error)
+{
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+          error) ||
+      !g_simple_async_result_is_valid (result, G_OBJECT (account),
+          empathy_account_set_enabled_finish))
+    return FALSE;
+
+  return TRUE;
+}
+
 void
-empathy_account_set_enabled (EmpathyAccount *account,
-    gboolean enabled)
+empathy_account_set_enabled_async (EmpathyAccount *account,
+    gboolean enabled,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
   EmpathyAccountPriv *priv = GET_PRIV (account);
   GValue value = {0, };
+  GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
+      callback, user_data, empathy_account_set_enabled_finish);
 
   if (priv->enabled == enabled)
-    return;
+    {
+      g_simple_async_result_complete_in_idle (result);
+      return;
+    }
 
   g_value_init (&value, G_TYPE_BOOLEAN);
   g_value_set_boolean (&value, enabled);
 
   tp_cli_dbus_properties_call_set (TP_PROXY (priv->account),
-    -1,
-    TP_IFACE_ACCOUNT,
-    "Enabled",
-    &value,
-    NULL,
-    NULL,
-    NULL,
-    NULL);
-
-  g_value_unset (&value);
+      -1, TP_IFACE_ACCOUNT, "Enabled", &value,
+      account_enabled_set_cb, result, NULL, G_OBJECT (account));
 }
 
 static void
index 6351c93161c3e6213e9bdf580ead22e619e4451b..f88ac43e4ca68d1d80db265a0668823e9074fea9 100644 (file)
@@ -67,8 +67,11 @@ const gchar *empathy_account_get_connection_manager (EmpathyAccount *account);
 const gchar *empathy_account_get_protocol (EmpathyAccount *account);
 const gchar *empathy_account_get_icon_name (EmpathyAccount *account);
 
-void empathy_account_set_enabled (EmpathyAccount *account,
-  gboolean enabled);
+void empathy_account_set_enabled_async (EmpathyAccount *account,
+    gboolean enabled, GAsyncReadyCallback callback, gpointer user_data);
+gboolean empathy_account_set_enabled_finish (EmpathyAccount *account,
+    GAsyncResult *result, GError **error);
+
 gboolean empathy_account_is_enabled (EmpathyAccount *account);
 
 gboolean empathy_account_is_valid (EmpathyAccount *account);