]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts.c
Add missing textdomain() call
[empathy.git] / src / empathy-accounts.c
index fa6b6b26f8b0a5396ecf0a123849d1bd2257b983..9788e11d599847083788f6b2ab4bb0f78c080b1e 100644 (file)
  *          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 <telepathy-glib/telepathy-glib-dbus.h>
 
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/defs.h>
-#include <telepathy-glib/util.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-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 gboolean assistant = FALSE;
 
 static void
-maybe_show_accounts_ui (TpAccountManager *manager)
+maybe_show_accounts_ui (TpAccountManager *manager,
+    GApplication *app)
 {
-  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);
+  if (hidden)
+    return;
+
+  if (only_if_needed && empathy_accounts_has_non_salut_accounts (manager))
+    return;
+
+  empathy_accounts_show_accounts_ui (manager, NULL, app);
 }
 
 static TpAccount *
@@ -73,7 +66,7 @@ find_account (TpAccountManager *mgr,
   GList *accounts, *l;
   TpAccount *found = NULL;
 
-  accounts = tp_account_manager_get_valid_accounts (mgr);
+  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))
@@ -83,7 +76,7 @@ find_account (TpAccountManager *mgr,
         }
     }
 
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
   return found;
 }
 
@@ -94,12 +87,13 @@ 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;
     }
 
   if (selected_account_name != NULL)
@@ -119,10 +113,8 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
 
       if (account != NULL)
         {
-          empathy_accounts_show_accounts_ui (manager, account, assistant,
-              G_CALLBACK (gtk_main_quit));
-
-          return;
+          empathy_accounts_show_accounts_ui (manager, account, app);
+          goto out;
         }
       else
         {
@@ -130,33 +122,35 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
 
           g_clear_error (&error);
 
-          maybe_show_accounts_ui (manager);
+          maybe_show_accounts_ui (manager, app);
         }
 
       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)
 {
   TpAccountManager *account_manager;
 
-  g_application_hold (app);
-
+  empathy_gtk_init ();
   account_manager = tp_account_manager_dup ();
 
+  /* Hold the application while preparing the AM */
+  g_application_hold (app);
+
   tp_proxy_prepare_async (account_manager, NULL,
-    account_manager_ready_for_accounts_cb, NULL);
+    account_manager_ready_for_accounts_cb, app);
 
   g_object_unref (account_manager);
-
-  return 0;
 }
 
 static gboolean
@@ -167,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;
@@ -185,17 +179,14 @@ local_cmdline (GApplication *app,
         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 }
   };
 
   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++)
@@ -206,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,26 +227,26 @@ main (int argc, char *argv[])
   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;
-
-  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);