[empathy] Move the call to empathy_idle_get_state() to once the AM is ready



commit 4a2917a052f26751f18df7865a444c001555826b
Author: Danielle Madeley <danielle madeley collabora co uk>
Date:   Mon Nov 9 20:38:32 2009 +1100

    Move the call to empathy_idle_get_state() to once the AM is ready
    
    Removes a race where the presence gets wiped because we check whether to go
    online before our connection to the AccountManager is ready.

 src/empathy.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/src/empathy.c b/src/empathy.c
index 72b691c..5fef070 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -83,6 +83,7 @@
 
 static gboolean account_dialog_only = FALSE;
 static gboolean start_hidden = FALSE;
+static gboolean no_connect = FALSE;
 
 static void
 dispatch_cb (EmpathyDispatcher *dispatcher,
@@ -642,6 +643,9 @@ account_manager_ready_cb (GObject *source_object,
 {
   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
   GError *error = NULL;
+  EmpathyIdle *idle;
+  EmpathyConnectivity *connectivity;
+  gboolean autoconnect = TRUE;
 
   if (!tp_account_manager_prepare_finish (manager, result, &error))
     {
@@ -650,6 +654,19 @@ account_manager_ready_cb (GObject *source_object,
       return;
     }
 
+  /* Autoconnect */
+  idle = empathy_idle_dup_singleton ();
+  connectivity = empathy_connectivity_dup_singleton ();
+
+  empathy_conf_get_bool (empathy_conf_get (),
+      EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
+  if (autoconnect && !no_connect &&
+      tp_connection_presence_type_cmp_availability
+          (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
+            <= 0)
+      /* if current state is Offline, then put it online */
+      empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
+
   if (should_create_salut_account (manager)
       || !empathy_import_mc4_has_imported ())
     {
@@ -857,8 +874,6 @@ main (int argc, char *argv[])
   GtkWidget *window;
   EmpathyIdle *idle;
   EmpathyConnectivity *connectivity;
-  gboolean autoconnect = TRUE;
-  gboolean no_connect = FALSE;
   GError *error = NULL;
   TpDBusDaemon *dbus_daemon;
   UniqueApp *unique_app;
@@ -974,15 +989,6 @@ main (int argc, char *argv[])
   empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
       use_conn_notify_cb, connectivity);
 
-  /* Autoconnect */
-  empathy_conf_get_bool (empathy_conf_get (),
-      EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
-  if (autoconnect && !no_connect &&
-      tp_connection_presence_type_cmp_availability
-          (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
-            <= 0)
-      empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
-
   /* account management */
   account_manager = tp_account_manager_dup ();
   tp_account_manager_prepare_async (account_manager, NULL,



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