]> git.0d.be Git - empathy.git/blob - src/empathy.c
Updated Polish translation
[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 accounts_application_exited_cb (GPid pid,
245     gint status,
246     gpointer data)
247 {
248   if (status)
249     {
250       g_warning ("accounts application exited with status %d: '%s'",
251           status, g_strerror (status));
252     }
253 }
254
255 static void
256 show_accounts_ui (GdkScreen *screen,
257     gboolean if_needed)
258 {
259   empathy_accounts_dialog_show_application (screen,
260       accounts_application_exited_cb, NULL, NULL, if_needed, start_hidden);
261 }
262
263 static UniqueResponse
264 unique_app_message_cb (UniqueApp *unique_app,
265     gint command,
266     UniqueMessageData *data,
267     guint timestamp,
268     gpointer user_data)
269 {
270   GtkWindow *window = user_data;
271   TpAccountManager *account_manager;
272
273   DEBUG ("Other instance launched, presenting the main window. "
274       "Command=%d, timestamp %u", command, timestamp);
275
276   /* XXX: the standalone app somewhat breaks this case, since
277    * communicating it would be a pain */
278
279   /* We're requested to show stuff again, disable the start hidden global
280    * in case the accounts wizard wants to pop up.
281    */
282   start_hidden = FALSE;
283
284   gtk_window_set_screen (GTK_WINDOW (window),
285       unique_message_data_get_screen (data));
286   gtk_window_set_startup_id (GTK_WINDOW (window),
287       unique_message_data_get_startup_id (data));
288   gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
289   gtk_window_set_skip_taskbar_hint (window, FALSE);
290
291   account_manager = tp_account_manager_dup ();
292   tp_account_manager_prepare_async (account_manager, NULL,
293       account_manager_ready_cb, NULL);
294   g_object_unref (account_manager);
295
296   return UNIQUE_RESPONSE_OK;
297 }
298
299 static gboolean
300 show_version_cb (const char *option_name,
301     const char *value,
302     gpointer data,
303     GError **error)
304 {
305   g_print ("%s\n", PACKAGE_STRING);
306
307   exit (EXIT_SUCCESS);
308
309   return FALSE;
310 }
311
312 static void
313 new_incoming_transfer_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_receive_file_with_file_chooser (handler);
322 }
323
324 static void
325 new_ft_handler_cb (EmpathyFTFactory *factory,
326     EmpathyFTHandler *handler,
327     GError *error,
328     gpointer user_data)
329 {
330   if (error)
331     empathy_ft_manager_display_error (handler, error);
332   else
333     empathy_ft_manager_add_handler (handler);
334
335   g_object_unref (handler);
336 }
337
338 static void
339 new_call_handler_cb (EmpathyCallFactory *factory,
340     EmpathyCallHandler *handler,
341     gboolean outgoing,
342     gpointer user_data)
343 {
344   EmpathyCallWindow *window;
345
346   window = empathy_call_window_new (handler);
347   gtk_widget_show (GTK_WIDGET (window));
348 }
349
350 static void
351 account_manager_ready_cb (GObject *source_object,
352     GAsyncResult *result,
353     gpointer user_data)
354 {
355   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
356   GError *error = NULL;
357   EmpathyIdle *idle;
358   EmpathyConnectivity *connectivity;
359   gboolean autoconnect = TRUE;
360   TpConnectionPresenceType presence;
361
362   if (!tp_account_manager_prepare_finish (manager, result, &error))
363     {
364       DEBUG ("Failed to prepare account manager: %s", error->message);
365       g_error_free (error);
366       return;
367     }
368
369   /* Autoconnect */
370   idle = empathy_idle_dup_singleton ();
371   connectivity = empathy_connectivity_dup_singleton ();
372
373   presence = tp_account_manager_get_most_available_presence (manager, NULL,
374       NULL);
375
376   empathy_conf_get_bool (empathy_conf_get (),
377       EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
378   if (autoconnect && !no_connect &&
379       tp_connection_presence_type_cmp_availability
380           (presence, TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
381             <= 0)
382       /* if current state is Offline, then put it online */
383       empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
384
385   /* Pop up the accounts dialog if it's needed (either when we don't have any
386    * non-salut accounts yet or when we haven't imported mc4 accounts yet */
387   if (!empathy_accounts_has_non_salut_accounts (manager)
388       || !empathy_import_mc4_has_imported ())
389     show_accounts_ui (gdk_screen_get_default (), TRUE);
390
391   g_object_unref (idle);
392   g_object_unref (connectivity);
393 }
394
395 static EmpathyDispatcher *
396 setup_dispatcher (void)
397 {
398   EmpathyDispatcher *d;
399   GPtrArray *filters;
400   struct {
401     const gchar *channeltype;
402     TpHandleType handletype;
403   } types[] = {
404     /* Text channels with handle types none, contact and room */
405     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_NONE  },
406     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_CONTACT  },
407     { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM  },
408     /* file transfer to contacts */
409     { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT  },
410     /* stream media to contacts */
411     { TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT  },
412     /* roomlists */
413     { TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE },
414   };
415   gchar *capabilities[] = {
416     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
417     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
418     NULL };
419   GHashTable *asv;
420   guint i;
421
422   /* Setup the basic Client.Handler that matches our client filter */
423   filters = g_ptr_array_new ();
424   asv = tp_asv_new (
425         TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
426            TP_IFACE_CHANNEL_TYPE_TEXT,
427         TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT,
428             TP_HANDLE_TYPE_CONTACT,
429         NULL);
430   g_ptr_array_add (filters, asv);
431
432   d = empathy_dispatcher_new (PACKAGE_NAME, filters, NULL);
433
434   g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
435   g_ptr_array_free (filters, TRUE);
436
437   /* Setup the an extended Client.Handler that matches everything we can do */
438   filters = g_ptr_array_new ();
439   for (i = 0 ; i < G_N_ELEMENTS (types); i++)
440     {
441       asv = tp_asv_new (
442         TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, types[i].channeltype,
443         TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT, types[i].handletype,
444         NULL);
445
446       g_ptr_array_add (filters, asv);
447     }
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 ".InitialAudio",
455           G_TYPE_BOOLEAN, TRUE,
456         NULL);
457   g_ptr_array_add (filters, asv);
458
459   asv = tp_asv_new (
460         TP_IFACE_CHANNEL ".ChannelType",
461           G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
462         TP_IFACE_CHANNEL ".TargetHandleType",
463           G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
464         TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo",
465           G_TYPE_BOOLEAN, TRUE,
466         NULL);
467   g_ptr_array_add (filters, asv);
468
469
470   empathy_dispatcher_add_handler (d, PACKAGE_NAME"MoreThanMeetsTheEye",
471     filters, capabilities);
472
473   g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
474   g_ptr_array_free (filters, TRUE);
475
476   return d;
477 }
478
479 static void
480 account_status_changed_cb (TpAccount *account,
481     guint old_status,
482     guint new_status,
483     guint reason,
484     gchar *dbus_error_name,
485     GHashTable *details,
486     EmpathyChatroom *room)
487 {
488   TpConnection *conn;
489
490   conn = tp_account_get_connection (account);
491   if (conn == NULL)
492     return;
493
494   empathy_dispatcher_join_muc (conn,
495       empathy_chatroom_get_room (room), NULL, NULL);
496 }
497
498 static void
499 account_manager_chatroom_ready_cb (GObject *source_object,
500     GAsyncResult *result,
501     gpointer user_data)
502 {
503   TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
504   EmpathyChatroomManager *chatroom_manager = user_data;
505   GList *accounts, *l;
506   GError *error = NULL;
507
508   if (!tp_account_manager_prepare_finish (account_manager, result, &error))
509     {
510       DEBUG ("Failed to prepare account manager: %s", error->message);
511       g_error_free (error);
512       return;
513     }
514
515   accounts = tp_account_manager_get_valid_accounts (account_manager);
516
517   for (l = accounts; l != NULL; l = g_list_next (l))
518     {
519       TpAccount *account = TP_ACCOUNT (l->data);
520       TpConnection *conn;
521       GList *chatrooms, *p;
522
523       conn = tp_account_get_connection (account);
524
525       chatrooms = empathy_chatroom_manager_get_chatrooms (
526           chatroom_manager, account);
527
528       for (p = chatrooms; p != NULL; p = p->next)
529         {
530           EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
531
532           if (!empathy_chatroom_get_auto_connect (room))
533             continue;
534
535           if (conn == NULL)
536             {
537               g_signal_connect (G_OBJECT (account), "status-changed",
538                   G_CALLBACK (account_status_changed_cb), room);
539             }
540           else
541             {
542               empathy_dispatcher_join_muc (conn,
543                   empathy_chatroom_get_room (room), NULL, NULL);
544             }
545         }
546
547       g_list_free (chatrooms);
548     }
549
550   g_list_free (accounts);
551 }
552
553 static void
554 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
555     GParamSpec *pspec,
556     gpointer user_data)
557 {
558   TpAccountManager *account_manager = user_data;
559
560   tp_account_manager_prepare_async (account_manager, NULL,
561       account_manager_chatroom_ready_cb, chatroom_manager);
562 }
563
564 int
565 main (int argc, char *argv[])
566 {
567 #if HAVE_GEOCLUE
568   EmpathyLocationManager *location_manager = NULL;
569 #endif
570   EmpathyStatusIcon *icon;
571   EmpathyDispatcher *dispatcher;
572   TpAccountManager *account_manager;
573 #ifdef ENABLE_TPL
574   TplLogManager *log_manager;
575 #else
576   EmpathyLogManager *log_manager;
577 #endif /* ENABLE_TPL */
578   EmpathyChatroomManager *chatroom_manager;
579   EmpathyCallFactory *call_factory;
580   EmpathyFTFactory  *ft_factory;
581   GtkWidget *window;
582   EmpathyIdle *idle;
583   EmpathyConnectivity *connectivity;
584   GError *error = NULL;
585   UniqueApp *unique_app;
586   gboolean chatroom_manager_ready;
587
588 #ifdef ENABLE_DEBUG
589   TpDebugSender *debug_sender;
590 #endif /* ENABLE_TPL */
591
592   GOptionContext *optcontext;
593   GOptionEntry options[] = {
594       { "no-connect", 'n',
595         0, G_OPTION_ARG_NONE, &no_connect,
596         N_("Don't connect on startup"),
597         NULL },
598       { "start-hidden", 'h',
599         0, G_OPTION_ARG_NONE, &start_hidden,
600         N_("Don't display the contact list or any other dialogs on startup"),
601         NULL },
602       { "version", 'v',
603         G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
604         NULL, NULL },
605       { NULL }
606   };
607
608   /* Init */
609   g_thread_init (NULL);
610   empathy_init ();
611
612   optcontext = g_option_context_new (N_("- Empathy IM Client"));
613   g_option_context_add_group (optcontext, gst_init_get_option_group ());
614   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
615 #if HAVE_LIBCHAMPLAIN
616   g_option_context_add_group (optcontext, clutter_get_option_group ());
617 #endif
618   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
619
620   if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
621     g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
622         error->message, argv[0]);
623     g_warning ("Error in empathy init: %s", error->message);
624     return EXIT_FAILURE;
625   }
626
627   g_option_context_free (optcontext);
628
629   empathy_gtk_init ();
630   g_set_application_name (_(PACKAGE_NAME));
631   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
632
633   gtk_window_set_default_icon_name ("empathy");
634   textdomain (GETTEXT_PACKAGE);
635
636 #ifdef ENABLE_DEBUG
637   /* Set up debug sender */
638   debug_sender = tp_debug_sender_dup ();
639   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
640 #endif
641
642   unique_app = unique_app_new ("org.gnome."PACKAGE_NAME, NULL);
643
644   if (unique_app_is_running (unique_app))
645     {
646       unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
647
648       g_object_unref (unique_app);
649       return EXIT_SUCCESS;
650     }
651
652   notify_init (_(PACKAGE_NAME));
653
654   /* Setting up Idle */
655   idle = empathy_idle_dup_singleton ();
656   empathy_idle_set_auto_away (idle, TRUE);
657
658   /* Setting up Connectivity */
659   connectivity = empathy_connectivity_dup_singleton ();
660   use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
661       connectivity);
662   empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
663       use_conn_notify_cb, connectivity);
664
665   /* account management */
666   account_manager = tp_account_manager_dup ();
667   tp_account_manager_prepare_async (account_manager, NULL,
668       account_manager_ready_cb, NULL);
669
670   /* Handle channels */
671   dispatcher = setup_dispatcher ();
672   g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
673
674   migrate_config_to_xdg_dir ();
675
676   /* Setting up UI */
677   window = empathy_main_window_show ();
678   icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
679
680   g_signal_connect (unique_app, "message-received",
681       G_CALLBACK (unique_app_message_cb), window);
682
683   /* Logging */
684 #ifdef ENABLE_TPL
685   log_manager = tpl_log_manager_dup_singleton ();
686 #else
687   log_manager = empathy_log_manager_dup_singleton ();
688   empathy_log_manager_observe (log_manager, dispatcher);
689 #endif
690
691   chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
692   empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
693
694   g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
695   if (!chatroom_manager_ready)
696     {
697       g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
698           G_CALLBACK (chatroom_manager_ready_cb), account_manager);
699     }
700   else
701     {
702       chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
703     }
704
705   /* Create the call factory */
706   call_factory = empathy_call_factory_initialise ();
707   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
708       G_CALLBACK (new_call_handler_cb), NULL);
709   /* Create the FT factory */
710   ft_factory = empathy_ft_factory_dup_singleton ();
711   g_signal_connect (ft_factory, "new-ft-handler",
712       G_CALLBACK (new_ft_handler_cb), NULL);
713   g_signal_connect (ft_factory, "new-incoming-transfer",
714       G_CALLBACK (new_incoming_transfer_cb), NULL);
715
716   /* Location mananger */
717 #if HAVE_GEOCLUE
718   location_manager = empathy_location_manager_dup_singleton ();
719 #endif
720
721   gtk_main ();
722
723   empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
724
725 #ifdef ENABLE_DEBUG
726   g_object_unref (debug_sender);
727 #endif
728
729   g_object_unref (idle);
730   g_object_unref (connectivity);
731   g_object_unref (icon);
732   g_object_unref (account_manager);
733   g_object_unref (log_manager);
734   g_object_unref (dispatcher);
735   g_object_unref (chatroom_manager);
736 #if HAVE_GEOCLUE
737   g_object_unref (location_manager);
738 #endif
739   g_object_unref (ft_factory);
740   g_object_unref (unique_app);
741
742   notify_uninit ();
743   xmlCleanupParser ();
744
745   return EXIT_SUCCESS;
746 }