]> git.0d.be Git - empathy.git/blob - src/empathy.c
Rework creating a salut account so it doesn't need profiles
[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/gtk-clutter-embed.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 <telepathy-glib/connection-manager.h>
44 #include <libmissioncontrol/mission-control.h>
45
46 #include <libempathy/empathy-idle.h>
47 #include <libempathy/empathy-utils.h>
48 #include <libempathy/empathy-call-factory.h>
49 #include <libempathy/empathy-chatroom-manager.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_nm_notify_cb (EmpathyConf *conf,
213                   const gchar *key,
214                   gpointer     user_data)
215 {
216         EmpathyIdle *idle = user_data;
217         gboolean     use_nm;
218
219         if (empathy_conf_get_bool (conf, key, &use_nm)) {
220                 empathy_idle_set_use_nm (idle, use_nm);
221         }
222 }
223
224 static gboolean
225 should_create_salut_account (void)
226 {
227         EmpathyAccountManager *manager;
228         gboolean salut_created = FALSE;
229         GList *accounts, *l;
230
231         /* Check if we already created a salut account */
232         empathy_conf_get_bool (empathy_conf_get (),
233                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
234                                &salut_created);
235
236         manager = empathy_account_manager_dup_singleton ();
237         accounts = empathy_account_manager_dup_accounts (manager);
238
239         for (l = accounts; l != NULL;  l = g_list_next (l)) {
240                 EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
241
242                 if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp"))
243                         salut_created = TRUE;
244
245                 g_object_unref (account);
246         }
247
248         g_object_unref (manager);
249
250         return !salut_created;
251 }
252
253 static void
254 create_salut_account_if_needed (void)
255 {
256         EmpathyAccount  *account;
257         EmpathyAccountManager *account_manager;
258         EBook      *book;
259         EContact   *contact;
260         gchar      *nickname = NULL;
261         gchar      *first_name = NULL;
262         gchar      *last_name = NULL;
263         gchar      *email = NULL;
264         gchar      *jid = NULL;
265         GError     *error = NULL;
266
267
268         if (!should_create_salut_account())
269                 return;
270         
271         DEBUG ("Trying to add a salut account...");
272
273         /* Get self EContact from EDS */
274         if (!e_book_get_self (&contact, &book, &error)) {
275                 DEBUG ("Failed to get self econtact: %s",
276                         error ? error->message : "No error given");
277                 g_clear_error (&error);
278                 return;
279         }
280
281         account_manager = empathy_account_manager_dup_singleton ();
282         account = empathy_account_manager_create (account_manager,
283                 "salut", "local-xmpp", _("People nearby"));
284         g_object_unref (account_manager);
285         empathy_account_set_enabled (account, TRUE);
286
287         nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
288         first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
289         last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
290         email = e_contact_get (contact, E_CONTACT_EMAIL_1);
291         jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
292
293         if (!tp_strdiff (nickname, "nickname")) {
294                 g_free (nickname);
295                 nickname = NULL;
296         }
297
298         DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
299                 "last-name=%s\nemail=%s\njid=%s\n",
300                 nickname, first_name, last_name, email, jid);
301
302         empathy_account_set_param_string (account, "nickname", nickname ? nickname : "");
303         empathy_account_set_param_string (account, "first-name", first_name ? first_name : "");
304         empathy_account_set_param_string (account, "last-name", last_name ? last_name : "");
305         empathy_account_set_param_string (account, "email", email ? email : "");
306         empathy_account_set_param_string (account, "jid", jid ? jid : "");
307
308         g_free (nickname);
309         g_free (first_name);
310         g_free (last_name);
311         g_free (email);
312         g_free (jid);
313         g_object_unref (account);
314         g_object_unref (contact);
315         g_object_unref (book);
316
317         empathy_conf_set_bool (empathy_conf_get (),
318                                EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
319                                TRUE);
320
321 }
322
323 static void
324 connection_manager_listed (TpConnectionManager * const * cms,
325         gsize n_cms,
326         const GError *error,
327         gpointer user_data,
328         GObject *weak_object)
329 {
330         int i;
331         if (error != NULL) {
332                 DEBUG ("Couldn't get the connection manager list: %s", error->message);
333                 return;
334         }
335
336         for (i = 0; i < n_cms; i++) {
337                 if (!tp_strdiff (tp_connection_manager_get_name (cms[i]), "salut")) {
338                                 /* salut installed, see if we need to create a new account */
339                                 create_salut_account_if_needed ();
340                                 return;
341                         }
342         }
343 }
344
345 static void
346 create_salut_account (void)
347 {
348         TpDBusDaemon *d;
349
350         if (!should_create_salut_account())
351                 return;
352
353         d = tp_dbus_daemon_dup (NULL);
354
355         tp_list_connection_managers (d, connection_manager_listed, NULL,
356                 NULL, NULL);
357
358         g_object_unref (d);
359 }
360
361 /* The code that handles single-instance and startup notification is
362  * copied from gedit.
363  *
364  * Copyright (C) 2005 - Paolo Maggi
365  */
366 static void
367 on_bacon_message_received (const char *message,
368                            gpointer    data)
369 {
370         GtkWidget *window = data;
371         guint32    startup_timestamp;
372
373         g_return_if_fail (message != NULL);
374
375         DEBUG ("Other instance launched, presenting the main window. message='%s'",
376                 message);
377
378         if (strcmp (message, "accounts") == 0) {
379                 /* accounts dialog requested */
380                 empathy_accounts_dialog_show (GTK_WINDOW (window), NULL);
381         } else {
382                 startup_timestamp = atoi (message);
383
384                 /* Set the proper interaction time on the window.
385                  * Fall back to roundtripping to the X server when we
386                  * don't have the timestamp, e.g. when launched from
387                  * terminal. We also need to make sure that the window
388                  * has been realized otherwise it will not work. lame. */
389                 if (startup_timestamp == 0) {
390                         /* Work if launched from the terminal */
391                         DEBUG ("Using X server timestamp as a fallback");
392
393                         if (!GTK_WIDGET_REALIZED (window)) {
394                                 gtk_widget_realize (GTK_WIDGET (window));
395                         }
396
397                         startup_timestamp = gdk_x11_get_server_time (window->window);
398                 }
399
400                 gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp);
401         }
402 }
403
404 static guint32
405 get_startup_timestamp ()
406 {
407         const gchar *startup_id_env;
408         gchar       *startup_id = NULL;
409         gchar       *time_str;
410         gchar       *end;
411         gulong       retval = 0;
412
413         /* we don't unset the env, since startup-notification
414          * may still need it */
415         startup_id_env = g_getenv ("DESKTOP_STARTUP_ID");
416         if (startup_id_env == NULL) {
417                 goto out;
418         }
419
420         startup_id = g_strdup (startup_id_env);
421
422         time_str = g_strrstr (startup_id, "_TIME");
423         if (time_str == NULL) {
424                 goto out;
425         }
426
427         errno = 0;
428
429         /* Skip past the "_TIME" part */
430         time_str += 5;
431
432         retval = strtoul (time_str, &end, 0);
433         if (end == time_str || errno != 0)
434                 retval = 0;
435
436  out:
437         g_free (startup_id);
438
439         return (retval > 0) ? retval : 0;
440 }
441
442 static gboolean
443 show_version_cb (const char *option_name,
444                  const char *value,
445                  gpointer data,
446                  GError **error)
447 {
448         g_print ("%s\n", PACKAGE_STRING);
449
450         exit (EXIT_SUCCESS);
451
452         return FALSE;
453 }
454
455 static void
456 new_incoming_transfer_cb (EmpathyFTFactory *factory,
457                           EmpathyFTHandler *handler,
458                           GError *error,
459                           gpointer user_data)
460 {
461         if (error) {
462                 empathy_ft_manager_display_error (handler, error);
463         } else {
464                 empathy_receive_file_with_file_chooser (handler);
465         }
466 }
467
468 static void
469 new_ft_handler_cb (EmpathyFTFactory *factory,
470                    EmpathyFTHandler *handler,
471                    GError *error,
472                    gpointer user_data)
473 {
474         if (error) {
475                 empathy_ft_manager_display_error (handler, error);
476         } else {
477                 empathy_ft_manager_add_handler (handler);
478         }
479
480         g_object_unref (handler);
481 }
482
483 static void
484 new_call_handler_cb (EmpathyCallFactory *factory, EmpathyCallHandler *handler,
485         gboolean outgoing, gpointer user_data)
486 {
487         EmpathyCallWindow *window;
488
489         window = empathy_call_window_new (handler);
490         gtk_widget_show (GTK_WIDGET (window));
491 }
492
493 #ifdef ENABLE_DEBUG
494 static void
495 default_log_handler (const gchar *log_domain,
496     GLogLevelFlags log_level,
497     const gchar *message,
498     gpointer user_data)
499 {
500         g_log_default_handler (log_domain, log_level, message, NULL);
501
502         /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
503          * debugger as they already have in empathy_debug. */
504         if (log_level != G_LOG_LEVEL_DEBUG
505             || tp_strdiff (log_domain, G_LOG_DOMAIN)) {
506                 EmpathyDebugger *dbg;
507                 GTimeVal now;
508
509                 dbg = empathy_debugger_get_singleton ();
510                 g_get_current_time (&now);
511
512                 empathy_debugger_add_message (dbg, &now, log_domain,
513                                               log_level, message);
514         }
515 }
516 #endif /* ENABLE_DEBUG */
517
518 int
519 main (int argc, char *argv[])
520 {
521         guint32            startup_timestamp;
522 #if HAVE_GEOCLUE
523         EmpathyLocationManager *location_manager = NULL;
524 #endif
525         EmpathyStatusIcon *icon;
526         EmpathyDispatcher *dispatcher;
527         EmpathyAccountManager *account_manager;
528         EmpathyLogManager *log_manager;
529         EmpathyChatroomManager *chatroom_manager;
530         EmpathyCallFactory *call_factory;
531         EmpathyFTFactory  *ft_factory;
532         GtkWidget         *window;
533         MissionControl    *mc;
534         EmpathyIdle       *idle;
535         gboolean           autoconnect = TRUE;
536         gboolean           no_connect = FALSE;
537         gboolean           hide_contact_list = FALSE;
538         gboolean           accounts_dialog = FALSE;
539         GError            *error = NULL;
540         TpDBusDaemon      *dbus_daemon;
541         GOptionEntry       options[] = {
542                 { "no-connect", 'n',
543                   0, G_OPTION_ARG_NONE, &no_connect,
544                   N_("Don't connect on startup"),
545                   NULL },
546                 { "hide-contact-list", 'h',
547                   0, G_OPTION_ARG_NONE, &hide_contact_list,
548                   N_("Don't show the contact list on startup"),
549                   NULL },
550                 { "accounts", 'a',
551                   0, G_OPTION_ARG_NONE, &accounts_dialog,
552                   N_("Show the accounts dialog"),
553                   NULL },
554                 { "version", 'v',
555                   G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb, NULL, NULL },
556                 { NULL }
557         };
558
559         /* Init */
560         g_thread_init (NULL);
561         empathy_init ();
562
563         if (!gtk_init_with_args (&argc, &argv,
564                                  N_("- Empathy Instant Messenger"),
565                                  options, GETTEXT_PACKAGE, &error)) {
566                 g_warning ("Error in empathy init: %s", error->message);
567                 return EXIT_FAILURE;
568         }
569
570         empathy_gtk_init ();
571         g_set_application_name (_(PACKAGE_NAME));
572         g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
573
574         gst_init (&argc, &argv);
575
576 #if HAVE_LIBCHAMPLAIN
577         gtk_clutter_init (&argc, &argv);
578 #endif
579
580         gtk_window_set_default_icon_name ("empathy");
581         textdomain (GETTEXT_PACKAGE);
582
583 #ifdef ENABLE_DEBUG
584         /* Set up debugger */
585         g_log_set_default_handler (default_log_handler, NULL);
586 #endif
587
588         /* Setting up the bacon connection */
589         startup_timestamp = get_startup_timestamp ();
590         connection = bacon_message_connection_new ("empathy");
591         if (connection != NULL) {
592                 if (!bacon_message_connection_get_is_server (connection)) {
593                         gchar *message;
594
595                         if (accounts_dialog) {
596                                 DEBUG ("Showing accounts dialog from existing Empathy instance");
597
598                                 message = g_strdup ("accounts");
599
600                         } else {
601
602                                 DEBUG ("Activating existing instance");
603
604                                 message = g_strdup_printf ("%" G_GUINT32_FORMAT,
605                                                            startup_timestamp);
606                         }
607
608                         bacon_message_connection_send (connection, message);
609
610                         /* We never popup a window, so tell startup-notification
611                          * that we are done. */
612                         gdk_notify_startup_complete ();
613
614                         g_free (message);
615                         bacon_message_connection_free (connection);
616
617                         return EXIT_SUCCESS;
618                 }
619         } else {
620                 g_warning ("Cannot create the 'empathy' bacon connection.");
621         }
622
623         /* Take well-known name */
624         dbus_daemon = tp_dbus_daemon_dup (&error);
625         if (error == NULL) {
626                 if (!tp_dbus_daemon_request_name (dbus_daemon,
627                                                   "org.gnome.Empathy",
628                                                   TRUE, &error)) {
629                         DEBUG ("Failed to request well-known name: %s",
630                                error ? error->message : "no message");
631                         g_clear_error (&error);
632                 }
633                 g_object_unref (dbus_daemon);
634         } else {
635                 DEBUG ("Failed to dup dbus daemon: %s",
636                        error ? error->message : "no message");
637                 g_clear_error (&error);
638         }
639
640         /* Setting up MC */
641         mc = empathy_mission_control_dup_singleton ();
642         g_signal_connect (mc, "ServiceEnded",
643                           G_CALLBACK (service_ended_cb),
644                           NULL);
645         g_signal_connect (mc, "Error",
646                           G_CALLBACK (operation_error_cb),
647                           NULL);
648
649         if (accounts_dialog) {
650                 GtkWidget *dialog;
651
652                 dialog = empathy_accounts_dialog_show (NULL, NULL);
653                 g_signal_connect (dialog, "destroy",
654                                   G_CALLBACK (gtk_main_quit),
655                                   NULL);
656
657                 gtk_main ();
658                 return 0;
659         }
660
661         /* Setting up Idle */
662         idle = empathy_idle_dup_singleton ();
663         empathy_idle_set_auto_away (idle, TRUE);
664         use_nm_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_NM, idle);
665         empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_NM,
666                                  use_nm_notify_cb, idle);
667
668         /* Autoconnect */
669         empathy_conf_get_bool (empathy_conf_get (),
670                                EMPATHY_PREFS_AUTOCONNECT,
671                                &autoconnect);
672         if (autoconnect && ! no_connect &&
673                 tp_connection_presence_type_cmp_availability (empathy_idle_get_state
674                         (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0) {
675                 empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE);
676         }
677
678         /* account management */
679         account_manager = empathy_account_manager_dup_singleton ();
680
681         create_salut_account ();
682
683         /* Setting up UI */
684         window = empathy_main_window_show ();
685         icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list);
686
687         if (connection) {
688                 /* We se the callback here because we need window */
689                 bacon_message_connection_set_callback (connection,
690                                                        on_bacon_message_received,
691                                                        window);
692         }
693
694         /* Handle channels */
695         dispatcher = empathy_dispatcher_dup_singleton ();
696         g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
697
698         /* Logging */
699         log_manager = empathy_log_manager_dup_singleton ();
700         empathy_log_manager_observe (log_manager, dispatcher);
701
702         chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
703         empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
704
705         notify_init (_(PACKAGE_NAME));
706         /* Create the call factory */
707         call_factory = empathy_call_factory_initialise ();
708         g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
709                 G_CALLBACK (new_call_handler_cb), NULL);
710         /* Create the FT factory */
711         ft_factory = empathy_ft_factory_dup_singleton ();
712         g_signal_connect (ft_factory, "new-ft-handler",
713                 G_CALLBACK (new_ft_handler_cb), NULL);
714         g_signal_connect (ft_factory, "new-incoming-transfer",
715                 G_CALLBACK (new_incoming_transfer_cb), NULL);
716
717         /* Location mananger */
718 #if HAVE_GEOCLUE
719         location_manager = empathy_location_manager_dup_singleton ();
720 #endif
721
722         gtk_main ();
723
724         empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
725
726         g_object_unref (mc);
727         g_object_unref (idle);
728         g_object_unref (icon);
729         g_object_unref (account_manager);
730         g_object_unref (log_manager);
731         g_object_unref (dispatcher);
732         g_object_unref (chatroom_manager);
733 #if HAVE_GEOCLUE
734         g_object_unref (location_manager);
735 #endif
736         g_object_unref (ft_factory);
737
738         notify_uninit ();
739
740         return EXIT_SUCCESS;
741 }
742