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_new (EmpathyContact *contact)
120 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
122 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
123 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
125 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
126 gtk_widget_show (image);
128 g_signal_connect_swapped (item, "activate",
129 G_CALLBACK (empathy_dispatcher_chat_with_contact),
136 empathy_contact_call_menu_item_activated (GtkMenuItem *item,
137 EmpathyContact *contact)
139 EmpathyCallFactory *factory;
141 factory = empathy_call_factory_get ();
142 empathy_call_factory_new_call (factory, contact);
146 empathy_contact_call_menu_item_new (EmpathyContact *contact)
151 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
153 item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
154 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
156 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
157 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
158 gtk_widget_show (image);
160 g_signal_connect (item, "activate",
161 G_CALLBACK (empathy_contact_call_menu_item_activated),
168 contact_log_menu_item_activate_cb (EmpathyContact *contact)
170 empathy_log_window_show (empathy_contact_get_account (contact),
171 empathy_contact_get_id (contact),
176 empathy_contact_log_menu_item_new (EmpathyContact *contact)
178 EmpathyLogManager *manager;
183 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
185 manager = empathy_log_manager_dup_singleton ();
186 have_log = empathy_log_manager_exists (manager,
187 empathy_contact_get_account (contact),
188 empathy_contact_get_id (contact),
190 g_object_unref (manager);
192 item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
193 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
195 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
196 gtk_widget_set_sensitive (item, have_log);
197 gtk_widget_show (image);
199 g_signal_connect_swapped (item, "activate",
200 G_CALLBACK (contact_log_menu_item_activate_cb),
207 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
212 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
214 item = gtk_image_menu_item_new_with_mnemonic (_("Send file"));
215 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
217 gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact));
218 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
219 gtk_widget_show (image);
221 g_signal_connect_swapped (item, "activate",
222 G_CALLBACK (empathy_send_file_with_file_chooser),
229 contact_info_menu_item_activate_cb (EmpathyContact *contact)
231 empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
235 empathy_contact_info_menu_item_new (EmpathyContact *contact)
240 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
242 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
243 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
245 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
246 gtk_widget_show (image);
248 g_signal_connect_swapped (item, "activate",
249 G_CALLBACK (contact_info_menu_item_activate_cb),
256 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
258 empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
262 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
267 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
269 item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
270 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
272 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
273 gtk_widget_show (image);
275 g_signal_connect_swapped (item, "activate",
276 G_CALLBACK (contact_edit_menu_item_activate_cb),
283 EmpathyContact *contact;
284 EmpathyChatroom *chatroom;
287 static RoomSubMenuData *
288 room_sub_menu_data_new (EmpathyContact *contact,
289 EmpathyChatroom *chatroom)
291 RoomSubMenuData *data;
293 data = g_slice_new (RoomSubMenuData);
294 data->contact = g_object_ref (contact);
295 data->chatroom = g_object_ref (chatroom);
301 room_sub_menu_data_free (RoomSubMenuData *data)
303 /* FIXME: seems this is never called... */
304 g_object_unref (data->contact);
305 g_object_unref (data->chatroom);
306 g_slice_free (RoomSubMenuData, data);
310 room_sub_menu_activate_cb (GtkWidget *item,
311 RoomSubMenuData *data)
314 GArray handles = {(gchar *) &handle, 1};
318 chat = empathy_chatroom_get_tp_chat (data->chatroom);
320 /* channel was invalidated. Ignoring */
324 /* send invitation */
325 handle = empathy_contact_get_handle (data->contact);
326 channel = empathy_tp_chat_get_channel (chat);
327 tp_cli_channel_interface_group_call_add_members (channel, -1, &handles,
328 _("Inviting to this room"), NULL, NULL, NULL, NULL);
332 create_room_sub_menu (EmpathyContact *contact,
333 EmpathyChatroom *chatroom)
336 RoomSubMenuData *data;
338 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
339 data = room_sub_menu_data_new (contact, chatroom);
340 g_signal_connect_data (item, "activate",
341 G_CALLBACK (room_sub_menu_activate_cb), data,
342 (GClosureNotify) room_sub_menu_data_free, 0);
348 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
352 GtkWidget *room_item;
353 EmpathyChatroomManager *mgr;
356 GtkMenuShell *submenu_shell;
357 gboolean have_rooms = FALSE;
359 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
361 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
362 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
364 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
366 mgr = empathy_chatroom_manager_dup_singleton (NULL);
367 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
368 empathy_contact_get_account (contact));
370 /* create rooms sub menu */
371 submenu = gtk_menu_new ();
372 submenu_shell = GTK_MENU_SHELL (submenu);
374 for (l = rooms; l != NULL; l = g_list_next (l)) {
375 EmpathyChatroom *chatroom = l->data;
377 if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
380 room_item = create_room_sub_menu (contact, chatroom);
381 gtk_menu_shell_append (submenu_shell, room_item);
382 gtk_widget_show (room_item);
387 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
389 gtk_widget_set_sensitive (item, FALSE);
390 gtk_widget_destroy (submenu);
393 gtk_widget_show (image);
395 g_object_unref (mgr);