]> git.0d.be Git - empathy.git/blobdiff - src/empathy.c
Reorder header inclusions accordingly to the Telepathy coding style
[empathy.git] / src / empathy.c
index 32aa25a8670d75fc5e53341a6d25a6830dcbbd3d..a8f23e82c3aa0cecd35c50cdd65e8cef29184694 100644 (file)
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 
-#include <config.h>
+#include "config.h"
 
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
+#include <libnotify/notify.h>
 
 #ifdef HAVE_LIBCHAMPLAIN
 #include <clutter-gtk/clutter-gtk.h>
 #endif
 
-#include <libnotify/notify.h>
-
-#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>
-
-#include <telepathy-yell/telepathy-yell.h>
-
-#include <telepathy-logger/log-manager.h>
-
-#include <libempathy/empathy-presence-manager.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-account-settings.h>
-#include <libempathy/empathy-connectivity.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-ft-factory.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-tp-chat.h>
-
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-location-manager.h>
-#include <libempathy-gtk/empathy-notify-manager.h>
-
-#include "empathy-main-window.h"
 #include "empathy-accounts-common.h"
 #include "empathy-accounts-dialog.h"
-#include "empathy-status-icon.h"
+#include "empathy-chatroom-manager.h"
+#include "empathy-client-factory.h"
+#include "empathy-connection-aggregator.h"
+#include "empathy-ft-factory.h"
 #include "empathy-ft-manager.h"
+#include "empathy-gsettings.h"
+#include "empathy-location-manager.h"
 #include "empathy-notifications-approver.h"
-
-#include "extensions/extensions.h"
+#include "empathy-presence-manager.h"
+#include "empathy-request-util.h"
+#include "empathy-roster-window.h"
+#include "empathy-status-icon.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #define EMPATHY_DBUS_NAME "org.gnome.Empathy"
 
@@ -119,9 +93,9 @@ struct _EmpathyApp
   EmpathyChatroomManager *chatroom_manager;
   EmpathyFTFactory  *ft_factory;
   EmpathyPresenceManager *presence_mgr;
-  EmpathyConnectivity *connectivity;
   GSettings *gsettings;
   EmpathyNotificationsApprover *notifications_approver;
+  EmpathyConnectionAggregator *conn_aggregator;
 #ifdef HAVE_GEOCLUE
   EmpathyLocationManager *location_manager;
 #endif
@@ -156,7 +130,6 @@ empathy_app_dispose (GObject *object)
 #endif
 
   tp_clear_object (&self->presence_mgr);
-  tp_clear_object (&self->connectivity);
   tp_clear_object (&self->icon);
   tp_clear_object (&self->account_manager);
   tp_clear_object (&self->log_manager);
@@ -167,6 +140,7 @@ empathy_app_dispose (GObject *object)
   tp_clear_object (&self->ft_factory);
   tp_clear_object (&self->gsettings);
   tp_clear_object (&self->notifications_approver);
+  tp_clear_object (&self->conn_aggregator);
 
   if (dispose != NULL)
     dispose (object);
@@ -181,9 +155,6 @@ empathy_app_finalize (GObject *object)
 
   g_free (self->preferences_tab);
 
-  if (self->window != NULL)
-    gtk_widget_destroy (self->window);
-
   if (finalize != NULL)
     finalize (object);
 }
@@ -287,6 +258,9 @@ out:
 
       /* Rely on GNOME Shell to watch session state */
       empathy_presence_manager_set_auto_away (self->presence_mgr, FALSE);
+
+      empathy_roster_window_set_shell_running (
+          EMPATHY_ROSTER_WINDOW (self->window), TRUE);
     }
   else
     {
@@ -348,11 +322,20 @@ empathy_app_command_line (GApplication *app,
           g_error_free (error);
         }
 
-      g_application_hold (G_APPLICATION (app));
       self->activated = TRUE;
 
       /* Setting up UI */
-      self->window = empathy_main_window_dup ();
+      self->window = empathy_roster_window_new (GTK_APPLICATION (app));
+      gtk_application_set_app_menu (GTK_APPLICATION (self),
+          empathy_roster_window_get_menu_model (
+            EMPATHY_ROSTER_WINDOW (self->window)));
+
+      gtk_application_add_window (GTK_APPLICATION (app),
+          GTK_WINDOW (self->window));
+      gtk_application_add_accelerator (GTK_APPLICATION (app),
+          "<Primary>h",
+          "win." EMPATHY_PREFS_UI_SHOW_OFFLINE,
+          NULL);
 
       /* check if Shell is running */
       dbus = tp_dbus_daemon_dup (&error);
@@ -366,17 +349,10 @@ empathy_app_command_line (GApplication *app,
       self->notifications_approver =
         empathy_notifications_approver_dup_singleton ();
     }
-  else
-    {
-      /* We're requested to show stuff again, disable the start hidden global in
-       * case the accounts wizard wants to pop up.
-       */
-      self->start_hidden = FALSE;
-    }
 
   if (self->show_preferences)
-    empathy_main_window_show_preferences (EMPATHY_MAIN_WINDOW (self->window),
-        self->preferences_tab);
+    empathy_roster_window_show_preferences (
+        EMPATHY_ROSTER_WINDOW (self->window), self->preferences_tab);
 
   if (!self->start_hidden)
     empathy_window_present (GTK_WINDOW (self->window));
@@ -445,6 +421,7 @@ empathy_app_local_command_line (GApplication *app,
 
   /* We create a group so that GOptionArgFuncs get the user data */
   group = g_option_group_new ("empathy", NULL, NULL, app, NULL);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
   g_option_group_add_entries (group, options);
 
   optcontext = g_option_context_new (N_("- Empathy IM Client"));
@@ -517,17 +494,6 @@ empathy_app_init (EmpathyApp *self)
 {
 }
 
-static void
-use_conn_notify_cb (GSettings *gsettings,
-    const gchar *key,
-    gpointer     user_data)
-{
-  EmpathyConnectivity *connectivity = user_data;
-
-  empathy_connectivity_set_use_conn (connectivity,
-      g_settings_get_boolean (gsettings, key));
-}
-
 static void
 migrate_config_to_xdg_dir (void)
 {
@@ -672,13 +638,10 @@ account_join_chatrooms (TpAccount *account,
   TpConnection *conn;
   GList *chatrooms, *p;
 
-  if (tp_account_get_connection_status (account, NULL) !=
-      TP_CONNECTION_STATUS_CONNECTED)
-    return;
-
-  /* If we're connected we should have a connection */
+  /* Wait if we are not connected or the TpConnection is not prepared yet */
   conn = tp_account_get_connection (account);
-  g_return_if_fail (conn != NULL);
+  if (conn == NULL)
+    return;
 
   chatrooms = empathy_chatroom_manager_get_chatrooms (
           chatroom_manager, account);
@@ -697,12 +660,8 @@ account_join_chatrooms (TpAccount *account,
 }
 
 static void
-account_status_changed_cb (TpAccount *account,
-    guint old_status,
-    guint new_status,
-    guint reason,
-    gchar *dbus_error_name,
-    GHashTable *details,
+account_connection_changed_cb (TpAccount *account,
+    GParamSpec *spec,
     EmpathyChatroomManager *manager)
 {
   account_join_chatrooms (account, manager);
@@ -725,7 +684,7 @@ account_manager_chatroom_ready_cb (GObject *source_object,
       return;
     }
 
-  accounts = tp_account_manager_get_valid_accounts (account_manager);
+  accounts = tp_account_manager_dup_valid_accounts (account_manager);
 
   for (l = accounts; l != NULL; l = g_list_next (l))
     {
@@ -735,10 +694,10 @@ account_manager_chatroom_ready_cb (GObject *source_object,
       account_join_chatrooms (account, chatroom_manager);
 
       /* And/or join them on (re)connection */
-      tp_g_signal_connect_object (account, "status-changed",
-        G_CALLBACK (account_status_changed_cb), chatroom_manager, 0);
+      tp_g_signal_connect_object (account, "notify::connection",
+        G_CALLBACK (account_connection_changed_cb), chatroom_manager, 0);
     }
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 static void
@@ -758,10 +717,10 @@ empathy_app_constructed (GObject *object)
   EmpathyApp *self = (EmpathyApp *) object;
   gboolean chatroom_manager_ready;
 
+  textdomain (GETTEXT_PACKAGE);
   g_set_application_name (_(PACKAGE_NAME));
 
   gtk_window_set_default_icon_name ("empathy");
-  textdomain (GETTEXT_PACKAGE);
 
 #ifdef ENABLE_DEBUG
   /* Set up debug sender */
@@ -776,19 +735,13 @@ empathy_app_constructed (GObject *object)
 
   self->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
 
-  /* Setting up Connectivity */
-  self->connectivity = empathy_connectivity_dup_singleton ();
-  use_conn_notify_cb (self->gsettings, EMPATHY_PREFS_USE_CONN,
-      self->connectivity);
-  g_signal_connect (self->gsettings,
-      "changed::" EMPATHY_PREFS_USE_CONN,
-      G_CALLBACK (use_conn_notify_cb), self->connectivity);
-
   /* account management */
   self->account_manager = tp_account_manager_dup ();
   tp_proxy_prepare_async (self->account_manager, NULL,
       account_manager_ready_cb, self);
 
+  tp_account_manager_enable_restart (self->account_manager);
+
   migrate_config_to_xdg_dir ();
 
   /* Logging */
@@ -813,30 +766,54 @@ empathy_app_constructed (GObject *object)
   self->location_manager = empathy_location_manager_dup_singleton ();
 #endif
 
+  self->conn_aggregator = empathy_connection_aggregator_dup_singleton ();
+
   self->activated = FALSE;
   self->ft_factory = NULL;
   self->window = NULL;
 }
 
+static void
+add_empathy_features (void)
+{
+  /* Add 'empathy' specific feature before doing any preparation */
+  EmpathyClientFactory *factory;
+
+  factory = empathy_client_factory_dup ();
+
+  tp_simple_client_factory_add_connection_features_varargs (
+      TP_SIMPLE_CLIENT_FACTORY (factory),
+      /* empathy_connection_aggregator_get_all_groups(), used by
+       * EmpathyGroupsWidget relies on it */
+      TP_CONNECTION_FEATURE_CONTACT_GROUPS,
+      /* empathy_connection_aggregator_dup_all_contacts(), used by
+       * EmpathyEventManager relies on it */
+      TP_CONNECTION_FEATURE_CONTACT_LIST,
+      NULL);
+
+  g_object_unref (factory);
+}
+
 int
 main (int argc, char *argv[])
 {
   EmpathyApp *app;
   gint retval;
 
-  g_thread_init (NULL);
   g_type_init ();
 
 #ifdef HAVE_LIBCHAMPLAIN
-  gtk_clutter_init (&argc, &argv);
+  g_return_val_if_fail (gtk_clutter_init (&argc, &argv) ==
+      CLUTTER_INIT_SUCCESS, 1);
 #endif
 
   g_type_init ();
-  tpy_cli_init ();
   empathy_init ();
   gtk_init (&argc, &argv);
   empathy_gtk_init ();
 
+  add_empathy_features ();
+
   app = g_object_new (EMPATHY_TYPE_APP,
       "application-id", EMPATHY_DBUS_NAME,
       "flags", G_APPLICATION_HANDLES_COMMAND_LINE,