38
38
#include <libebook/e-book.h>
39
39
#include <libnotify/notify.h>
41
#include <telepathy-glib/account-manager.h>
41
42
#include <telepathy-glib/dbus.h>
42
43
#include <telepathy-glib/util.h>
43
44
#include <telepathy-glib/connection-manager.h>
49
50
#include <libempathy/empathy-chatroom-manager.h>
50
51
#include <libempathy/empathy-account-settings.h>
51
52
#include <libempathy/empathy-connectivity.h>
52
#include <libempathy/empathy-account-manager.h>
53
53
#include <libempathy/empathy-connection-managers.h>
54
54
#include <libempathy/empathy-debugger.h>
55
55
#include <libempathy/empathy-dispatcher.h>
82
82
#define COMMAND_ACCOUNTS_DIALOG 1
84
static gboolean account_dialog_only = FALSE;
85
static gboolean start_hidden = FALSE;
86
static gboolean no_connect = FALSE;
85
89
dispatch_cb (EmpathyDispatcher *dispatcher,
86
90
EmpathyDispatchOperation *operation,
100
104
(empathy_dispatch_operation_get_channel_wrapper (operation));
102
106
id = empathy_tp_chat_get_id (tp_chat);
105
EmpathyContact *contact;
107
contact = empathy_tp_chat_get_remote_contact (tp_chat);
109
id = empathy_contact_get_id (contact);
114
EmpathyAccountManager *manager;
107
if (!EMP_STR_EMPTY (id))
115
109
TpConnection *connection;
116
EmpathyAccount *account;
118
manager = empathy_account_manager_dup_singleton ();
119
112
connection = empathy_tp_chat_get_connection (tp_chat);
120
account = empathy_account_manager_get_account_for_connection (
121
manager, connection);
113
account = empathy_get_account_for_connection (connection);
122
114
chat = empathy_chat_window_find_chat (account, id);
123
g_object_unref (manager);
127
empathy_chat_set_tp_chat (chat, tp_chat);
119
empathy_chat_set_tp_chat (chat, tp_chat);
129
chat = empathy_chat_new (tp_chat);
123
chat = empathy_chat_new (tp_chat);
124
/* empathy_chat_new returns a floating reference as EmpathyChat is
125
* a GtkWidget. This reference will be taken by a container
126
* (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
131
129
empathy_chat_window_present_chat (chat);
157
/* Salut account creation */
155
/* Salut account creation. The TpAccountManager first argument
156
* must already be prepared when calling this function. */
159
should_create_salut_account (void)
158
should_create_salut_account (TpAccountManager *manager)
161
EmpathyAccountManager *manager;
162
160
gboolean salut_created = FALSE;
163
161
GList *accounts, *l;
176
manager = empathy_account_manager_dup_singleton ();
177
accounts = empathy_account_manager_dup_accounts (manager);
174
accounts = tp_account_manager_get_valid_accounts (manager);
179
176
for (l = accounts; l != NULL; l = g_list_next (l))
181
EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
183
if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp"))
184
salut_created = TRUE;
186
g_object_unref (account);
178
TpAccount *account = TP_ACCOUNT (l->data);
180
if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp"))
182
salut_created = TRUE;
189
g_object_unref (manager);
187
g_list_free (accounts);
191
189
if (salut_created)
218
216
account = empathy_account_settings_get_account (settings);
220
empathy_account_set_enabled_async (account, TRUE, NULL, NULL);
218
tp_account_set_enabled_async (account, TRUE, NULL, NULL);
221
219
empathy_conf_set_bool (empathy_conf_get (),
222
220
EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
241
create_salut_account_if_needed (EmpathyConnectionManagers *managers)
239
create_salut_account_am_ready_cb (GObject *source_object,
240
GAsyncResult *result,
243
TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
244
EmpathyConnectionManagers *managers = user_data;
243
245
EmpathyAccountSettings *settings;
244
246
TpConnectionManager *manager;
245
247
const TpConnectionManagerProtocol *protocol;
252
254
gchar *jid = NULL;
253
255
GError *error = NULL;
257
if (!tp_account_manager_prepare_finish (account_manager, result, &error))
259
DEBUG ("Failed to prepare account manager: %s", error->message);
260
g_error_free (error);
256
if (!should_create_salut_account ())
264
if (!should_create_salut_account (account_manager))
259
267
manager = empathy_connection_managers_get_cm (managers, "salut");
260
268
if (manager == NULL)
262
270
DEBUG ("Salut not installed, not making a salut account");
266
274
protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
267
275
if (protocol == NULL)
269
277
DEBUG ("Salut doesn't support local-xmpp!!");
273
281
DEBUG ("Trying to add a salut account...");
278
286
DEBUG ("Failed to get self econtact: %s",
279
287
error ? error->message : "No error given");
280
288
g_clear_error (&error);
284
292
settings = empathy_account_settings_new ("salut", "local-xmpp",
320
328
g_object_unref (settings);
321
329
g_object_unref (contact);
322
330
g_object_unref (book);
333
g_object_unref (managers);
337
create_salut_account_if_needed (EmpathyConnectionManagers *managers)
339
TpAccountManager *manager;
341
manager = tp_account_manager_dup ();
343
tp_account_manager_prepare_async (manager, NULL,
344
create_salut_account_am_ready_cb, g_object_ref (managers));
346
g_object_unref (manager);
350
has_non_salut_accounts (TpAccountManager *manager)
352
gboolean ret = FALSE;
355
accounts = tp_account_manager_get_valid_accounts (manager);
357
for (l = accounts ; l != NULL; l = g_list_next (l))
359
if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp"))
366
g_list_free (accounts);
326
372
maybe_show_account_assistant (void)
328
EmpathyAccountManager *manager;
329
manager = empathy_account_manager_dup_singleton ();
331
if (empathy_account_manager_get_count (manager) == 0)
333
GtkWidget * assistant = empathy_account_assistant_new (
334
GTK_WINDOW (empathy_main_window_get ()));
335
gtk_window_present (GTK_WINDOW (assistant));
374
TpAccountManager *manager;
375
manager = tp_account_manager_dup ();
377
if (!has_non_salut_accounts (manager))
378
empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ()));
380
g_object_unref (manager);
342
386
if (empathy_connection_managers_is_ready (managers))
344
if (!empathy_import_mc4_accounts (managers))
388
if (!empathy_import_mc4_accounts (managers) && !start_hidden)
345
389
maybe_show_account_assistant ();
347
391
create_salut_account_if_needed (managers);
428
472
g_free (old_dir);
476
do_show_accounts_ui (GtkWindow *window,
477
TpAccountManager *manager)
482
if (has_non_salut_accounts (manager))
483
ui = empathy_accounts_dialog_show (window, NULL);
485
ui = empathy_account_assistant_show (window);
487
if (account_dialog_only)
488
g_signal_connect (ui, "destroy",
489
G_CALLBACK (gtk_main_quit), NULL);
493
account_manager_ready_for_accounts_cb (GObject *source_object,
494
GAsyncResult *result,
497
TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
498
GError *error = NULL;
500
if (!tp_account_manager_prepare_finish (manager, result, &error))
502
DEBUG ("Failed to prepare account manager: %s", error->message);
503
g_error_free (error);
507
do_show_accounts_ui (user_data, manager);
511
show_accounts_ui (GtkWindow *window,
514
TpAccountManager *manager;
519
manager = tp_account_manager_dup ();
521
tp_account_manager_prepare_async (manager, NULL,
522
account_manager_ready_for_accounts_cb, window);
524
g_object_unref (manager);
431
527
static UniqueResponse
432
528
unique_app_message_cb (UniqueApp *unique_app,
436
532
gpointer user_data)
438
GtkWidget *window = user_data;
534
GtkWindow *window = user_data;
440
536
DEBUG ("Other instance launched, presenting the main window. "
441
537
"Command=%d, timestamp %u", command, timestamp);
443
539
if (command == COMMAND_ACCOUNTS_DIALOG)
445
empathy_accounts_dialog_show (GTK_WINDOW (window), NULL);
541
show_accounts_ui (window, TRUE);
545
/* We're requested to show stuff again, disable the start hidden global
546
* in case the accounts wizard wants to pop up.
548
start_hidden = FALSE;
550
show_accounts_ui (window, FALSE);
449
552
gtk_window_set_screen (GTK_WINDOW (window),
450
553
unique_message_data_get_screen (data));
451
554
gtk_window_set_startup_id (GTK_WINDOW (window),
534
637
#endif /* ENABLE_DEBUG */
537
account_manager_ready_cb (EmpathyAccountManager *manager,
640
account_manager_ready_cb (GObject *source_object,
641
GAsyncResult *result,
539
642
gpointer user_data)
541
if (!empathy_account_manager_is_ready (manager))
544
if (should_create_salut_account () || !empathy_import_mc4_has_imported ())
644
TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
645
GError *error = NULL;
647
EmpathyConnectivity *connectivity;
648
gboolean autoconnect = TRUE;
650
if (!tp_account_manager_prepare_finish (manager, result, &error))
652
DEBUG ("Failed to prepare account manager: %s", error->message);
653
g_error_free (error);
658
idle = empathy_idle_dup_singleton ();
659
connectivity = empathy_connectivity_dup_singleton ();
661
empathy_conf_get_bool (empathy_conf_get (),
662
EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
663
if (autoconnect && !no_connect &&
664
tp_connection_presence_type_cmp_availability
665
(empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
667
/* if current state is Offline, then put it online */
668
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
670
if (should_create_salut_account (manager)
671
|| !empathy_import_mc4_has_imported ())
546
673
EmpathyConnectionManagers *managers;
547
674
managers = empathy_connection_managers_dup_singleton ();
552
679
G_CALLBACK (connection_managers_ready_cb), NULL);
682
else if (!start_hidden)
557
684
maybe_show_account_assistant ();
687
g_object_unref (idle);
688
g_object_unref (connectivity);
561
691
static EmpathyDispatcher *
618
748
g_ptr_array_add (filters, asv);
752
TP_IFACE_CHANNEL ".ChannelType",
753
G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
754
TP_IFACE_CHANNEL ".TargetHandleType",
755
G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
756
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialAudio",
757
G_TYPE_BOOLEAN, TRUE,
759
g_ptr_array_add (filters, asv);
762
TP_IFACE_CHANNEL ".ChannelType",
763
G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
764
TP_IFACE_CHANNEL ".TargetHandleType",
765
G_TYPE_INT, TP_HANDLE_TYPE_CONTACT,
766
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo",
767
G_TYPE_BOOLEAN, TRUE,
769
g_ptr_array_add (filters, asv);
621
772
empathy_dispatcher_add_handler (d, PACKAGE_NAME"MoreThanMeetsTheEye",
622
773
filters, capabilities);
631
account_connection_notify_cb (EmpathyAccount *account,
782
account_status_changed_cb (TpAccount *account,
786
gchar *dbus_error_name,
633
788
EmpathyChatroom *room)
635
790
TpConnection *conn;
637
conn = empathy_account_get_connection (account);
792
conn = tp_account_get_connection (account);
642
794
empathy_dispatcher_join_muc (conn,
643
795
empathy_chatroom_get_room (room), NULL, NULL);
647
account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager,
649
EmpathyChatroomManager *chatroom_manager)
799
account_manager_chatroom_ready_cb (GObject *source_object,
800
GAsyncResult *result,
803
TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
804
EmpathyChatroomManager *chatroom_manager = user_data;
651
805
GList *accounts, *l;
653
accounts = empathy_account_manager_dup_accounts (account_manager);
806
GError *error = NULL;
808
if (!tp_account_manager_prepare_finish (account_manager, result, &error))
810
DEBUG ("Failed to prepare account manager: %s", error->message);
811
g_error_free (error);
815
accounts = tp_account_manager_get_valid_accounts (account_manager);
655
817
for (l = accounts; l != NULL; l = g_list_next (l))
657
EmpathyAccount *account = EMPATHY_ACCOUNT (l->data);
819
TpAccount *account = TP_ACCOUNT (l->data);
658
820
TpConnection *conn;
659
821
GList *chatrooms, *p;
661
conn = empathy_account_get_connection (account);
823
conn = tp_account_get_connection (account);
663
825
chatrooms = empathy_chatroom_manager_get_chatrooms (
664
826
chatroom_manager, account);
673
835
if (conn == NULL)
675
g_signal_connect (G_OBJECT (account), "notify::connection",
676
G_CALLBACK (account_connection_notify_cb), room);
837
g_signal_connect (G_OBJECT (account), "status-changed",
838
G_CALLBACK (account_status_changed_cb), room);
685
847
g_list_free (chatrooms);
688
g_list_foreach (accounts, (GFunc) g_object_unref, NULL);
689
850
g_list_free (accounts);
693
854
chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager,
694
855
GParamSpec *pspec,
695
EmpathyAccountManager *account_manager)
699
g_object_get (G_OBJECT (account_manager), "ready", &ready, NULL);
703
account_manager_chatroom_ready_cb (account_manager, NULL,
708
g_signal_connect (account_manager, "notify::ready",
709
G_CALLBACK (account_manager_chatroom_ready_cb), chatroom_manager);
858
TpAccountManager *account_manager = user_data;
860
tp_account_manager_prepare_async (account_manager, NULL,
861
account_manager_chatroom_ready_cb, chatroom_manager);
719
870
EmpathyStatusIcon *icon;
720
871
EmpathyDispatcher *dispatcher;
721
EmpathyAccountManager *account_manager;
872
TpAccountManager *account_manager;
722
873
EmpathyLogManager *log_manager;
723
874
EmpathyChatroomManager *chatroom_manager;
724
875
EmpathyCallFactory *call_factory;
726
877
GtkWidget *window;
727
878
EmpathyIdle *idle;
728
879
EmpathyConnectivity *connectivity;
729
gboolean autoconnect = TRUE;
730
gboolean no_connect = FALSE;
731
gboolean hide_contact_list = FALSE;
732
gboolean accounts_dialog = FALSE;
733
880
GError *error = NULL;
734
881
TpDBusDaemon *dbus_daemon;
735
882
UniqueApp *unique_app;
741
888
0, G_OPTION_ARG_NONE, &no_connect,
742
889
N_("Don't connect on startup"),
744
{ "hide-contact-list", 'h',
745
0, G_OPTION_ARG_NONE, &hide_contact_list,
746
N_("Don't show the contact list on startup"),
891
{ "start-hidden", 'h',
892
0, G_OPTION_ARG_NONE, &start_hidden,
893
N_("Don't display the contact list or any other dialogs on startup"),
748
895
{ "accounts", 'a',
749
0, G_OPTION_ARG_NONE, &accounts_dialog,
896
0, G_OPTION_ARG_NONE, &account_dialog_only,
750
897
N_("Show the accounts dialog"),
752
899
{ "version", 'v',
795
942
if (unique_app_is_running (unique_app))
797
unique_app_send_message (unique_app, accounts_dialog ?
944
unique_app_send_message (unique_app, account_dialog_only ?
798
945
COMMAND_ACCOUNTS_DIALOG : UNIQUE_ACTIVATE, NULL);
800
947
g_object_unref (unique_app);
821
968
g_clear_error (&error);
971
if (account_dialog_only)
828
dialog = empathy_accounts_dialog_show (NULL, NULL);
829
g_signal_connect (dialog, "destroy",
830
G_CALLBACK (gtk_main_quit), NULL);
973
account_manager = tp_account_manager_dup ();
974
show_accounts_ui (NULL, TRUE);
978
g_object_unref (account_manager);
982
notify_init (_(PACKAGE_NAME));
836
984
/* Setting up Idle */
837
985
idle = empathy_idle_dup_singleton ();
838
986
empathy_idle_set_auto_away (idle, TRUE);
844
992
empathy_conf_notify_add (empathy_conf_get (), EMPATHY_PREFS_USE_CONN,
845
993
use_conn_notify_cb, connectivity);
848
empathy_conf_get_bool (empathy_conf_get (),
849
EMPATHY_PREFS_AUTOCONNECT, &autoconnect);
850
if (autoconnect && !no_connect &&
851
tp_connection_presence_type_cmp_availability
852
(empathy_idle_get_state (idle), TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
854
empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
856
995
/* account management */
857
account_manager = empathy_account_manager_dup_singleton ();
858
g_signal_connect (account_manager, "notify::ready",
859
G_CALLBACK (account_manager_ready_cb), NULL);
996
account_manager = tp_account_manager_dup ();
997
tp_account_manager_prepare_async (account_manager, NULL,
998
account_manager_ready_cb, NULL);
861
1000
/* Handle channels */
862
1001
dispatcher = setup_dispatcher ();
867
1006
/* Setting up UI */
868
1007
window = empathy_main_window_show ();
869
icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list);
1008
icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
871
1010
g_signal_connect (unique_app, "message-received",
872
1011
G_CALLBACK (unique_app_message_cb), window);
889
1028
chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
892
notify_init (_(PACKAGE_NAME));
893
1031
/* Create the call factory */
894
1032
call_factory = empathy_call_factory_initialise ();
895
1033
g_signal_connect (G_OBJECT (call_factory), "new-call-handler",