]> git.0d.be Git - empathy.git/blobdiff - src/empathy.c
Merge branch 'undo-close-tab'
[empathy.git] / src / empathy.c
index 8609794e81cf24f21d3553a19d12e069b98891b2..637778d4714e38a84adfbd966cc0828f191ce732 100644 (file)
 #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>
@@ -53,7 +60,6 @@
 #include <libempathy/empathy-connection-managers.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-location-manager.h>
 
 #include "empathy-main-window.h"
+#include "empathy-import-mc4-accounts.h"
+#include "empathy-accounts-common.h"
 #include "empathy-accounts-dialog.h"
+#include "empathy-chat-manager.h"
 #include "empathy-status-icon.h"
 #include "empathy-call-window.h"
 #include "empathy-chat-window.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,
@@ -231,27 +241,12 @@ migrate_config_to_xdg_dir (void)
   g_free (old_dir);
 }
 
-static void
-accounts_application_exited_cb (GPid pid,
-    gint status,
-    gpointer data)
-{
-  if (status)
-    {
-      g_warning ("accounts application exited with status %d: '%s'",
-          status, g_strerror (status));
-    }
-
-  if (account_dialog_only)
-    gtk_main_quit ();
-}
-
 static void
 show_accounts_ui (GdkScreen *screen,
-    gboolean try_import)
+    gboolean if_needed)
 {
   empathy_accounts_dialog_show_application (screen,
-      accounts_application_exited_cb, NULL, NULL, try_import, start_hidden);
+      NULL, if_needed, start_hidden);
 }
 
 static UniqueResponse
@@ -262,30 +257,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 (gdk_screen_get_default (), TRUE);
-    }
-  else
-    {
-      /* XXX: the standalone app somewhat breaks this case, since
-       * communicating it would be a pain */
+  /* XXX: the standalone app somewhat breaks this case, since
+   * communicating it would be a pain */
 
-      /* We're requested to show stuff again, disable the start hidden global
-       * in case the accounts wizard wants to pop up.
-       */
-      start_hidden = 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;
 }
@@ -376,7 +371,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);
 
-  show_accounts_ui (gdk_screen_get_default (), TRUE);
+  /* 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);
@@ -551,6 +550,18 @@ chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
       account_manager_chatroom_ready_cb, chatroom_manager);
 }
 
+static void
+empathy_idle_set_auto_away_cb (EmpathyConf *conf,
+                               const gchar *key,
+                               gpointer user_data)
+{
+       gboolean autoaway;
+       EmpathyIdle *idle = user_data;
+
+       empathy_conf_get_bool (conf, key, &autoaway);
+       empathy_idle_set_auto_away (idle, autoaway);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -560,17 +571,22 @@ 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;
   GtkWidget *window;
   EmpathyIdle *idle;
   EmpathyConnectivity *connectivity;
+  EmpathyChatManager *chat_manager;
   GError *error = NULL;
   UniqueApp *unique_app;
   gboolean chatroom_manager_ready;
-
+  gboolean autoaway = TRUE;
 #ifdef ENABLE_DEBUG
   TpDebugSender *debug_sender;
 #endif
@@ -585,10 +601,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 },
@@ -629,34 +641,30 @@ main (int argc, char *argv[])
   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
 #endif
 
-  unique_app = unique_app_new_with_commands (EMPATHY_CLIENT_NAME,
-      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;
     }
 
-  if (account_dialog_only)
-    {
-      account_manager = tp_account_manager_dup ();
-      show_accounts_ui (gdk_screen_get_default (), FALSE);
-
-      gtk_main ();
-
-      g_object_unref (account_manager);
-      return 0;
-    }
-
   notify_init (_(PACKAGE_NAME));
 
   /* Setting up Idle */
   idle = empathy_idle_dup_singleton ();
-  empathy_idle_set_auto_away (idle, TRUE);
+
+  empathy_conf_get_bool (empathy_conf_get (),
+      EMPATHY_PREFS_AUTOAWAY, &autoaway);
+
+  empathy_conf_notify_add (empathy_conf_get (),
+                          EMPATHY_PREFS_AUTOAWAY,
+                          empathy_idle_set_auto_away_cb,
+                          idle);
+
+  empathy_idle_set_auto_away (idle, autoaway);
 
   /* Setting up Connectivity */
   connectivity = empathy_connectivity_dup_singleton ();
@@ -680,12 +688,19 @@ main (int argc, char *argv[])
   window = empathy_main_window_show ();
   icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
 
+  /* Chat manager */
+  chat_manager = empathy_chat_manager_dup_singleton ();
+
   g_signal_connect (unique_app, "message-received",
       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);
@@ -725,6 +740,7 @@ main (int argc, char *argv[])
   g_object_unref (debug_sender);
 #endif
 
+  g_object_unref (chat_manager);
   g_object_unref (idle);
   g_object_unref (connectivity);
   g_object_unref (icon);