]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts.c
Merge branch 'sasl'
[empathy.git] / src / empathy-accounts.c
index 0eaa8553e1aa9604665642f9477141b1f3ab6210..6d0561b143455df4c14222f839f119e48c744a7b 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
-#include <unique/unique.h>
 
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/defs.h>
@@ -45,7 +44,6 @@
 #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"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
@@ -56,6 +54,7 @@
 static gboolean only_if_needed = FALSE;
 static gboolean hidden = FALSE;
 static gchar *selected_account_name = NULL;
+static gboolean account_manager_prepared = FALSE;
 
 static void
 account_prepare_cb (GObject *source_object,
@@ -88,25 +87,6 @@ maybe_show_accounts_ui (TpAccountManager *manager)
     empathy_accounts_show_accounts_ui (manager, NULL, gtk_main_quit);
 }
 
-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))
-    {
-      g_warning ("Failed to prepare connection managers singleton");
-      gtk_main_quit ();
-      return;
-    }
-
-  empathy_accounts_import (TP_ACCOUNT_MANAGER (user_data),
-    EMPATHY_CONNECTION_MANAGERS (source));
-
-  maybe_show_accounts_ui (TP_ACCOUNT_MANAGER (user_data));
-}
-
 static void
 account_manager_ready_for_accounts_cb (GObject *source_object,
     GAsyncResult *result,
@@ -151,60 +131,50 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
     }
   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);
+      account_manager_prepared = TRUE;
     }
 }
 
-static UniqueResponse
-unique_app_message_cb (UniqueApp *unique_app,
-    gint command,
-    UniqueMessageData *data,
-    guint timestamp,
-    gpointer user_data)
+static int
+app_command_line_cb (GApplication *app,
+    GApplicationCommandLine *cmdline)
 {
-  DEBUG ("Other instance launched, presenting the main window. "
-      "Command=%d, timestamp %u", command, timestamp);
+  gchar **argv;
+  gint argc;
+
+  g_application_hold (app);
 
-  if (command == UNIQUE_ACTIVATE)
+  argv = g_application_command_line_get_arguments (cmdline, &argc);
+
+  /* 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 ();
-
       empathy_accounts_show_accounts_ui (account_manager, NULL,
-          G_CALLBACK (gtk_main_quit));
+              G_CALLBACK (gtk_main_quit));
 
       g_object_unref (account_manager);
     }
-  else
-    {
-      g_warning (G_STRLOC "unhandled unique app command %d", command);
 
-      return UNIQUE_RESPONSE_PASSTHROUGH;
-    }
+  g_strfreev (argv);
 
-  return UNIQUE_RESPONSE_OK;
+  return 0;
 }
 
-#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 = FALSE;
   GError *error = NULL;
-  UniqueApp *unique_app;
 
   GOptionContext *optcontext;
   GOptionEntry options[] = {
@@ -214,7 +184,7 @@ main (int argc, char *argv[])
         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,
@@ -225,51 +195,67 @@ main (int argc, char *argv[])
       { 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_main_entries (optcontext, options, 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;
+
+      *exit_status = EXIT_FAILURE;
+      retval = TRUE;
     }
 
   g_option_context_free (optcontext);
 
+  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 ();
+
+  gtk_init (&argc, &argv);
   empathy_gtk_init ();
 
   g_set_application_name (_("Empathy Accounts"));
 
   gtk_window_set_default_icon_name ("empathy");
+  textdomain (GETTEXT_PACKAGE);
 
-  unique_app = unique_app_new (EMPATHY_ACCOUNTS_DBUS_NAME, NULL);
-
-  if (unique_app_is_running (unique_app))
-    {
-      unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
-
-      g_object_unref (unique_app);
-      return EXIT_SUCCESS;
-    }
+  app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME,
+      G_APPLICATION_HANDLES_COMMAND_LINE);
+  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 (unique_app, "message-received",
-      G_CALLBACK (unique_app_message_cb), NULL);
+  g_signal_connect (app, "command-line", G_CALLBACK (app_command_line_cb),
+      NULL);
 
-  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;
 }