]> git.0d.be Git - empathy.git/blob - src/empathy.c
Rename EmpathyDebugDialog to EmpathyDebugWindow
[empathy.git] / src / empathy.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <stdlib.h>
26 #include <errno.h>
27 #include <string.h>
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32 #include <gdk/gdkx.h>
33
34 #if HAVE_LIBCHAMPLAIN
35 #include <clutter-gtk/clutter-gtk.h>
36 #endif
37
38 #include <libebook/e-book.h>
39 #include <libnotify/notify.h>
40
41 #include <telepathy-glib/dbus.h>
42 #include <telepathy-glib/util.h>
43 #include <libmissioncontrol/mission-control.h>
44
45 #include <libempathy/empathy-idle.h>
46 #include <libempathy/empathy-utils.h>
47 #include <libempathy/empathy-call-factory.h>
48 #include <libempathy/empathy-chatroom-manager.h>
49 #include <libempathy/empathy-connectivity.h>
50 #include <libempathy/empathy-account-manager.h>
51 #include <libempathy/empathy-debugger.h>
52 #include <libempathy/empathy-dispatcher.h>
53 #include <libempathy/empathy-dispatch-operation.h>
54 #include <libempathy/empathy-log-manager.h>
55 #include <libempathy/empathy-ft-factory.h>
56 #include <libempathy/empathy-tp-chat.h>
57 #include <libempathy/empathy-tp-call.h>
58
59 #include <libempathy-gtk/empathy-conf.h>
60 #include <libempathy-gtk/empathy-ui-utils.h>
61 #include <libempathy-gtk/empathy-location-manager.h>
62
63 #include "empathy-accounts-dialog.h"
64 #include "empathy-main-window.h"
65 #include "empathy-status-icon.h"
66 #include "empathy-call-window.h"
67 #include "empathy-chat-window.h"
68 #include "empathy-ft-manager.h"
69 #include "bacon-message-connection.h"
70
71 #include "extensions/extensions.h"
72
73 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
74 #include <libempathy/empathy-debug.h>
75
76 #include <gst/gst.h>
77
78 static BaconMessageConnection *connection = NULL;
79
80 static void
81 dispatch_cb (EmpathyDispatcher *dispatcher,
82              EmpathyDispatchOperation *operation,
83              gpointer           user_data)
84 {
85         GQuark channel_type;
86
87         channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
88
89         if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) {
90                 EmpathyTpChat *tp_chat;
91                 EmpathyChat   *chat = NULL;
92                 const gchar   *id;
93
94                 tp_chat = EMPATHY_TP_CHAT (
95                         empathy_dispatch_operation_get_channel_wrapper (operation));
96
97                 id = empathy_tp_chat_get_id (tp_chat);
98                 if (!id) {
99                         EmpathyContact *contact;
100
101                         contact = empathy_tp_chat_get_remote_contact (tp_chat);
102                         if (contact) {
103                                 id = empathy_contact_get_id (contact);
104                         }
105                 }
106
107                 if (id) {
108                         EmpathyAccountManager *manager;
109                         TpConnection *connection;
110                         EmpathyAccount *account;
111
112                         manager = empathy_account_manager_dup_singleton ();
113                         connection = empathy_tp_chat_get_connection (tp_chat);
114                         account = empathy_account_manager_get_account (manager,
115                                                                        connection);
116                         chat = empathy_chat_window_find_chat (account, id);
117                         g_object_unref (manager);
118                 }
119
120                 if (chat) {
121                         empathy_chat_set_tp_chat (chat, tp_chat);
122                 } else {
123                         chat = empathy_chat_new (tp_chat);
124                 }
125
126                 empathy_chat_window_present_chat (chat);
127
128                 empathy_dispatch_operation_claim (operation);
129         } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) {
130                 EmpathyCallFactory *factory;
131
132                 factory = empathy_call_factory_get ();
133                 empathy_call_factory_claim_channel (factory, operation);
134         } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) {
135                 EmpathyFTFactory *factory;
136
137                 factory = empathy_ft_factory_dup_singleton ();
138
139                 /* if the operation is not incoming, don't claim it,
140                  * as it might have been triggered by another client, and
141                  * we are observing it.
142                  */
143                 if (empathy_dispatch_operation_is_incoming (operation)) {
144                         empathy_ft_factory_claim_channel (factory, operation);
145                 }
146         }
147 }
148
149 static void
150 service_ended_cb (MissionControl *mc,
151                   gpointer        user_data)
152 {
153         DEBUG ("Mission Control stopped");
154 }
155
156 static void
157 operation_error_cb (MissionControl *mc,
158                     guint           operation_id,
159                     guint           error_code,
160                     gpointer        user_data)
161 {
162         const gchar *message;
163
164         switch (error_code) {
165         case MC_DISCONNECTED_ERROR:
166                 message = "Disconnected";
167                 break;
168         case MC_INVALID_HANDLE_ERROR:
169                 message = "Invalid handle";
170                 break;
171         case MC_NO_MATCHING_CONNECTION_ERROR:
172                 message = "No matching connection";
173                 break;
174         case MC_INVALID_ACCOUNT_ERROR:
175                 message = "Invalid account";
176                 break;
177         case MC_PRESENCE_FAILURE_ERROR:
178                 message = "Presence failure";
179                 break;
180         case MC_NO_ACCOUNTS_ERROR:
181                 message = "No accounts";
182                 break;
183         case MC_NETWORK_ERROR:
184                 message = "Network error";
185                 break;
186         case MC_CONTACT_DOES_NOT_SUPPORT_VOICE_ERROR:
187                 message = "Contact does not support voice";
188                 break;
189         case MC_LOWMEM_ERROR:
190                 message = "Lowmem";
191                 break;
192         case MC_CHANNEL_REQUEST_GENERIC_ERROR:
193                 message = "Channel request generic error";
194                 break;
195         case MC_CHANNEL_BANNED_ERROR:
196                 message = "Channel banned";
197                 break;
198         case MC_CHANNEL_FULL_ERROR:
199                 message = "Channel full";
200                 break;
201         case MC_CHANNEL_INVITE_ONLY_ERROR:
202                 message = "Channel invite only";
203                 break;
204         default:
205                 message = "Unknown error code";
206         }
207
208         DEBUG ("Error during operation %d: %s", operation_id, message);
209 }
210
211 static void
212 use_conn_notify_cb (EmpathyConf *conf,
213                     const gchar *key,
214                     gpointer     user_data)
215 {
216         EmpathyConnectivity *connectivity = user_data;
217         gboolean     use_conn;
218
219         if (empathy_conf_get_bool (conf, key, &use_conn)) {
220                 empathy_connectivity_set_use_conn (connectivity, use_conn);
221         }
222 }
223
224 static void
225 create_salut_account (void)
226 {
227         McProfile  *profile;
228         McProtocol *protocol;
229         gboolean    salut_created = FALSE;
230         EmpathyAccount  *account;
231         EmpathyAccountManager *account_manager;
232         GList      *accounts;
233         EBook      *book;
234         EContact   *contact;
235         gchar      *nickname = NULL;
236         gchar      *first_name = NULL;
237         gchar      *last_name = NULL;
238         gchar      *email = NULL;
239         gchar      *jid = NULL;
240         GError     *error = NULL;
241
242         /* Check if we already created a salut account */
243         empathy_conf_get_bool (empathy_conf_get (),
244                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
245                                &salut_created);
246         if (salut_created) {
247                 return;
248         }
249
250         DEBUG ("Try to add a salut account...");
251
252         /* Check if the salut CM is installed */
253         profile = mc_profile_lookup ("salut");
254         if (!profile) {
255                 DEBUG ("No salut profile");
256                 return;
257         }
258         protocol = mc_profile_get_protocol (profile);
259         if (!protocol) {
260                 DEBUG ("Salut not installed");
261                 g_object_unref (profile);
262                 return;
263         }
264         g_object_unref (protocol);
265
266         /* Get self EContact from EDS */
267         if (!e_book_get_self (&contact, &book, &error)) {
268                 DEBUG ("Failed to get self econtact: %s",
269                         error ? error->message : "No error given");
270                 g_clear_error (&error);
271                 g_object_unref (profile);
272                 return;
273         }
274
275         empathy_conf_set_bool (empathy_conf_get (),
276                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
277                                TRUE);
278
279         /* Check if there is already a salut account */
280         accounts = mc_accounts_list_by_profile (profile);
281         if (accounts) {
282                 DEBUG ("There is already a salut account");
283                 mc_accounts_list_free (accounts);
284                 g_object_unref (profile);
285                 return;
286         }
287
288         account_manager = empathy_account_manager_dup_singleton ();
289         account = empathy_account_manager_create (account_manager, profile);
290         empathy_account_set_display_name (account, _("People nearby"));
291         g_object_unref (account_manager);
292
293         nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
294         first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
295         last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
296         email = e_contact_get (contact, E_CONTACT_EMAIL_1);
297         jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
298
299         if (!tp_strdiff (nickname, "nickname")) {
300                 g_free (nickname);
301                 nickname = NULL;
302         }
303
304         DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
305                 "last-name=%s\nemail=%s\njid=%s\n",
306                 nickname, first_name, last_name, email, jid);
307
308         empathy_account_set_param_string (account, "nickname", nickname ? nickname : "");
309         empathy_account_set_param_string (account, "first-name", first_name ? first_name : "");
310         empathy_account_set_param_string (account, "last-name", last_name ? last_name : "");
311         empathy_account_set_param_string (account, "email", email ? email : "");
312         empathy_account_set_param_string (account, "jid", jid ? jid : "");
313
314         g_free (nickname);
315         g_free (first_name);
316         g_free (last_name);
317         g_free (email);
318         g_free (jid);
319         g_object_unref (account);
320         g_object_unref (profile);
321         g_object_unref (contact);
322         g_object_unref (book);
323 }
324
325 static void
326 migrate_config_to_xdg_dir (void)
327 {
328         gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
329         int i;
330         GFile *xdg_file, *old_file;
331         static const gchar* filenames[] = {
332                 "geometry.ini",
333                 "irc-networks.xml",
334                 "chatrooms.xml",
335                 "contact-groups.xml",
336                 "status-presets.xml",
337                 "accels.txt",
338                 NULL
339         };
340
341         xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
342         if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
343                 /* xdg config dir already exists */
344                 g_free (xdg_dir);
345                 return;
346         }
347
348         old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
349         if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
350                 /* old config dir didn't exist */
351                 g_free (xdg_dir);
352                 g_free (old_dir);
353                 return;
354         }
355
356         if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) {
357                 DEBUG ("Failed to create configuration directory; aborting migration");
358                 g_free (xdg_dir);
359                 g_free (old_dir);
360                 return;
361         }
362
363         for (i = 0; filenames[i]; i++) {
364                 old_filename = g_build_filename (old_dir, filenames[i], NULL);
365                 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
366                         g_free (old_filename);
367                         continue;
368                 }
369                 xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
370                 old_file = g_file_new_for_path (old_filename);
371                 xdg_file = g_file_new_for_path (xdg_filename);
372                 if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
373                                   NULL, NULL, NULL, NULL)) {
374                         DEBUG ("Failed to migrate %s", filenames[i]);
375                 }
376                 g_free (old_filename);
377                 g_free (xdg_filename);
378                 g_object_unref (old_file);
379                 g_object_unref (xdg_file);
380         }
381
382         g_free (xdg_dir);
383         g_free (old_dir);
384 }
385
386 /* The code that handles single-instance and startup notification is
387  * copied from gedit.
388  *
389  * Copyright (C) 2005 - Paolo Maggi
390  */
391 static void
392 on_bacon_message_received (const char *message,
393                            gpointer    data)
394 {
395         GtkWidget *window = data;
396         guint32    startup_timestamp;
397
398         g_return_if_fail (message != NULL);
399
400         DEBUG ("Other instance launched, presenting the main window. message='%s'",
401                 message);
402
403         if (strcmp (message, "accounts") == 0) {
404                 /* accounts dialog requested */
405                 empathy_accounts_dialog_show (GTK_WINDOW (window), NULL);
406         } else {
407                 startup_timestamp = atoi (message);
408
409                 /* Set the proper interaction time on the window.
410                  * Fall back to roundtripping to the X server when we
411                  * don't have the timestamp, e.g. when launched from
412                  * terminal. We also need to make sure that the window
413                  * has been realized otherwise it will not work. lame. */
414                 if (startup_timestamp == 0) {
415                         /* Work if launched from the terminal */
416                         DEBUG ("Using X server timestamp as a fallback");
417
418                         if (!GTK_WIDGET_REALIZED (window)) {
419                                 gtk_widget_realize (GTK_WIDGET (window));
420                         }
421
422                         startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (window));
423                 }
424
425                 gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp);
426         }
427 }
428
429 static guint32
430 get_startup_timestamp ()
431 {
432         const gchar *startup_id_env;
433         gchar       *startup_id = NULL;
434         gchar       *time_str;
435         gchar       *end;
436         gulong       retval = 0;
437
438         /* we don't unset the env, since startup-notification
439          * may still need it */
440         startup_id_env = g_getenv ("DESKTOP_STARTUP_ID");
441         if (startup_id_env == NULL) {
442                 goto out;
443         }
444
445         startup_id = g_strdup (startup_id_env);
446
447         time_str = g_strrstr (startup_id, "_TIME");
448         if (time_str == NULL) {
449                 goto out;
450         }
451
452         errno = 0;
453
454         /* Skip past the "_TIME" part */
455         time_str += 5;
456
457         retval = strtoul (time_str, &end, 0);
458         if (end == time_str || errno != 0)
459                 retval = 0;
460
461  out:
462         g_free (startup_id);
463
464         return (retval > 0) ? retval : 0;
465 }
466
467 static gboolean
468 show_version_cb (const char *option_name,
469                  const char *value,
470                  gpointer data,
471                  GError **error)
472 {
473         g_print ("%s\n", PACKAGE_STRING);
474
475         exit (EXIT_SUCCESS);
476
477         return FALSE;
478 }
479
480 static void
481 new_incoming_transfer_cb (EmpathyFTFactory *factory,
482                           EmpathyFTHandler *handler,
483                           GError *error,
484                           gpointer user_data)
485 {
486         if (error) {
487                 empathy_ft_manager_display_error (handler, error);
488         } else {
489                 empathy_receive_file_with_file_chooser (handler);
490         }
491 }
492
493 static void
494 new_ft_handler_cb (EmpathyFTFactory *factory,
495                    EmpathyFTHandler *handler,
496                    GError *error,
497                    gpointer user_data)
498 {
499         if (error) {
500                 empathy_ft_manager_display_error (handler, error);
501         } else {
502                 empathy_ft_manager_add_handler (handler);
503         }
504
505         g_object_unref (handler);
506 }
507
508 static void
509 new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler,
510         gboolean outgoing, gpointer user_data)
511 {
512         EmpathyCallWindow *window;
513
514         window = empathy_call_window_new (handler);
515         gtk_widget_show (GTK_WIDGET (window));
516 }
517
518 #ifdef ENABLE_DEBUG
519 static void
520 default_log_handler (const gchar *log_domain,
521     GLogLevelFlags log_level,
522     const gchar *message,
523     gpointer user_data)
524 {
525         g_log_default_handler (log_domain, log_level, message, NULL);
526
527         /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
528          * debugger as they already have in empathy_debug. */
529         if (log_level != G_LOG_LEVEL_DEBUG
530             || tp_strdiff (log_domain, G_LOG_DOMAIN)) {
531                 EmpathyDebugger *dbg;
532                 GTimeVal now;
533
534                 dbg = empathy_debugger_get_singleton ();
535                 g_get_current_time (&now);
536
537                 empathy_debugger_add_message (dbg, &now, log_domain,
538                                               log_level, message);
539         }
540 }
541 #endif /* ENABLE_DEBUG */
542
543 int
544 main (int argc, char *argv[])
545 {
546         guint32            startup_timestamp;
547 #if HAVE_GEOCLUE
548         EmpathyLocationManager *location_manager = NULL;
549 #endif
550         EmpathyStatusIcon *icon;
551         EmpathyDispatcher *dispatcher;
552         EmpathyLogManager *log_manager;
553         EmpathyChatroomManager *chatroom_manager;
554         EmpathyCallFactory *call_factory;
555         EmpathyFTFactory  *ft_factory;
556         GtkWidget         *window;
557         MissionControl    *mc;
558         EmpathyIdle       *idle;
559         EmpathyConnectivity *connectivity;
560         gboolean           autoconnect = TRUE;
561         gboolean           no_connect = FALSE;
562         gboolean           hide_contact_list = FALSE;
563         gboolean           accounts_dialog = FALSE;
564         GError            *error = NULL;
565         TpDBusDaemon      *dbus_daemon;
566         GOptionEntry       options[] = {
567                 { "no-connect", 'n',
568                   0, G_OPTION_ARG_NONE, &no_connect,
569                   N_("Don't connect on startup"),
570                   NULL },
571                 { "hide-contact-list", 'h',
572                   0, G_OPTION_ARG_NONE, &hide_contact_list,
573                   N_("Don't show the contact list on startup"),
574                   NULL },
575                 { "accounts", 'a',
576                   0, G_OPTION_ARG_NONE, &accounts_dialog,
577                   N_("Show the accounts dialog"),
578                   NULL },
579                 { "version", 'v',
580                   G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL },
581                 { NULL }
582         };
583
584         /* Init */
585         g_thread_init (NULL);
586         empathy_init ();
587
588         if (!gtk_init_with_args (&argc, &argv,
589                                  N_("- Empathy IM Client"),
590                                  options, GETTEXT_PACKAGE, &error)) {
591                 g_warning ("Error in empathy init: %s", error->message);
592                 return EXIT_FAILURE;
593         }
594
595         empathy_gtk_init ();
596         g_set_application_name (_(PACKAGE_NAME));
597         g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
598
599         gst_init (&argc, &argv);
600
601 #if HAVE_LIBCHAMPLAIN
602         gtk_clutter_init (&argc, &argv);
603 #endif
604
605         gtk_window_set_default_icon_name ("empathy");
606         textdomain (GETTEXT_PACKAGE);
607
608 #ifdef ENABLE_DEBUG
609         /* Set up debugger */
610         g_log_set_default_handler (default_log_handler, NULL);
611 #endif
612
613         /* Setting up the bacon connection */
614         startup_timestamp = get_startup_timestamp ();
615         connection = bacon_message_connection_new ("empathy");
616         if (connection != NULL) {
617                 if (!bacon_message_connection_get_is_server (connection)) {
618                         gchar *message;
619
620                         if (accounts_dialog) {
621                                 DEBUG ("Showing accounts dialog from existing Empathy instance");
622
623                                 message = g_strdup ("accounts");
624
625                         } else {
626
627                                 DEBUG ("Activating existing instance");
628
629                                 message = g_strdup_printf ("%" G_GUINT32_FORMAT,
630                                                            startup_timestamp);
631                         }
632
633                         bacon_message_connection_send (connection, message);
634
635                         /* We never popup a window, so tell startup-notification
636                          * that we are done. */
637                         gdk_notify_startup_complete ();
638
639                         g_free (message);
640                         bacon_message_connection_free (connection);
641
642                         return EXIT_SUCCESS;
643                 }
644         } else {
645                 g_warning ("Cannot create the 'empathy' bacon connection.");
646         }
647
648         /* Take well-known name */
649         dbus_daemon = tp_dbus_daemon_dup (&error);
650         if (error == NULL) {
651                 if (!tp_dbus_daemon_request_name (dbus_daemon,
652                                                   "org.gnome.Empathy",
653                                                   TRUE, &error)) {
654                         DEBUG ("Failed to request well-known name: %s",
655                                error ? error->message : "no message");
656                         g_clear_error (&error);
657                 }
658                 g_object_unref (dbus_daemon);
659         } else {
660                 DEBUG ("Failed to dup dbus daemon: %s",
661                        error ? error->message : "no message");
662                 g_clear_error (&error);
663         }
664
665         /* Setting up MC */
666         mc = empathy_mission_control_dup_singleton ();
667         g_signal_connect (mc, "ServiceEnded",
668                           G_CALLBACK (service_ended_cb),
669                           NULL);
670         g_signal_connect (mc, "Error",
671                           G_CALLBACK (operation_error_cb),
672                           NULL);
673
674         if (accounts_dialog) {
675                 GtkWidget *dialog;
676
677                 dialog = empathy_accounts_dialog_show (NULL, NULL);
678                 g_signal_connect (dialog, "destroy",
679                                   G_CALLBACK (gtk_main_quit),
680                                   NULL);
681
682                 gtk_main ();
683                 return 0;
684         }
685
686         /* Setting up Idle */
687         idle = empathy_idle_dup_singleton ();
688         empathy_idle_set_auto_away (idle, TRUE);
689
690         /* Setting up Connectivity */
691         connectivity = empathy_connectivity_dup_singleton ();
692         use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
693                             connectivity);
694         empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
695                                  use_conn_notify_cb, connectivity);
696
697         /* Autoconnect */
698         empathy_conf_get_bool (empathy_conf_get (),
699                                EMPATHY_PREFS_AUTOCONNECT,
700                                &autoconnect);
701         if (autoconnect && ! no_connect &&
702                 tp_connection_presence_type_cmp_availability (empathy_idle_get_state
703                         (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) {
704                 empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE);
705         }
706
707
708         migrate_config_to_xdg_dir ();
709         create_salut_account ();
710
711         /* Setting up UI */
712         window = empathy_main_window_show ();
713         icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list);
714
715         if (connection) {
716                 /* We se the callback here because we need window */
717                 bacon_message_connection_set_callback (connection,
718                                                        on_bacon_message_received,
719                                                        window);
720         }
721
722         /* Handle channels */
723         dispatcher = empathy_dispatcher_dup_singleton ();
724         g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
725
726         /* Logging */
727         log_manager = empathy_log_manager_dup_singleton ();
728         empathy_log_manager_observe (log_manager, dispatcher);
729
730         chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
731         empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
732
733         notify_init (_(PACKAGE_NAME));
734         /* Create the call factory */
735         call_factory = empathy_call_factory_initialise ();
736         g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
737                 G_CALLBACK (new_call_handler_cb), NULL);
738         /* Create the FT factory */
739         ft_factory = empathy_ft_factory_dup_singleton ();
740         g_signal_connect (ft_factory, "new-ft-handler",
741                 G_CALLBACK (new_ft_handler_cb), NULL);
742         g_signal_connect (ft_factory, "new-incoming-transfer",
743                 G_CALLBACK (new_incoming_transfer_cb), NULL);
744
745         /* Location mananger */
746 #if HAVE_GEOCLUE
747         location_manager = empathy_location_manager_dup_singleton ();
748 #endif
749
750         gtk_main ();
751
752         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
753
754         g_object_unref (mc);
755         g_object_unref (idle);
756         g_object_unref (connectivity);
757         g_object_unref (icon);
758         g_object_unref (log_manager);
759         g_object_unref (dispatcher);
760         g_object_unref (chatroom_manager);
761 #if HAVE_GEOCLUE
762         g_object_unref (location_manager);
763 #endif
764         g_object_unref (ft_factory);
765
766         notify_uninit ();
767
768         return EXIT_SUCCESS;
769 }
770