1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2008 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
26 #include <glib/gi18n-lib.h>
28 #include <telepathy-logger/log-manager.h>
30 #include <libempathy/empathy-call-factory.h>
31 #include <libempathy/empathy-contact-manager.h>
32 #include <libempathy/empathy-dispatcher.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-chatroom-manager.h>
35 #include <libempathy/empathy-contact-manager.h>
37 #include "empathy-contact-menu.h"
38 #include "empathy-images.h"
39 #include "empathy-log-window.h"
40 #include "empathy-contact-dialogs.h"
41 #include "empathy-ui-utils.h"
42 #include "empathy-share-my-desktop.h"
45 empathy_contact_menu_new (EmpathyContact
*contact
,
46 EmpathyContactFeatureFlags features
)
52 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
54 if (features
== EMPATHY_CONTACT_FEATURE_NONE
) {
58 menu
= gtk_menu_new ();
59 shell
= GTK_MENU_SHELL (menu
);
62 item
= empathy_contact_add_menu_item_new (contact
);
64 gtk_menu_shell_append (shell
, item
);
65 gtk_widget_show (item
);
69 if (features
& EMPATHY_CONTACT_FEATURE_CHAT
) {
70 item
= empathy_contact_chat_menu_item_new (contact
);
71 gtk_menu_shell_append (shell
, item
);
72 gtk_widget_show (item
);
75 if (features
& EMPATHY_CONTACT_FEATURE_CALL
) {
77 item
= empathy_contact_audio_call_menu_item_new (contact
);
78 gtk_menu_shell_append (shell
, item
);
79 gtk_widget_show (item
);
82 item
= empathy_contact_video_call_menu_item_new (contact
);
83 gtk_menu_shell_append (shell
, item
);
84 gtk_widget_show (item
);
88 if (features
& EMPATHY_CONTACT_FEATURE_LOG
) {
89 item
= empathy_contact_log_menu_item_new (contact
);
90 gtk_menu_shell_append (shell
, item
);
91 gtk_widget_show (item
);
95 item
= empathy_contact_invite_menu_item_new (contact
);
96 gtk_menu_shell_append (shell
, item
);
97 gtk_widget_show (item
);
100 item
= empathy_contact_file_transfer_menu_item_new (contact
);
101 gtk_menu_shell_append (shell
, item
);
102 gtk_widget_show (item
);
104 /* Share my desktop */
105 /* FIXME we should add the "Share my desktop" menu item if Vino is
106 a registered handler in MC5 */
107 item
= empathy_contact_share_my_desktop_menu_item_new (contact
);
108 gtk_menu_shell_append (shell
, item
);
109 gtk_widget_show (item
);
112 if (features
& (EMPATHY_CONTACT_FEATURE_EDIT
|
113 EMPATHY_CONTACT_FEATURE_INFO
|
114 EMPATHY_CONTACT_FEATURE_FAVOURITE
)) {
115 item
= gtk_separator_menu_item_new ();
116 gtk_menu_shell_append (shell
, item
);
117 gtk_widget_show (item
);
121 if (features
& EMPATHY_CONTACT_FEATURE_EDIT
) {
122 item
= empathy_contact_edit_menu_item_new (contact
);
123 gtk_menu_shell_append (shell
, item
);
124 gtk_widget_show (item
);
128 if (features
& EMPATHY_CONTACT_FEATURE_INFO
) {
129 item
= empathy_contact_info_menu_item_new (contact
);
130 gtk_menu_shell_append (shell
, item
);
131 gtk_widget_show (item
);
134 /* Favorite checkbox */
135 if (features
& EMPATHY_CONTACT_FEATURE_FAVOURITE
) {
136 item
= empathy_contact_favourite_menu_item_new (contact
);
137 gtk_menu_shell_append (shell
, item
);
138 gtk_widget_show (item
);
145 empathy_contact_add_menu_item_activated (GtkMenuItem
*item
,
146 EmpathyContact
*contact
)
150 toplevel
= gtk_widget_get_toplevel (GTK_WIDGET (item
));
151 if (!gtk_widget_is_toplevel (toplevel
) || !GTK_IS_WINDOW (toplevel
)) {
155 empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel
),
160 empathy_contact_add_menu_item_new (EmpathyContact
*contact
)
164 EmpathyContactManager
*manager
;
165 TpConnection
*connection
;
167 gboolean found
= FALSE
;
168 EmpathyContactListFlags flags
;
170 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
172 if (!empathy_contact_manager_initialized ()) {
176 manager
= empathy_contact_manager_dup_singleton ();
177 connection
= empathy_contact_get_connection (contact
);
179 flags
= empathy_contact_manager_get_flags_for_connection (manager
,
182 if (!(flags
& EMPATHY_CONTACT_LIST_CAN_ADD
)) {
186 members
= empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (manager
));
187 for (l
= members
; l
; l
= l
->next
) {
188 if (!found
&& empathy_contact_equal (l
->data
, contact
)) {
190 /* we keep iterating so that we don't leak contact
194 g_object_unref (l
->data
);
196 g_list_free (members
);
197 g_object_unref (manager
);
203 item
= gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
204 image
= gtk_image_new_from_icon_name (GTK_STOCK_ADD
,
206 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
208 g_signal_connect (item
, "activate",
209 G_CALLBACK (empathy_contact_add_menu_item_activated
),
216 empathy_contact_chat_menu_item_activated (GtkMenuItem
*item
,
217 EmpathyContact
*contact
)
219 empathy_dispatcher_chat_with_contact (contact
, gtk_get_current_event_time ());
223 empathy_contact_chat_menu_item_new (EmpathyContact
*contact
)
228 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
230 item
= gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
231 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE
,
233 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
234 gtk_widget_show (image
);
236 g_signal_connect (item
, "activate",
237 G_CALLBACK (empathy_contact_chat_menu_item_activated
),
244 empathy_contact_audio_call_menu_item_activated (GtkMenuItem
*item
,
245 EmpathyContact
*contact
)
248 empathy_call_factory_new_call_with_streams (contact
, TRUE
, FALSE
,
249 gtk_get_current_event_time (), NULL
);
253 empathy_contact_audio_call_menu_item_new (EmpathyContact
*contact
)
258 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
260 item
= gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
261 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP
,
263 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
264 gtk_widget_set_sensitive (item
, empathy_contact_can_voip_audio (contact
));
265 gtk_widget_show (image
);
267 g_signal_connect (item
, "activate",
268 G_CALLBACK (empathy_contact_audio_call_menu_item_activated
),
275 empathy_contact_video_call_menu_item_activated (GtkMenuItem
*item
,
276 EmpathyContact
*contact
)
278 empathy_call_factory_new_call_with_streams (contact
, TRUE
, TRUE
,
279 gtk_get_current_event_time (), NULL
);
283 empathy_contact_video_call_menu_item_new (EmpathyContact
*contact
)
288 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
290 item
= gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
291 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL
,
293 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
294 gtk_widget_set_sensitive (item
, empathy_contact_can_voip_video (contact
));
295 gtk_widget_show (image
);
297 g_signal_connect (item
, "activate",
298 G_CALLBACK (empathy_contact_video_call_menu_item_activated
),
305 contact_log_menu_item_activate_cb (EmpathyContact
*contact
)
307 empathy_log_window_show (empathy_contact_get_account (contact
),
308 empathy_contact_get_id (contact
),
313 empathy_contact_log_menu_item_new (EmpathyContact
*contact
)
315 TplLogManager
*manager
;
320 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
322 manager
= tpl_log_manager_dup_singleton ();
323 have_log
= tpl_log_manager_exists (manager
,
324 empathy_contact_get_account (contact
),
325 empathy_contact_get_id (contact
),
328 g_object_unref (manager
);
330 item
= gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
331 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG
,
333 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
334 gtk_widget_set_sensitive (item
, have_log
);
335 gtk_widget_show (image
);
337 g_signal_connect_swapped (item
, "activate",
338 G_CALLBACK (contact_log_menu_item_activate_cb
),
345 empathy_contact_file_transfer_menu_item_new (EmpathyContact
*contact
)
350 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
352 item
= gtk_image_menu_item_new_with_mnemonic (_("Send File"));
353 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND
,
355 gtk_widget_set_sensitive (item
, empathy_contact_can_send_files (contact
));
356 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
357 gtk_widget_show (image
);
359 g_signal_connect_swapped (item
, "activate",
360 G_CALLBACK (empathy_send_file_with_file_chooser
),
366 /* FIXME we should check if the contact supports vnc stream tube */
368 empathy_contact_share_my_desktop_menu_item_new (EmpathyContact
*contact
)
373 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
375 item
= gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
376 image
= gtk_image_new_from_icon_name (GTK_STOCK_NETWORK
,
378 gtk_widget_set_sensitive (item
, empathy_contact_can_use_rfb_stream_tube (
380 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
381 gtk_widget_show (image
);
383 g_signal_connect_swapped (item
, "activate",
384 G_CALLBACK (empathy_share_my_desktop_share_with_contact
),
391 favourite_menu_item_toggled_cb (GtkCheckMenuItem
*item
,
392 EmpathyContact
*contact
)
394 EmpathyContactManager
*manager
;
395 EmpathyContactList
*list
;
397 manager
= empathy_contact_manager_dup_singleton ();
398 list
= EMPATHY_CONTACT_LIST (manager
);
400 if (gtk_check_menu_item_get_active (item
)) {
401 empathy_contact_list_add_to_favourites (list
, contact
);
403 empathy_contact_list_remove_from_favourites (list
, contact
);
406 g_object_unref (manager
);
410 empathy_contact_favourite_menu_item_new (EmpathyContact
*contact
)
413 EmpathyContactManager
*manager
;
415 item
= gtk_check_menu_item_new_with_label (_("Favorite"));
417 manager
= empathy_contact_manager_dup_singleton ();
418 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item
),
419 empathy_contact_list_is_favourite (EMPATHY_CONTACT_LIST (manager
),
422 g_signal_connect (item
, "toggled",
423 G_CALLBACK (favourite_menu_item_toggled_cb
),
426 g_object_unref (manager
);
431 contact_info_menu_item_activate_cb (EmpathyContact
*contact
)
433 empathy_contact_information_dialog_show (contact
, NULL
);
437 empathy_contact_info_menu_item_new (EmpathyContact
*contact
)
442 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
444 item
= gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
445 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION
,
447 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
448 gtk_widget_show (image
);
450 g_signal_connect_swapped (item
, "activate",
451 G_CALLBACK (contact_info_menu_item_activate_cb
),
458 contact_edit_menu_item_activate_cb (EmpathyContact
*contact
)
460 empathy_contact_edit_dialog_show (contact
, NULL
);
464 empathy_contact_edit_menu_item_new (EmpathyContact
*contact
)
466 EmpathyContactManager
*manager
;
469 gboolean enable
= FALSE
;
471 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
473 if (empathy_contact_manager_initialized ()) {
474 TpConnection
*connection
;
475 EmpathyContactListFlags flags
;
477 manager
= empathy_contact_manager_dup_singleton ();
478 connection
= empathy_contact_get_connection (contact
);
479 flags
= empathy_contact_manager_get_flags_for_connection (
480 manager
, connection
);
482 enable
= (flags
& EMPATHY_CONTACT_LIST_CAN_ALIAS
||
483 flags
& EMPATHY_CONTACT_LIST_CAN_GROUP
);
485 g_object_unref (manager
);
488 item
= gtk_image_menu_item_new_with_mnemonic (
489 C_("Edit contact (contextual menu)",
491 image
= gtk_image_new_from_icon_name (GTK_STOCK_EDIT
,
493 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
494 gtk_widget_show (image
);
496 gtk_widget_set_sensitive (item
, enable
);
498 g_signal_connect_swapped (item
, "activate",
499 G_CALLBACK (contact_edit_menu_item_activate_cb
),
506 EmpathyContact
*contact
;
507 EmpathyChatroom
*chatroom
;
510 static RoomSubMenuData
*
511 room_sub_menu_data_new (EmpathyContact
*contact
,
512 EmpathyChatroom
*chatroom
)
514 RoomSubMenuData
*data
;
516 data
= g_slice_new (RoomSubMenuData
);
517 data
->contact
= g_object_ref (contact
);
518 data
->chatroom
= g_object_ref (chatroom
);
523 room_sub_menu_data_free (RoomSubMenuData
*data
)
525 g_object_unref (data
->contact
);
526 g_object_unref (data
->chatroom
);
527 g_slice_free (RoomSubMenuData
, data
);
531 room_sub_menu_activate_cb (GtkWidget
*item
,
532 RoomSubMenuData
*data
)
536 chat
= empathy_chatroom_get_tp_chat (data
->chatroom
);
538 /* channel was invalidated. Ignoring */
542 /* send invitation */
543 empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat
), data
->contact
,
544 _("Inviting you to this room"));
548 create_room_sub_menu (EmpathyContact
*contact
,
549 EmpathyChatroom
*chatroom
)
552 RoomSubMenuData
*data
;
554 item
= gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom
));
555 data
= room_sub_menu_data_new (contact
, chatroom
);
556 g_signal_connect_data (item
, "activate",
557 G_CALLBACK (room_sub_menu_activate_cb
), data
,
558 (GClosureNotify
) room_sub_menu_data_free
, 0);
564 empathy_contact_invite_menu_item_new (EmpathyContact
*contact
)
568 GtkWidget
*room_item
;
569 EmpathyChatroomManager
*mgr
;
571 GtkWidget
*submenu
= NULL
;
573 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
575 item
= gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
576 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE
,
578 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
580 mgr
= empathy_chatroom_manager_dup_singleton (NULL
);
581 rooms
= empathy_chatroom_manager_get_chatrooms (mgr
,
582 empathy_contact_get_account (contact
));
584 for (l
= rooms
; l
!= NULL
; l
= g_list_next (l
)) {
585 EmpathyChatroom
*chatroom
= l
->data
;
587 if (empathy_chatroom_get_tp_chat (chatroom
) != NULL
) {
588 if (G_UNLIKELY (submenu
== NULL
))
589 submenu
= gtk_menu_new ();
591 room_item
= create_room_sub_menu (contact
, chatroom
);
592 gtk_menu_shell_append ((GtkMenuShell
*) submenu
, room_item
);
593 gtk_widget_show (room_item
);
598 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item
), submenu
);
600 gtk_widget_set_sensitive (item
, FALSE
);
603 gtk_widget_show (image
);
605 g_object_unref (mgr
);