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>
29 #include <libempathy/empathy-call-factory.h>
30 #include <libempathy/empathy-log-manager.h>
31 #include <libempathy/empathy-dispatcher.h>
32 #include <libempathy/empathy-utils.h>
33 #include <libempathy/empathy-chatroom-manager.h>
35 #include "empathy-contact-menu.h"
36 #include "empathy-images.h"
37 #include "empathy-log-window.h"
38 #include "empathy-contact-dialogs.h"
39 #include "empathy-ui-utils.h"
42 empathy_contact_menu_new (EmpathyContact
*contact
,
43 EmpathyContactFeatureFlags features
)
49 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
51 if (features
== EMPATHY_CONTACT_FEATURE_NONE
) {
55 menu
= gtk_menu_new ();
56 shell
= GTK_MENU_SHELL (menu
);
59 if (features
& EMPATHY_CONTACT_FEATURE_CHAT
) {
60 item
= empathy_contact_chat_menu_item_new (contact
);
61 gtk_menu_shell_append (shell
, item
);
62 gtk_widget_show (item
);
66 if (features
& EMPATHY_CONTACT_FEATURE_CALL
) {
67 item
= empathy_contact_call_menu_item_new (contact
);
68 gtk_menu_shell_append (shell
, item
);
69 gtk_widget_show (item
);
73 if (features
& EMPATHY_CONTACT_FEATURE_LOG
) {
74 item
= empathy_contact_log_menu_item_new (contact
);
75 gtk_menu_shell_append (shell
, item
);
76 gtk_widget_show (item
);
80 item
= empathy_contact_invite_menu_item_new (contact
);
81 gtk_menu_shell_append (shell
, item
);
82 gtk_widget_show (item
);
85 item
= empathy_contact_file_transfer_menu_item_new (contact
);
86 gtk_menu_shell_append (shell
, item
);
87 gtk_widget_show (item
);
90 if (features
& (EMPATHY_CONTACT_FEATURE_EDIT
|
91 EMPATHY_CONTACT_FEATURE_INFO
)) {
92 item
= gtk_separator_menu_item_new ();
93 gtk_menu_shell_append (shell
, item
);
94 gtk_widget_show (item
);
98 if (features
& EMPATHY_CONTACT_FEATURE_EDIT
) {
99 item
= empathy_contact_edit_menu_item_new (contact
);
100 gtk_menu_shell_append (shell
, item
);
101 gtk_widget_show (item
);
105 if (features
& EMPATHY_CONTACT_FEATURE_INFO
) {
106 item
= empathy_contact_info_menu_item_new (contact
);
107 gtk_menu_shell_append (shell
, item
);
108 gtk_widget_show (item
);
115 empathy_contact_chat_menu_item_activated (GtkMenuItem
*item
,
116 EmpathyContact
*contact
)
118 empathy_dispatcher_chat_with_contact (contact
, NULL
, NULL
);
123 empathy_contact_chat_menu_item_new (EmpathyContact
*contact
)
128 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
130 item
= gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
131 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE
,
133 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
134 gtk_widget_show (image
);
136 g_signal_connect (item
, "activate",
137 G_CALLBACK (empathy_contact_chat_menu_item_activated
),
144 empathy_contact_call_menu_item_activated (GtkMenuItem
*item
,
145 EmpathyContact
*contact
)
147 EmpathyCallFactory
*factory
;
149 factory
= empathy_call_factory_get ();
150 empathy_call_factory_new_call (factory
, contact
);
154 empathy_contact_call_menu_item_new (EmpathyContact
*contact
)
159 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
161 item
= gtk_image_menu_item_new_with_mnemonic (_("_Call"));
162 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP
,
164 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
165 gtk_widget_set_sensitive (item
, empathy_contact_can_voip (contact
));
166 gtk_widget_show (image
);
168 g_signal_connect (item
, "activate",
169 G_CALLBACK (empathy_contact_call_menu_item_activated
),
176 contact_log_menu_item_activate_cb (EmpathyContact
*contact
)
178 empathy_log_window_show (empathy_contact_get_account (contact
),
179 empathy_contact_get_id (contact
),
184 empathy_contact_log_menu_item_new (EmpathyContact
*contact
)
186 EmpathyLogManager
*manager
;
191 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
193 manager
= empathy_log_manager_dup_singleton ();
194 have_log
= empathy_log_manager_exists (manager
,
195 empathy_contact_get_account (contact
),
196 empathy_contact_get_id (contact
),
198 g_object_unref (manager
);
200 item
= gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
201 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG
,
203 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
204 gtk_widget_set_sensitive (item
, have_log
);
205 gtk_widget_show (image
);
207 g_signal_connect_swapped (item
, "activate",
208 G_CALLBACK (contact_log_menu_item_activate_cb
),
215 empathy_contact_file_transfer_menu_item_new (EmpathyContact
*contact
)
220 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
222 item
= gtk_image_menu_item_new_with_mnemonic (_("Send file"));
223 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND
,
225 gtk_widget_set_sensitive (item
, empathy_contact_can_send_files (contact
));
226 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
227 gtk_widget_show (image
);
229 g_signal_connect_swapped (item
, "activate",
230 G_CALLBACK (empathy_send_file_with_file_chooser
),
237 contact_info_menu_item_activate_cb (EmpathyContact
*contact
)
239 empathy_contact_information_dialog_show (contact
, NULL
, FALSE
, FALSE
);
243 empathy_contact_info_menu_item_new (EmpathyContact
*contact
)
248 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
250 item
= gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
251 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION
,
253 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
254 gtk_widget_show (image
);
256 g_signal_connect_swapped (item
, "activate",
257 G_CALLBACK (contact_info_menu_item_activate_cb
),
264 contact_edit_menu_item_activate_cb (EmpathyContact
*contact
)
266 empathy_contact_information_dialog_show (contact
, NULL
, TRUE
, FALSE
);
270 empathy_contact_edit_menu_item_new (EmpathyContact
*contact
)
275 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
277 item
= gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
278 image
= gtk_image_new_from_icon_name (GTK_STOCK_EDIT
,
280 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
281 gtk_widget_show (image
);
283 g_signal_connect_swapped (item
, "activate",
284 G_CALLBACK (contact_edit_menu_item_activate_cb
),
291 EmpathyContact
*contact
;
292 EmpathyChatroom
*chatroom
;
295 static RoomSubMenuData
*
296 room_sub_menu_data_new (EmpathyContact
*contact
,
297 EmpathyChatroom
*chatroom
)
299 RoomSubMenuData
*data
;
301 data
= g_slice_new (RoomSubMenuData
);
302 data
->contact
= g_object_ref (contact
);
303 data
->chatroom
= g_object_ref (chatroom
);
309 room_sub_menu_data_free (RoomSubMenuData
*data
)
311 /* FIXME: seems this is never called... */
312 g_object_unref (data
->contact
);
313 g_object_unref (data
->chatroom
);
314 g_slice_free (RoomSubMenuData
, data
);
318 room_sub_menu_activate_cb (GtkWidget
*item
,
319 RoomSubMenuData
*data
)
322 GArray handles
= {(gchar
*) &handle
, 1};
326 chat
= empathy_chatroom_get_tp_chat (data
->chatroom
);
328 /* channel was invalidated. Ignoring */
332 /* send invitation */
333 handle
= empathy_contact_get_handle (data
->contact
);
334 channel
= empathy_tp_chat_get_channel (chat
);
335 tp_cli_channel_interface_group_call_add_members (channel
, -1, &handles
,
336 _("Inviting to this room"), NULL
, NULL
, NULL
, NULL
);
340 create_room_sub_menu (EmpathyContact
*contact
,
341 EmpathyChatroom
*chatroom
)
344 RoomSubMenuData
*data
;
346 item
= gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom
));
347 data
= room_sub_menu_data_new (contact
, chatroom
);
348 g_signal_connect_data (item
, "activate",
349 G_CALLBACK (room_sub_menu_activate_cb
), data
,
350 (GClosureNotify
) room_sub_menu_data_free
, 0);
356 empathy_contact_invite_menu_item_new (EmpathyContact
*contact
)
360 GtkWidget
*room_item
;
361 EmpathyChatroomManager
*mgr
;
364 GtkMenuShell
*submenu_shell
;
365 gboolean have_rooms
= FALSE
;
367 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
369 item
= gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
370 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE
,
372 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
374 mgr
= empathy_chatroom_manager_dup_singleton (NULL
);
375 rooms
= empathy_chatroom_manager_get_chatrooms (mgr
,
376 empathy_contact_get_account (contact
));
378 /* create rooms sub menu */
379 submenu
= gtk_menu_new ();
380 submenu_shell
= GTK_MENU_SHELL (submenu
);
382 for (l
= rooms
; l
!= NULL
; l
= g_list_next (l
)) {
383 EmpathyChatroom
*chatroom
= l
->data
;
385 if (empathy_chatroom_get_tp_chat (chatroom
) != NULL
) {
388 room_item
= create_room_sub_menu (contact
, chatroom
);
389 gtk_menu_shell_append (submenu_shell
, room_item
);
390 gtk_widget_show (room_item
);
395 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item
), submenu
);
397 gtk_widget_set_sensitive (item
, FALSE
);
398 gtk_widget_destroy (submenu
);
401 gtk_widget_show (image
);
403 g_object_unref (mgr
);