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