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),
245 EmpathyContact *contact;
246 EmpathyChatroom *chatroom;
247 } contact_room_sub_menu_item_activate_cb_ctx;
249 static contact_room_sub_menu_item_activate_cb_ctx *
250 contact_room_sub_menu_item_activate_cb_ctx_new (EmpathyContact *contact,
251 EmpathyChatroom *chatroom)
253 contact_room_sub_menu_item_activate_cb_ctx *ctx;
255 ctx = g_slice_new (contact_room_sub_menu_item_activate_cb_ctx);
257 ctx->contact = g_object_ref (contact);
258 ctx->chatroom = g_object_ref (chatroom);
264 contact_room_sub_menu_item_activate_cb_ctx_free (
265 contact_room_sub_menu_item_activate_cb_ctx *ctx)
267 /* FIXME: seems this is never called... */
268 g_object_unref (ctx->contact);
269 g_object_unref (ctx->chatroom);
271 g_slice_free (contact_room_sub_menu_item_activate_cb_ctx, ctx);
275 contact_room_sub_menu_item_activate_cb (
277 contact_room_sub_menu_item_activate_cb_ctx *ctx)
283 g_object_get (ctx->chatroom, "tp-channel", &channel, NULL);
285 /* channel was invalidated. Ignoring */
288 /* send invitation */
289 handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
290 handle = empathy_contact_get_handle (ctx->contact);
291 g_array_append_val (handles, handle);
293 tp_cli_channel_interface_group_call_add_members (channel, -1, handles,
294 _("Inviting to this room"), NULL, NULL, NULL, NULL);
296 g_array_free (handles, TRUE);
297 g_object_unref (channel);
301 create_room_sub_menu_item (EmpathyContact *contact,
302 EmpathyChatroom *chatroom)
305 contact_room_sub_menu_item_activate_cb_ctx *ctx;
307 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
309 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
311 ctx = contact_room_sub_menu_item_activate_cb_ctx_new (contact, chatroom);
313 g_signal_connect_data (item, "activate",
314 G_CALLBACK (contact_room_sub_menu_item_activate_cb), ctx,
315 (GClosureNotify) contact_room_sub_menu_item_activate_cb_ctx_free, 0);
321 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
325 GtkWidget *room_item;
326 EmpathyChatroomManager *mgr;
329 GtkMenuShell *submenu_shell;
330 gboolean have_rooms = FALSE;
332 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
334 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
335 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
337 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
339 mgr = empathy_chatroom_manager_new (NULL);
340 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
341 empathy_contact_get_account (contact));
343 /* create rooms sub menu */
344 submenu = gtk_menu_new ();
345 submenu_shell = GTK_MENU_SHELL (submenu);
347 for (l = rooms; l != NULL; l = g_list_next (l))
349 EmpathyChatroom *chatroom = l->data;
352 g_object_get (chatroom, "tp-channel", &channel, NULL);
357 room_item = create_room_sub_menu_item (contact, chatroom);
358 gtk_menu_shell_append (submenu_shell, room_item);
359 gtk_widget_show (room_item);
361 g_object_unref (channel);
367 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
371 gtk_widget_set_sensitive (item, FALSE);
372 gtk_widget_destroy (submenu);
375 gtk_widget_show (image);
377 g_object_unref (mgr);