#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"
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
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 (!tp_account_prepare_finish (account, result, &error))
- {
- DEBUG ("Failed to prepare account: %s", error->message);
- g_error_free (error);
+ if (hidden)
+ return;
- account = NULL;
- }
+ if (only_if_needed && empathy_accounts_has_non_salut_accounts (manager))
+ return;
- empathy_accounts_show_accounts_ui (manager, account,
- G_CALLBACK (gtk_main_quit));
+ empathy_accounts_show_accounts_ui (manager, NULL, assistant, 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, gtk_main_quit);
+ GList *accounts, *l;
+ TpAccount *found = NULL;
+
+ accounts = tp_account_manager_get_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 (accounts);
+ return found;
}
static void
gpointer user_data)
{
TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
- const gchar *account_id = (const gchar*) user_data;
GError *error = NULL;
+ GApplication *app = G_APPLICATION (user_data);
- if (!tp_account_manager_prepare_finish (manager, result, &error))
+ if (!tp_proxy_prepare_finish (manager, result, &error))
{
DEBUG ("Failed to prepare account manager: %s", error->message);
g_clear_error (&error);
- return;
+ goto out;
}
- if (account_id != NULL)
+ 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 */
- account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE,
- account_id);
- bus = tp_dbus_daemon_dup (NULL);
- if ((account = tp_account_new (bus, account_path, &error)))
+ if (g_str_has_prefix (selected_account_name, TP_ACCOUNT_OBJECT_PATH_BASE))
+ account_path = g_strdup (selected_account_name);
+ else
+ account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE,
+ selected_account_name);
+
+ account = find_account (manager, account_path);
+
+ if (account != NULL)
{
- tp_account_prepare_async (account, NULL, account_prepare_cb, manager);
- return;
+ empathy_accounts_show_accounts_ui (manager, account, assistant, 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, app);
}
- g_object_unref (bus);
g_free (account_path);
}
else
{
- maybe_show_accounts_ui (manager);
- account_manager_prepared = TRUE;
+ maybe_show_accounts_ui (manager, app);
}
+
+out:
+ g_application_release (app);
}
static int
app_command_line_cb (GApplication *app,
GApplicationCommandLine *cmdline)
{
- gchar **argv;
- gint argc;
-
- g_application_hold (app);
-
- argv = g_application_command_line_get_arguments (cmdline, &argc);
+ 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;
+ account_manager = tp_account_manager_dup ();
- account_manager = tp_account_manager_dup ();
- empathy_accounts_show_accounts_ui (account_manager, NULL,
- 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);
- g_strfreev (argv);
+ g_object_unref (account_manager);
return 0;
}
N_("Initially select given account (eg, "
"gabble/jabber/foo_40example_2eorg0)"),
N_("<account-id>") },
+ { "assistant", 'a',
+ 0, G_OPTION_ARG_NONE, &assistant,
+ N_("Show account assistant"),
+ NULL },
{ NULL }
};
return retval;
}
-#define COMMAND_ACCOUNTS_DIALOG 1
-
int
main (int argc, char *argv[])
{
- TpAccountManager *account_manager;
GtkApplication *app;
GObjectClass *app_class;
gint retval;
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_class = G_OBJECT_GET_CLASS (app);
G_APPLICATION_CLASS (app_class)->local_command_line = local_cmdline;
- account_manager = tp_account_manager_dup ();
-
- tp_account_manager_prepare_async (account_manager, NULL,
- account_manager_ready_for_accounts_cb, selected_account_name);
-
g_signal_connect (app, "command-line", G_CALLBACK (app_command_line_cb),
NULL);
retval = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (account_manager);
g_object_unref (app);
return retval;