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>
34 #include <libempathy/empathy-contact-manager.h>
36 #include "empathy-contact-menu.h"
37 #include "empathy-images.h"
38 #include "empathy-log-window.h"
39 #include "empathy-contact-dialogs.h"
40 #include "empathy-ui-utils.h"
43 empathy_contact_menu_new (EmpathyContact *contact,
44 EmpathyContactFeatureFlags features)
50 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
52 if (features == EMPATHY_CONTACT_FEATURE_NONE) {
56 menu = gtk_menu_new ();
57 shell = GTK_MENU_SHELL (menu);
60 if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
61 item = empathy_contact_chat_menu_item_new (contact);
62 gtk_menu_shell_append (shell, item);
63 gtk_widget_show (item);
66 if (features & EMPATHY_CONTACT_FEATURE_CALL) {
68 item = empathy_contact_audio_call_menu_item_new (contact);
69 gtk_menu_shell_append (shell, item);
70 gtk_widget_show (item);
73 item = empathy_contact_video_call_menu_item_new (contact);
74 gtk_menu_shell_append (shell, item);
75 gtk_widget_show (item);
79 if (features & EMPATHY_CONTACT_FEATURE_LOG) {
80 item = empathy_contact_log_menu_item_new (contact);
81 gtk_menu_shell_append (shell, item);
82 gtk_widget_show (item);
86 item = empathy_contact_invite_menu_item_new (contact);
87 gtk_menu_shell_append (shell, item);
88 gtk_widget_show (item);
91 item = empathy_contact_file_transfer_menu_item_new (contact);
92 gtk_menu_shell_append (shell, item);
93 gtk_widget_show (item);
96 if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
97 EMPATHY_CONTACT_FEATURE_INFO)) {
98 item = gtk_separator_menu_item_new ();
99 gtk_menu_shell_append (shell, item);
100 gtk_widget_show (item);
104 if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
105 item = empathy_contact_edit_menu_item_new (contact);
106 gtk_menu_shell_append (shell, item);
107 gtk_widget_show (item);
111 if (features & EMPATHY_CONTACT_FEATURE_INFO) {
112 item = empathy_contact_info_menu_item_new (contact);
113 gtk_menu_shell_append (shell, item);
114 gtk_widget_show (item);
121 empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
122 EmpathyContact *contact)
124 empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
129 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
134 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
136 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
137 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
139 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
140 gtk_widget_show (image);
142 g_signal_connect (item, "activate",
143 G_CALLBACK (empathy_contact_chat_menu_item_activated),
150 empathy_contact_audio_call_menu_item_activated (GtkMenuItem *item,
151 EmpathyContact *contact)
153 EmpathyCallFactory *factory;
155 factory = empathy_call_factory_get ();
156 empathy_call_factory_new_call_with_streams (factory, contact, TRUE, FALSE);
160 empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
165 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
167 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
168 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
170 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
171 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
172 gtk_widget_show (image);
174 g_signal_connect (item, "activate",
175 G_CALLBACK (empathy_contact_audio_call_menu_item_activated),
182 empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
183 EmpathyContact *contact)
185 EmpathyCallFactory *factory;
187 factory = empathy_call_factory_get ();
188 empathy_call_factory_new_call_with_streams (factory, contact, TRUE, TRUE);
192 empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
197 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
199 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
200 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
202 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
203 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
204 gtk_widget_show (image);
206 g_signal_connect (item, "activate",
207 G_CALLBACK (empathy_contact_video_call_menu_item_activated),
214 contact_log_menu_item_activate_cb (EmpathyContact *contact)
216 empathy_log_window_show (empathy_contact_get_account (contact),
217 empathy_contact_get_id (contact),
222 empathy_contact_log_menu_item_new (EmpathyContact *contact)
224 EmpathyLogManager *manager;
229 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
231 manager = empathy_log_manager_dup_singleton ();
232 have_log = empathy_log_manager_exists (manager,
233 empathy_contact_get_account (contact),
234 empathy_contact_get_id (contact),
236 g_object_unref (manager);
238 item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
239 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
241 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
242 gtk_widget_set_sensitive (item, have_log);
243 gtk_widget_show (image);
245 g_signal_connect_swapped (item, "activate",
246 G_CALLBACK (contact_log_menu_item_activate_cb),
253 empathy_contact_file_transfer_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 (_("Send file"));
261 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
263 gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact));
264 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
265 gtk_widget_show (image);
267 g_signal_connect_swapped (item, "activate",
268 G_CALLBACK (empathy_send_file_with_file_chooser),
275 contact_info_menu_item_activate_cb (EmpathyContact *contact)
277 empathy_contact_information_dialog_show (contact, NULL);
281 empathy_contact_info_menu_item_new (EmpathyContact *contact)
286 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
288 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
289 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
291 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
292 gtk_widget_show (image);
294 g_signal_connect_swapped (item, "activate",
295 G_CALLBACK (contact_info_menu_item_activate_cb),
302 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
304 empathy_contact_edit_dialog_show (contact, NULL);
308 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
310 EmpathyContactManager *manager;
313 gboolean enable = FALSE;
315 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
317 if (empathy_contact_manager_initialized ()) {
318 TpConnection *connection;
319 EmpathyContactListFlags flags;
321 manager = empathy_contact_manager_dup_singleton ();
322 connection = empathy_contact_get_connection (contact);
323 flags = empathy_contact_manager_get_flags_for_connection (
324 manager, connection);
326 enable = (flags & EMPATHY_CONTACT_LIST_CAN_ALIAS ||
327 flags & EMPATHY_CONTACT_LIST_CAN_GROUP);
329 g_object_unref (manager);
332 item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
333 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
335 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
336 gtk_widget_show (image);
338 gtk_widget_set_sensitive (item, enable);
340 g_signal_connect_swapped (item, "activate",
341 G_CALLBACK (contact_edit_menu_item_activate_cb),
348 EmpathyContact *contact;
349 EmpathyChatroom *chatroom;
352 static RoomSubMenuData *
353 room_sub_menu_data_new (EmpathyContact *contact,
354 EmpathyChatroom *chatroom)
356 RoomSubMenuData *data;
358 data = g_slice_new (RoomSubMenuData);
359 data->contact = g_object_ref (contact);
360 data->chatroom = g_object_ref (chatroom);
365 room_sub_menu_data_free (RoomSubMenuData *data)
367 /* FIXME: seems this is never called... */
368 g_object_unref (data->contact);
369 g_object_unref (data->chatroom);
370 g_slice_free (RoomSubMenuData, data);
374 room_sub_menu_activate_cb (GtkWidget *item,
375 RoomSubMenuData *data)
378 GArray handles = {(gchar *) &handle, 1};
382 chat = empathy_chatroom_get_tp_chat (data->chatroom);
384 /* channel was invalidated. Ignoring */
388 /* send invitation */
389 handle = empathy_contact_get_handle (data->contact);
390 channel = empathy_tp_chat_get_channel (chat);
391 tp_cli_channel_interface_group_call_add_members (channel, -1, &handles,
392 _("Inviting to this room"), NULL, NULL, NULL, NULL);
396 create_room_sub_menu (EmpathyContact *contact,
397 EmpathyChatroom *chatroom)
400 RoomSubMenuData *data;
402 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
403 data = room_sub_menu_data_new (contact, chatroom);
404 g_signal_connect_data (item, "activate",
405 G_CALLBACK (room_sub_menu_activate_cb), data,
406 (GClosureNotify) room_sub_menu_data_free, 0);
412 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
416 GtkWidget *room_item;
417 EmpathyChatroomManager *mgr;
419 GtkWidget *submenu = NULL;
421 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
423 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
424 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
426 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
428 mgr = empathy_chatroom_manager_dup_singleton (NULL);
429 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
430 empathy_contact_get_account (contact));
432 for (l = rooms; l != NULL; l = g_list_next (l)) {
433 EmpathyChatroom *chatroom = l->data;
435 if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
436 if (G_UNLIKELY (submenu == NULL))
437 submenu = gtk_menu_new ();
439 room_item = create_room_sub_menu (contact, chatroom);
440 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
441 gtk_widget_show (room_item);
446 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
448 gtk_widget_set_sensitive (item, FALSE);
451 gtk_widget_show (image);
453 g_object_unref (mgr);