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