2 * Copyright (C) 2007-2009 Collabora Ltd.
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.
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.
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
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
29 #include <glib/gi18n.h>
32 #include <unique/unique.h>
35 #include <clutter-gtk/clutter-gtk.h>
38 #include <libebook/e-book.h>
39 #include <libnotify/notify.h>
41 #include <telepathy-glib/dbus.h>
42 #include <telepathy-glib/util.h>
43 #include <telepathy-glib/connection-manager.h>
44 #include <telepathy-glib/interfaces.h>
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-settings.h>
51 #include <libempathy/empathy-connectivity.h>
52 #include <libempathy/empathy-account-manager.h>
53 #include <libempathy/empathy-connection-managers.h>
54 #include <libempathy/empathy-debugger.h>
55 #include <libempathy/empathy-dispatcher.h>
56 #include <libempathy/empathy-dispatch-operation.h>
57 #include <libempathy/empathy-log-manager.h>
58 #include <libempathy/empathy-ft-factory.h>
59 #include <libempathy/empathy-tp-chat.h>
60 #include <libempathy/empathy-tp-call.h>
62 #include <libempathy-gtk/empathy-conf.h>
63 #include <libempathy-gtk/empathy-ui-utils.h>
64 #include <libempathy-gtk/empathy-location-manager.h>
66 #include "empathy-account-assistant.h"
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 #include "empathy-import-mc4-accounts.h"
75 #include "extensions/extensions.h"
77 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
78 #include <libempathy/empathy-debug.h>
82 #define COMMAND_ACCOUNTS_DIALOG 1
84 static gboolean account_dialog_only = FALSE;
85 static gboolean start_hidden = FALSE;
88 dispatch_cb (EmpathyDispatcher *dispatcher,
89 EmpathyDispatchOperation *operation,
94 channel_type = empathy_dispatch_operation_get_channel_type_id (operation);
96 if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
98 EmpathyTpChat *tp_chat;
99 EmpathyChat *chat = NULL;
102 tp_chat = EMPATHY_TP_CHAT
103 (empathy_dispatch_operation_get_channel_wrapper (operation));
105 id = empathy_tp_chat_get_id (tp_chat);
106 if (!EMP_STR_EMPTY (id))
108 EmpathyAccountManager *manager;
109 TpConnection *connection;
110 EmpathyAccount *account;
112 manager = empathy_account_manager_dup_singleton ();
113 connection = empathy_tp_chat_get_connection (tp_chat);
114 account = empathy_account_manager_get_account_for_connection (
115 manager, connection);
116 chat = empathy_chat_window_find_chat (account, id);
117 g_object_unref (manager);
121 empathy_chat_set_tp_chat (chat, tp_chat);
123 chat = empathy_chat_new (tp_chat);
125 empathy_chat_window_present_chat (chat);
127 empathy_dispatch_operation_claim (operation);
129 else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
131 EmpathyCallFactory *factory;
133 factory = empathy_call_factory_get ();
134 empathy_call_factory_claim_channel (factory, operation);
136 else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
138 EmpathyFTFactory *factory;
140 factory = empathy_ft_factory_dup_singleton ();
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.
146 if (empathy_dispatch_operation_is_incoming (operation))
147 empathy_ft_factory_claim_channel (factory, operation);
151 /* Salut account creation */
153 should_create_salut_account (void)
155 EmpathyAccountManager *manager;
156 gboolean salut_created = FALSE;
159 /* Check if we already created a salut account */
160 empathy_conf_get_bool (empathy_conf_get (),
161 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
166 DEBUG ("Gconf says we already created a salut account once");
170 manager = empathy_account_manager_dup_singleton ();
171 accounts = empathy_account_manager_dup_accounts (manager);
173 for (l = accounts; l != NULL; l = g_list_next (l))
175 EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
177 if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp"))
178 salut_created = TRUE;
180 g_object_unref (account);
183 g_object_unref (manager);
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,
193 return !salut_created;
197 salut_account_created (GObject *source,
198 GAsyncResult *result,
201 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
202 EmpathyAccount *account;
203 GError *error = NULL;
205 if (!empathy_account_settings_apply_finish (settings, result, &error))
207 DEBUG ("Failed to create salut account: %s", error->message);
208 g_error_free (error);
212 account = empathy_account_settings_get_account (settings);
214 empathy_account_set_enabled_async (account, TRUE, NULL, NULL);
215 empathy_conf_set_bool (empathy_conf_get (),
216 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
221 use_conn_notify_cb (EmpathyConf *conf,
225 EmpathyConnectivity *connectivity = user_data;
228 if (empathy_conf_get_bool (conf, key, &use_conn))
230 empathy_connectivity_set_use_conn (connectivity, use_conn);
235 create_salut_account_if_needed (EmpathyConnectionManagers *managers)
237 EmpathyAccountSettings *settings;
238 TpConnectionManager *manager;
239 const TpConnectionManagerProtocol *protocol;
242 gchar *nickname = NULL;
243 gchar *first_name = NULL;
244 gchar *last_name = NULL;
247 GError *error = NULL;
250 if (!should_create_salut_account ())
253 manager = empathy_connection_managers_get_cm (managers, "salut");
256 DEBUG ("Salut not installed, not making a salut account");
260 protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
261 if (protocol == NULL)
263 DEBUG ("Salut doesn't support local-xmpp!!");
267 DEBUG ("Trying to add a salut account...");
269 /* Get self EContact from EDS */
270 if (!e_book_get_self (&contact, &book, &error))
272 DEBUG ("Failed to get self econtact: %s",
273 error ? error->message : "No error given");
274 g_clear_error (&error);
278 settings = empathy_account_settings_new ("salut", "local-xmpp",
281 nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
282 first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
283 last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
284 email = e_contact_get (contact, E_CONTACT_EMAIL_1);
285 jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
287 if (!tp_strdiff (nickname, "nickname"))
293 DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
294 "last-name=%s\nemail=%s\njid=%s\n",
295 nickname, first_name, last_name, email, jid);
297 empathy_account_settings_set_string (settings,
298 "nickname", nickname ? nickname : "");
299 empathy_account_settings_set_string (settings,
300 "first-name", first_name ? first_name : "");
301 empathy_account_settings_set_string (settings,
302 "last-name", last_name ? last_name : "");
303 empathy_account_settings_set_string (settings, "email", email ? email : "");
304 empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
306 empathy_account_settings_apply_async (settings,
307 salut_account_created, NULL);
314 g_object_unref (settings);
315 g_object_unref (contact);
316 g_object_unref (book);
320 has_non_salut_accounts (EmpathyAccountManager *manager)
322 gboolean ret = FALSE;
325 accounts = empathy_account_manager_dup_accounts (manager);
327 for (l = accounts ; l != NULL; l = g_list_next (l))
329 EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
331 if (tp_strdiff (empathy_account_get_protocol (l->data), "local-xmpp"))
334 g_object_unref (account);
337 g_list_free (accounts);
343 maybe_show_account_assistant (void)
345 EmpathyAccountManager *manager;
346 manager = empathy_account_manager_dup_singleton ();
348 if (!has_non_salut_accounts (manager))
349 empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()));
353 check_connection_managers_ready (EmpathyConnectionManagers *managers)
355 if (empathy_connection_managers_is_ready (managers))
357 if (!empathy_import_mc4_accounts (managers))
358 maybe_show_account_assistant ();
360 create_salut_account_if_needed (managers);
361 g_object_unref (managers);
369 connection_managers_ready_cb (EmpathyConnectionManagers *managers,
373 check_connection_managers_ready (managers);
377 migrate_config_to_xdg_dir (void)
379 gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
381 GFile *xdg_file, *old_file;
382 static const gchar* filenames[] = {
386 "contact-groups.xml",
387 "status-presets.xml",
392 xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
393 if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
395 /* xdg config dir already exists */
400 old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
402 if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
404 /* old config dir didn't exist */
410 if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1)
412 DEBUG ("Failed to create configuration directory; aborting migration");
418 for (i = 0; filenames[i]; i++)
420 old_filename = g_build_filename (old_dir, filenames[i], NULL);
421 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS))
423 g_free (old_filename);
426 xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
427 old_file = g_file_new_for_path (old_filename);
428 xdg_file = g_file_new_for_path (xdg_filename);
430 if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
431 NULL, NULL, NULL, NULL))
432 DEBUG ("Failed to migrate %s", filenames[i]);
434 g_free (old_filename);
435 g_free (xdg_filename);
436 g_object_unref (old_file);
437 g_object_unref (xdg_file);
445 do_show_accounts_ui (GtkWindow *window, EmpathyAccountManager *manager)
450 if (has_non_salut_accounts (manager))
451 ui = empathy_accounts_dialog_show (window, NULL);
453 ui = empathy_account_assistant_show (window);
455 if (account_dialog_only)
456 g_signal_connect (ui, "destroy",
457 G_CALLBACK (gtk_main_quit), NULL);
461 account_manager_ready_for_accounts_cb (EmpathyAccountManager *manager,
465 if (!empathy_account_manager_is_ready (manager))
468 do_show_accounts_ui (user_data, manager);
472 show_accounts_ui (GtkWindow *window)
474 EmpathyAccountManager *manager;
476 manager = empathy_account_manager_dup_singleton ();
477 if (empathy_account_manager_is_ready (manager))
479 do_show_accounts_ui (window, manager);
483 g_signal_connect (manager, "notify::ready",
484 G_CALLBACK (account_manager_ready_for_accounts_cb), window);
487 g_object_unref (manager);
490 static UniqueResponse
491 unique_app_message_cb (UniqueApp *unique_app,
493 UniqueMessageData *data,
497 GtkWindow *window = user_data;
499 DEBUG ("Other instance launched, presenting the main window. "
500 "Command=%d, timestamp %u", command, timestamp);
502 if (command == COMMAND_ACCOUNTS_DIALOG)
504 show_accounts_ui (window);
508 gtk_window_set_screen (GTK_WINDOW (window),
509 unique_message_data_get_screen (data));
510 gtk_window_set_startup_id (GTK_WINDOW (window),
511 unique_message_data_get_startup_id (data));
512 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
515 return UNIQUE_RESPONSE_OK;
519 show_version_cb (const char *option_name,
524 g_print ("%s\n", PACKAGE_STRING);
532 new_incoming_transfer_cb (EmpathyFTFactory *factory,
533 EmpathyFTHandler *handler,
538 empathy_ft_manager_display_error (handler, error);
540 empathy_receive_file_with_file_chooser (handler);
544 new_ft_handler_cb (EmpathyFTFactory *factory,
545 EmpathyFTHandler *handler,
550 empathy_ft_manager_display_error (handler, error);
552 empathy_ft_manager_add_handler (handler);
554 g_object_unref (handler);
558 new_call_handler_cb (EmpathyCallFactory *factory,
559 EmpathyCallHandler *handler,
563 EmpathyCallWindow *window;
565 window = empathy_call_window_new (handler);
566 gtk_widget_show (GTK_WIDGET (window));
571 default_log_handler (const gchar *log_domain,
572 GLogLevelFlags log_level,
573 const gchar *message,
576 g_log_default_handler (log_domain, log_level, message, NULL);
578 /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
579 * debugger as they already have in empathy_debug. */
580 if (log_level != G_LOG_LEVEL_DEBUG
581 || tp_strdiff (log_domain, G_LOG_DOMAIN))
583 EmpathyDebugger *dbg;
586 dbg = empathy_debugger_get_singleton ();
587 g_get_current_time (&now);
589 empathy_debugger_add_message (dbg, &now, log_domain,
593 #endif /* ENABLE_DEBUG */
596 account_manager_ready_cb (EmpathyAccountManager *manager,
600 if (!empathy_account_manager_is_ready (manager))
603 if (should_create_salut_account () || !empathy_import_mc4_has_imported ())
605 EmpathyConnectionManagers *managers;
606 managers = empathy_connection_managers_dup_singleton ();
608 if (!check_connection_managers_ready (managers))
610 g_signal_connect (managers, "notify::ready",
611 G_CALLBACK (connection_managers_ready_cb), NULL);
614 else if (!start_hidden)
616 maybe_show_account_assistant ();
620 static EmpathyDispatcher *
621 setup_dispatcher (void)
623 EmpathyDispatcher *d;
626 const gchar *channeltype;
627 TpHandleType handletype;
629 /* Text channels with handle types none, contact and room */
630 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_NONE },
631 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_CONTACT },
632 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM },
633 /* file transfer to contacts */
634 { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT },
635 /* stream media to contacts */
636 { TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT },
637 /* stream tubes to contacts and rooms */
638 { TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, TP_HANDLE_TYPE_CONTACT },
639 { TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, TP_HANDLE_TYPE_ROOM },
640 /* d-bus tubes to contacts and rooms */
641 { TP_IFACE_CHANNEL_TYPE_DBUS_TUBE, TP_HANDLE_TYPE_CONTACT },
642 { TP_IFACE_CHANNEL_TYPE_DBUS_TUBE, TP_HANDLE_TYPE_ROOM },
644 { TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE },
646 gchar *capabilities[] = {
647 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
648 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
653 /* Setup the basic Client.Handler that matches our client filter */
654 filters = g_ptr_array_new ();
656 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
657 TP_IFACE_CHANNEL_TYPE_TEXT,
658 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT,
659 TP_HANDLE_TYPE_CONTACT,
661 g_ptr_array_add (filters, asv);
663 d = empathy_dispatcher_new (PACKAGE_NAME, filters, NULL);
665 g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
666 g_ptr_array_free (filters, TRUE);
668 /* Setup the an extended Client.Handler that matches everything we can do */
669 filters = g_ptr_array_new ();
670 for (i = 0 ; i < G_N_ELEMENTS (types); i++)
673 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, types[i].channeltype,
674 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT, types[i].handletype,
677 g_ptr_array_add (filters, asv);
681 TP_IFACE_CHANNEL ".ChannelType",
682 G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
683 TP_IFACE_CHANNEL ".TargetHandleType",
684 G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
685 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialAudio",
686 G_TYPE_BOOLEAN, TRUE,
688 g_ptr_array_add (filters, asv);
691 TP_IFACE_CHANNEL ".ChannelType",
692 G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
693 TP_IFACE_CHANNEL ".TargetHandleType",
694 G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
695 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo",
696 G_TYPE_BOOLEAN, TRUE,
698 g_ptr_array_add (filters, asv);
701 empathy_dispatcher_add_handler (d, PACKAGE_NAME"MoreThanMeetsTheEye",
702 filters, capabilities);
704 g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
705 g_ptr_array_free (filters, TRUE);
711 account_connection_notify_cb (EmpathyAccount *account,
713 EmpathyChatroom *room)
717 conn = empathy_account_get_connection (account);
722 empathy_dispatcher_join_muc (conn,
723 empathy_chatroom_get_room (room), NULL, NULL);
727 account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager,
729 EmpathyChatroomManager *chatroom_manager)
733 accounts = empathy_account_manager_dup_accounts (account_manager);
735 for (l = accounts; l != NULL; l = g_list_next (l))
737 EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
739 GList *chatrooms, *p;
741 conn = empathy_account_get_connection (account);
743 chatrooms = empathy_chatroom_manager_get_chatrooms (
744 chatroom_manager, account);
746 for (p = chatrooms; p != NULL; p = p->next)
748 EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
750 if (!empathy_chatroom_get_auto_connect (room))
755 g_signal_connect (G_OBJECT (account), "notify::connection",
756 G_CALLBACK (account_connection_notify_cb), room);
760 empathy_dispatcher_join_muc (conn,
761 empathy_chatroom_get_room (room), NULL, NULL);
765 g_list_free (chatrooms);
768 g_list_foreach (accounts, (GFunc) g_object_unref, NULL);
769 g_list_free (accounts);
773 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
775 EmpathyAccountManager *account_manager)
779 g_object_get (G_OBJECT (account_manager), "ready", &ready, NULL);
783 account_manager_chatroom_ready_cb (account_manager, NULL,
788 g_signal_connect (account_manager, "notify::ready",
789 G_CALLBACK (account_manager_chatroom_ready_cb), chatroom_manager);
794 main (int argc, char *argv[])
797 EmpathyLocationManager *location_manager = NULL;
799 EmpathyStatusIcon *icon;
800 EmpathyDispatcher *dispatcher;
801 EmpathyAccountManager *account_manager;
802 EmpathyLogManager *log_manager;
803 EmpathyChatroomManager *chatroom_manager;
804 EmpathyCallFactory *call_factory;
805 EmpathyFTFactory *ft_factory;
808 EmpathyConnectivity *connectivity;
809 gboolean autoconnect = TRUE;
810 gboolean no_connect = FALSE;
811 GError *error = NULL;
812 TpDBusDaemon *dbus_daemon;
813 UniqueApp *unique_app;
814 gboolean chatroom_manager_ready;
816 GOptionContext *optcontext;
817 GOptionEntry options[] = {
819 0, G_OPTION_ARG_NONE, &no_connect,
820 N_("Don't connect on startup"),
822 { "hide-contact-list", 'h',
823 0, G_OPTION_ARG_NONE, &start_hidden,
824 N_("Don't show the contact list on startup"),
827 0, G_OPTION_ARG_NONE, &account_dialog_only,
828 N_("Show the accounts dialog"),
831 G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
837 g_thread_init (NULL);
840 optcontext = g_option_context_new (N_("- Empathy IM Client"));
841 g_option_context_add_group (optcontext, gst_init_get_option_group ());
842 g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
843 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
845 if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
846 g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
847 error->message, argv[0]);
848 g_warning ("Error in empathy init: %s", error->message);
852 g_option_context_free (optcontext);
855 g_set_application_name (_(PACKAGE_NAME));
856 g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
858 #if HAVE_LIBCHAMPLAIN
859 gtk_clutter_init (&argc, &argv);
862 gtk_window_set_default_icon_name ("empathy");
863 textdomain (GETTEXT_PACKAGE);
866 /* Set up debugger */
867 g_log_set_default_handler (default_log_handler, NULL);
870 unique_app = unique_app_new_with_commands ("org.gnome.Empathy",
871 NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL);
873 if (unique_app_is_running (unique_app))
875 unique_app_send_message (unique_app, account_dialog_only ?
876 COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL);
878 g_object_unref (unique_app);
882 /* Take well-known name */
883 dbus_daemon = tp_dbus_daemon_dup (&error);
886 if (!tp_dbus_daemon_request_name (dbus_daemon,
887 "org.gnome.Empathy", TRUE, &error))
889 DEBUG ("Failed to request well-known name: %s",
890 error ? error->message : "no message");
891 g_clear_error (&error);
893 g_object_unref (dbus_daemon);
897 DEBUG ("Failed to dup dbus daemon: %s",
898 error ? error->message : "no message");
899 g_clear_error (&error);
902 if (account_dialog_only)
904 account_manager = empathy_account_manager_dup_singleton ();
905 show_accounts_ui (NULL);
909 g_object_unref (account_manager);
913 notify_init (_(PACKAGE_NAME));
915 /* Setting up Idle */
916 idle = empathy_idle_dup_singleton ();
917 empathy_idle_set_auto_away (idle, TRUE);
919 /* Setting up Connectivity */
920 connectivity = empathy_connectivity_dup_singleton ();
921 use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
923 empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
924 use_conn_notify_cb, connectivity);
927 empathy_conf_get_bool (empathy_conf_get (),
928 EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
929 if (autoconnect && !no_connect &&
930 tp_connection_presence_type_cmp_availability
931 (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
933 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
935 /* account management */
936 account_manager = empathy_account_manager_dup_singleton ();
937 g_signal_connect (account_manager, "notify::ready",
938 G_CALLBACK (account_manager_ready_cb), NULL);
940 /* Handle channels */
941 dispatcher = setup_dispatcher ();
942 g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
944 migrate_config_to_xdg_dir ();
947 window = empathy_main_window_show ();
948 icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
950 g_signal_connect (unique_app, "message-received",
951 G_CALLBACK (unique_app_message_cb), window);
954 log_manager = empathy_log_manager_dup_singleton ();
955 empathy_log_manager_observe (log_manager, dispatcher);
957 chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
958 empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
960 g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
961 if (!chatroom_manager_ready)
963 g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
964 G_CALLBACK (chatroom_manager_ready_cb), account_manager);
968 chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
971 /* Create the call factory */
972 call_factory = empathy_call_factory_initialise ();
973 g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
974 G_CALLBACK (new_call_handler_cb), NULL);
975 /* Create the FT factory */
976 ft_factory = empathy_ft_factory_dup_singleton ();
977 g_signal_connect (ft_factory, "new-ft-handler",
978 G_CALLBACK (new_ft_handler_cb), NULL);
979 g_signal_connect (ft_factory, "new-incoming-transfer",
980 G_CALLBACK (new_incoming_transfer_cb), NULL);
982 /* Location mananger */
984 location_manager = empathy_location_manager_dup_singleton ();
989 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
991 g_object_unref (idle);
992 g_object_unref (connectivity);
993 g_object_unref (icon);
994 g_object_unref (account_manager);
995 g_object_unref (log_manager);
996 g_object_unref (dispatcher);
997 g_object_unref (chatroom_manager);
999 g_object_unref (location_manager);
1001 g_object_unref (ft_factory);
1002 g_object_unref (unique_app);
1006 return EXIT_SUCCESS;