]> git.0d.be Git - empathy.git/blob - src/empathy.c
Merge back from master
[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 #include <unique/unique.h>
34
35 #if HAVE_LIBCHAMPLAIN
36 #include <clutter-gtk/clutter-gtk.h>
37 #endif
38
39 #include <libebook/e-book.h>
40 #include <libnotify/notify.h>
41
42 #include <telepathy-glib/dbus.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-account-manager.h>
54 #include <libempathy/empathy-connection-managers.h>
55 #include <libempathy/empathy-debugger.h>
56 #include <libempathy/empathy-dispatcher.h>
57 #include <libempathy/empathy-dispatch-operation.h>
58 #include <libempathy/empathy-log-manager.h>
59 #include <libempathy/empathy-ft-factory.h>
60 #include <libempathy/empathy-tp-chat.h>
61 #include <libempathy/empathy-tp-call.h>
62
63 #include <libempathy-gtk/empathy-conf.h>
64 #include <libempathy-gtk/empathy-ui-utils.h>
65 #include <libempathy-gtk/empathy-location-manager.h>
66
67 #include "empathy-accounts-dialog.h"
68 #include "empathy-main-window.h"
69 #include "empathy-status-icon.h"
70 #include "empathy-call-window.h"
71 #include "empathy-chat-window.h"
72 #include "empathy-ft-manager.h"
73
74 #include "extensions/extensions.h"
75
76 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
77 #include <libempathy/empathy-debug.h>
78
79 #include <gst/gst.h>
80
81 #define COMMAND_ACCOUNTS_DIALOG 1
82
83 static void
84 dispatch_cb (EmpathyDispatcher *dispatcher,
85              EmpathyDispatchOperation *operation,
86              gpointer           user_data)
87 {
88         GQuark channel_type;
89
90         channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
91
92         if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) {
93                 EmpathyTpChat *tp_chat;
94                 EmpathyChat   *chat = NULL;
95                 const gchar   *id;
96
97                 tp_chat = EMPATHY_TP_CHAT (
98                         empathy_dispatch_operation_get_channel_wrapper (operation));
99
100                 id = empathy_tp_chat_get_id (tp_chat);
101                 if (!id) {
102                         EmpathyContact *contact;
103
104                         contact = empathy_tp_chat_get_remote_contact (tp_chat);
105                         if (contact) {
106                                 id = empathy_contact_get_id (contact);
107                         }
108                 }
109
110                 if (id) {
111                         EmpathyAccountManager *manager;
112                         TpConnection *connection;
113                         EmpathyAccount *account;
114
115                         manager = empathy_account_manager_dup_singleton ();
116                         connection = empathy_tp_chat_get_connection (tp_chat);
117                         account = empathy_account_manager_get_account_for_connection (manager,
118                                                                        connection);
119                         chat = empathy_chat_window_find_chat (account, id);
120                         g_object_unref (manager);
121                 }
122
123                 if (chat) {
124                         empathy_chat_set_tp_chat (chat, tp_chat);
125                 } else {
126                         chat = empathy_chat_new (tp_chat);
127                 }
128
129                 empathy_chat_window_present_chat (chat);
130
131                 empathy_dispatch_operation_claim (operation);
132         } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) {
133                 EmpathyCallFactory *factory;
134
135                 factory = empathy_call_factory_get ();
136                 empathy_call_factory_claim_channel (factory, operation);
137         } else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) {
138                 EmpathyFTFactory *factory;
139
140                 factory = empathy_ft_factory_dup_singleton ();
141
142                 /* if the operation is not incoming, don't claim it,
143                  * as it might have been triggered by another client, and
144                  * we are observing it.
145                  */
146                 if (empathy_dispatch_operation_is_incoming (operation)) {
147                         empathy_ft_factory_claim_channel (factory, operation);
148                 }
149         }
150 }
151
152 /* Salut account creation */
153 static gboolean
154 should_create_salut_account (void)
155 {
156         EmpathyAccountManager *manager;
157         gboolean salut_created = FALSE;
158         GList *accounts, *l;
159
160         /* Check if we already created a salut account */
161         empathy_conf_get_bool (empathy_conf_get (),
162                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
163                                &salut_created);
164
165         if (salut_created)
166                 {
167                         DEBUG ("Gconf says we already created a salut account once");
168                         return FALSE;
169                 }
170
171         manager = empathy_account_manager_dup_singleton ();
172         accounts = empathy_account_manager_dup_accounts (manager);
173
174         for (l = accounts; l != NULL;  l = g_list_next (l)) {
175                 EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
176
177                 if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp"))
178                         salut_created = TRUE;
179
180                 g_object_unref (account);
181         }
182
183         g_object_unref (manager);
184
185         if (salut_created)
186                 {
187                         DEBUG ("Existing salut account already exists, flagging so in gconf");
188                         empathy_conf_set_bool (empathy_conf_get (),
189                                 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
190                                 TRUE);
191                 }
192
193         return !salut_created;
194 }
195
196 static void
197 salut_account_created (GObject *source,
198         GAsyncResult *result, gpointer user_data)
199 {
200         EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
201         EmpathyAccount *account;
202         GError *error = NULL;
203
204         if (!empathy_account_settings_apply_finish (settings, result, &error))
205                 {
206                         DEBUG ("Failed to create salut account: %s", error->message);
207                         g_error_free (error);
208                         return;
209                 }
210
211         account = empathy_account_settings_get_account (settings);
212
213         empathy_account_set_enabled (account, TRUE);
214         empathy_conf_set_bool (empathy_conf_get (),
215                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
216                                TRUE);
217 }
218
219 static void
220 use_conn_notify_cb (EmpathyConf *conf,
221                     const gchar *key,
222                     gpointer     user_data)
223 {
224         EmpathyConnectivity *connectivity = user_data;
225         gboolean     use_conn;
226
227         if (empathy_conf_get_bool (conf, key, &use_conn)) {
228                 empathy_connectivity_set_use_conn (connectivity, use_conn);
229         }
230 }
231
232 static void
233 create_salut_account_if_needed (EmpathyConnectionManagers *managers)
234 {
235         EmpathyAccountSettings  *settings;
236         TpConnectionManager *manager;
237         const TpConnectionManagerProtocol *protocol;
238         EBook      *book;
239         EContact   *contact;
240         gchar      *nickname = NULL;
241         gchar      *first_name = NULL;
242         gchar      *last_name = NULL;
243         gchar      *email = NULL;
244         gchar      *jid = NULL;
245         GError     *error = NULL;
246
247
248         if (!should_create_salut_account ())
249                 return;
250
251         manager = empathy_connection_managers_get_cm (managers, "salut");
252         if (manager == NULL)
253                 {
254                         DEBUG ("Salut not installed, not making a salut account");
255                         return;
256                 }
257
258         protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
259         if (protocol == NULL)
260                 {
261                         DEBUG ("Salut doesn't support local-xmpp!!");
262                         return;
263                 }
264
265         DEBUG ("Trying to add a salut account...");
266
267         /* Get self EContact from EDS */
268         if (!e_book_get_self (&contact, &book, &error)) {
269                 DEBUG ("Failed to get self econtact: %s",
270                         error ? error->message : "No error given");
271                 g_clear_error (&error);
272                 return;
273         }
274
275         settings = empathy_account_settings_new ("salut", "local-xmpp",
276                 _("People nearby"));
277
278         nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
279         first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
280         last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
281         email = e_contact_get (contact, E_CONTACT_EMAIL_1);
282         jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
283
284         if (!tp_strdiff (nickname, "nickname")) {
285                 g_free (nickname);
286                 nickname = NULL;
287         }
288
289         DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
290                 "last-name=%s\nemail=%s\njid=%s\n",
291                 nickname, first_name, last_name, email, jid);
292
293         empathy_account_settings_set_string (settings, "nickname", nickname ? nickname : "");
294         empathy_account_settings_set_string (settings, "first-name", first_name ? first_name : "");
295         empathy_account_settings_set_string (settings, "last-name", last_name ? last_name : "");
296         empathy_account_settings_set_string (settings, "email", email ? email : "");
297         empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
298
299         empathy_account_settings_apply_async (settings,
300                 salut_account_created, NULL);
301
302         g_free (nickname);
303         g_free (first_name);
304         g_free (last_name);
305         g_free (email);
306         g_free (jid);
307         g_object_unref (settings);
308         g_object_unref (contact);
309         g_object_unref (book);
310 }
311
312 static void
313 connection_managers_ready_cb (EmpathyConnectionManagers *managers,
314         GParamSpec *spec, gpointer user_data)
315 {
316         if (empathy_connection_managers_is_ready (managers))
317                 {
318                         create_salut_account_if_needed (managers);
319                         g_object_unref (managers);
320                         managers = NULL;
321                 }
322 }
323
324 static void
325 create_salut_account (void)
326 {
327         EmpathyConnectionManagers *managers;
328
329         if (!should_create_salut_account ())
330                 return;
331
332         managers = empathy_connection_managers_dup_singleton ();
333
334         if (empathy_connection_managers_is_ready (managers))
335                 {
336                         create_salut_account_if_needed (managers);
337                         g_object_unref (managers);
338                 }
339         else
340                 {
341                         g_signal_connect (managers, "notify::ready",
342                                 G_CALLBACK (connection_managers_ready_cb), NULL);
343                 }
344 }
345
346 static void
347 migrate_config_to_xdg_dir (void)
348 {
349         gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
350         int i;
351         GFile *xdg_file, *old_file;
352         static const gchar* filenames[] = {
353                 "geometry.ini",
354                 "irc-networks.xml",
355                 "chatrooms.xml",
356                 "contact-groups.xml",
357                 "status-presets.xml",
358                 "accels.txt",
359                 NULL
360         };
361
362         xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
363         if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
364                 /* xdg config dir already exists */
365                 g_free (xdg_dir);
366                 return;
367         }
368
369         old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL);
370         if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
371                 /* old config dir didn't exist */
372                 g_free (xdg_dir);
373                 g_free (old_dir);
374                 return;
375         }
376
377         if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) {
378                 DEBUG ("Failed to create configuration directory; aborting migration");
379                 g_free (xdg_dir);
380                 g_free (old_dir);
381                 return;
382         }
383
384         for (i = 0; filenames[i]; i++) {
385                 old_filename = g_build_filename (old_dir, filenames[i], NULL);
386                 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
387                         g_free (old_filename);
388                         continue;
389                 }
390                 xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
391                 old_file = g_file_new_for_path (old_filename);
392                 xdg_file = g_file_new_for_path (xdg_filename);
393                 if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
394                                   NULL, NULL, NULL, NULL)) {
395                         DEBUG ("Failed to migrate %s", filenames[i]);
396                 }
397                 g_free (old_filename);
398                 g_free (xdg_filename);
399                 g_object_unref (old_file);
400                 g_object_unref (xdg_file);
401         }
402
403         g_free (xdg_dir);
404         g_free (old_dir);
405 }
406
407 static UniqueResponse
408 unique_app_message_cb (UniqueApp *unique_app,
409                        gint command,
410                        UniqueMessageData *data,
411                        guint timestamp,
412                        gpointer user_data)
413 {
414         GtkWidget *window = user_data;
415
416         DEBUG ("Other instance launched, presenting the main window. "
417                "Command=%d, timestamp %u", command, timestamp);
418
419         if (command == COMMAND_ACCOUNTS_DIALOG) {
420                 empathy_accounts_dialog_show (GTK_WINDOW (window), NULL);
421         } else {
422                 gtk_window_set_screen (GTK_WINDOW (window),
423                                        unique_message_data_get_screen (data));
424                 gtk_window_set_startup_id (GTK_WINDOW (window),
425                                            unique_message_data_get_startup_id (data));
426                 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
427         }
428
429         return UNIQUE_RESPONSE_OK;
430 }
431
432 static gboolean
433 show_version_cb (const char *option_name,
434                  const char *value,
435                  gpointer data,
436                  GError **error)
437 {
438         g_print ("%s\n", PACKAGE_STRING);
439
440         exit (EXIT_SUCCESS);
441
442         return FALSE;
443 }
444
445 static void
446 new_incoming_transfer_cb (EmpathyFTFactory *factory,
447                           EmpathyFTHandler *handler,
448                           GError *error,
449                           gpointer user_data)
450 {
451         if (error) {
452                 empathy_ft_manager_display_error (handler, error);
453         } else {
454                 empathy_receive_file_with_file_chooser (handler);
455         }
456 }
457
458 static void
459 new_ft_handler_cb (EmpathyFTFactory *factory,
460                    EmpathyFTHandler *handler,
461                    GError *error,
462                    gpointer user_data)
463 {
464         if (error) {
465                 empathy_ft_manager_display_error (handler, error);
466         } else {
467                 empathy_ft_manager_add_handler (handler);
468         }
469
470         g_object_unref (handler);
471 }
472
473 static void
474 new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler,
475         gboolean outgoing, gpointer user_data)
476 {
477         EmpathyCallWindow *window;
478
479         window = empathy_call_window_new (handler);
480         gtk_widget_show (GTK_WIDGET (window));
481 }
482
483 #ifdef ENABLE_DEBUG
484 static void
485 default_log_handler (const gchar *log_domain,
486     GLogLevelFlags log_level,
487     const gchar *message,
488     gpointer user_data)
489 {
490         g_log_default_handler (log_domain, log_level, message, NULL);
491
492         /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
493          * debugger as they already have in empathy_debug. */
494         if (log_level != G_LOG_LEVEL_DEBUG
495             || tp_strdiff (log_domain, G_LOG_DOMAIN)) {
496                 EmpathyDebugger *dbg;
497                 GTimeVal now;
498
499                 dbg = empathy_debugger_get_singleton ();
500                 g_get_current_time (&now);
501
502                 empathy_debugger_add_message (dbg, &now, log_domain,
503                                               log_level, message);
504         }
505 }
506 #endif /* ENABLE_DEBUG */
507
508 static void
509 account_manager_ready_cb (EmpathyAccountManager *manager,
510         GParamSpec *spec,
511         gpointer user_data)
512 {
513         if (!empathy_account_manager_is_ready (manager))
514                 return;
515
516         if (empathy_account_manager_get_count (manager) == 0)
517                 {
518                         empathy_accounts_dialog_show (GTK_WINDOW (empathy_main_window_get ()),
519                                 NULL);
520                 }
521         create_salut_account ();
522 }
523
524 int
525 main (int argc, char *argv[])
526 {
527 #if HAVE_GEOCLUE
528         EmpathyLocationManager *location_manager = NULL;
529 #endif
530         EmpathyStatusIcon *icon;
531         EmpathyDispatcher *dispatcher;
532         EmpathyAccountManager *account_manager;
533         EmpathyLogManager *log_manager;
534         EmpathyChatroomManager *chatroom_manager;
535         EmpathyCallFactory *call_factory;
536         EmpathyFTFactory  *ft_factory;
537         GtkWidget         *window;
538         EmpathyIdle       *idle;
539         EmpathyConnectivity *connectivity;
540         gboolean           autoconnect = TRUE;
541         gboolean           no_connect = FALSE;
542         gboolean           hide_contact_list = FALSE;
543         gboolean           accounts_dialog = FALSE;
544         GError            *error = NULL;
545         TpDBusDaemon      *dbus_daemon;
546         UniqueApp         *unique_app;
547         GOptionEntry       options[] = {
548                 { "no-connect", 'n',
549                   0, G_OPTION_ARG_NONE, &no_connect,
550                   N_("Don't connect on startup"),
551                   NULL },
552                 { "hide-contact-list", 'h',
553                   0, G_OPTION_ARG_NONE, &hide_contact_list,
554                   N_("Don't show the contact list on startup"),
555                   NULL },
556                 { "accounts", 'a',
557                   0, G_OPTION_ARG_NONE, &accounts_dialog,
558                   N_("Show the accounts dialog"),
559                   NULL },
560                 { "version", 'v',
561                   G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL },
562                 { NULL }
563         };
564
565         /* Init */
566         g_thread_init (NULL);
567         empathy_init ();
568
569         if (!gtk_init_with_args (&argc, &argv,
570                                  N_("- Empathy IM Client"),
571                                  options, GETTEXT_PACKAGE, &error)) {
572                 g_warning ("Error in empathy init: %s", error->message);
573                 return EXIT_FAILURE;
574         }
575
576         empathy_gtk_init ();
577         g_set_application_name (_(PACKAGE_NAME));
578         g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
579
580         gst_init (&argc, &argv);
581
582 #if HAVE_LIBCHAMPLAIN
583         gtk_clutter_init (&argc, &argv);
584 #endif
585
586         gtk_window_set_default_icon_name ("empathy");
587         textdomain (GETTEXT_PACKAGE);
588
589 #ifdef ENABLE_DEBUG
590         /* Set up debugger */
591         g_log_set_default_handler (default_log_handler, NULL);
592 #endif
593
594         unique_app = unique_app_new_with_commands ("org.gnome.Empathy",
595                                                    NULL,
596                                                    "accounts_dialog",
597                                                    COMMAND_ACCOUNTS_DIALOG,
598                                                    NULL);
599
600         if (unique_app_is_running (unique_app)) {
601                 unique_app_send_message (unique_app,
602                                          accounts_dialog ?
603                                          COMMAND_ACCOUNTS_DIALOG :
604                                                  UNIQUE_ACTIVATE,
605                                          NULL);
606                 g_object_unref (unique_app);
607                 return EXIT_SUCCESS;
608         }
609
610         /* Take well-known name */
611         dbus_daemon = tp_dbus_daemon_dup (&error);
612         if (error == NULL) {
613                 if (!tp_dbus_daemon_request_name (dbus_daemon,
614                                                   "org.gnome.Empathy",
615                                                   TRUE, &error)) {
616                         DEBUG ("Failed to request well-known name: %s",
617                                error ? error->message : "no message");
618                         g_clear_error (&error);
619                 }
620                 g_object_unref (dbus_daemon);
621         } else {
622                 DEBUG ("Failed to dup dbus daemon: %s",
623                        error ? error->message : "no message");
624                 g_clear_error (&error);
625         }
626
627         if (accounts_dialog) {
628                 GtkWidget *dialog;
629
630                 dialog = empathy_accounts_dialog_show (NULL, NULL);
631                 g_signal_connect (dialog, "destroy",
632                                   G_CALLBACK (gtk_main_quit),
633                                   NULL);
634
635                 gtk_main ();
636                 return 0;
637         }
638
639         /* Setting up Idle */
640         idle = empathy_idle_dup_singleton ();
641         empathy_idle_set_auto_away (idle, TRUE);
642
643         /* Setting up Connectivity */
644         connectivity = empathy_connectivity_dup_singleton ();
645         use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
646                             connectivity);
647         empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
648                                  use_conn_notify_cb, connectivity);
649
650         /* Autoconnect */
651         empathy_conf_get_bool (empathy_conf_get (),
652                                EMPATHY_PREFS_AUTOCONNECT,
653                                &autoconnect);
654         if (autoconnect && ! no_connect &&
655                 tp_connection_presence_type_cmp_availability (empathy_idle_get_state
656                         (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) {
657                 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
658         }
659
660         /* account management */
661         account_manager = empathy_account_manager_dup_singleton ();
662         g_signal_connect (account_manager, "notify::ready",
663                 G_CALLBACK (account_manager_ready_cb), NULL);
664
665         migrate_config_to_xdg_dir ();
666
667         /* Setting up UI */
668         window = empathy_main_window_show ();
669         icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list);
670
671         g_signal_connect (unique_app, "message-received",
672                           G_CALLBACK (unique_app_message_cb),
673                           window);
674
675         /* Handle channels */
676         dispatcher = empathy_dispatcher_dup_singleton ();
677         g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
678
679         /* Logging */
680         log_manager = empathy_log_manager_dup_singleton ();
681         empathy_log_manager_observe (log_manager, dispatcher);
682
683         chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
684         empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
685
686         notify_init (_(PACKAGE_NAME));
687         /* Create the call factory */
688         call_factory = empathy_call_factory_initialise ();
689         g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
690                 G_CALLBACK (new_call_handler_cb), NULL);
691         /* Create the FT factory */
692         ft_factory = empathy_ft_factory_dup_singleton ();
693         g_signal_connect (ft_factory, "new-ft-handler",
694                 G_CALLBACK (new_ft_handler_cb), NULL);
695         g_signal_connect (ft_factory, "new-incoming-transfer",
696                 G_CALLBACK (new_incoming_transfer_cb), NULL);
697
698         /* Location mananger */
699 #if HAVE_GEOCLUE
700         location_manager = empathy_location_manager_dup_singleton ();
701 #endif
702
703         gtk_main ();
704
705         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
706
707         g_object_unref (idle);
708         g_object_unref (connectivity);
709         g_object_unref (icon);
710         g_object_unref (account_manager);
711         g_object_unref (log_manager);
712         g_object_unref (dispatcher);
713         g_object_unref (chatroom_manager);
714 #if HAVE_GEOCLUE
715         g_object_unref (location_manager);
716 #endif
717         g_object_unref (ft_factory);
718         g_object_unref (unique_app);
719
720         notify_uninit ();
721
722         return EXIT_SUCCESS;
723 }