]> git.0d.be Git - empathy.git/blob - src/empathy.c
add timestamp arg to empathy_dispatcher_join_muc
[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/gi18n.h>
30 #include <gtk/gtk.h>
31 #include <gdk/gdkx.h>
32 #include <unique/unique.h>
33
34 #if 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 #ifdef ENABLE_TPL
48 #include <telepathy-logger/log-manager.h>
49 #include <telepathy-logger/log-store-empathy.h>
50 #else
51
52 #include <libempathy/empathy-log-manager.h>
53 #endif /* ENABLE_TPL */
54 #include <libempathy/empathy-idle.h>
55 #include <libempathy/empathy-utils.h>
56 #include <libempathy/empathy-call-factory.h>
57 #include <libempathy/empathy-chatroom-manager.h>
58 #include <libempathy/empathy-account-settings.h>
59 #include <libempathy/empathy-connectivity.h>
60 #include <libempathy/empathy-connection-managers.h>
61 #include <libempathy/empathy-dispatcher.h>
62 #include <libempathy/empathy-dispatch-operation.h>
63 #include <libempathy/empathy-ft-factory.h>
64 #include <libempathy/empathy-tp-chat.h>
65 #include <libempathy/empathy-tp-call.h>
66
67 #include <libempathy-gtk/empathy-conf.h>
68 #include <libempathy-gtk/empathy-ui-utils.h>
69 #include <libempathy-gtk/empathy-location-manager.h>
70
71 #include "empathy-main-window.h"
72 #include "empathy-import-mc4-accounts.h"
73 #include "empathy-accounts-common.h"
74 #include "empathy-accounts-dialog.h"
75 #include "empathy-chat-manager.h"
76 #include "empathy-status-icon.h"
77 #include "empathy-call-window.h"
78 #include "empathy-chat-window.h"
79 #include "empathy-ft-manager.h"
80
81 #include "extensions/extensions.h"
82
83 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
84 #include <libempathy/empathy-debug.h>
85
86 #include <gst/gst.h>
87
88 static gboolean start_hidden = FALSE;
89 static gboolean no_connect = FALSE;
90
91 static void account_manager_ready_cb (GObject *source_object,
92     GAsyncResult *result,
93     gpointer user_data);
94
95 static void
96 dispatch_cb (EmpathyDispatcher *dispatcher,
97     EmpathyDispatchOperation *operation,
98     gpointer user_data)
99 {
100   GQuark channel_type;
101
102   channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
103
104   if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
105     {
106       EmpathyTpChat *tp_chat;
107       EmpathyChat   *chat = NULL;
108       const gchar   *id;
109
110       tp_chat = EMPATHY_TP_CHAT
111         (empathy_dispatch_operation_get_channel_wrapper (operation));
112
113       id = empathy_tp_chat_get_id (tp_chat);
114       if (!EMP_STR_EMPTY (id))
115         {
116           TpConnection *connection;
117           TpAccount *account;
118
119           connection = empathy_tp_chat_get_connection (tp_chat);
120           account = empathy_get_account_for_connection (connection);
121           chat = empathy_chat_window_find_chat (account, id);
122         }
123
124       if (chat)
125         {
126           empathy_chat_set_tp_chat (chat, tp_chat);
127         }
128       else
129         {
130           chat = empathy_chat_new (tp_chat);
131           /* empathy_chat_new returns a floating reference as EmpathyChat is
132            * a GtkWidget. This reference will be taken by a container
133            * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
134         }
135
136       empathy_chat_window_present_chat (chat);
137
138       empathy_dispatch_operation_claim (operation);
139     }
140   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
141     {
142       EmpathyCallFactory *factory;
143
144       factory = empathy_call_factory_get ();
145       empathy_call_factory_claim_channel (factory, operation);
146     }
147   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
148     {
149       EmpathyFTFactory *factory;
150
151       factory = empathy_ft_factory_dup_singleton ();
152
153       /* if the operation is not incoming, don't claim it,
154        * as it might have been triggered by another client, and
155        * we are observing it.
156        */
157       if (empathy_dispatch_operation_is_incoming (operation))
158         empathy_ft_factory_claim_channel (factory, operation);
159     }
160 }
161
162 static void
163 use_conn_notify_cb (EmpathyConf *conf,
164     const gchar *key,
165     gpointer     user_data)
166 {
167   EmpathyConnectivity *connectivity = user_data;
168   gboolean     use_conn;
169
170   if (empathy_conf_get_bool (conf, key, &use_conn))
171     {
172       empathy_connectivity_set_use_conn (connectivity, use_conn);
173     }
174 }
175
176 static void
177 migrate_config_to_xdg_dir (void)
178 {
179   gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
180   int i;
181   GFile *xdg_file, *old_file;
182   static const gchar* filenames[] = {
183     "geometry.ini",
184     "irc-networks.xml",
185     "chatrooms.xml",
186     "contact-groups.xml",
187     "status-presets.xml",
188     "accels.txt",
189     NULL
190   };
191
192   xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
193   if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
194     {
195       /* xdg config dir already exists */
196       g_free (xdg_dir);
197       return;
198     }
199
200   old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
201       PACKAGE_NAME, NULL);
202   if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
203     {
204       /* old config dir didn't exist */
205       g_free (xdg_dir);
206       g_free (old_dir);
207       return;
208     }
209
210   if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1)
211     {
212       DEBUG ("Failed to create configuration directory; aborting migration");
213       g_free (xdg_dir);
214       g_free (old_dir);
215       return;
216     }
217
218   for (i = 0; filenames[i]; i++)
219     {
220       old_filename = g_build_filename (old_dir, filenames[i], NULL);
221       if (!g_file_test (old_filename, G_FILE_TEST_EXISTS))
222         {
223           g_free (old_filename);
224           continue;
225         }
226       xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
227       old_file = g_file_new_for_path (old_filename);
228       xdg_file = g_file_new_for_path (xdg_filename);
229
230       if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
231           NULL, NULL, NULL, NULL))
232         DEBUG ("Failed to migrate %s", filenames[i]);
233
234       g_free (old_filename);
235       g_free (xdg_filename);
236       g_object_unref (old_file);
237       g_object_unref (xdg_file);
238     }
239
240   g_free (xdg_dir);
241   g_free (old_dir);
242 }
243
244 static void
245 show_accounts_ui (GdkScreen *screen,
246     gboolean if_needed)
247 {
248   empathy_accounts_dialog_show_application (screen,
249       NULL, if_needed, start_hidden);
250 }
251
252 static UniqueResponse
253 unique_app_message_cb (UniqueApp *unique_app,
254     gint command,
255     UniqueMessageData *data,
256     guint timestamp,
257     gpointer user_data)
258 {
259   GtkWindow *window = user_data;
260   TpAccountManager *account_manager;
261
262   DEBUG ("Other instance launched, presenting the main window. "
263       "Command=%d, timestamp %u", command, timestamp);
264
265   /* XXX: the standalone app somewhat breaks this case, since
266    * communicating it would be a pain */
267
268   /* We're requested to show stuff again, disable the start hidden global
269    * in case the accounts wizard wants to pop up.
270    */
271   start_hidden = FALSE;
272
273   gtk_window_set_screen (GTK_WINDOW (window),
274       unique_message_data_get_screen (data));
275   gtk_window_set_startup_id (GTK_WINDOW (window),
276       unique_message_data_get_startup_id (data));
277   gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
278   gtk_window_set_skip_taskbar_hint (window, FALSE);
279
280   account_manager = tp_account_manager_dup ();
281   tp_account_manager_prepare_async (account_manager, NULL,
282       account_manager_ready_cb, NULL);
283   g_object_unref (account_manager);
284
285   return UNIQUE_RESPONSE_OK;
286 }
287
288 static gboolean
289 show_version_cb (const char *option_name,
290     const char *value,
291     gpointer data,
292     GError **error)
293 {
294   g_print ("%s\n", PACKAGE_STRING);
295
296   exit (EXIT_SUCCESS);
297
298   return FALSE;
299 }
300
301 static void
302 new_incoming_transfer_cb (EmpathyFTFactory *factory,
303     EmpathyFTHandler *handler,
304     GError *error,
305     gpointer user_data)
306 {
307   if (error)
308     empathy_ft_manager_display_error (handler, error);
309   else
310     empathy_receive_file_with_file_chooser (handler);
311 }
312
313 static void
314 new_ft_handler_cb (EmpathyFTFactory *factory,
315     EmpathyFTHandler *handler,
316     GError *error,
317     gpointer user_data)
318 {
319   if (error)
320     empathy_ft_manager_display_error (handler, error);
321   else
322     empathy_ft_manager_add_handler (handler);
323
324   g_object_unref (handler);
325 }
326
327 static void
328 new_call_handler_cb (EmpathyCallFactory *factory,
329     EmpathyCallHandler *handler,
330     gboolean outgoing,
331     gpointer user_data)
332 {
333   EmpathyCallWindow *window;
334
335   window = empathy_call_window_new (handler);
336   gtk_widget_show (GTK_WIDGET (window));
337 }
338
339 static void
340 account_manager_ready_cb (GObject *source_object,
341     GAsyncResult *result,
342     gpointer user_data)
343 {
344   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
345   GError *error = NULL;
346   EmpathyIdle *idle;
347   EmpathyConnectivity *connectivity;
348   gboolean autoconnect = TRUE;
349   TpConnectionPresenceType presence;
350
351   if (!tp_account_manager_prepare_finish (manager, result, &error))
352     {
353       DEBUG ("Failed to prepare account manager: %s", error->message);
354       g_error_free (error);
355       return;
356     }
357
358   /* Autoconnect */
359   idle = empathy_idle_dup_singleton ();
360   connectivity = empathy_connectivity_dup_singleton ();
361
362   presence = tp_account_manager_get_most_available_presence (manager, NULL,
363       NULL);
364
365   empathy_conf_get_bool (empathy_conf_get (),
366       EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
367   if (autoconnect && !no_connect &&
368       tp_connection_presence_type_cmp_availability
369           (presence, TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
370             <= 0)
371       /* if current state is Offline, then put it online */
372       empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
373
374   /* Pop up the accounts dialog if it's needed (either when we don't have any
375    * accounts yet or when we haven't imported mc4 accounts yet */
376   if (!empathy_accounts_has_accounts (manager)
377       || !empathy_import_mc4_has_imported ())
378     show_accounts_ui (gdk_screen_get_default (), TRUE);
379
380   g_object_unref (idle);
381   g_object_unref (connectivity);
382 }
383
384 static EmpathyDispatcher *
385 setup_dispatcher (void)
386 {
387   EmpathyDispatcher *d;
388   GPtrArray *filters;
389   struct {
390     const gchar *channeltype;
391     TpHandleType handletype;
392   } types[] = {
393     /* Text channels with handle types none, contact and room */
394     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_NONE  },
395     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_CONTACT  },
396     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM  },
397     /* file transfer to contacts */
398     { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT  },
399     /* stream media to contacts */
400     { TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT  },
401     /* roomlists */
402     { TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE },
403   };
404   gchar *capabilities[] = {
405     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
406     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
407     NULL };
408   GHashTable *asv;
409   guint i;
410
411   /* Setup the basic Client.Handler that matches our client filter */
412   filters = g_ptr_array_new ();
413   asv = tp_asv_new (
414         TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
415            TP_IFACE_CHANNEL_TYPE_TEXT,
416         TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT,
417             TP_HANDLE_TYPE_CONTACT,
418         NULL);
419   g_ptr_array_add (filters, asv);
420
421   d = empathy_dispatcher_new (PACKAGE_NAME, filters, NULL);
422
423   g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
424   g_ptr_array_free (filters, TRUE);
425
426   /* Setup the an extended Client.Handler that matches everything we can do */
427   filters = g_ptr_array_new ();
428   for (i = 0 ; i < G_N_ELEMENTS (types); i++)
429     {
430       asv = tp_asv_new (
431         TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, types[i].channeltype,
432         TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT, types[i].handletype,
433         NULL);
434
435       g_ptr_array_add (filters, asv);
436     }
437
438   asv = tp_asv_new (
439         TP_IFACE_CHANNEL ".ChannelType",
440           G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
441         TP_IFACE_CHANNEL ".TargetHandleType",
442           G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
443         TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialAudio",
444           G_TYPE_BOOLEAN, TRUE,
445         NULL);
446   g_ptr_array_add (filters, asv);
447
448   asv = tp_asv_new (
449         TP_IFACE_CHANNEL ".ChannelType",
450           G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
451         TP_IFACE_CHANNEL ".TargetHandleType",
452           G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
453         TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo",
454           G_TYPE_BOOLEAN, TRUE,
455         NULL);
456   g_ptr_array_add (filters, asv);
457
458
459   empathy_dispatcher_add_handler (d, PACKAGE_NAME"MoreThanMeetsTheEye",
460     filters, capabilities);
461
462   g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
463   g_ptr_array_free (filters, TRUE);
464
465   return d;
466 }
467
468 static void
469 account_status_changed_cb (TpAccount *account,
470     guint old_status,
471     guint new_status,
472     guint reason,
473     gchar *dbus_error_name,
474     GHashTable *details,
475     EmpathyChatroom *room)
476 {
477   TpConnection *conn;
478
479   conn = tp_account_get_connection (account);
480   if (conn == NULL)
481     return;
482
483   empathy_dispatcher_join_muc (conn,
484       empathy_chatroom_get_room (room), EMPATHY_DISPATCHER_NON_USER_ACTION,
485       NULL, NULL);
486 }
487
488 static void
489 account_manager_chatroom_ready_cb (GObject *source_object,
490     GAsyncResult *result,
491     gpointer user_data)
492 {
493   TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
494   EmpathyChatroomManager *chatroom_manager = user_data;
495   GList *accounts, *l;
496   GError *error = NULL;
497
498   if (!tp_account_manager_prepare_finish (account_manager, result, &error))
499     {
500       DEBUG ("Failed to prepare account manager: %s", error->message);
501       g_error_free (error);
502       return;
503     }
504
505   accounts = tp_account_manager_get_valid_accounts (account_manager);
506
507   for (l = accounts; l != NULL; l = g_list_next (l))
508     {
509       TpAccount *account = TP_ACCOUNT (l->data);
510       TpConnection *conn;
511       GList *chatrooms, *p;
512
513       conn = tp_account_get_connection (account);
514
515       chatrooms = empathy_chatroom_manager_get_chatrooms (
516           chatroom_manager, account);
517
518       for (p = chatrooms; p != NULL; p = p->next)
519         {
520           EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
521
522           if (!empathy_chatroom_get_auto_connect (room))
523             continue;
524
525           if (conn == NULL)
526             {
527               g_signal_connect (G_OBJECT (account), "status-changed",
528                   G_CALLBACK (account_status_changed_cb), room);
529             }
530           else
531             {
532               empathy_dispatcher_join_muc (conn,
533                   empathy_chatroom_get_room (room),
534                   EMPATHY_DISPATCHER_NON_USER_ACTION, NULL, NULL);
535             }
536         }
537
538       g_list_free (chatrooms);
539     }
540
541   g_list_free (accounts);
542 }
543
544 static void
545 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
546     GParamSpec *pspec,
547     gpointer user_data)
548 {
549   TpAccountManager *account_manager = user_data;
550
551   tp_account_manager_prepare_async (account_manager, NULL,
552       account_manager_chatroom_ready_cb, chatroom_manager);
553 }
554
555 static void
556 empathy_idle_set_auto_away_cb (EmpathyConf *conf,
557                                 const gchar *key,
558                                 gpointer user_data)
559 {
560         gboolean autoaway;
561         EmpathyIdle *idle = user_data;
562
563         empathy_conf_get_bool (conf, key, &autoaway);
564         empathy_idle_set_auto_away (idle, autoaway);
565 }
566
567 int
568 main (int argc, char *argv[])
569 {
570 #if HAVE_GEOCLUE
571   EmpathyLocationManager *location_manager = NULL;
572 #endif
573   EmpathyStatusIcon *icon;
574   EmpathyDispatcher *dispatcher;
575   TpAccountManager *account_manager;
576 #ifdef ENABLE_TPL
577   TplLogManager *log_manager;
578 #else
579   EmpathyLogManager *log_manager;
580 #endif /* ENABLE_TPL */
581   EmpathyChatroomManager *chatroom_manager;
582   EmpathyCallFactory *call_factory;
583   EmpathyFTFactory  *ft_factory;
584   GtkWidget *window;
585   EmpathyIdle *idle;
586   EmpathyConnectivity *connectivity;
587   EmpathyChatManager *chat_manager;
588   GError *error = NULL;
589   UniqueApp *unique_app;
590   gboolean chatroom_manager_ready;
591   gboolean autoaway = TRUE;
592 #ifdef ENABLE_DEBUG
593   TpDebugSender *debug_sender;
594 #endif
595
596   GOptionContext *optcontext;
597   GOptionEntry options[] = {
598       { "no-connect", 'n',
599         0, G_OPTION_ARG_NONE, &no_connect,
600         N_("Don't connect on startup"),
601         NULL },
602       { "start-hidden", 'h',
603         0, G_OPTION_ARG_NONE, &start_hidden,
604         N_("Don't display the contact list or any other dialogs on startup"),
605         NULL },
606       { "version", 'v',
607         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
608         NULL, NULL },
609       { NULL }
610   };
611
612   /* Init */
613   g_thread_init (NULL);
614   empathy_init ();
615
616   optcontext = g_option_context_new (N_("- Empathy IM Client"));
617   g_option_context_add_group (optcontext, gst_init_get_option_group ());
618   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
619 #if HAVE_LIBCHAMPLAIN
620   g_option_context_add_group (optcontext, clutter_get_option_group ());
621 #endif
622   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
623
624   if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
625     g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
626         error->message, argv[0]);
627     g_warning ("Error in empathy init: %s", error->message);
628     return EXIT_FAILURE;
629   }
630
631   g_option_context_free (optcontext);
632
633   empathy_gtk_init ();
634   g_set_application_name (_(PACKAGE_NAME));
635   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
636
637   gtk_window_set_default_icon_name ("empathy");
638   textdomain (GETTEXT_PACKAGE);
639
640 #ifdef ENABLE_DEBUG
641   /* Set up debug sender */
642   debug_sender = tp_debug_sender_dup ();
643   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
644 #endif
645
646   unique_app = unique_app_new ("org.gnome."PACKAGE_NAME, NULL);
647
648   if (unique_app_is_running (unique_app))
649     {
650       unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
651
652       g_object_unref (unique_app);
653       return EXIT_SUCCESS;
654     }
655
656   notify_init (_(PACKAGE_NAME));
657
658   /* Setting up Idle */
659   idle = empathy_idle_dup_singleton ();
660
661   empathy_conf_get_bool (empathy_conf_get (),
662       EMPATHY_PREFS_AUTOAWAY, &autoaway);
663
664   empathy_conf_notify_add (empathy_conf_get (),
665                            EMPATHY_PREFS_AUTOAWAY,
666                            empathy_idle_set_auto_away_cb,
667                            idle);
668
669   empathy_idle_set_auto_away (idle, autoaway);
670
671   /* Setting up Connectivity */
672   connectivity = empathy_connectivity_dup_singleton ();
673   use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
674       connectivity);
675   empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
676       use_conn_notify_cb, connectivity);
677
678   /* account management */
679   account_manager = tp_account_manager_dup ();
680   tp_account_manager_prepare_async (account_manager, NULL,
681       account_manager_ready_cb, NULL);
682
683   /* Handle channels */
684   dispatcher = setup_dispatcher ();
685   g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
686
687   migrate_config_to_xdg_dir ();
688
689   /* Setting up UI */
690   window = empathy_main_window_show ();
691   icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
692
693   /* Chat manager */
694   chat_manager = empathy_chat_manager_dup_singleton ();
695
696   g_signal_connect (unique_app, "message-received",
697       G_CALLBACK (unique_app_message_cb), window);
698
699   /* Logging */
700 #ifdef ENABLE_TPL
701   log_manager = tpl_log_manager_dup_singleton ();
702 #else
703   log_manager = empathy_log_manager_dup_singleton ();
704   empathy_log_manager_observe (log_manager, dispatcher);
705 #endif
706
707   chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
708   empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
709
710   g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
711   if (!chatroom_manager_ready)
712     {
713       g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
714           G_CALLBACK (chatroom_manager_ready_cb), account_manager);
715     }
716   else
717     {
718       chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
719     }
720
721   /* Create the call factory */
722   call_factory = empathy_call_factory_initialise ();
723   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
724       G_CALLBACK (new_call_handler_cb), NULL);
725   /* Create the FT factory */
726   ft_factory = empathy_ft_factory_dup_singleton ();
727   g_signal_connect (ft_factory, "new-ft-handler",
728       G_CALLBACK (new_ft_handler_cb), NULL);
729   g_signal_connect (ft_factory, "new-incoming-transfer",
730       G_CALLBACK (new_incoming_transfer_cb), NULL);
731
732   /* Location mananger */
733 #if HAVE_GEOCLUE
734   location_manager = empathy_location_manager_dup_singleton ();
735 #endif
736
737   gtk_main ();
738
739   empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
740
741 #ifdef ENABLE_DEBUG
742   g_object_unref (debug_sender);
743 #endif
744
745   g_object_unref (chat_manager);
746   g_object_unref (idle);
747   g_object_unref (connectivity);
748   g_object_unref (icon);
749   g_object_unref (account_manager);
750   g_object_unref (log_manager);
751   g_object_unref (dispatcher);
752   g_object_unref (chatroom_manager);
753 #if HAVE_GEOCLUE
754   g_object_unref (location_manager);
755 #endif
756   g_object_unref (ft_factory);
757   g_object_unref (unique_app);
758
759   notify_uninit ();
760   xmlCleanupParser ();
761
762   return EXIT_SUCCESS;
763 }