* Travis Reitter <travis.reitter@collabora.co.uk>
*/
-#include <config.h>
-
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-accounts.h"
-#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <unique/unique.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/defs.h>
-#include <telepathy-glib/util.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
+#ifdef HAVE_CHEESE
+#include <cheese-gtk.h>
+#endif
-#include "empathy-accounts.h"
#include "empathy-accounts-common.h"
-#include "empathy-accounts-dialog.h"
-#include "empathy-account-assistant.h"
-#include "empathy-import-mc4-accounts.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 <libempathy/empathy-debug.h>
-
-#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 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, 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;
-static void
-cm_manager_prepared_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- if (!empathy_connection_managers_prepare_finish (
- EMPATHY_CONNECTION_MANAGERS (source), result, NULL))
+ accounts = tp_account_manager_dup_valid_accounts (mgr);
+ for (l = accounts; l != NULL; l = g_list_next (l))
{
- g_warning ("Failed to prepare connection managers singleton");
- gtk_main_quit ();
- return;
+ if (!tp_strdiff (tp_proxy_get_object_path (l->data), path))
+ {
+ found = l->data;
+ break;
+ }
}
- empathy_accounts_import (TP_ACCOUNT_MANAGER (user_data),
- EMPATHY_CONNECTION_MANAGERS (source));
-
- maybe_show_accounts_ui (TP_ACCOUNT_MANAGER (user_data));
+ g_list_free_full (accounts, g_object_unref);
+ 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, 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
{
- 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);
- }
+ maybe_show_accounts_ui (manager, app);
}
+
+out:
+ g_application_release (app);
}
-static UniqueResponse
-unique_app_message_cb (UniqueApp *unique_app,
- gint command,
- UniqueMessageData *data,
- guint timestamp,
- gpointer user_data)
+static void
+app_activate (GApplication *app)
{
- DEBUG ("Other instance launched, presenting the main window. "
- "Command=%d, timestamp %u", command, timestamp);
-
- if (command == UNIQUE_ACTIVATE)
- {
- TpAccountManager *account_manager;
-
- account_manager = tp_account_manager_dup ();
+ TpAccountManager *account_manager;
- empathy_accounts_show_accounts_ui (account_manager, NULL,
- G_CALLBACK (gtk_main_quit));
+ empathy_gtk_init ();
+ account_manager = tp_account_manager_dup ();
- g_object_unref (account_manager);
- }
- else
- {
- g_warning (G_STRLOC "unhandled unique app command %d", command);
+ /* Hold the application while preparing the AM */
+ g_application_hold (app);
- return UNIQUE_RESPONSE_PASSTHROUGH;
- }
+ tp_proxy_prepare_async (account_manager, NULL,
+ account_manager_ready_for_accounts_cb, app);
- return UNIQUE_RESPONSE_OK;
+ g_object_unref (account_manager);
}
-#define COMMAND_ACCOUNTS_DIALOG 1
-
-int
-main (int argc, char *argv[])
+static gboolean
+local_cmdline (GApplication *app,
+ gchar ***arguments,
+ gint *exit_status)
{
- TpAccountManager *account_manager;
+ gint i;
+ gchar **argv;
+ gint argc = 0;
+ gboolean retval = TRUE;
GError *error = NULL;
- TpDBusDaemon *dbus_daemon;
- UniqueApp *unique_app;
GOptionContext *optcontext;
GOptionEntry options[] = {
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"),
+ N_("Don't display any dialogs unless there are only \"People Nearby\" accounts"),
NULL },
{ "select-account", 's',
G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name,
{ NULL }
};
- g_thread_init (NULL);
- empathy_init ();
-
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++)
+ argc++;
if (!g_option_context_parse (optcontext, &argc, &argv, &error))
{
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);
- return EXIT_FAILURE;
+ g_clear_error (&error);
+
+ *exit_status = EXIT_FAILURE;
+ }
+ 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);
- empathy_gtk_init ();
-
- g_set_application_name (_(PACKAGE_NAME " Accounts"));
+ return retval;
+}
- gtk_window_set_default_icon_name ("empathy");
+int
+main (int argc, char *argv[])
+{
+ GtkApplication *app;
+ GObjectClass *app_class;
+ gint retval;
- unique_app = unique_app_new (EMPATHY_ACCOUNTS_DBUS_NAME, NULL);
+ g_type_init ();
- if (unique_app_is_running (unique_app))
- {
- unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
+#ifdef HAVE_CHEESE
+ /* Used by the avatar chooser */
+ g_return_val_if_fail (cheese_gtk_init (&argc, &argv), 1);
+#endif
- g_object_unref (unique_app);
- return EXIT_SUCCESS;
- }
+ empathy_init ();
- account_manager = tp_account_manager_dup ();
+ textdomain (GETTEXT_PACKAGE);
+ g_set_application_name (_("Empathy Accounts"));
- tp_account_manager_prepare_async (account_manager, NULL,
- account_manager_ready_for_accounts_cb, selected_account_name);
+ /* 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");
- g_signal_connect (unique_app, "message-received",
- G_CALLBACK (unique_app_message_cb), NULL);
+ 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;
+ G_APPLICATION_CLASS (app_class)->activate = app_activate;
- gtk_main ();
+ retval = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (account_manager);
- g_object_unref (unique_app);
+ g_object_unref (app);
- return EXIT_SUCCESS;
+ return retval;
}