From 8254654ccb030f05cd72f1c011d02c4de8816589 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 1 Mar 2010 18:25:19 +0000 Subject: Also potentially popup the account dialog when activate by libunique --- src/empathy.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/empathy.c b/src/empathy.c index 2cc5a9f28..1b5ad7200 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -85,6 +85,10 @@ static gboolean start_hidden = FALSE; static gboolean no_connect = FALSE; +static void account_manager_ready_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data); + static void dispatch_cb (EmpathyDispatcher *dispatcher, EmpathyDispatchOperation *operation, @@ -262,6 +266,7 @@ unique_app_message_cb (UniqueApp *unique_app, gpointer user_data) { GtkWindow *window = user_data; + TpAccountManager *account_manager; DEBUG ("Other instance launched, presenting the main window. " "Command=%d, timestamp %u", command, timestamp); @@ -281,6 +286,11 @@ unique_app_message_cb (UniqueApp *unique_app, gtk_window_present_with_time (GTK_WINDOW (window), timestamp); gtk_window_set_skip_taskbar_hint (window, FALSE); + account_manager = tp_account_manager_dup (); + tp_account_manager_prepare_async (account_manager, NULL, + account_manager_ready_cb, NULL); + g_object_unref (account_manager); + return UNIQUE_RESPONSE_OK; } -- cgit v1.2.3 From 8fb1b3a30ee4a9bc98087781cd6651cab8c4c96d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 1 Mar 2010 18:28:24 +0000 Subject: Only launch empathy-accounts if needed --- src/empathy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/empathy.c b/src/empathy.c index 1b5ad7200..ef2f2106e 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -69,6 +69,8 @@ #include #include "empathy-main-window.h" +#include "empathy-import-mc4-accounts.h" +#include "empathy-accounts-common.h" #include "empathy-accounts-dialog.h" #include "empathy-status-icon.h" #include "empathy-call-window.h" @@ -380,7 +382,11 @@ 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); - show_accounts_ui (gdk_screen_get_default (), TRUE); + /* Pop up the accounts dialog if it's needed (either when we don't have any + * non-salut accounts yet or when we haven't imported mc4 accounts yet */ + if (!empathy_accounts_has_non_salut_accounts (manager) + || !empathy_import_mc4_has_imported ()) + show_accounts_ui (gdk_screen_get_default (), TRUE); g_object_unref (idle); g_object_unref (connectivity); -- cgit v1.2.3 From 886357ee6af17fe37523337209a09aa6f3112604 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 1 Mar 2010 18:32:28 +0000 Subject: Always popup the accounts wizard if we don't have salut accounts --- src/cc-empathy-accounts-page.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cc-empathy-accounts-page.c b/src/cc-empathy-accounts-page.c index 15c7e5689..bf4d46af7 100644 --- a/src/cc-empathy-accounts-page.c +++ b/src/cc-empathy-accounts-page.c @@ -89,7 +89,9 @@ connection_managers_prepare (GObject *source, page_pack_with_accounts_dialog (page); - if (empathy_accounts_import (account_mgr, cm_mgr)) + empathy_accounts_import (account_mgr, cm_mgr); + + if (!empathy_accounts_has_non_salut_accounts (account_mgr)) empathy_account_assistant_show (NULL, cm_mgr); out: -- cgit v1.2.3 From b0de7c5d5d8c93dd7b74a77b4892c331f37f5441 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 1 Mar 2010 18:59:38 +0000 Subject: Make the empathy-account code be slightly more streamlined On every run of the accounts UI we should try to import MC4 accounts (if they weren't imported already). Also replace the --try-import option with --if-needed to better document the fact that it will only display the UI if needed. --- src/empathy-accounts-common.c | 56 +--------------------------- src/empathy-accounts-common.h | 4 -- src/empathy-accounts-dialog.c | 6 +-- src/empathy-accounts-dialog.h | 2 +- src/empathy-accounts.c | 85 ++++++++++++++++++++++++------------------- src/empathy.c | 5 ++- 6 files changed, 55 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-common.c b/src/empathy-accounts-common.c index cf730fab2..ff9c8c438 100644 --- a/src/empathy-accounts-common.c +++ b/src/empathy-accounts-common.c @@ -111,7 +111,7 @@ do_show_accounts_ui (TpAccountManager *manager, gtk_window_present (GTK_WINDOW (accounts_window)); } -static GtkWidget* +static GtkWidget * show_account_assistant (EmpathyConnectionManagers *connection_mgrs, GCallback assistant_destroy_cb) { @@ -124,60 +124,6 @@ show_account_assistant (EmpathyConnectionManagers *connection_mgrs, return assistant; } -static void -connection_managers_prepare_cb ( - EmpathyConnectionManagers *cm_mgr, - GAsyncResult *result, - gpointer user_data) -{ - GCallback assistant_destroy_cb = g_object_get_data (G_OBJECT (cm_mgr), - "assistant-destroy-callback"); - TpAccountManager *account_mgr = g_object_get_data (G_OBJECT (cm_mgr), - "account-manager"); - gboolean hidden = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (cm_mgr), - "hidden")); - - if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL)) - goto out; - - if (empathy_accounts_import (account_mgr, cm_mgr) && - !hidden) - { - show_account_assistant (cm_mgr, assistant_destroy_cb); - } - else if (!empathy_accounts_has_non_salut_accounts (account_mgr)) - { - show_account_assistant (cm_mgr, assistant_destroy_cb); - } - else - { - if (assistant_destroy_cb) - assistant_destroy_cb (); - } - -out: - g_object_unref (cm_mgr); -} - -void -empathy_accounts_manager_ready_for_show_assistant ( - TpAccountManager *account_mgr, - gboolean hidden) -{ - EmpathyConnectionManagers *cm_mgr; - - cm_mgr = empathy_connection_managers_dup_singleton (); - - g_object_set_data (G_OBJECT (cm_mgr), "assistant-destroy-callback", - g_object_get_data (G_OBJECT (account_mgr), "assistant-destroy-callback")); - g_object_set_data_full (G_OBJECT (cm_mgr), "account-manager", - g_object_ref (account_mgr), g_object_unref); - g_object_set_data (G_OBJECT (cm_mgr), "hidden", GUINT_TO_POINTER (hidden)); - - empathy_connection_managers_prepare_async (cm_mgr, - (GAsyncReadyCallback) connection_managers_prepare_cb, NULL); -} - static void connection_managers_prepare_for_accounts (GObject *source, GAsyncResult *result, diff --git a/src/empathy-accounts-common.h b/src/empathy-accounts-common.h index 6782d77e2..c8e5c654c 100644 --- a/src/empathy-accounts-common.h +++ b/src/empathy-accounts-common.h @@ -28,10 +28,6 @@ void empathy_accounts_show_accounts_ui (TpAccountManager *manager, TpAccount *account, GCallback window_destroyed_cb); -void empathy_accounts_manager_ready_for_show_assistant ( - TpAccountManager *account_mgr, - gboolean hidden); - gboolean empathy_accounts_import (TpAccountManager *account_mgr, EmpathyConnectionManagers *cm_mgr); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 1256a1758..c300065f9 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -2229,7 +2229,7 @@ empathy_accounts_dialog_show_application (GdkScreen *screen, GChildWatchFunc application_exit_cb, gpointer user_data, TpAccount *selected_account, - gboolean try_import, + gboolean if_needed, gboolean hidden) { gint command_pid; @@ -2265,8 +2265,8 @@ empathy_accounts_dialog_show_application (GdkScreen *screen, argv[i++] = account_option; } - if (try_import) - argv[i++] = "--import"; + if (if_needed) + argv[i++] = "--if-needed"; if (hidden) argv[i++] = "--hidden"; diff --git a/src/empathy-accounts-dialog.h b/src/empathy-accounts-dialog.h index dd9cd7d55..c171e3d24 100644 --- a/src/empathy-accounts-dialog.h +++ b/src/empathy-accounts-dialog.h @@ -60,7 +60,7 @@ void empathy_accounts_dialog_show_application (GdkScreen *screen, GChildWatchFunc application_exit_cb, gpointer user_data, TpAccount *selected_account, - gboolean try_import, + gboolean if_needed, gboolean hidden); G_END_DECLS diff --git a/src/empathy-accounts.c b/src/empathy-accounts.c index 942f6a475..f924acc73 100644 --- a/src/empathy-accounts.c +++ b/src/empathy-accounts.c @@ -53,50 +53,58 @@ #define EMPATHY_ACCOUNTS_DBUS_NAME "org.gnome.EmpathyAccounts" -static gboolean try_import = FALSE; +static gboolean only_if_needed = FALSE; static gboolean hidden = FALSE; static gchar *selected_account_name = NULL; static void -account_manager_ready_for_assistant_cb (GObject *source_object, +account_prepare_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { - TpAccountManager *account_mgr = TP_ACCOUNT_MANAGER (source_object); + TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data); + TpAccount *account = TP_ACCOUNT (source_object); GError *error = NULL; - if (!tp_account_manager_prepare_finish (account_mgr, result, &error)) + if (!tp_account_prepare_finish (account, result, &error)) { - DEBUG ("Failed to prepare account manager: %s", error->message); + DEBUG ("Failed to prepare account: %s", error->message); g_error_free (error); - return; + + account = NULL; } - g_object_set_data (G_OBJECT (account_mgr), "assistant-destroy-callback", + empathy_accounts_show_accounts_ui (manager, account, G_CALLBACK (gtk_main_quit)); +} - empathy_accounts_manager_ready_for_show_assistant (account_mgr, hidden); +static void +maybe_show_accounts_ui (TpAccountManager *manager) +{ + if (hidden || + (only_if_needed && empathy_accounts_has_non_salut_accounts (manager))) + gtk_main_quit (); + else + empathy_accounts_show_accounts_ui (manager, NULL, gtk_main_quit); } static void -account_prepare_cb (GObject *source_object, +cm_manager_prepared_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data); - TpAccount *account = TP_ACCOUNT (source_object); - GError *error = NULL; - - if (!tp_account_prepare_finish (account, result, &error)) + if (!empathy_connection_managers_prepare_finish ( + EMPATHY_CONNECTION_MANAGERS (source), result, NULL)) { - DEBUG ("Failed to prepare account: %s", error->message); - g_error_free (error); - - account = NULL; + g_warning ("Failed to prepare connection managers singleton"); + gtk_main_quit (); + return; } - empathy_accounts_show_accounts_ui (manager, account, - G_CALLBACK (gtk_main_quit)); + empathy_accounts_import (TP_ACCOUNT_MANAGER (user_data), + EMPATHY_CONNECTION_MANAGERS (source)); + + maybe_show_accounts_ui (TP_ACCOUNT_MANAGER (user_data)); } static void @@ -115,7 +123,7 @@ account_manager_ready_for_accounts_cb (GObject *source_object, return; } - if (account_id) + if (account_id != NULL) { gchar *account_path; TpAccount *account = NULL; @@ -143,8 +151,18 @@ account_manager_ready_for_accounts_cb (GObject *source_object, } else { - empathy_accounts_show_accounts_ui (manager, NULL, - G_CALLBACK (gtk_main_quit)); + if (empathy_import_mc4_has_imported ()) + { + maybe_show_accounts_ui (manager); + } + else + { + EmpathyConnectionManagers *cm_mgr = + empathy_connection_managers_dup_singleton (); + + empathy_connection_managers_prepare_async ( + cm_mgr, cm_manager_prepared_cb, manager); + } } } @@ -191,15 +209,14 @@ main (int argc, char *argv[]) GOptionContext *optcontext; GOptionEntry options[] = { - { "import", 'i', - G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &try_import, - N_("Try to import any recognized accounts and display an assistant if " - "that fails"), - NULL }, { "hidden", 'h', 0, G_OPTION_ARG_NONE, &hidden, N_("Don't display any dialogs; do any work (eg, importing) and exit"), NULL }, + { "if-needed", 'n', + 0, G_OPTION_ARG_NONE, &only_if_needed, + N_("Don't display any dialogs if there are any non-salut accounts"), + NULL }, { "select-account", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name, N_("Initially select given account (eg, " @@ -264,16 +281,8 @@ main (int argc, char *argv[]) account_manager = tp_account_manager_dup (); - if (try_import) - { - tp_account_manager_prepare_async (account_manager, NULL, - account_manager_ready_for_assistant_cb, NULL); - } - else - { - tp_account_manager_prepare_async (account_manager, NULL, - account_manager_ready_for_accounts_cb, selected_account_name); - } + tp_account_manager_prepare_async (account_manager, NULL, + account_manager_ready_for_accounts_cb, selected_account_name); g_signal_connect (unique_app, "message-received", G_CALLBACK (unique_app_message_cb), NULL); diff --git a/src/empathy.c b/src/empathy.c index ef2f2106e..b0c731a4b 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -254,10 +254,11 @@ accounts_application_exited_cb (GPid pid, static void show_accounts_ui (GdkScreen *screen, - gboolean try_import) + gboolean if_needed) { + g_debug ("launching accounts UI"); empathy_accounts_dialog_show_application (screen, - accounts_application_exited_cb, NULL, NULL, try_import, start_hidden); + accounts_application_exited_cb, NULL, NULL, if_needed, start_hidden); } static UniqueResponse -- cgit v1.2.3 From 7210d151056d3c0a1b0469f7af1aee06b7805538 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Mon, 1 Mar 2010 19:01:54 +0000 Subject: Simplify empathy_accounts_import --- src/empathy-accounts-common.c | 25 ++++++------------------- src/empathy-accounts-common.h | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-common.c b/src/empathy-accounts-common.c index ff9c8c438..3032e065e 100644 --- a/src/empathy-accounts-common.c +++ b/src/empathy-accounts-common.c @@ -71,29 +71,16 @@ empathy_accounts_has_non_salut_accounts (TpAccountManager *manager) return ret; } -/* Try to import accounts from MC4 and returns TRUE if we should display the - * accounts assistant. */ -gboolean +void empathy_accounts_import (TpAccountManager *account_mgr, EmpathyConnectionManagers *cm_mgr) { - 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 (empathy_import_mc4_has_imported ()) - return FALSE; - - if (empathy_import_mc4_accounts (cm_mgr)) - return FALSE; - - if (empathy_accounts_has_non_salut_accounts (account_mgr)) - return FALSE; - - if (!should_create_salut_account (account_mgr)) - return FALSE; + g_return_if_fail (tp_account_manager_is_prepared (account_mgr, + TP_ACCOUNT_MANAGER_FEATURE_CORE)); + g_return_if_fail (empathy_connection_managers_is_ready (cm_mgr)); - return TRUE; + if (!empathy_import_mc4_has_imported ()) + empathy_import_mc4_accounts (cm_mgr); } static void diff --git a/src/empathy-accounts-common.h b/src/empathy-accounts-common.h index c8e5c654c..2bd51bf0d 100644 --- a/src/empathy-accounts-common.h +++ b/src/empathy-accounts-common.h @@ -28,7 +28,7 @@ void empathy_accounts_show_accounts_ui (TpAccountManager *manager, TpAccount *account, GCallback window_destroyed_cb); -gboolean empathy_accounts_import (TpAccountManager *account_mgr, +void empathy_accounts_import (TpAccountManager *account_mgr, EmpathyConnectionManagers *cm_mgr); -- cgit v1.2.3 From 9a9ce40c7f0a6e5fc19e035dba5c1812a9d4434a Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 2 Mar 2010 11:17:35 +0000 Subject: Improve debugging and don't use g_debug --- src/empathy-accounts-common.c | 2 +- src/empathy-accounts-dialog.c | 5 +++++ src/empathy.c | 1 - 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-common.c b/src/empathy-accounts-common.c index 3032e065e..334f3cba8 100644 --- a/src/empathy-accounts-common.c +++ b/src/empathy-accounts-common.c @@ -123,7 +123,7 @@ connection_managers_prepare_for_accounts (GObject *source, goto out; show_account_assistant (cm_mgr, assistant_destroy_cb); - g_debug ("would show the account assistant"); + DEBUG ("would show the account assistant"); out: g_object_unref (cm_mgr); diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index c300065f9..b2e21dc8d 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -2271,6 +2271,11 @@ empathy_accounts_dialog_show_application (GdkScreen *screen, if (hidden) argv[i++] = "--hidden"; + DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)", + if_needed, hidden, + selected_account == NULL ? "" : + tp_proxy_get_object_path (TP_PROXY (selected_account))); + gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &command_pid, &error); diff --git a/src/empathy.c b/src/empathy.c index b0c731a4b..2dc62943e 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -256,7 +256,6 @@ static void show_accounts_ui (GdkScreen *screen, gboolean if_needed) { - g_debug ("launching accounts UI"); empathy_accounts_dialog_show_application (screen, accounts_application_exited_cb, NULL, NULL, if_needed, start_hidden); } -- cgit v1.2.3 From 3c8e671463630b94f8238ea8caaf6a03b2165278 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 2 Mar 2010 11:17:54 +0000 Subject: Remove code that will always fail and has no use libunique will already register a unique name and we have no other dbus services so we don't need to register a unique name ourselves. Also trying to register one which is the same as what we suggest to libunique will always fail and is thus pointless --- src/empathy-accounts.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts.c b/src/empathy-accounts.c index f924acc73..b97bc4533 100644 --- a/src/empathy-accounts.c +++ b/src/empathy-accounts.c @@ -259,26 +259,6 @@ main (int argc, char *argv[]) return EXIT_SUCCESS; } - /* Take well-known name */ - dbus_daemon = tp_dbus_daemon_dup (&error); - if (error == NULL) - { - if (!tp_dbus_daemon_request_name (dbus_daemon, - EMPATHY_ACCOUNTS_DBUS_NAME, TRUE, &error)) - { - DEBUG ("Failed to request well-known name: %s", - error ? error->message : "no message"); - g_clear_error (&error); - } - g_object_unref (dbus_daemon); - } - else - { - DEBUG ("Failed to dup dbus daemon: %s", - error ? error->message : "no message"); - g_clear_error (&error); - } - account_manager = tp_account_manager_dup (); tp_account_manager_prepare_async (account_manager, NULL, -- cgit v1.2.3