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.h>
29 #include <libempathy/empathy-log-manager.h>
30 #include <libempathy/empathy-dispatcher.h>
31 #include <libempathy/empathy-utils.h>
32 #include <libempathy/empathy-chatroom-manager.h>
34 #include "empathy-contact-menu.h"
35 #include "empathy-images.h"
36 #include "empathy-log-window.h"
37 #include "empathy-contact-dialogs.h"
40 empathy_contact_menu_new (EmpathyContact *contact,
41 EmpathyContactFeatureFlags features)
47 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
49 if (features == EMPATHY_CONTACT_FEATURE_NONE) {
53 menu = gtk_menu_new ();
54 shell = GTK_MENU_SHELL (menu);
57 if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
58 item = empathy_contact_chat_menu_item_new (contact);
59 gtk_menu_shell_append (shell, item);
60 gtk_widget_show (item);
64 if (features & EMPATHY_CONTACT_FEATURE_CALL) {
65 item = empathy_contact_call_menu_item_new (contact);
66 gtk_menu_shell_append (shell, item);
67 gtk_widget_show (item);
71 if (features & EMPATHY_CONTACT_FEATURE_LOG) {
72 item = empathy_contact_log_menu_item_new (contact);
73 gtk_menu_shell_append (shell, item);
74 gtk_widget_show (item);
78 item = empathy_contact_invite_menu_item_new (contact);
79 gtk_menu_shell_append (shell, item);
80 gtk_widget_show (item);
83 if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
84 EMPATHY_CONTACT_FEATURE_INFO)) {
85 item = gtk_separator_menu_item_new ();
86 gtk_menu_shell_append (shell, item);
87 gtk_widget_show (item);
91 if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
92 item = empathy_contact_edit_menu_item_new (contact);
93 gtk_menu_shell_append (shell, item);
94 gtk_widget_show (item);
98 if (features & EMPATHY_CONTACT_FEATURE_INFO) {
99 item = empathy_contact_info_menu_item_new (contact);
100 gtk_menu_shell_append (shell, item);
101 gtk_widget_show (item);
108 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
113 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
115 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
116 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
118 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
119 gtk_widget_show (image);
121 g_signal_connect_swapped (item, "activate",
122 G_CALLBACK (empathy_dispatcher_chat_with_contact),
129 empathy_contact_call_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 (_("_Call"));
137 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
139 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
140 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
141 gtk_widget_show (image);
143 g_signal_connect_swapped (item, "activate",
144 G_CALLBACK (empathy_dispatcher_call_with_contact),
151 contact_log_menu_item_activate_cb (EmpathyContact *contact)
153 empathy_log_window_show (empathy_contact_get_account (contact),
154 empathy_contact_get_id (contact),
159 empathy_contact_log_menu_item_new (EmpathyContact *contact)
161 EmpathyLogManager *manager;
166 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
168 manager = empathy_log_manager_new ();
169 have_log = empathy_log_manager_exists (manager,
170 empathy_contact_get_account (contact),
171 empathy_contact_get_id (contact),
173 g_object_unref (manager);
175 item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
176 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
178 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
179 gtk_widget_set_sensitive (item, have_log);
180 gtk_widget_show (image);
182 g_signal_connect_swapped (item, "activate",
183 G_CALLBACK (contact_log_menu_item_activate_cb),
190 contact_info_menu_item_activate_cb (EmpathyContact *contact)
192 empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
196 empathy_contact_info_menu_item_new (EmpathyContact *contact)
201 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
203 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
204 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
206 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
207 gtk_widget_show (image);
209 g_signal_connect_swapped (item, "activate",
210 G_CALLBACK (contact_info_menu_item_activate_cb),
217 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
219 empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
223 empathy_contact_edit_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 (_("_Edit"));
231 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
233 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
234 gtk_widget_show (image);
236 g_signal_connect_swapped (item, "activate",
237 G_CALLBACK (contact_edit_menu_item_activate_cb),
244 contact_room_sub_menu_item_activate_cb (EmpathyContact *contact)
250 create_room_sub_menu_item (EmpathyContact *contact,
251 EmpathyChatroom *chatroom)
255 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
256 g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL);
258 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
260 g_signal_connect_swapped (item, "activate",
261 G_CALLBACK (contact_room_sub_menu_item_activate_cb),
268 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
272 GtkWidget *room_item;
273 EmpathyChatroomManager *mgr;
276 GtkMenuShell *submenu_shell;
277 gboolean have_rooms = FALSE;
279 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
281 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to..."));
282 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
284 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
286 mgr = empathy_chatroom_manager_new ();
287 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
288 empathy_contact_get_account (contact));
290 /* create rooms sub menu */
291 submenu = gtk_menu_new ();
292 submenu_shell = GTK_MENU_SHELL (submenu);
294 for (l = rooms; l != NULL; l = g_list_next (l))
296 EmpathyChatroom *room = l->data;
299 g_object_get (room, "tp-channel", &channel, NULL);
304 room_item = create_room_sub_menu_item (contact, room);
305 gtk_menu_shell_append (submenu_shell, room_item);
306 gtk_widget_show (room_item);
308 g_object_unref (channel);
314 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
318 gtk_widget_set_sensitive (item, FALSE);
319 gtk_widget_destroy (submenu);
322 gtk_widget_show (image);
324 g_object_unref (mgr);