]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-utils.c
factor out empathy_connect_new_account
[empathy.git] / libempathy / empathy-utils.c
index fedb14b9893562049c12293c332841f415ab2a7c..7d169ff94d55d1c465e432c17f4ada1a042e3152 100644 (file)
@@ -606,3 +606,40 @@ empathy_account_manager_get_accounts_connected (gboolean *connecting)
 
   return out_connected;
 }
+
+/* Change the RequestedPresence of a newly created account to ensure that it
+ * is actually connected. */
+void
+empathy_connect_new_account (TpAccount *account,
+    TpAccountManager *account_manager)
+{
+  TpConnectionPresenceType presence;
+  gchar *status, *message;
+
+  /* only force presence if presence was offline, unknown or unset */
+  presence = tp_account_get_requested_presence (account, NULL, NULL);
+  switch (presence)
+    {
+      case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
+      case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
+      case TP_CONNECTION_PRESENCE_TYPE_UNSET:
+        presence = tp_account_manager_get_most_available_presence (
+            account_manager, &status, &message);
+
+        if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
+          /* Global presence is offline; we force it so user doesn't have to
+           * manually change the presence to connect his new account. */
+          presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+
+        tp_account_request_presence_async (account, presence,
+            status, NULL, NULL, NULL);
+
+        g_free (status);
+        g_free (message);
+        break;
+
+       default:
+        /* do nothing if the presence is not offline */
+        break;
+    }
+}