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