]> git.0d.be Git - empathy.git/blob - src/empathy.c
8609794e81cf24f21d3553a19d12e069b98891b2
[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 #include <libempathy/empathy-idle.h>
48 #include <libempathy/empathy-utils.h>
49 #include <libempathy/empathy-call-factory.h>
50 #include <libempathy/empathy-chatroom-manager.h>
51 #include <libempathy/empathy-account-settings.h>
52 #include <libempathy/empathy-connectivity.h>
53 #include <libempathy/empathy-connection-managers.h>
54 #include <libempathy/empathy-dispatcher.h>
55 #include <libempathy/empathy-dispatch-operation.h>
56 #include <libempathy/empathy-log-manager.h>
57 #include <libempathy/empathy-ft-factory.h>
58 #include <libempathy/empathy-tp-chat.h>
59 #include <libempathy/empathy-tp-call.h>
60
61 #include <libempathy-gtk/empathy-conf.h>
62 #include <libempathy-gtk/empathy-ui-utils.h>
63 #include <libempathy-gtk/empathy-location-manager.h>
64
65 #include "empathy-main-window.h"
66 #include "empathy-accounts-dialog.h"
67 #include "empathy-status-icon.h"
68 #include "empathy-call-window.h"
69 #include "empathy-chat-window.h"
70 #include "empathy-ft-manager.h"
71
72 #include "extensions/extensions.h"
73
74 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
75 #include <libempathy/empathy-debug.h>
76
77 #include <gst/gst.h>
78
79 #define COMMAND_ACCOUNTS_DIALOG 1
80
81 static gboolean account_dialog_only = FALSE;
82 static gboolean start_hidden = FALSE;
83 static gboolean no_connect = FALSE;
84
85 static void
86 dispatch_cb (EmpathyDispatcher *dispatcher,
87     EmpathyDispatchOperation *operation,
88     gpointer user_data)
89 {
90   GQuark channel_type;
91
92   channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
93
94   if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
95     {
96       EmpathyTpChat *tp_chat;
97       EmpathyChat   *chat = NULL;
98       const gchar   *id;
99
100       tp_chat = EMPATHY_TP_CHAT
101         (empathy_dispatch_operation_get_channel_wrapper (operation));
102
103       id = empathy_tp_chat_get_id (tp_chat);
104       if (!EMP_STR_EMPTY (id))
105         {
106           TpConnection *connection;
107           TpAccount *account;
108
109           connection = empathy_tp_chat_get_connection (tp_chat);
110           account = empathy_get_account_for_connection (connection);
111           chat = empathy_chat_window_find_chat (account, id);
112         }
113
114       if (chat)
115         {
116           empathy_chat_set_tp_chat (chat, tp_chat);
117         }
118       else
119         {
120           chat = empathy_chat_new (tp_chat);
121           /* empathy_chat_new returns a floating reference as EmpathyChat is
122            * a GtkWidget. This reference will be taken by a container
123            * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
124         }
125
126       empathy_chat_window_present_chat (chat);
127
128       empathy_dispatch_operation_claim (operation);
129     }
130   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
131     {
132       EmpathyCallFactory *factory;
133
134       factory = empathy_call_factory_get ();
135       empathy_call_factory_claim_channel (factory, operation);
136     }
137   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
138     {
139       EmpathyFTFactory *factory;
140
141       factory = empathy_ft_factory_dup_singleton ();
142
143       /* if the operation is not incoming, don't claim it,
144        * as it might have been triggered by another client, and
145        * we are observing it.
146        */
147       if (empathy_dispatch_operation_is_incoming (operation))
148         empathy_ft_factory_claim_channel (factory, operation);
149     }
150 }
151
152 static void
153 use_conn_notify_cb (EmpathyConf *conf,
154     const gchar *key,
155     gpointer     user_data)
156 {
157   EmpathyConnectivity *connectivity = user_data;
158   gboolean     use_conn;
159
160   if (empathy_conf_get_bool (conf, key, &use_conn))
161     {
162       empathy_connectivity_set_use_conn (connectivity, use_conn);
163     }
164 }
165
166 static void
167 migrate_config_to_xdg_dir (void)
168 {
169   gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
170   int i;
171   GFile *xdg_file, *old_file;
172   static const gchar* filenames[] = {
173     "geometry.ini",
174     "irc-networks.xml",
175     "chatrooms.xml",
176     "contact-groups.xml",
177     "status-presets.xml",
178     "accels.txt",
179     NULL
180   };
181
182   xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
183   if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
184     {
185       /* xdg config dir already exists */
186       g_free (xdg_dir);
187       return;
188     }
189
190   old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
191       PACKAGE_NAME, NULL);
192   if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
193     {
194       /* old config dir didn't exist */
195       g_free (xdg_dir);
196       g_free (old_dir);
197       return;
198     }
199
200   if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1)
201     {
202       DEBUG ("Failed to create configuration directory; aborting migration");
203       g_free (xdg_dir);
204       g_free (old_dir);
205       return;
206     }
207
208   for (i = 0; filenames[i]; i++)
209     {
210       old_filename = g_build_filename (old_dir, filenames[i], NULL);
211       if (!g_file_test (old_filename, G_FILE_TEST_EXISTS))
212         {
213           g_free (old_filename);
214           continue;
215         }
216       xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
217       old_file = g_file_new_for_path (old_filename);
218       xdg_file = g_file_new_for_path (xdg_filename);
219
220       if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
221           NULL, NULL, NULL, NULL))
222         DEBUG ("Failed to migrate %s", filenames[i]);
223
224       g_free (old_filename);
225       g_free (xdg_filename);
226       g_object_unref (old_file);
227       g_object_unref (xdg_file);
228     }
229
230   g_free (xdg_dir);
231   g_free (old_dir);
232 }
233
234 static void
235 accounts_application_exited_cb (GPid pid,
236     gint status,
237     gpointer data)
238 {
239   if (status)
240     {
241       g_warning ("accounts application exited with status %d: '%s'",
242           status, g_strerror (status));
243     }
244
245   if (account_dialog_only)
246     gtk_main_quit ();
247 }
248
249 static void
250 show_accounts_ui (GdkScreen *screen,
251     gboolean try_import)
252 {
253   empathy_accounts_dialog_show_application (screen,
254       accounts_application_exited_cb, NULL, NULL, try_import, start_hidden);
255 }
256
257 static UniqueResponse
258 unique_app_message_cb (UniqueApp *unique_app,
259     gint command,
260     UniqueMessageData *data,
261     guint timestamp,
262     gpointer user_data)
263 {
264   GtkWindow *window = user_data;
265
266   DEBUG ("Other instance launched, presenting the main window. "
267       "Command=%d, timestamp %u", command, timestamp);
268
269   if (command == COMMAND_ACCOUNTS_DIALOG)
270     {
271       show_accounts_ui (gdk_screen_get_default (), TRUE);
272     }
273   else
274     {
275       /* XXX: the standalone app somewhat breaks this case, since
276        * communicating it would be a pain */
277
278       /* We're requested to show stuff again, disable the start hidden global
279        * in case the accounts wizard wants to pop up.
280        */
281       start_hidden = FALSE;
282
283       gtk_window_set_screen (GTK_WINDOW (window),
284           unique_message_data_get_screen (data));
285       gtk_window_set_startup_id (GTK_WINDOW (window),
286           unique_message_data_get_startup_id (data));
287       gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
288     }
289
290   return UNIQUE_RESPONSE_OK;
291 }
292
293 static gboolean
294 show_version_cb (const char *option_name,
295     const char *value,
296     gpointer data,
297     GError **error)
298 {
299   g_print ("%s\n", PACKAGE_STRING);
300
301   exit (EXIT_SUCCESS);
302
303   return FALSE;
304 }
305
306 static void
307 new_incoming_transfer_cb (EmpathyFTFactory *factory,
308     EmpathyFTHandler *handler,
309     GError *error,
310     gpointer user_data)
311 {
312   if (error)
313     empathy_ft_manager_display_error (handler, error);
314   else
315     empathy_receive_file_with_file_chooser (handler);
316 }
317
318 static void
319 new_ft_handler_cb (EmpathyFTFactory *factory,
320     EmpathyFTHandler *handler,
321     GError *error,
322     gpointer user_data)
323 {
324   if (error)
325     empathy_ft_manager_display_error (handler, error);
326   else
327     empathy_ft_manager_add_handler (handler);
328
329   g_object_unref (handler);
330 }
331
332 static void
333 new_call_handler_cb (EmpathyCallFactory *factory,
334     EmpathyCallHandler *handler,
335     gboolean outgoing,
336     gpointer user_data)
337 {
338   EmpathyCallWindow *window;
339
340   window = empathy_call_window_new (handler);
341   gtk_widget_show (GTK_WIDGET (window));
342 }
343
344 static void
345 account_manager_ready_cb (GObject *source_object,
346     GAsyncResult *result,
347     gpointer user_data)
348 {
349   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
350   GError *error = NULL;
351   EmpathyIdle *idle;
352   EmpathyConnectivity *connectivity;
353   gboolean autoconnect = TRUE;
354   TpConnectionPresenceType presence;
355
356   if (!tp_account_manager_prepare_finish (manager, result, &error))
357     {
358       DEBUG ("Failed to prepare account manager: %s", error->message);
359       g_error_free (error);
360       return;
361     }
362
363   /* Autoconnect */
364   idle = empathy_idle_dup_singleton ();
365   connectivity = empathy_connectivity_dup_singleton ();
366
367   presence = tp_account_manager_get_most_available_presence (manager, NULL,
368       NULL);
369
370   empathy_conf_get_bool (empathy_conf_get (),
371       EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
372   if (autoconnect && !no_connect &&
373       tp_connection_presence_type_cmp_availability
374           (presence, TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
375             <= 0)
376       /* if current state is Offline, then put it online */
377       empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
378
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), 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), NULL, NULL);
534             }
535         }
536
537       g_list_free (chatrooms);
538     }
539
540   g_list_free (accounts);
541 }
542
543 static void
544 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
545     GParamSpec *pspec,
546     gpointer user_data)
547 {
548   TpAccountManager *account_manager = user_data;
549
550   tp_account_manager_prepare_async (account_manager, NULL,
551       account_manager_chatroom_ready_cb, chatroom_manager);
552 }
553
554 int
555 main (int argc, char *argv[])
556 {
557 #if HAVE_GEOCLUE
558   EmpathyLocationManager *location_manager = NULL;
559 #endif
560   EmpathyStatusIcon *icon;
561   EmpathyDispatcher *dispatcher;
562   TpAccountManager *account_manager;
563   EmpathyLogManager *log_manager;
564   EmpathyChatroomManager *chatroom_manager;
565   EmpathyCallFactory *call_factory;
566   EmpathyFTFactory  *ft_factory;
567   GtkWidget *window;
568   EmpathyIdle *idle;
569   EmpathyConnectivity *connectivity;
570   GError *error = NULL;
571   UniqueApp *unique_app;
572   gboolean chatroom_manager_ready;
573
574 #ifdef ENABLE_DEBUG
575   TpDebugSender *debug_sender;
576 #endif
577
578   GOptionContext *optcontext;
579   GOptionEntry options[] = {
580       { "no-connect", 'n',
581         0, G_OPTION_ARG_NONE, &no_connect,
582         N_("Don't connect on startup"),
583         NULL },
584       { "start-hidden", 'h',
585         0, G_OPTION_ARG_NONE, &start_hidden,
586         N_("Don't display the contact list or any other dialogs on startup"),
587         NULL },
588       { "accounts", 'a',
589         0, G_OPTION_ARG_NONE, &account_dialog_only,
590         N_("Show the accounts dialog"),
591         NULL },
592       { "version", 'v',
593         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
594         NULL, NULL },
595       { NULL }
596   };
597
598   /* Init */
599   g_thread_init (NULL);
600   empathy_init ();
601
602   optcontext = g_option_context_new (N_("- Empathy IM Client"));
603   g_option_context_add_group (optcontext, gst_init_get_option_group ());
604   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
605 #if HAVE_LIBCHAMPLAIN
606   g_option_context_add_group (optcontext, clutter_get_option_group ());
607 #endif
608   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
609
610   if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
611     g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
612         error->message, argv[0]);
613     g_warning ("Error in empathy init: %s", error->message);
614     return EXIT_FAILURE;
615   }
616
617   g_option_context_free (optcontext);
618
619   empathy_gtk_init ();
620   g_set_application_name (_(PACKAGE_NAME));
621   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
622
623   gtk_window_set_default_icon_name ("empathy");
624   textdomain (GETTEXT_PACKAGE);
625
626 #ifdef ENABLE_DEBUG
627   /* Set up debug sender */
628   debug_sender = tp_debug_sender_dup ();
629   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
630 #endif
631
632   unique_app = unique_app_new_with_commands (EMPATHY_CLIENT_NAME,
633       NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL);
634
635   if (unique_app_is_running (unique_app))
636     {
637       unique_app_send_message (unique_app, account_dialog_only ?
638           COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL);
639
640       g_object_unref (unique_app);
641       return EXIT_SUCCESS;
642     }
643
644   if (account_dialog_only)
645     {
646       account_manager = tp_account_manager_dup ();
647       show_accounts_ui (gdk_screen_get_default (), FALSE);
648
649       gtk_main ();
650
651       g_object_unref (account_manager);
652       return 0;
653     }
654
655   notify_init (_(PACKAGE_NAME));
656
657   /* Setting up Idle */
658   idle = empathy_idle_dup_singleton ();
659   empathy_idle_set_auto_away (idle, TRUE);
660
661   /* Setting up Connectivity */
662   connectivity = empathy_connectivity_dup_singleton ();
663   use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
664       connectivity);
665   empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
666       use_conn_notify_cb, connectivity);
667
668   /* account management */
669   account_manager = tp_account_manager_dup ();
670   tp_account_manager_prepare_async (account_manager, NULL,
671       account_manager_ready_cb, NULL);
672
673   /* Handle channels */
674   dispatcher = setup_dispatcher ();
675   g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
676
677   migrate_config_to_xdg_dir ();
678
679   /* Setting up UI */
680   window = empathy_main_window_show ();
681   icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
682
683   g_signal_connect (unique_app, "message-received",
684       G_CALLBACK (unique_app_message_cb), window);
685
686   /* Logging */
687   log_manager = empathy_log_manager_dup_singleton ();
688   empathy_log_manager_observe (log_manager, dispatcher);
689
690   chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
691   empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
692
693   g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
694   if (!chatroom_manager_ready)
695     {
696       g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
697           G_CALLBACK (chatroom_manager_ready_cb), account_manager);
698     }
699   else
700     {
701       chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
702     }
703
704   /* Create the call factory */
705   call_factory = empathy_call_factory_initialise ();
706   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
707       G_CALLBACK (new_call_handler_cb), NULL);
708   /* Create the FT factory */
709   ft_factory = empathy_ft_factory_dup_singleton ();
710   g_signal_connect (ft_factory, "new-ft-handler",
711       G_CALLBACK (new_ft_handler_cb), NULL);
712   g_signal_connect (ft_factory, "new-incoming-transfer",
713       G_CALLBACK (new_incoming_transfer_cb), NULL);
714
715   /* Location mananger */
716 #if HAVE_GEOCLUE
717   location_manager = empathy_location_manager_dup_singleton ();
718 #endif
719
720   gtk_main ();
721
722   empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
723
724 #ifdef ENABLE_DEBUG
725   g_object_unref (debug_sender);
726 #endif
727
728   g_object_unref (idle);
729   g_object_unref (connectivity);
730   g_object_unref (icon);
731   g_object_unref (account_manager);
732   g_object_unref (log_manager);
733   g_object_unref (dispatcher);
734   g_object_unref (chatroom_manager);
735 #if HAVE_GEOCLUE
736   g_object_unref (location_manager);
737 #endif
738   g_object_unref (ft_factory);
739   g_object_unref (unique_app);
740
741   notify_uninit ();
742   xmlCleanupParser ();
743
744   return EXIT_SUCCESS;
745 }