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);
65 if (features & EMPATHY_CONTACT_FEATURE_CALL) {
67 item = empathy_contact_audio_call_menu_item_new (contact);
68 gtk_menu_shell_append (shell, item);
69 gtk_widget_show (item);
72 item = empathy_contact_video_call_menu_item_new (contact);
73 gtk_menu_shell_append (shell, item);
74 gtk_widget_show (item);
78 if (features & EMPATHY_CONTACT_FEATURE_LOG) {
79 item = empathy_contact_log_menu_item_new (contact);
80 gtk_menu_shell_append (shell, item);
81 gtk_widget_show (item);
85 item = empathy_contact_invite_menu_item_new (contact);
86 gtk_menu_shell_append (shell, item);
87 gtk_widget_show (item);
90 item = empathy_contact_file_transfer_menu_item_new (contact);
91 gtk_menu_shell_append (shell, item);
92 gtk_widget_show (item);
95 if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
96 EMPATHY_CONTACT_FEATURE_INFO)) {
97 item = gtk_separator_menu_item_new ();
98 gtk_menu_shell_append (shell, item);
99 gtk_widget_show (item);
103 if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
104 item = empathy_contact_edit_menu_item_new (contact);
105 gtk_menu_shell_append (shell, item);
106 gtk_widget_show (item);
110 if (features & EMPATHY_CONTACT_FEATURE_INFO) {
111 item = empathy_contact_info_menu_item_new (contact);
112 gtk_menu_shell_append (shell, item);
113 gtk_widget_show (item);
120 empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
121 EmpathyContact *contact)
123 empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
128 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
133 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
135 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
136 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
138 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
139 gtk_widget_show (image);
141 g_signal_connect (item, "activate",
142 G_CALLBACK (empathy_contact_chat_menu_item_activated),
149 empathy_contact_audio_call_menu_item_activated (GtkMenuItem *item,
150 EmpathyContact *contact)
152 EmpathyCallFactory *factory;
154 factory = empathy_call_factory_get ();
155 empathy_call_factory_new_call_with_streams (factory, contact, TRUE, FALSE);
159 empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
164 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
166 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
167 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
169 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
170 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
171 gtk_widget_show (image);
173 g_signal_connect (item, "activate",
174 G_CALLBACK (empathy_contact_audio_call_menu_item_activated),
181 empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
182 EmpathyContact *contact)
184 EmpathyCallFactory *factory;
186 factory = empathy_call_factory_get ();
187 empathy_call_factory_new_call_with_streams (factory, contact, TRUE, TRUE);
191 empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
196 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
198 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
199 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
201 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
202 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
203 gtk_widget_show (image);
205 g_signal_connect (item, "activate",
206 G_CALLBACK (empathy_contact_video_call_menu_item_activated),
213 contact_log_menu_item_activate_cb (EmpathyContact *contact)
215 empathy_log_window_show (empathy_contact_get_account (contact),
216 empathy_contact_get_id (contact),
221 empathy_contact_log_menu_item_new (EmpathyContact *contact)
223 EmpathyLogManager *manager;
228 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
230 manager = empathy_log_manager_dup_singleton ();
231 have_log = empathy_log_manager_exists (manager,
232 empathy_contact_get_account (contact),
233 empathy_contact_get_id (contact),
235 g_object_unref (manager);
237 item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
238 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
240 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
241 gtk_widget_set_sensitive (item, have_log);
242 gtk_widget_show (image);
244 g_signal_connect_swapped (item, "activate",
245 G_CALLBACK (contact_log_menu_item_activate_cb),
252 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
257 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
259 item = gtk_image_menu_item_new_with_mnemonic (_("Send file"));
260 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
262 gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact));
263 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
264 gtk_widget_show (image);
266 g_signal_connect_swapped (item, "activate",
267 G_CALLBACK (empathy_send_file_with_file_chooser),
274 contact_info_menu_item_activate_cb (EmpathyContact *contact)
276 empathy_contact_information_dialog_show (contact, NULL);
280 empathy_contact_info_menu_item_new (EmpathyContact *contact)
285 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
287 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
288 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
290 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
291 gtk_widget_show (image);
293 g_signal_connect_swapped (item, "activate",
294 G_CALLBACK (contact_info_menu_item_activate_cb),
301 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
303 empathy_contact_edit_dialog_show (contact, NULL);
307 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
312 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
314 item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
315 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
317 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
318 gtk_widget_show (image);
320 g_signal_connect_swapped (item, "activate",
321 G_CALLBACK (contact_edit_menu_item_activate_cb),
328 EmpathyContact *contact;
329 EmpathyChatroom *chatroom;
332 static RoomSubMenuData *
333 room_sub_menu_data_new (EmpathyContact *contact,
334 EmpathyChatroom *chatroom)
336 RoomSubMenuData *data;
338 data = g_slice_new (RoomSubMenuData);
339 data->contact = g_object_ref (contact);
340 data->chatroom = g_object_ref (chatroom);
345 room_sub_menu_data_free (RoomSubMenuData *data)
347 /* FIXME: seems this is never called... */
348 g_object_unref (data->contact);
349 g_object_unref (data->chatroom);
350 g_slice_free (RoomSubMenuData, data);
354 room_sub_menu_activate_cb (GtkWidget *item,
355 RoomSubMenuData *data)
358 GArray handles = {(gchar *) &handle, 1};
362 chat = empathy_chatroom_get_tp_chat (data->chatroom);
364 /* channel was invalidated. Ignoring */
368 /* send invitation */
369 handle = empathy_contact_get_handle (data->contact);
370 channel = empathy_tp_chat_get_channel (chat);
371 tp_cli_channel_interface_group_call_add_members (channel, -1, &handles,
372 _("Inviting to this room"), NULL, NULL, NULL, NULL);
376 create_room_sub_menu (EmpathyContact *contact,
377 EmpathyChatroom *chatroom)
380 RoomSubMenuData *data;
382 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
383 data = room_sub_menu_data_new (contact, chatroom);
384 g_signal_connect_data (item, "activate",
385 G_CALLBACK (room_sub_menu_activate_cb), data,
386 (GClosureNotify) room_sub_menu_data_free, 0);
392 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
396 GtkWidget *room_item;
397 EmpathyChatroomManager *mgr;
399 GtkWidget *submenu = NULL;
401 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
403 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
404 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
406 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
408 mgr = empathy_chatroom_manager_dup_singleton (NULL);
409 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
410 empathy_contact_get_account (contact));
412 for (l = rooms; l != NULL; l = g_list_next (l)) {
413 EmpathyChatroom *chatroom = l->data;
415 if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
416 if (G_UNLIKELY (submenu == NULL))
417 submenu = gtk_menu_new ();
419 room_item = create_room_sub_menu (contact, chatroom);
420 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
421 gtk_widget_show (room_item);
426 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
428 gtk_widget_set_sensitive (item, FALSE);
431 gtk_widget_show (image);
433 g_object_unref (mgr);