X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=src%2Fempathy-accounts.c;h=9788e11d599847083788f6b2ab4bb0f78c080b1e;hp=3cad967448c9e44f8a45034d38c0daf225de1c05;hb=6598a3c9d90ce78fd2fd641ca552840742756dfb;hpb=f8148be971e1b51e43374473ab33e5ac8fd14a40 diff --git a/src/empathy-accounts.c b/src/empathy-accounts.c index 3cad9674..9788e11d 100644 --- a/src/empathy-accounts.c +++ b/src/empathy-accounts.c @@ -24,68 +24,60 @@ * Travis Reitter */ -#include - -#include -#include +#include "config.h" +#include "empathy-accounts.h" -#include #include +#include -#include -#include -#include +#ifdef HAVE_CHEESE +#include +#endif -#include -#include -#include - -#include "empathy-accounts.h" #include "empathy-accounts-common.h" -#include "empathy-accounts-dialog.h" -#include "empathy-account-assistant.h" -#include "empathy-auto-salut-account-helper.h" +#include "empathy-bus-names.h" +#include "empathy-ui-utils.h" +#include "empathy-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT -#include - -#define EMPATHY_ACCOUNTS_DBUS_NAME "org.gnome.EmpathyAccounts" +#include "empathy-debug.h" static gboolean only_if_needed = FALSE; static gboolean hidden = FALSE; static gchar *selected_account_name = NULL; -static gboolean account_manager_prepared = FALSE; -static gboolean assistant = FALSE; static void -account_prepare_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +maybe_show_accounts_ui (TpAccountManager *manager, + GApplication *app) { - TpAccountManager *manager = TP_ACCOUNT_MANAGER (user_data); - TpAccount *account = TP_ACCOUNT (source_object); - GError *error = NULL; + if (hidden) + return; - if (!tp_proxy_prepare_finish (account, result, &error)) - { - DEBUG ("Failed to prepare account: %s", error->message); - g_error_free (error); - - account = NULL; - } + if (only_if_needed && empathy_accounts_has_non_salut_accounts (manager)) + return; - empathy_accounts_show_accounts_ui (manager, account, assistant, - G_CALLBACK (gtk_main_quit)); + empathy_accounts_show_accounts_ui (manager, NULL, app); } -static void -maybe_show_accounts_ui (TpAccountManager *manager) +static TpAccount * +find_account (TpAccountManager *mgr, + const gchar *path) { - if (hidden || - (only_if_needed && empathy_accounts_has_non_salut_accounts (manager))) - gtk_main_quit (); - else - empathy_accounts_show_accounts_ui (manager, NULL, assistant, gtk_main_quit); + GList *accounts, *l; + TpAccount *found = NULL; + + accounts = tp_account_manager_dup_valid_accounts (mgr); + for (l = accounts; l != NULL; l = g_list_next (l)) + { + if (!tp_strdiff (tp_proxy_get_object_path (l->data), path)) + { + found = l->data; + break; + } + } + + g_list_free_full (accounts, g_object_unref); + return found; } static void @@ -95,21 +87,19 @@ account_manager_ready_for_accounts_cb (GObject *source_object, { TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); GError *error = NULL; + GApplication *app = G_APPLICATION (user_data); if (!tp_proxy_prepare_finish (manager, result, &error)) { DEBUG ("Failed to prepare account manager: %s", error->message); g_clear_error (&error); - return; + goto out; } - account_manager_prepared = TRUE; - if (selected_account_name != NULL) { gchar *account_path; - TpAccount *account = NULL; - TpDBusDaemon *bus; + TpAccount *account; /* create and prep the corresponding TpAccount so it's fully ready by the * time we try to select it in the accounts dialog */ @@ -119,51 +109,48 @@ account_manager_ready_for_accounts_cb (GObject *source_object, account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, selected_account_name); - bus = tp_dbus_daemon_dup (NULL); - if ((account = tp_account_new (bus, account_path, &error))) + account = find_account (manager, account_path); + + if (account != NULL) { - tp_proxy_prepare_async (account, NULL, account_prepare_cb, manager); - g_object_unref (bus); - return; + empathy_accounts_show_accounts_ui (manager, account, app); + goto out; } else { - DEBUG ("Failed to find account with path %s: %s", account_path, - error->message); + DEBUG ("Failed to find account with path %s", account_path); + g_clear_error (&error); - maybe_show_accounts_ui (manager); + maybe_show_accounts_ui (manager, app); } - g_object_unref (bus); g_free (account_path); } else { - maybe_show_accounts_ui (manager); + maybe_show_accounts_ui (manager, app); } + +out: + g_application_release (app); } -static int -app_command_line_cb (GApplication *app, - GApplicationCommandLine *cmdline) +static void +app_activate (GApplication *app) { - g_application_hold (app); + TpAccountManager *account_manager; - /* if the window is ready, present it; otherwise, it will be presented when - * the accounts manager is prepared */ - if (account_manager_prepared) - { - TpAccountManager *account_manager; + empathy_gtk_init (); + account_manager = tp_account_manager_dup (); - account_manager = tp_account_manager_dup (); - empathy_accounts_show_accounts_ui (account_manager, NULL, assistant, - G_CALLBACK (gtk_main_quit)); + /* Hold the application while preparing the AM */ + g_application_hold (app); - g_object_unref (account_manager); - } + tp_proxy_prepare_async (account_manager, NULL, + account_manager_ready_for_accounts_cb, app); - return 0; + g_object_unref (account_manager); } static gboolean @@ -174,7 +161,7 @@ local_cmdline (GApplication *app, gint i; gchar **argv; gint argc = 0; - gboolean retval = FALSE; + gboolean retval = TRUE; GError *error = NULL; GOptionContext *optcontext; @@ -192,17 +179,14 @@ local_cmdline (GApplication *app, N_("Initially select given account (eg, " "gabble/jabber/foo_40example_2eorg0)"), N_("") }, - { "assistant", 'a', - 0, G_OPTION_ARG_NONE, &assistant, - N_("Show account assistant"), - NULL }, { NULL } }; optcontext = g_option_context_new (N_("- Empathy Accounts")); - g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); + g_option_context_add_group (optcontext, gtk_get_option_group (FALSE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); + g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE); argv = *arguments; for (i = 0; argv[i] != NULL; i++) @@ -213,9 +197,22 @@ local_cmdline (GApplication *app, g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n", error->message, argv[0]); g_warning ("Error in empathy init: %s", error->message); + g_clear_error (&error); *exit_status = EXIT_FAILURE; - retval = TRUE; + } + else + { + if (g_application_register (app, NULL, &error)) + { + g_application_activate (app); + } + else + { + g_warning ("Impossible to register empathy-application: %s", error->message); + g_clear_error (&error); + *exit_status = EXIT_FAILURE; + } } g_option_context_free (optcontext); @@ -223,45 +220,36 @@ local_cmdline (GApplication *app, return retval; } -#define COMMAND_ACCOUNTS_DIALOG 1 - int main (int argc, char *argv[]) { - TpAccountManager *account_manager; GtkApplication *app; GObjectClass *app_class; gint retval; - g_thread_init (NULL); - empathy_init (); + g_type_init (); - gtk_init (&argc, &argv); - empathy_gtk_init (); +#ifdef HAVE_CHEESE + /* Used by the avatar chooser */ + g_return_val_if_fail (cheese_gtk_init (&argc, &argv), 1); +#endif + empathy_init (); + + textdomain (GETTEXT_PACKAGE); g_set_application_name (_("Empathy Accounts")); /* Make empathy and empathy-accounts appear as the same app in gnome-shell */ gdk_set_program_class ("Empathy"); gtk_window_set_default_icon_name ("empathy"); - textdomain (GETTEXT_PACKAGE); - app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME, - G_APPLICATION_HANDLES_COMMAND_LINE); + app = gtk_application_new (EMPATHY_ACCOUNTS_BUS_NAME, G_APPLICATION_FLAGS_NONE); app_class = G_OBJECT_GET_CLASS (app); G_APPLICATION_CLASS (app_class)->local_command_line = local_cmdline; - - account_manager = tp_account_manager_dup (); - - tp_proxy_prepare_async (account_manager, NULL, - account_manager_ready_for_accounts_cb, NULL); - - g_signal_connect (app, "command-line", G_CALLBACK (app_command_line_cb), - NULL); + G_APPLICATION_CLASS (app_class)->activate = app_activate; retval = g_application_run (G_APPLICATION (app), argc, argv); - g_object_unref (account_manager); g_object_unref (app); return retval;