]> git.0d.be Git - empathy.git/blobdiff - src/empathy.c
Updated Polish translation
[empathy.git] / src / empathy.c
index f272ecfec1673b50c87714592c3abc8ddbd77175..f8479142316c8b30f99dd2bf3a0ca3a2e9ff9e3b 100644 (file)
 
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug-sender.h>
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/connection-manager.h>
 #include <telepathy-glib/interfaces.h>
 
+#ifdef ENABLE_TPL
+#include <telepathy-logger/log-manager.h>
+#include <telepathy-logger/log-store-empathy.h>
+#else
+
+#include <libempathy/empathy-log-manager.h>
+#endif /* ENABLE_TPL */
 #include <libempathy/empathy-idle.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-call-factory.h>
 #include <libempathy/empathy-account-settings.h>
 #include <libempathy/empathy-connectivity.h>
 #include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-debugger.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-dispatch-operation.h>
-#include <libempathy/empathy-log-manager.h>
 #include <libempathy/empathy-ft-factory.h>
 #include <libempathy/empathy-tp-chat.h>
 #include <libempathy/empathy-tp-call.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 #include <libempathy-gtk/empathy-location-manager.h>
 
-#include "empathy-account-assistant.h"
-#include "empathy-accounts-dialog.h"
 #include "empathy-main-window.h"
+#include "empathy-import-mc4-accounts.h"
+#include "empathy-accounts-common.h"
+#include "empathy-accounts-dialog.h"
 #include "empathy-status-icon.h"
 #include "empathy-call-window.h"
 #include "empathy-chat-window.h"
 #include "empathy-ft-manager.h"
-#include "empathy-import-mc4-accounts.h"
-#include "empathy-auto-salut-account-helper.h"
 
 #include "extensions/extensions.h"
 
 
 #include <gst/gst.h>
 
-#define COMMAND_ACCOUNTS_DIALOG 1
-
-static gboolean account_dialog_only = FALSE;
 static gboolean start_hidden = FALSE;
 static gboolean no_connect = FALSE;
 
+static void account_manager_ready_cb (GObject *source_object,
+    GAsyncResult *result,
+    gpointer user_data);
+
 static void
 dispatch_cb (EmpathyDispatcher *dispatcher,
     EmpathyDispatchOperation *operation,
@@ -166,108 +172,6 @@ use_conn_notify_cb (EmpathyConf *conf,
     }
 }
 
-static gboolean
-has_non_salut_accounts (TpAccountManager *manager)
-{
-  gboolean ret = FALSE;
-  GList *accounts, *l;
-
-  accounts = tp_account_manager_get_valid_accounts (manager);
-
-  for (l = accounts ; l != NULL; l = g_list_next (l))
-    {
-      if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp"))
-        {
-          ret = TRUE;
-          break;
-        }
-    }
-
-  g_list_free (accounts);
-
-  return ret;
-}
-
-/* Try to import accounts from MC4 and returns TRUE if we should display the
- * accounts assistant. */
-static gboolean
-should_show_account_assistant (TpAccountManager *account_mgr,
-    EmpathyConnectionManagers *cm_mgr)
-{
-  g_return_val_if_fail (tp_account_manager_is_prepared (account_mgr,
-      TP_ACCOUNT_MANAGER_FEATURE_CORE), FALSE);
-  g_return_val_if_fail (empathy_connection_managers_is_ready (cm_mgr), FALSE);
-
-  if (empathy_import_mc4_has_imported ())
-    return FALSE;
-
-  if (empathy_import_mc4_accounts (cm_mgr))
-    return FALSE;
-
-  if (start_hidden)
-    return FALSE;
-
-  if (has_non_salut_accounts (account_mgr))
-    return FALSE;
-
-  if (!should_create_salut_account (account_mgr))
-    return FALSE;
-
-  return TRUE;
-}
-
-static void
-connection_managers_prepare_cb (GObject *source,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
-  TpAccountManager *account_mgr = user_data;
-
-  if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
-    goto out;
-
-  if (should_show_account_assistant (account_mgr, cm_mgr))
-    empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()),
-          cm_mgr);
-
-out:
-  g_object_unref (cm_mgr);
-  g_object_unref (account_mgr);
-}
-
-static void
-account_manager_ready_for_show_assistant (GObject *source_object,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  TpAccountManager *account_mgr = TP_ACCOUNT_MANAGER (source_object);
-  GError *error = NULL;
-  EmpathyConnectionManagers *cm_mgr;
-
-  if (!tp_account_manager_prepare_finish (account_mgr, result, &error))
-    {
-      DEBUG ("Failed to prepare account manager: %s", error->message);
-      g_error_free (error);
-      g_object_unref (account_mgr);
-      return;
-    }
-
-  cm_mgr = empathy_connection_managers_dup_singleton ();
-
-  empathy_connection_managers_prepare_async (cm_mgr,
-      connection_managers_prepare_cb, account_mgr);
-}
-
-static void
-maybe_show_account_assistant (void)
-{
-  TpAccountManager *account_mgr = tp_account_manager_dup ();
-
-  tp_account_manager_prepare_async (account_mgr, NULL,
-      account_manager_ready_for_show_assistant, NULL);
-}
-
 static void
 migrate_config_to_xdg_dir (void)
 {
@@ -337,81 +241,23 @@ migrate_config_to_xdg_dir (void)
 }
 
 static void
-connection_managers_prepare_for_accounts (GObject *source,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
-  GtkWidget *ui;
-
-  if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
-    goto out;
-
-  ui = empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()),
-          cm_mgr);
-
-  if (account_dialog_only)
-    g_signal_connect (ui, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
-out:
-  g_object_unref (cm_mgr);
-}
-
-static void
-do_show_accounts_ui (GtkWindow *window,
-    TpAccountManager *manager)
-{
-  if (has_non_salut_accounts (manager))
-    {
-      GtkWidget *ui;
-
-      ui = empathy_accounts_dialog_show (window, NULL);
-
-      if (account_dialog_only)
-        g_signal_connect (ui, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-    }
-  else
-    {
-      EmpathyConnectionManagers *cm_mgr;
-
-      empathy_connection_managers_prepare_async (cm_mgr,
-          connection_managers_prepare_for_accounts, NULL);
-    }
-}
-
-static void
-account_manager_ready_for_accounts_cb (GObject *source_object,
-    GAsyncResult *result,
-    gpointer user_data)
+accounts_application_exited_cb (GPid pid,
+    gint status,
+    gpointer data)
 {
-  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
-  GError *error = NULL;
-
-  if (!tp_account_manager_prepare_finish (manager, result, &error))
+  if (status)
     {
-      DEBUG ("Failed to prepare account manager: %s", error->message);
-      g_error_free (error);
-      return;
+      g_warning ("accounts application exited with status %d: '%s'",
+          status, g_strerror (status));
     }
-
-  do_show_accounts_ui (user_data, manager);
 }
 
 static void
-show_accounts_ui (GtkWindow *window,
-    gboolean force)
+show_accounts_ui (GdkScreen *screen,
+    gboolean if_needed)
 {
-  TpAccountManager *manager;
-
-  if (!force)
-    return;
-
-  manager = tp_account_manager_dup ();
-
-  tp_account_manager_prepare_async (manager, NULL,
-      account_manager_ready_for_accounts_cb, window);
-
-  g_object_unref (manager);
+  empathy_accounts_dialog_show_application (screen,
+      accounts_application_exited_cb, NULL, NULL, if_needed, start_hidden);
 }
 
 static UniqueResponse
@@ -422,29 +268,30 @@ unique_app_message_cb (UniqueApp *unique_app,
     gpointer user_data)
 {
   GtkWindow *window = user_data;
+  TpAccountManager *account_manager;
 
   DEBUG ("Other instance launched, presenting the main window. "
       "Command=%d, timestamp %u", command, timestamp);
 
-  if (command == COMMAND_ACCOUNTS_DIALOG)
-    {
-      show_accounts_ui (NULL, TRUE);
-    }
-  else
-    {
-      /* We're requested to show stuff again, disable the start hidden global
-       * in case the accounts wizard wants to pop up.
-       */
-      start_hidden = FALSE;
+  /* XXX: the standalone app somewhat breaks this case, since
+   * communicating it would be a pain */
 
-      show_accounts_ui (window, FALSE);
+  /* We're requested to show stuff again, disable the start hidden global
+   * in case the accounts wizard wants to pop up.
+   */
+  start_hidden = FALSE;
 
-      gtk_window_set_screen (GTK_WINDOW (window),
-          unique_message_data_get_screen (data));
-      gtk_window_set_startup_id (GTK_WINDOW (window),
-          unique_message_data_get_startup_id (data));
-      gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
-    }
+  gtk_window_set_screen (GTK_WINDOW (window),
+      unique_message_data_get_screen (data));
+  gtk_window_set_startup_id (GTK_WINDOW (window),
+      unique_message_data_get_startup_id (data));
+  gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
+  gtk_window_set_skip_taskbar_hint (window, FALSE);
+
+  account_manager = tp_account_manager_dup ();
+  tp_account_manager_prepare_async (account_manager, NULL,
+      account_manager_ready_cb, NULL);
+  g_object_unref (account_manager);
 
   return UNIQUE_RESPONSE_OK;
 }
@@ -500,32 +347,6 @@ new_call_handler_cb (EmpathyCallFactory *factory,
   gtk_widget_show (GTK_WIDGET (window));
 }
 
-#ifdef ENABLE_DEBUG
-static void
-default_log_handler (const gchar *log_domain,
-    GLogLevelFlags log_level,
-    const gchar *message,
-    gpointer user_data)
-{
-  g_log_default_handler (log_domain, log_level, message, NULL);
-
-  /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
-   * debugger as they already have in empathy_debug. */
-  if (log_level != G_LOG_LEVEL_DEBUG
-      || tp_strdiff (log_domain, G_LOG_DOMAIN))
-    {
-        EmpathyDebugger *dbg;
-        GTimeVal now;
-
-        dbg = empathy_debugger_get_singleton ();
-        g_get_current_time (&now);
-
-        empathy_debugger_add_message (dbg, &now, log_domain,
-                                      log_level, message);
-    }
-}
-#endif /* ENABLE_DEBUG */
-
 static void
 account_manager_ready_cb (GObject *source_object,
     GAsyncResult *result,
@@ -561,7 +382,11 @@ account_manager_ready_cb (GObject *source_object,
       /* if current state is Offline, then put it online */
       empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
 
-  maybe_show_account_assistant ();
+  /* Pop up the accounts dialog if it's needed (either when we don't have any
+   * accounts yet or when we haven't imported mc4 accounts yet */
+  if (!empathy_accounts_has_accounts (manager)
+      || !empathy_import_mc4_has_imported ())
+    show_accounts_ui (gdk_screen_get_default (), TRUE);
 
   g_object_unref (idle);
   g_object_unref (connectivity);
@@ -663,6 +488,8 @@ account_status_changed_cb (TpAccount *account,
   TpConnection *conn;
 
   conn = tp_account_get_connection (account);
+  if (conn == NULL)
+    return;
 
   empathy_dispatcher_join_muc (conn,
       empathy_chatroom_get_room (room), NULL, NULL);
@@ -743,7 +570,11 @@ main (int argc, char *argv[])
   EmpathyStatusIcon *icon;
   EmpathyDispatcher *dispatcher;
   TpAccountManager *account_manager;
+#ifdef ENABLE_TPL
+  TplLogManager *log_manager;
+#else
   EmpathyLogManager *log_manager;
+#endif /* ENABLE_TPL */
   EmpathyChatroomManager *chatroom_manager;
   EmpathyCallFactory *call_factory;
   EmpathyFTFactory  *ft_factory;
@@ -751,10 +582,13 @@ main (int argc, char *argv[])
   EmpathyIdle *idle;
   EmpathyConnectivity *connectivity;
   GError *error = NULL;
-  TpDBusDaemon *dbus_daemon;
   UniqueApp *unique_app;
   gboolean chatroom_manager_ready;
 
+#ifdef ENABLE_DEBUG
+  TpDebugSender *debug_sender;
+#endif /* ENABLE_TPL */
+
   GOptionContext *optcontext;
   GOptionEntry options[] = {
       { "no-connect", 'n',
@@ -765,10 +599,6 @@ main (int argc, char *argv[])
         0, G_OPTION_ARG_NONE, &start_hidden,
         N_("Don't display the contact list or any other dialogs on startup"),
         NULL },
-      { "accounts", 'a',
-        0, G_OPTION_ARG_NONE, &account_dialog_only,
-        N_("Show the accounts dialog"),
-        NULL },
       { "version", 'v',
         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
         NULL, NULL },
@@ -804,53 +634,21 @@ main (int argc, char *argv[])
   textdomain (GETTEXT_PACKAGE);
 
 #ifdef ENABLE_DEBUG
-  /* Set up debugger */
-  g_log_set_default_handler (default_log_handler, NULL);
+  /* Set up debug sender */
+  debug_sender = tp_debug_sender_dup ();
+  g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
 #endif
 
-  unique_app = unique_app_new_with_commands ("org.gnome.Empathy",
-      NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL);
+  unique_app = unique_app_new ("org.gnome."PACKAGE_NAME, NULL);
 
   if (unique_app_is_running (unique_app))
     {
-      unique_app_send_message (unique_app, account_dialog_only ?
-          COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL);
+      unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
 
       g_object_unref (unique_app);
       return EXIT_SUCCESS;
     }
 
-  /* Take well-known name */
-  dbus_daemon = tp_dbus_daemon_dup (&error);
-  if (error == NULL)
-    {
-      if (!tp_dbus_daemon_request_name (dbus_daemon,
-          "org.gnome.Empathy", TRUE, &error))
-        {
-          DEBUG ("Failed to request well-known name: %s",
-                 error ? error->message : "no message");
-          g_clear_error (&error);
-        }
-      g_object_unref (dbus_daemon);
-    }
-  else
-    {
-      DEBUG ("Failed to dup dbus daemon: %s",
-             error ? error->message : "no message");
-      g_clear_error (&error);
-    }
-
-  if (account_dialog_only)
-    {
-      account_manager = tp_account_manager_dup ();
-      show_accounts_ui (NULL, TRUE);
-
-      gtk_main ();
-
-      g_object_unref (account_manager);
-      return 0;
-    }
-
   notify_init (_(PACKAGE_NAME));
 
   /* Setting up Idle */
@@ -883,8 +681,12 @@ main (int argc, char *argv[])
       G_CALLBACK (unique_app_message_cb), window);
 
   /* Logging */
+#ifdef ENABLE_TPL
+  log_manager = tpl_log_manager_dup_singleton ();
+#else
   log_manager = empathy_log_manager_dup_singleton ();
   empathy_log_manager_observe (log_manager, dispatcher);
+#endif
 
   chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
   empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
@@ -920,6 +722,10 @@ main (int argc, char *argv[])
 
   empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
 
+#ifdef ENABLE_DEBUG
+  g_object_unref (debug_sender);
+#endif
+
   g_object_unref (idle);
   g_object_unref (connectivity);
   g_object_unref (icon);