]> git.0d.be Git - empathy.git/blob - src/empathy.c
Add a command line option to Empathy to show the preferences
[empathy.git] / src / empathy.c
1 /*
2  * Copyright (C) 2007-2009 Collabora Ltd.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA  02110-1301  USA
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <string.h>
27
28 #include <glib.h>
29 #include <glib/gstdio.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkx.h>
33
34 #ifdef HAVE_LIBCHAMPLAIN
35 #include <clutter-gtk/clutter-gtk.h>
36 #endif
37
38 #include <libnotify/notify.h>
39
40 #include <telepathy-glib/account-manager.h>
41 #include <telepathy-glib/dbus.h>
42 #include <telepathy-glib/debug-sender.h>
43 #include <telepathy-glib/util.h>
44 #include <telepathy-glib/connection-manager.h>
45 #include <telepathy-glib/interfaces.h>
46
47 #include <telepathy-yell/telepathy-yell.h>
48
49 #include <telepathy-logger/log-manager.h>
50
51 #include <libempathy/empathy-presence-manager.h>
52 #include <libempathy/empathy-utils.h>
53 #include <libempathy/empathy-chatroom-manager.h>
54 #include <libempathy/empathy-account-settings.h>
55 #include <libempathy/empathy-connectivity.h>
56 #include <libempathy/empathy-connection-managers.h>
57 #include <libempathy/empathy-request-util.h>
58 #include <libempathy/empathy-ft-factory.h>
59 #include <libempathy/empathy-gsettings.h>
60 #include <libempathy/empathy-tp-chat.h>
61
62 #include <libempathy-gtk/empathy-ui-utils.h>
63 #include <libempathy-gtk/empathy-location-manager.h>
64
65 #include "empathy-main-window.h"
66 #include "empathy-accounts-common.h"
67 #include "empathy-accounts-dialog.h"
68 #include "empathy-status-icon.h"
69 #include "empathy-ft-manager.h"
70 #include "empathy-notifications-approver.h"
71
72 #include "extensions/extensions.h"
73
74 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
75 #include <libempathy/empathy-debug.h>
76
77 #define EMPATHY_DBUS_NAME "org.gnome.Empathy"
78
79 #define EMPATHY_TYPE_APP (empathy_app_get_type ())
80 #define EMPATHY_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_APP, EmpathyApp))
81 #define EMPATHY_APP_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), EMPATHY_TYPE_APP, EmpathyAppClass))
82 #define EMPATHY_IS_EMPATHY_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_APP))
83 #define EMPATHY_IS_EMPATHY_APP_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EMPATHY_TYPE_APP))
84 #define EMPATHY_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_APP, EmpathyAppClass))
85
86 typedef struct _EmpathyApp EmpathyApp;
87 typedef struct _EmpathyAppClass EmpathyAppClass;
88
89 enum
90 {
91   PROP_NO_CONNECT = 1,
92   PROP_START_HIDDEN
93 };
94
95 GType empathy_app_get_type (void);
96
97 struct _EmpathyAppClass
98 {
99   GtkApplicationClass parent_class;
100 };
101
102 struct _EmpathyApp
103 {
104   GtkApplication parent;
105
106   /* Properties */
107   gboolean no_connect;
108   gboolean start_hidden;
109   gboolean show_preferences;
110
111   gboolean activated;
112
113   GtkWidget *window;
114   EmpathyStatusIcon *icon;
115   TpAccountManager *account_manager;
116   TplLogManager *log_manager;
117   EmpathyChatroomManager *chatroom_manager;
118   EmpathyFTFactory  *ft_factory;
119   EmpathyPresenceManager *presence_mgr;
120   EmpathyConnectivity *connectivity;
121   GSettings *gsettings;
122   EmpathyNotificationsApprover *notifications_approver;
123 #ifdef HAVE_GEOCLUE
124   EmpathyLocationManager *location_manager;
125 #endif
126 #ifdef ENABLE_DEBUG
127   TpDebugSender *debug_sender;
128 #endif
129 };
130
131
132 G_DEFINE_TYPE(EmpathyApp, empathy_app, GTK_TYPE_APPLICATION)
133
134 static void
135 empathy_app_dispose (GObject *object)
136 {
137   EmpathyApp *self = EMPATHY_APP (object);
138   void (*dispose) (GObject *) =
139     G_OBJECT_CLASS (empathy_app_parent_class)->dispose;
140
141   if (self->presence_mgr != NULL)
142     {
143       empathy_presence_manager_set_state (self->presence_mgr,
144           TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
145     }
146
147 #ifdef ENABLE_DEBUG
148   tp_clear_object (&self->debug_sender);
149 #endif
150
151   tp_clear_object (&self->presence_mgr);
152   tp_clear_object (&self->connectivity);
153   tp_clear_object (&self->icon);
154   tp_clear_object (&self->account_manager);
155   tp_clear_object (&self->log_manager);
156   tp_clear_object (&self->chatroom_manager);
157 #ifdef HAVE_GEOCLUE
158   tp_clear_object (&self->location_manager);
159 #endif
160   tp_clear_object (&self->ft_factory);
161   tp_clear_object (&self->gsettings);
162   tp_clear_object (&self->notifications_approver);
163
164   if (dispose != NULL)
165     dispose (object);
166 }
167
168 static void
169 empathy_app_finalize (GObject *object)
170 {
171   EmpathyApp *self = EMPATHY_APP (object);
172   void (*finalize) (GObject *) =
173     G_OBJECT_CLASS (empathy_app_parent_class)->finalize;
174
175   if (self->window != NULL)
176     gtk_widget_destroy (self->window);
177
178   if (finalize != NULL)
179     finalize (object);
180 }
181
182 static void account_manager_ready_cb (GObject *source_object,
183     GAsyncResult *result,
184     gpointer user_data);
185
186 static void
187 empathy_app_set_property (GObject *object,
188     guint prop_id,
189     const GValue *value,
190     GParamSpec *pspec)
191 {
192   EmpathyApp *self = EMPATHY_APP (object);
193
194   switch (prop_id)
195     {
196       case PROP_NO_CONNECT:
197         self->no_connect = g_value_get_boolean (value);
198         break;
199       case PROP_START_HIDDEN:
200         self->start_hidden = g_value_get_boolean (value);
201         break;
202       default:
203         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204         break;
205     }
206 }
207
208 static void
209 new_incoming_transfer_cb (EmpathyFTFactory *factory,
210     EmpathyFTHandler *handler,
211     GError *error,
212     gpointer user_data)
213 {
214   if (error)
215     empathy_ft_manager_display_error (handler, error);
216   else
217     empathy_receive_file_with_file_chooser (handler);
218 }
219
220 static void
221 new_ft_handler_cb (EmpathyFTFactory *factory,
222     EmpathyFTHandler *handler,
223     GError *error,
224     gpointer user_data)
225 {
226   if (error)
227     empathy_ft_manager_display_error (handler, error);
228   else
229     empathy_ft_manager_add_handler (handler);
230
231   g_object_unref (handler);
232 }
233
234 static gboolean
235 empathy_app_local_command_line (GApplication *app,
236     gchar ***arguments,
237     gint *exit_status);
238
239 static int
240 empathy_app_command_line (GApplication *app,
241     GApplicationCommandLine *cmdline)
242 {
243   EmpathyApp *self = (EmpathyApp *) app;
244   gchar **args, **argv;
245   gint argc, exit_status, i;
246
247   args = g_application_command_line_get_arguments (cmdline, &argc);
248   /* We have to make an extra copy of the array, since g_option_context_parse()
249    * assumes that it can remove strings from the array without freeing them. */
250   argv = g_new (gchar*, argc + 1);
251   for (i = 0; i <= argc; i++)
252     argv[i] = args[i];
253
254   if (empathy_app_local_command_line (app, &argv, &exit_status))
255     DEBUG ("failed to parse command line!");
256
257   g_free (argv);
258   g_strfreev (args);
259
260   if (!self->activated)
261     {
262       GError *error = NULL;
263
264       /* Create the FT factory */
265       self->ft_factory = empathy_ft_factory_dup_singleton ();
266       g_signal_connect (self->ft_factory, "new-ft-handler",
267           G_CALLBACK (new_ft_handler_cb), NULL);
268       g_signal_connect (self->ft_factory, "new-incoming-transfer",
269           G_CALLBACK (new_incoming_transfer_cb), NULL);
270
271       if (!empathy_ft_factory_register (self->ft_factory, &error))
272         {
273           g_warning ("Failed to register FileTransfer handler: %s",
274               error->message);
275           g_error_free (error);
276         }
277
278       g_application_hold (G_APPLICATION (app));
279       self->activated = TRUE;
280
281       /* Setting up UI */
282       self->window = empathy_main_window_dup ();
283       self->icon = empathy_status_icon_new (GTK_WINDOW (self->window),
284           self->start_hidden);
285
286       self->notifications_approver =
287         empathy_notifications_approver_dup_singleton ();
288     }
289   else
290     {
291       /* We're requested to show stuff again, disable the start hidden global in
292        * case the accounts wizard wants to pop up.
293        */
294       self->start_hidden = FALSE;
295     }
296
297   if (self->show_preferences)
298     empathy_main_window_show_preferences (EMPATHY_MAIN_WINDOW (self->window));
299
300   if (!self->start_hidden)
301     empathy_window_present (GTK_WINDOW (self->window));
302
303   /* Display the accounts dialog if needed */
304   tp_account_manager_prepare_async (self->account_manager, NULL,
305       account_manager_ready_cb, self);
306
307   return 0;
308 }
309
310 static gboolean
311 show_version_cb (const char *option_name,
312     const char *value,
313     gpointer data,
314     GError **error);
315
316 static gboolean
317 empathy_app_local_command_line (GApplication *app,
318     gchar ***arguments,
319     gint *exit_status)
320 {
321   EmpathyApp *self = (EmpathyApp *) app;
322   gint i;
323   gchar **argv;
324   gint argc = 0;
325   gboolean retval = FALSE;
326   GError *error = NULL;
327   gboolean no_connect = FALSE, start_hidden = FALSE;
328   gboolean show_preferences = FALSE;
329
330   GOptionContext *optcontext;
331   GOptionEntry options[] = {
332       { "no-connect", 'n',
333         0, G_OPTION_ARG_NONE, &no_connect,
334         N_("Don't connect on startup"),
335         NULL },
336       { "start-hidden", 'h',
337         0, G_OPTION_ARG_NONE, &start_hidden,
338         N_("Don't display the contact list or any other dialogs on startup"),
339         NULL },
340       { "show-preferences", 'p',
341         0, G_OPTION_ARG_NONE, &show_preferences,
342         NULL, NULL },
343       { "version", 'v',
344         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
345         NULL, NULL },
346       { NULL }
347   };
348
349   optcontext = g_option_context_new (N_("- Empathy IM Client"));
350   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
351   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
352
353   argc = g_strv_length (*arguments);
354
355   /* We dup the args because g_option_context_parse() sets things to NULL,
356    * but we want to parse all the command line to the primary instance
357    * if necessary. */
358   argv = g_new (gchar*, argc + 1);
359   for (i = 0; i <= argc; i++)
360     argv[i] = (*arguments)[i];
361
362   if (!g_option_context_parse (optcontext, &argc, &argv, &error))
363     {
364       g_print ("%s\nRun '%s --help' to see a full list of available command "
365           "line options.\n",
366           error->message, argv[0]);
367       g_warning ("Error in empathy init: %s", error->message);
368
369       *exit_status = EXIT_FAILURE;
370       retval = TRUE;
371     }
372
373   g_free (argv);
374
375   g_option_context_free (optcontext);
376
377   self->no_connect = no_connect;
378   self->start_hidden = start_hidden;
379   self->show_preferences = show_preferences;
380
381   return retval;
382 }
383
384 static void empathy_app_constructed (GObject *object);
385
386 static void
387 empathy_app_class_init (EmpathyAppClass *klass)
388 {
389   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
390   GApplicationClass *g_app_class = G_APPLICATION_CLASS (klass);
391   GParamSpec *spec;
392
393   gobject_class->set_property = empathy_app_set_property;
394   gobject_class->constructed = empathy_app_constructed;
395   gobject_class->dispose = empathy_app_dispose;
396   gobject_class->finalize = empathy_app_finalize;
397
398   g_app_class->command_line = empathy_app_command_line;
399   g_app_class->local_command_line = empathy_app_local_command_line;
400
401   spec = g_param_spec_boolean ("no-connect", "no connect",
402       "Don't connect on startup",
403       FALSE,
404       G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
405   g_object_class_install_property (gobject_class, PROP_NO_CONNECT, spec);
406
407   spec = g_param_spec_boolean ("start-hidden", "start hidden",
408       "Don't display the contact list or any other dialogs on startup",
409       FALSE,
410       G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
411   g_object_class_install_property (gobject_class, PROP_START_HIDDEN, spec);
412 }
413
414 static void
415 empathy_app_init (EmpathyApp *self)
416 {
417 }
418
419 static void
420 use_conn_notify_cb (GSettings *gsettings,
421     const gchar *key,
422     gpointer     user_data)
423 {
424   EmpathyConnectivity *connectivity = user_data;
425
426   empathy_connectivity_set_use_conn (connectivity,
427       g_settings_get_boolean (gsettings, key));
428 }
429
430 static void
431 migrate_config_to_xdg_dir (void)
432 {
433   gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
434   int i;
435   GFile *xdg_file, *old_file;
436   static const gchar* filenames[] = {
437     "geometry.ini",
438     "irc-networks.xml",
439     "chatrooms.xml",
440     "contact-groups.xml",
441     "status-presets.xml",
442     "accels.txt",
443     NULL
444   };
445
446   xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
447   if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
448     {
449       /* xdg config dir already exists */
450       g_free (xdg_dir);
451       return;
452     }
453
454   old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
455       PACKAGE_NAME, NULL);
456   if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
457     {
458       /* old config dir didn't exist */
459       g_free (xdg_dir);
460       g_free (old_dir);
461       return;
462     }
463
464   if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1)
465     {
466       DEBUG ("Failed to create configuration directory; aborting migration");
467       g_free (xdg_dir);
468       g_free (old_dir);
469       return;
470     }
471
472   for (i = 0; filenames[i]; i++)
473     {
474       old_filename = g_build_filename (old_dir, filenames[i], NULL);
475       if (!g_file_test (old_filename, G_FILE_TEST_EXISTS))
476         {
477           g_free (old_filename);
478           continue;
479         }
480       xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
481       old_file = g_file_new_for_path (old_filename);
482       xdg_file = g_file_new_for_path (xdg_filename);
483
484       if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
485           NULL, NULL, NULL, NULL))
486         DEBUG ("Failed to migrate %s", filenames[i]);
487
488       g_free (old_filename);
489       g_free (xdg_filename);
490       g_object_unref (old_file);
491       g_object_unref (xdg_file);
492     }
493
494   g_free (xdg_dir);
495   g_free (old_dir);
496 }
497
498 static void
499 show_accounts_ui (EmpathyApp *self,
500     GdkScreen *screen,
501     gboolean if_needed)
502 {
503   empathy_accounts_dialog_show_application (screen,
504       NULL, if_needed, self->start_hidden);
505 }
506
507 static gboolean
508 show_version_cb (const char *option_name,
509     const char *value,
510     gpointer data,
511     GError **error)
512 {
513   g_print ("%s\n", PACKAGE_STRING);
514
515   exit (EXIT_SUCCESS);
516 }
517
518 static void
519 account_manager_ready_cb (GObject *source_object,
520     GAsyncResult *result,
521     gpointer user_data)
522 {
523   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
524   EmpathyApp *self = user_data;
525   GError *error = NULL;
526   TpConnectionPresenceType presence;
527
528   if (!tp_account_manager_prepare_finish (manager, result, &error))
529     {
530       GtkWidget *dialog;
531
532       DEBUG ("Failed to prepare account manager: %s", error->message);
533
534       dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
535           GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
536           _("Error contacting the Account Manager"));
537       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
538           _("There was an error while trying to connect to the Telepathy "
539             "Account Manager. The error was:\n\n%s"),
540           error->message);
541
542       gtk_dialog_run (GTK_DIALOG (dialog));
543       gtk_widget_destroy (dialog);
544
545       g_error_free (error);
546       return;
547     }
548
549   /* Autoconnect */
550   presence = tp_account_manager_get_most_available_presence (manager, NULL,
551       NULL);
552
553   if (g_settings_get_boolean (self->gsettings, EMPATHY_PREFS_AUTOCONNECT) &&
554       !self->no_connect &&
555       tp_connection_presence_type_cmp_availability
556           (presence, TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
557             <= 0)
558       /* if current state is Offline, then put it online */
559       empathy_presence_manager_set_state (self->presence_mgr,
560           TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
561
562   /* Pop up the accounts dialog if we don't have any account */
563   if (!empathy_accounts_has_accounts (manager))
564     show_accounts_ui (self, gdk_screen_get_default (), TRUE);
565 }
566
567 static void
568 account_join_chatrooms (TpAccount *account,
569   EmpathyChatroomManager *chatroom_manager)
570 {
571   TpConnection *conn;
572   GList *chatrooms, *p;
573
574   if (tp_account_get_connection_status (account, NULL) !=
575       TP_CONNECTION_STATUS_CONNECTED)
576     return;
577
578   /* If we're connected we should have a connection */
579   conn = tp_account_get_connection (account);
580   g_return_if_fail (conn != NULL);
581
582   chatrooms = empathy_chatroom_manager_get_chatrooms (
583           chatroom_manager, account);
584
585   for (p = chatrooms; p != NULL; p = p->next)
586     {
587       EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
588
589       if (!empathy_chatroom_get_auto_connect (room))
590         continue;
591
592       empathy_join_muc (account, empathy_chatroom_get_room (room),
593         TP_USER_ACTION_TIME_NOT_USER_ACTION);
594     }
595   g_list_free (chatrooms);
596 }
597
598 static void
599 account_status_changed_cb (TpAccount *account,
600     guint old_status,
601     guint new_status,
602     guint reason,
603     gchar *dbus_error_name,
604     GHashTable *details,
605     EmpathyChatroomManager *manager)
606 {
607   account_join_chatrooms (account, manager);
608 }
609
610 static void
611 account_manager_chatroom_ready_cb (GObject *source_object,
612     GAsyncResult *result,
613     gpointer user_data)
614 {
615   TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
616   EmpathyChatroomManager *chatroom_manager = user_data;
617   GList *accounts, *l;
618   GError *error = NULL;
619
620   if (!tp_account_manager_prepare_finish (account_manager, result, &error))
621     {
622       DEBUG ("Failed to prepare account manager: %s", error->message);
623       g_error_free (error);
624       return;
625     }
626
627   accounts = tp_account_manager_get_valid_accounts (account_manager);
628
629   for (l = accounts; l != NULL; l = g_list_next (l))
630     {
631       TpAccount *account = TP_ACCOUNT (l->data);
632
633       /* Try to join all rooms if we're connected */
634       account_join_chatrooms (account, chatroom_manager);
635
636       /* And/or join them on (re)connection */
637       tp_g_signal_connect_object (account, "status-changed",
638         G_CALLBACK (account_status_changed_cb), chatroom_manager, 0);
639     }
640   g_list_free (accounts);
641 }
642
643 static void
644 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
645     GParamSpec *pspec,
646     gpointer user_data)
647 {
648   TpAccountManager *account_manager = user_data;
649
650   tp_account_manager_prepare_async (account_manager, NULL,
651       account_manager_chatroom_ready_cb, chatroom_manager);
652 }
653
654 static void
655 empathy_presence_manager_set_auto_away_cb (GSettings *gsettings,
656                                 const gchar *key,
657                                 gpointer user_data)
658 {
659         EmpathyPresenceManager *presence_mgr = user_data;
660
661         empathy_presence_manager_set_auto_away (presence_mgr,
662       g_settings_get_boolean (gsettings, key));
663 }
664
665 static void
666 empathy_app_constructed (GObject *object)
667 {
668   EmpathyApp *self = (EmpathyApp *) object;
669   gboolean chatroom_manager_ready;
670   gboolean autoaway;
671
672   g_set_application_name (_(PACKAGE_NAME));
673
674   gtk_window_set_default_icon_name ("empathy");
675   textdomain (GETTEXT_PACKAGE);
676
677 #ifdef ENABLE_DEBUG
678   /* Set up debug sender */
679   self->debug_sender = tp_debug_sender_dup ();
680   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
681 #endif
682
683   notify_init (_(PACKAGE_NAME));
684
685   /* Setting up Idle */
686   self->presence_mgr = empathy_presence_manager_dup_singleton ();
687
688   self->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
689   autoaway = g_settings_get_boolean (self->gsettings, EMPATHY_PREFS_AUTOAWAY);
690
691   g_signal_connect (self->gsettings,
692       "changed::" EMPATHY_PREFS_AUTOAWAY,
693       G_CALLBACK (empathy_presence_manager_set_auto_away_cb),
694       self->presence_mgr);
695
696   empathy_presence_manager_set_auto_away (self->presence_mgr, autoaway);
697
698   /* Setting up Connectivity */
699   self->connectivity = empathy_connectivity_dup_singleton ();
700   use_conn_notify_cb (self->gsettings, EMPATHY_PREFS_USE_CONN,
701       self->connectivity);
702   g_signal_connect (self->gsettings,
703       "changed::" EMPATHY_PREFS_USE_CONN,
704       G_CALLBACK (use_conn_notify_cb), self->connectivity);
705
706   /* account management */
707   self->account_manager = tp_account_manager_dup ();
708   tp_account_manager_prepare_async (self->account_manager, NULL,
709       account_manager_ready_cb, self);
710
711   migrate_config_to_xdg_dir ();
712
713   /* Logging */
714   self->log_manager = tpl_log_manager_dup_singleton ();
715
716   self->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
717
718   g_object_get (self->chatroom_manager, "ready", &chatroom_manager_ready, NULL);
719   if (!chatroom_manager_ready)
720     {
721       g_signal_connect (G_OBJECT (self->chatroom_manager), "notify::ready",
722           G_CALLBACK (chatroom_manager_ready_cb), self->account_manager);
723     }
724   else
725     {
726       chatroom_manager_ready_cb (self->chatroom_manager, NULL,
727           self->account_manager);
728     }
729
730   /* Location mananger */
731 #ifdef HAVE_GEOCLUE
732   self->location_manager = empathy_location_manager_dup_singleton ();
733 #endif
734
735   self->activated = FALSE;
736   self->ft_factory = NULL;
737   self->window = NULL;
738 }
739
740 int
741 main (int argc, char *argv[])
742 {
743   EmpathyApp *app;
744   gint retval;
745
746   g_thread_init (NULL);
747   g_type_init ();
748
749 #ifdef HAVE_LIBCHAMPLAIN
750   gtk_clutter_init (&argc, &argv);
751 #endif
752
753   g_type_init ();
754   tpy_cli_init ();
755   empathy_init ();
756   gtk_init (&argc, &argv);
757   empathy_gtk_init ();
758
759   app = g_object_new (EMPATHY_TYPE_APP,
760       "application-id", EMPATHY_DBUS_NAME,
761       "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
762       NULL);
763
764   retval = g_application_run (G_APPLICATION (app), argc, argv);
765
766   notify_uninit ();
767   xmlCleanupParser ();
768
769   g_object_unref (app);
770
771   return retval;
772 }