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/account-manager.h>
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>
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-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 TpConnection *connection;
111 connection = empathy_tp_chat_get_connection (tp_chat);
112 account = empathy_get_account_for_connection (connection);
113 chat = empathy_chat_window_find_chat (account, id);
118 empathy_chat_set_tp_chat (chat, tp_chat);
122 chat = empathy_chat_new (tp_chat);
123 /* empathy_chat_new returns a floating reference as EmpathyChat is
124 * a GtkWidget. This reference will be taken by a container
125 * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
128 empathy_chat_window_present_chat (chat);
130 empathy_dispatch_operation_claim (operation);
132 else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
134 EmpathyCallFactory *factory;
136 factory = empathy_call_factory_get ();
137 empathy_call_factory_claim_channel (factory, operation);
139 else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
141 EmpathyFTFactory *factory;
143 factory = empathy_ft_factory_dup_singleton ();
145 /* if the operation is not incoming, don't claim it,
146 * as it might have been triggered by another client, and
147 * we are observing it.
149 if (empathy_dispatch_operation_is_incoming (operation))
150 empathy_ft_factory_claim_channel (factory, operation);
154 /* Salut account creation. The TpAccountManager first argument
155 * must already be prepared when calling this function. */
157 should_create_salut_account (TpAccountManager *manager)
159 gboolean salut_created = FALSE;
162 /* Check if we already created a salut account */
163 empathy_conf_get_bool (empathy_conf_get (),
164 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
169 DEBUG ("Gconf says we already created a salut account once");
173 accounts = tp_account_manager_get_valid_accounts (manager);
175 for (l = accounts; l != NULL; l = g_list_next (l))
177 TpAccount *account = TP_ACCOUNT (l->data);
179 if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
181 salut_created = TRUE;
186 g_list_free (accounts);
190 DEBUG ("Existing salut account already exists, flagging so in gconf");
191 empathy_conf_set_bool (empathy_conf_get (),
192 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
196 return !salut_created;
200 salut_account_created (GObject *source,
201 GAsyncResult *result,
204 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
206 GError *error = NULL;
208 if (!empathy_account_settings_apply_finish (settings, result, &error))
210 DEBUG ("Failed to create salut account: %s", error->message);
211 g_error_free (error);
215 account = empathy_account_settings_get_account (settings);
217 tp_account_set_enabled_async (account, TRUE, NULL, NULL);
218 empathy_conf_set_bool (empathy_conf_get (),
219 EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
224 use_conn_notify_cb (EmpathyConf *conf,
228 EmpathyConnectivity *connectivity = user_data;
231 if (empathy_conf_get_bool (conf, key, &use_conn))
233 empathy_connectivity_set_use_conn (connectivity, use_conn);
238 create_salut_account_am_ready_cb (GObject *source_object,
239 GAsyncResult *result,
242 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
243 EmpathyConnectionManagers *managers = user_data;
244 EmpathyAccountSettings *settings;
245 TpConnectionManager *manager;
246 const TpConnectionManagerProtocol *protocol;
249 gchar *nickname = NULL;
250 gchar *first_name = NULL;
251 gchar *last_name = NULL;
254 GError *error = NULL;
256 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
258 DEBUG ("Failed to prepare account manager: %s", error->message);
259 g_error_free (error);
263 if (!should_create_salut_account (account_manager))
266 manager = empathy_connection_managers_get_cm (managers, "salut");
269 DEBUG ("Salut not installed, not making a salut account");
273 protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
274 if (protocol == NULL)
276 DEBUG ("Salut doesn't support local-xmpp!!");
280 DEBUG ("Trying to add a salut account...");
282 /* Get self EContact from EDS */
283 if (!e_book_get_self (&contact, &book, &error))
285 DEBUG ("Failed to get self econtact: %s",
286 error ? error->message : "No error given");
287 g_clear_error (&error);
291 settings = empathy_account_settings_new ("salut", "local-xmpp",
294 nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
295 first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
296 last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
297 email = e_contact_get (contact, E_CONTACT_EMAIL_1);
298 jid = e_contact_get (contact, E_CONTACT_IM_JABBER_HOME_1);
300 if (!tp_strdiff (nickname, "nickname"))
306 DEBUG ("Salut account created:\nnickname=%s\nfirst-name=%s\n"
307 "last-name=%s\nemail=%s\njid=%s\n",
308 nickname, first_name, last_name, email, jid);
310 empathy_account_settings_set_string (settings,
311 "nickname", nickname ? nickname : "");
312 empathy_account_settings_set_string (settings,
313 "first-name", first_name ? first_name : "");
314 empathy_account_settings_set_string (settings,
315 "last-name", last_name ? last_name : "");
316 empathy_account_settings_set_string (settings, "email", email ? email : "");
317 empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
319 empathy_account_settings_apply_async (settings,
320 salut_account_created, NULL);
327 g_object_unref (settings);
328 g_object_unref (contact);
329 g_object_unref (book);
332 g_object_unref (managers);
336 create_salut_account_if_needed (EmpathyConnectionManagers *managers)
338 TpAccountManager *manager;
340 manager = tp_account_manager_dup ();
342 tp_account_manager_prepare_async (manager, NULL,
343 create_salut_account_am_ready_cb, g_object_ref (managers));
345 g_object_unref (manager);
349 has_non_salut_accounts (TpAccountManager *manager)
351 gboolean ret = FALSE;
354 accounts = tp_account_manager_get_valid_accounts (manager);
356 for (l = accounts ; l != NULL; l = g_list_next (l))
358 if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp"))
365 g_list_free (accounts);
371 maybe_show_account_assistant (void)
373 TpAccountManager *manager;
374 manager = tp_account_manager_dup ();
376 if (!has_non_salut_accounts (manager))
377 empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()));
379 g_object_unref (manager);
383 check_connection_managers_ready (EmpathyConnectionManagers *managers)
385 if (empathy_connection_managers_is_ready (managers))
387 if (!empathy_import_mc4_accounts (managers) && !start_hidden)
388 maybe_show_account_assistant ();
390 create_salut_account_if_needed (managers);
391 g_object_unref (managers);
399 connection_managers_ready_cb (EmpathyConnectionManagers *managers,
403 check_connection_managers_ready (managers);
407 migrate_config_to_xdg_dir (void)
409 gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename;
411 GFile *xdg_file, *old_file;
412 static const gchar* filenames[] = {
416 "contact-groups.xml",
417 "status-presets.xml",
422 xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL);
423 if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
425 /* xdg config dir already exists */
430 old_dir = g_build_filename (g_get_home_dir (), ".gnome2",
432 if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
434 /* old config dir didn't exist */
440 if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1)
442 DEBUG ("Failed to create configuration directory; aborting migration");
448 for (i = 0; filenames[i]; i++)
450 old_filename = g_build_filename (old_dir, filenames[i], NULL);
451 if (!g_file_test (old_filename, G_FILE_TEST_EXISTS))
453 g_free (old_filename);
456 xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL);
457 old_file = g_file_new_for_path (old_filename);
458 xdg_file = g_file_new_for_path (xdg_filename);
460 if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE,
461 NULL, NULL, NULL, NULL))
462 DEBUG ("Failed to migrate %s", filenames[i]);
464 g_free (old_filename);
465 g_free (xdg_filename);
466 g_object_unref (old_file);
467 g_object_unref (xdg_file);
475 do_show_accounts_ui (GtkWindow *window,
476 TpAccountManager *manager)
481 if (has_non_salut_accounts (manager))
482 ui = empathy_accounts_dialog_show (window, NULL);
484 ui = empathy_account_assistant_show (window);
486 if (account_dialog_only)
487 g_signal_connect (ui, "destroy",
488 G_CALLBACK (gtk_main_quit), NULL);
492 account_manager_ready_for_accounts_cb (GObject *source_object,
493 GAsyncResult *result,
496 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
497 GError *error = NULL;
499 if (!tp_account_manager_prepare_finish (manager, result, &error))
501 DEBUG ("Failed to prepare account manager: %s", error->message);
502 g_error_free (error);
506 do_show_accounts_ui (user_data, manager);
510 show_accounts_ui (GtkWindow *window,
513 TpAccountManager *manager;
518 manager = tp_account_manager_dup ();
520 tp_account_manager_prepare_async (manager, NULL,
521 account_manager_ready_for_accounts_cb, window);
523 g_object_unref (manager);
526 static UniqueResponse
527 unique_app_message_cb (UniqueApp *unique_app,
529 UniqueMessageData *data,
533 GtkWindow *window = user_data;
535 DEBUG ("Other instance launched, presenting the main window. "
536 "Command=%d, timestamp %u", command, timestamp);
538 if (command == COMMAND_ACCOUNTS_DIALOG)
540 show_accounts_ui (window, TRUE);
544 /* We're requested to show stuff again, disable the start hidden global
545 * in case the accounts wizard wants to pop up.
547 start_hidden = FALSE;
549 show_accounts_ui (window, FALSE);
551 gtk_window_set_screen (GTK_WINDOW (window),
552 unique_message_data_get_screen (data));
553 gtk_window_set_startup_id (GTK_WINDOW (window),
554 unique_message_data_get_startup_id (data));
555 gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
558 return UNIQUE_RESPONSE_OK;
562 show_version_cb (const char *option_name,
567 g_print ("%s\n", PACKAGE_STRING);
575 new_incoming_transfer_cb (EmpathyFTFactory *factory,
576 EmpathyFTHandler *handler,
581 empathy_ft_manager_display_error (handler, error);
583 empathy_receive_file_with_file_chooser (handler);
587 new_ft_handler_cb (EmpathyFTFactory *factory,
588 EmpathyFTHandler *handler,
593 empathy_ft_manager_display_error (handler, error);
595 empathy_ft_manager_add_handler (handler);
597 g_object_unref (handler);
601 new_call_handler_cb (EmpathyCallFactory *factory,
602 EmpathyCallHandler *handler,
606 EmpathyCallWindow *window;
608 window = empathy_call_window_new (handler);
609 gtk_widget_show (GTK_WIDGET (window));
614 default_log_handler (const gchar *log_domain,
615 GLogLevelFlags log_level,
616 const gchar *message,
619 g_log_default_handler (log_domain, log_level, message, NULL);
621 /* G_LOG_DOMAIN = "empathy". No need to send empathy messages to the
622 * debugger as they already have in empathy_debug. */
623 if (log_level != G_LOG_LEVEL_DEBUG
624 || tp_strdiff (log_domain, G_LOG_DOMAIN))
626 EmpathyDebugger *dbg;
629 dbg = empathy_debugger_get_singleton ();
630 g_get_current_time (&now);
632 empathy_debugger_add_message (dbg, &now, log_domain,
636 #endif /* ENABLE_DEBUG */
639 account_manager_ready_cb (GObject *source_object,
640 GAsyncResult *result,
643 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
644 GError *error = NULL;
646 if (!tp_account_manager_prepare_finish (manager, result, &error))
648 DEBUG ("Failed to prepare account manager: %s", error->message);
649 g_error_free (error);
653 if (should_create_salut_account (manager)
654 || !empathy_import_mc4_has_imported ())
656 EmpathyConnectionManagers *managers;
657 managers = empathy_connection_managers_dup_singleton ();
659 if (!check_connection_managers_ready (managers))
661 g_signal_connect (managers, "notify::ready",
662 G_CALLBACK (connection_managers_ready_cb), NULL);
665 else if (!start_hidden)
667 maybe_show_account_assistant ();
671 static EmpathyDispatcher *
672 setup_dispatcher (void)
674 EmpathyDispatcher *d;
677 const gchar *channeltype;
678 TpHandleType handletype;
680 /* Text channels with handle types none, contact and room */
681 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_NONE },
682 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_CONTACT },
683 { TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM },
684 /* file transfer to contacts */
685 { TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_HANDLE_TYPE_CONTACT },
686 /* stream media to contacts */
687 { TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT },
688 /* stream tubes to contacts and rooms */
689 { TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, TP_HANDLE_TYPE_CONTACT },
690 { TP_IFACE_CHANNEL_TYPE_STREAM_TUBE, TP_HANDLE_TYPE_ROOM },
691 /* d-bus tubes to contacts and rooms */
692 { TP_IFACE_CHANNEL_TYPE_DBUS_TUBE, TP_HANDLE_TYPE_CONTACT },
693 { TP_IFACE_CHANNEL_TYPE_DBUS_TUBE, TP_HANDLE_TYPE_ROOM },
695 { TP_IFACE_CHANNEL_TYPE_ROOM_LIST, TP_HANDLE_TYPE_NONE },
697 gchar *capabilities[] = {
698 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
699 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
704 /* Setup the basic Client.Handler that matches our client filter */
705 filters = g_ptr_array_new ();
707 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
708 TP_IFACE_CHANNEL_TYPE_TEXT,
709 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT,
710 TP_HANDLE_TYPE_CONTACT,
712 g_ptr_array_add (filters, asv);
714 d = empathy_dispatcher_new (PACKAGE_NAME, filters, NULL);
716 g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
717 g_ptr_array_free (filters, TRUE);
719 /* Setup the an extended Client.Handler that matches everything we can do */
720 filters = g_ptr_array_new ();
721 for (i = 0 ; i < G_N_ELEMENTS (types); i++)
724 TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, types[i].channeltype,
725 TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_INT, types[i].handletype,
728 g_ptr_array_add (filters, asv);
732 TP_IFACE_CHANNEL ".ChannelType",
733 G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
734 TP_IFACE_CHANNEL ".TargetHandleType",
735 G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
736 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialAudio",
737 G_TYPE_BOOLEAN, TRUE,
739 g_ptr_array_add (filters, asv);
742 TP_IFACE_CHANNEL ".ChannelType",
743 G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
744 TP_IFACE_CHANNEL ".TargetHandleType",
745 G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
746 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo",
747 G_TYPE_BOOLEAN, TRUE,
749 g_ptr_array_add (filters, asv);
752 empathy_dispatcher_add_handler (d, PACKAGE_NAME"MoreThanMeetsTheEye",
753 filters, capabilities);
755 g_ptr_array_foreach (filters, (GFunc) g_hash_table_destroy, NULL);
756 g_ptr_array_free (filters, TRUE);
762 account_status_changed_cb (TpAccount *account,
766 gchar *dbus_error_name,
768 EmpathyChatroom *room)
772 conn = tp_account_get_connection (account);
774 empathy_dispatcher_join_muc (conn,
775 empathy_chatroom_get_room (room), NULL, NULL);
779 account_manager_chatroom_ready_cb (GObject *source_object,
780 GAsyncResult *result,
783 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
784 EmpathyChatroomManager *chatroom_manager = user_data;
786 GError *error = NULL;
788 if (!tp_account_manager_prepare_finish (account_manager, result, &error))
790 DEBUG ("Failed to prepare account manager: %s", error->message);
791 g_error_free (error);
795 accounts = tp_account_manager_get_valid_accounts (account_manager);
797 for (l = accounts; l != NULL; l = g_list_next (l))
799 TpAccount *account = TP_ACCOUNT (l->data);
801 GList *chatrooms, *p;
803 conn = tp_account_get_connection (account);
805 chatrooms = empathy_chatroom_manager_get_chatrooms (
806 chatroom_manager, account);
808 for (p = chatrooms; p != NULL; p = p->next)
810 EmpathyChatroom *room = EMPATHY_CHATROOM (p->data);
812 if (!empathy_chatroom_get_auto_connect (room))
817 g_signal_connect (G_OBJECT (account), "status-changed",
818 G_CALLBACK (account_status_changed_cb), room);
822 empathy_dispatcher_join_muc (conn,
823 empathy_chatroom_get_room (room), NULL, NULL);
827 g_list_free (chatrooms);
830 g_list_free (accounts);
834 chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
838 TpAccountManager *account_manager = user_data;
840 tp_account_manager_prepare_async (account_manager, NULL,
841 account_manager_chatroom_ready_cb, chatroom_manager);
845 main (int argc, char *argv[])
848 EmpathyLocationManager *location_manager = NULL;
850 EmpathyStatusIcon *icon;
851 EmpathyDispatcher *dispatcher;
852 TpAccountManager *account_manager;
853 EmpathyLogManager *log_manager;
854 EmpathyChatroomManager *chatroom_manager;
855 EmpathyCallFactory *call_factory;
856 EmpathyFTFactory *ft_factory;
859 EmpathyConnectivity *connectivity;
860 gboolean autoconnect = TRUE;
861 gboolean no_connect = FALSE;
862 GError *error = NULL;
863 TpDBusDaemon *dbus_daemon;
864 UniqueApp *unique_app;
865 gboolean chatroom_manager_ready;
867 GOptionContext *optcontext;
868 GOptionEntry options[] = {
870 0, G_OPTION_ARG_NONE, &no_connect,
871 N_("Don't connect on startup"),
873 { "start-hidden", 'h',
874 0, G_OPTION_ARG_NONE, &start_hidden,
875 N_("Don't display the contact list or any other dialogs on startup"),
878 0, G_OPTION_ARG_NONE, &account_dialog_only,
879 N_("Show the accounts dialog"),
882 G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
888 g_thread_init (NULL);
891 optcontext = g_option_context_new (N_("- Empathy IM Client"));
892 g_option_context_add_group (optcontext, gst_init_get_option_group ());
893 g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
894 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
896 if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
897 g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
898 error->message, argv[0]);
899 g_warning ("Error in empathy init: %s", error->message);
903 g_option_context_free (optcontext);
906 g_set_application_name (_(PACKAGE_NAME));
907 g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
909 #if HAVE_LIBCHAMPLAIN
910 gtk_clutter_init (&argc, &argv);
913 gtk_window_set_default_icon_name ("empathy");
914 textdomain (GETTEXT_PACKAGE);
917 /* Set up debugger */
918 g_log_set_default_handler (default_log_handler, NULL);
921 unique_app = unique_app_new_with_commands ("org.gnome.Empathy",
922 NULL, "accounts_dialog", COMMAND_ACCOUNTS_DIALOG, NULL);
924 if (unique_app_is_running (unique_app))
926 unique_app_send_message (unique_app, account_dialog_only ?
927 COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL);
929 g_object_unref (unique_app);
933 /* Take well-known name */
934 dbus_daemon = tp_dbus_daemon_dup (&error);
937 if (!tp_dbus_daemon_request_name (dbus_daemon,
938 "org.gnome.Empathy", TRUE, &error))
940 DEBUG ("Failed to request well-known name: %s",
941 error ? error->message : "no message");
942 g_clear_error (&error);
944 g_object_unref (dbus_daemon);
948 DEBUG ("Failed to dup dbus daemon: %s",
949 error ? error->message : "no message");
950 g_clear_error (&error);
953 if (account_dialog_only)
955 account_manager = tp_account_manager_dup ();
956 show_accounts_ui (NULL, TRUE);
960 g_object_unref (account_manager);
964 notify_init (_(PACKAGE_NAME));
966 /* Setting up Idle */
967 idle = empathy_idle_dup_singleton ();
968 empathy_idle_set_auto_away (idle, TRUE);
970 /* Setting up Connectivity */
971 connectivity = empathy_connectivity_dup_singleton ();
972 use_conn_notify_cb (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
974 empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
975 use_conn_notify_cb, connectivity);
978 empathy_conf_get_bool (empathy_conf_get (),
979 EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
980 if (autoconnect && !no_connect &&
981 tp_connection_presence_type_cmp_availability
982 (empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
984 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
986 /* account management */
987 account_manager = tp_account_manager_dup ();
988 tp_account_manager_prepare_async (account_manager, NULL,
989 account_manager_ready_cb, NULL);
991 /* Handle channels */
992 dispatcher = setup_dispatcher ();
993 g_signal_connect (dispatcher, "dispatch", G_CALLBACK (dispatch_cb), NULL);
995 migrate_config_to_xdg_dir ();
998 window = empathy_main_window_show ();
999 icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
1001 g_signal_connect (unique_app, "message-received",
1002 G_CALLBACK (unique_app_message_cb), window);
1005 log_manager = empathy_log_manager_dup_singleton ();
1006 empathy_log_manager_observe (log_manager, dispatcher);
1008 chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1009 empathy_chatroom_manager_observe (chatroom_manager, dispatcher);
1011 g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
1012 if (!chatroom_manager_ready)
1014 g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
1015 G_CALLBACK (chatroom_manager_ready_cb), account_manager);
1019 chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
1022 /* Create the call factory */
1023 call_factory = empathy_call_factory_initialise ();
1024 g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
1025 G_CALLBACK (new_call_handler_cb), NULL);
1026 /* Create the FT factory */
1027 ft_factory = empathy_ft_factory_dup_singleton ();
1028 g_signal_connect (ft_factory, "new-ft-handler",
1029 G_CALLBACK (new_ft_handler_cb), NULL);
1030 g_signal_connect (ft_factory, "new-incoming-transfer",
1031 G_CALLBACK (new_incoming_transfer_cb), NULL);
1033 /* Location mananger */
1035 location_manager = empathy_location_manager_dup_singleton ();
1040 empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1042 g_object_unref (idle);
1043 g_object_unref (connectivity);
1044 g_object_unref (icon);
1045 g_object_unref (account_manager);
1046 g_object_unref (log_manager);
1047 g_object_unref (dispatcher);
1048 g_object_unref (chatroom_manager);
1050 g_object_unref (location_manager);
1052 g_object_unref (ft_factory);
1053 g_object_unref (unique_app);
1057 return EXIT_SUCCESS;