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"
38 #include "empathy-ui-utils.h"
41 empathy_contact_menu_new (EmpathyContact *contact,
42 EmpathyContactFeatureFlags features)
48 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
50 if (features == EMPATHY_CONTACT_FEATURE_NONE) {
54 menu = gtk_menu_new ();
55 shell = GTK_MENU_SHELL (menu);
58 if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
59 item = empathy_contact_chat_menu_item_new (contact);
60 gtk_menu_shell_append (shell, item);
61 gtk_widget_show (item);
65 if (features & EMPATHY_CONTACT_FEATURE_CALL) {
66 item = empathy_contact_call_menu_item_new (contact);
67 gtk_menu_shell_append (shell, item);
68 gtk_widget_show (item);
72 if (features & EMPATHY_CONTACT_FEATURE_LOG) {
73 item = empathy_contact_log_menu_item_new (contact);
74 gtk_menu_shell_append (shell, item);
75 gtk_widget_show (item);
79 item = empathy_contact_invite_menu_item_new (contact);
80 gtk_menu_shell_append (shell, item);
81 gtk_widget_show (item);
84 item = empathy_contact_file_transfer_menu_item_new (contact);
85 gtk_menu_shell_append (shell, item);
86 gtk_widget_show (item);
89 if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
90 EMPATHY_CONTACT_FEATURE_INFO)) {
91 item = gtk_separator_menu_item_new ();
92 gtk_menu_shell_append (shell, item);
93 gtk_widget_show (item);
97 if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
98 item = empathy_contact_edit_menu_item_new (contact);
99 gtk_menu_shell_append (shell, item);
100 gtk_widget_show (item);
104 if (features & EMPATHY_CONTACT_FEATURE_INFO) {
105 item = empathy_contact_info_menu_item_new (contact);
106 gtk_menu_shell_append (shell, item);
107 gtk_widget_show (item);
114 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
119 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
121 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
122 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
124 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
125 gtk_widget_show (image);
127 g_signal_connect_swapped (item, "activate",
128 G_CALLBACK (empathy_dispatcher_chat_with_contact),
135 empathy_contact_call_menu_item_new (EmpathyContact *contact)
140 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
142 item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
143 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
145 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
146 gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
147 gtk_widget_show (image);
149 g_signal_connect_swapped (item, "activate",
150 G_CALLBACK (empathy_dispatcher_call_with_contact),
157 contact_log_menu_item_activate_cb (EmpathyContact *contact)
159 empathy_log_window_show (empathy_contact_get_account (contact),
160 empathy_contact_get_id (contact),
165 empathy_contact_log_menu_item_new (EmpathyContact *contact)
167 EmpathyLogManager *manager;
172 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
174 manager = empathy_log_manager_new ();
175 have_log = empathy_log_manager_exists (manager,
176 empathy_contact_get_account (contact),
177 empathy_contact_get_id (contact),
179 g_object_unref (manager);
181 item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
182 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
184 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
185 gtk_widget_set_sensitive (item, have_log);
186 gtk_widget_show (image);
188 g_signal_connect_swapped (item, "activate",
189 G_CALLBACK (contact_log_menu_item_activate_cb),
196 contact_file_transfer_menu_item_activate_cb (EmpathyContact *contact)
198 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
199 empathy_send_file_with_file_chooser (contact);
203 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
208 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
210 item = gtk_image_menu_item_new_with_mnemonic (_("Send file"));
211 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
213 gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact));
214 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
215 gtk_widget_show (image);
217 g_signal_connect_swapped (item, "activate",
218 G_CALLBACK (contact_file_transfer_menu_item_activate_cb),
225 contact_info_menu_item_activate_cb (EmpathyContact *contact)
227 empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
231 empathy_contact_info_menu_item_new (EmpathyContact *contact)
236 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
238 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
239 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
241 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
242 gtk_widget_show (image);
244 g_signal_connect_swapped (item, "activate",
245 G_CALLBACK (contact_info_menu_item_activate_cb),
252 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
254 empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
258 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
263 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
265 item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
266 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
268 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
269 gtk_widget_show (image);
271 g_signal_connect_swapped (item, "activate",
272 G_CALLBACK (contact_edit_menu_item_activate_cb),
280 EmpathyContact *contact;
281 EmpathyChatroom *chatroom;
282 } contact_room_sub_menu_item_activate_cb_ctx;
284 static contact_room_sub_menu_item_activate_cb_ctx *
285 contact_room_sub_menu_item_activate_cb_ctx_new (EmpathyContact *contact,
286 EmpathyChatroom *chatroom)
288 contact_room_sub_menu_item_activate_cb_ctx *ctx;
290 ctx = g_slice_new (contact_room_sub_menu_item_activate_cb_ctx);
292 ctx->contact = g_object_ref (contact);
293 ctx->chatroom = g_object_ref (chatroom);
299 contact_room_sub_menu_item_activate_cb_ctx_free (
300 contact_room_sub_menu_item_activate_cb_ctx *ctx)
302 /* FIXME: seems this is never called... */
303 g_object_unref (ctx->contact);
304 g_object_unref (ctx->chatroom);
306 g_slice_free (contact_room_sub_menu_item_activate_cb_ctx, ctx);
310 contact_room_sub_menu_item_activate_cb (
312 contact_room_sub_menu_item_activate_cb_ctx *ctx)
318 g_object_get (ctx->chatroom, "tp-channel", &channel, NULL);
320 /* channel was invalidated. Ignoring */
323 /* send invitation */
324 handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
325 handle = empathy_contact_get_handle (ctx->contact);
326 g_array_append_val (handles, handle);
328 tp_cli_channel_interface_group_call_add_members (channel, -1, handles,
329 _("Inviting to this room"), NULL, NULL, NULL, NULL);
331 g_array_free (handles, TRUE);
332 g_object_unref (channel);
336 create_room_sub_menu_item (EmpathyContact *contact,
337 EmpathyChatroom *chatroom)
340 contact_room_sub_menu_item_activate_cb_ctx *ctx;
342 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
344 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
346 ctx = contact_room_sub_menu_item_activate_cb_ctx_new (contact, chatroom);
348 g_signal_connect_data (item, "activate",
349 G_CALLBACK (contact_room_sub_menu_item_activate_cb), ctx,
350 (GClosureNotify) contact_room_sub_menu_item_activate_cb_ctx_free, 0);
356 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
360 GtkWidget *room_item;
361 EmpathyChatroomManager *mgr;
364 GtkMenuShell *submenu_shell;
365 gboolean have_rooms = FALSE;
367 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
369 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
370 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
372 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
374 mgr = empathy_chatroom_manager_new (NULL);
375 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
376 empathy_contact_get_account (contact));
378 /* create rooms sub menu */
379 submenu = gtk_menu_new ();
380 submenu_shell = GTK_MENU_SHELL (submenu);
382 for (l = rooms; l != NULL; l = g_list_next (l))
384 EmpathyChatroom *chatroom = l->data;
387 g_object_get (chatroom, "tp-channel", &channel, NULL);
392 room_item = create_room_sub_menu_item (contact, chatroom);
393 gtk_menu_shell_append (submenu_shell, room_item);
394 gtk_widget_show (room_item);
396 g_object_unref (channel);
402 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
406 gtk_widget_set_sensitive (item, FALSE);
407 gtk_widget_destroy (submenu);
410 gtk_widget_show (image);
412 g_object_unref (mgr);