diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-01-21 22:03:06 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-01-25 22:13:39 +0800 |
commit | fcfdcc4011d7131d852d19474eb09eaa4a6e43d7 (patch) | |
tree | 13ef19f226d2ec77193e7723ad230c9eda745cd8 /src | |
parent | 54190b275f2328e9e43ccfcfafaa63177fe1018f (diff) | |
download | gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar.gz gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar.bz2 gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar.lz gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar.xz gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.tar.zst gsoc2013-empathy-fcfdcc4011d7131d852d19474eb09eaa4a6e43d7.zip |
Move all the tests checking if we should display the the assistant to a single function
We used to check that in a lot of different places. Refactor the code to make
it clearer and easier to understand.
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy.c | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/src/empathy.c b/src/empathy.c index 7bdea3be9..b18e349e6 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -188,16 +188,32 @@ has_non_salut_accounts (TpAccountManager *manager) return ret; } -static void -maybe_show_account_assistant (void) +/* Try to import accounts from MC4 and returns TRUE if we should display the + * accounts assistant. */ +static gboolean +should_show_account_assistant (TpAccountManager *account_mgr, + EmpathyConnectionManagers *cm_mgr) { - TpAccountManager *manager; - manager = tp_account_manager_dup (); + g_return_val_if_fail (tp_account_manager_is_prepared (account_mgr, + TP_ACCOUNT_MANAGER_FEATURE_CORE), FALSE); + g_return_val_if_fail (empathy_connection_managers_is_ready (cm_mgr), FALSE); - if (!has_non_salut_accounts (manager)) - empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ())); + if (empathy_import_mc4_has_imported ()) + return FALSE; - g_object_unref (manager); + if (empathy_import_mc4_accounts (cm_mgr)) + return FALSE; + + if (start_hidden) + return FALSE; + + if (has_non_salut_accounts (account_mgr)) + return FALSE; + + if (!should_create_salut_account (account_mgr)) + return FALSE; + + return TRUE; } static void @@ -205,16 +221,50 @@ connection_managers_prepare_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (source); + EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source); + TpAccountManager *account_mgr = user_data; - if (!empathy_connection_managers_prepare_finish (managers, result, NULL)) + if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL)) goto out; - if (!empathy_import_mc4_accounts (managers) && !start_hidden) - maybe_show_account_assistant (); + if (should_show_account_assistant (account_mgr, cm_mgr)) + empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ())); out: - g_object_unref (managers); + g_object_unref (cm_mgr); + g_object_unref (account_mgr); +} + +static void +account_manager_ready_for_show_assistant (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + TpAccountManager *account_mgr = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; + EmpathyConnectionManagers *cm_mgr; + + if (!tp_account_manager_prepare_finish (account_mgr, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + g_object_unref (account_mgr); + return; + } + + cm_mgr = empathy_connection_managers_dup_singleton (); + + empathy_connection_managers_prepare_async (cm_mgr, + connection_managers_prepare_cb, account_mgr); +} + +static void +maybe_show_account_assistant (void) +{ + TpAccountManager *account_mgr = tp_account_manager_dup (); + + tp_account_manager_prepare_async (account_mgr, NULL, + account_manager_ready_for_show_assistant, NULL); } static void @@ -484,19 +534,7 @@ account_manager_ready_cb (GObject *source_object, /* 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 ()) - { - EmpathyConnectionManagers *managers; - managers = empathy_connection_managers_dup_singleton (); - - empathy_connection_managers_prepare_async (managers, - connection_managers_prepare_cb, NULL); - } - else if (!start_hidden) - { - maybe_show_account_assistant (); - } + maybe_show_account_assistant (); g_object_unref (idle); g_object_unref (connectivity); |