]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-menu.c
hindi update
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2008 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include "config.h"
23
24 #include <string.h>
25
26 #include <glib/gi18n-lib.h>
27 #include <gtk/gtk.h>
28 #include <telepathy-logger/log-manager.h>
29
30 #include <libempathy/empathy-contact-manager.h>
31 #include <libempathy/empathy-request-util.h>
32 #include <libempathy/empathy-utils.h>
33 #include <libempathy/empathy-chatroom-manager.h>
34 #include <libempathy/empathy-contact-manager.h>
35
36 #include "empathy-contact-menu.h"
37 #include "empathy-images.h"
38 #include "empathy-log-window.h"
39 #include "empathy-contact-dialogs.h"
40 #include "empathy-ui-utils.h"
41 #include "empathy-share-my-desktop.h"
42 #include "empathy-call-utils.h"
43
44 static GtkWidget *empathy_contact_block_menu_item_new (EmpathyContact *);
45
46 GtkWidget *
47 empathy_contact_menu_new (EmpathyContact             *contact,
48                           EmpathyContactFeatureFlags  features)
49 {
50         GtkWidget    *menu;
51         GtkMenuShell *shell;
52         GtkWidget    *item;
53
54         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
55
56         if (features == EMPATHY_CONTACT_FEATURE_NONE) {
57                 return NULL;
58         }
59
60         menu = gtk_menu_new ();
61         shell = GTK_MENU_SHELL (menu);
62
63         /* Add Contact */
64         item = empathy_contact_add_menu_item_new (contact);
65         if (item) {
66                 gtk_menu_shell_append (shell, item);
67                 gtk_widget_show (item);
68         }
69
70         /* Chat */
71         if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
72                 item = empathy_contact_chat_menu_item_new (contact);
73                 gtk_menu_shell_append (shell, item);
74                 gtk_widget_show (item);
75         }
76
77         if (features & EMPATHY_CONTACT_FEATURE_CALL) {
78                 /* Audio Call */
79                 item = empathy_contact_audio_call_menu_item_new (contact);
80                 gtk_menu_shell_append (shell, item);
81                 gtk_widget_show (item);
82
83                 /* Video Call */
84                 item = empathy_contact_video_call_menu_item_new (contact);
85                 gtk_menu_shell_append (shell, item);
86                 gtk_widget_show (item);
87         }
88
89         /* Invite */
90         item = empathy_contact_invite_menu_item_new (contact);
91         gtk_menu_shell_append (shell, item);
92         gtk_widget_show (item);
93
94         /* File transfer */
95         if (features & EMPATHY_CONTACT_FEATURE_FT) {
96                 item = empathy_contact_file_transfer_menu_item_new (contact);
97                 gtk_menu_shell_append (shell, item);
98                 gtk_widget_show (item);
99         }
100
101         /* Share my desktop */
102         /* FIXME we should add the "Share my desktop" menu item if Vino is
103         a registered handler in MC5 */
104         item = empathy_contact_share_my_desktop_menu_item_new (contact);
105         gtk_menu_shell_append (shell, item);
106         gtk_widget_show (item);
107
108         /* Separator */
109         if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
110                         EMPATHY_CONTACT_FEATURE_INFO |
111                         EMPATHY_CONTACT_FEATURE_FAVOURITE)) {
112                 item = gtk_separator_menu_item_new ();
113                 gtk_menu_shell_append (shell, item);
114                 gtk_widget_show (item);
115         }
116
117         /* Edit */
118         if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
119                 item = empathy_contact_edit_menu_item_new (contact);
120                 gtk_menu_shell_append (shell, item);
121                 gtk_widget_show (item);
122         }
123
124         /* Log */
125         if (features & EMPATHY_CONTACT_FEATURE_LOG) {
126                 item = empathy_contact_log_menu_item_new (contact);
127                 gtk_menu_shell_append (shell, item);
128                 gtk_widget_show (item);
129         }
130
131         /* Info */
132         if (features & EMPATHY_CONTACT_FEATURE_INFO) {
133                 item = empathy_contact_info_menu_item_new (contact);
134                 gtk_menu_shell_append (shell, item);
135                 gtk_widget_show (item);
136         }
137
138         /* Favorite checkbox */
139         if (features & EMPATHY_CONTACT_FEATURE_FAVOURITE) {
140                 item = empathy_contact_favourite_menu_item_new (contact);
141                 gtk_menu_shell_append (shell, item);
142                 gtk_widget_show (item);
143         }
144
145         /* Separator & Block */
146         if (features & EMPATHY_CONTACT_FEATURE_BLOCK &&
147             (item = empathy_contact_block_menu_item_new (contact)) != NULL) {
148                 GtkWidget *sep;
149
150                 sep = gtk_separator_menu_item_new ();
151                 gtk_menu_shell_append (shell, sep);
152                 gtk_widget_show (sep);
153
154                 gtk_menu_shell_append (shell, item);
155                 gtk_widget_show (item);
156         }
157
158         return menu;
159 }
160
161 static void
162 empathy_contact_add_menu_item_activated (GtkMenuItem *item,
163         EmpathyContact *contact)
164 {
165         GtkWidget *toplevel;
166
167         toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
168         if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel)) {
169                 toplevel = NULL;
170         }
171
172         empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
173                                                       contact);
174 }
175
176 GtkWidget *
177 empathy_contact_add_menu_item_new (EmpathyContact *contact)
178 {
179         GtkWidget *item;
180         GtkWidget *image;
181         EmpathyContactManager *manager;
182         TpConnection *connection;
183         GList *l, *members;
184         gboolean found = FALSE;
185         EmpathyContactListFlags flags;
186
187         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
188
189         if (!empathy_contact_manager_initialized ()) {
190                 return NULL;
191         }
192
193         manager = empathy_contact_manager_dup_singleton ();
194         connection = empathy_contact_get_connection (contact);
195
196         flags = empathy_contact_manager_get_flags_for_connection (manager,
197                         connection);
198
199         if (!(flags & EMPATHY_CONTACT_LIST_CAN_ADD)) {
200                 return NULL;
201         }
202
203         members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (manager));
204         for (l = members; l; l = l->next) {
205                 if (!found && empathy_contact_equal (l->data, contact)) {
206                         found = TRUE;
207                         /* we keep iterating so that we don't leak contact
208                          * refs */
209                 }
210
211                 g_object_unref (l->data);
212         }
213         g_list_free (members);
214         g_object_unref (manager);
215
216         if (found) {
217                 return NULL;
218         }
219
220         item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
221         image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
222                                               GTK_ICON_SIZE_MENU);
223         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
224
225         g_signal_connect (item, "activate",
226                         G_CALLBACK (empathy_contact_add_menu_item_activated),
227                         contact);
228
229         return item;
230 }
231
232 static void
233 empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item,
234                                          EmpathyContact   *contact)
235 {
236         static guint block_signal = 0;
237         EmpathyContactManager *manager;
238         gboolean blocked, abusive;
239
240         if (block_signal > 0)
241                 return;
242
243         blocked = gtk_check_menu_item_get_active (item);
244
245         if (blocked) {
246                 /* confirm the user really wishes to block the contact */
247                 GtkWidget *parent;
248                 GdkPixbuf *avatar;
249
250                 /* gtk_menu_get_attach_widget () doesn't behave properly here
251                  * for some reason */
252                 parent = g_object_get_data (
253                         G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
254                         "window");
255
256                 avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 48, 48);
257
258                 if (!empathy_block_contact_dialog_show (GTK_WINDOW (parent),
259                                         contact, avatar, &abusive))
260                         return;
261         }
262
263         manager = empathy_contact_manager_dup_singleton ();
264         empathy_contact_list_set_blocked (EMPATHY_CONTACT_LIST (manager),
265                                           contact, blocked, abusive);
266         g_object_unref (manager);
267
268         /* update the toggle with the blocked status */
269         block_signal++;
270         gtk_check_menu_item_set_active (item, blocked);
271         block_signal--;
272 }
273
274 static GtkWidget *
275 empathy_contact_block_menu_item_new (EmpathyContact *contact)
276 {
277         GtkWidget *item;
278         EmpathyContactManager *manager;
279         TpConnection *connection;
280         EmpathyContactListFlags flags;
281         gboolean blocked;
282
283         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
284
285         manager = empathy_contact_manager_dup_singleton ();
286
287         if (!empathy_contact_manager_initialized ()) {
288                 return NULL;
289         }
290
291         connection = empathy_contact_get_connection (contact);
292
293         flags = empathy_contact_manager_get_flags_for_connection (manager,
294                         connection);
295
296         if (!(flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)) {
297                 return NULL;
298         }
299
300         item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
301         blocked = empathy_contact_list_get_blocked (
302                         EMPATHY_CONTACT_LIST (manager),
303                         contact);
304
305         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), blocked);
306
307         g_signal_connect (item, "toggled",
308                         G_CALLBACK (empathy_contact_block_menu_item_toggled),
309                         contact);
310
311         return item;
312 }
313
314 static void
315 empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
316         EmpathyContact *contact)
317 {
318         empathy_chat_with_contact (contact, empathy_get_current_action_time ());
319 }
320
321 GtkWidget *
322 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
323 {
324         GtkWidget *item;
325         GtkWidget *image;
326
327         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
328
329         item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
330         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
331                                               GTK_ICON_SIZE_MENU);
332         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
333         gtk_widget_set_sensitive (item, !empathy_contact_is_user (contact));
334         gtk_widget_show (image);
335
336         g_signal_connect (item, "activate",
337                                   G_CALLBACK (empathy_contact_chat_menu_item_activated),
338                                   contact);
339
340         return item;
341 }
342
343 static void
344 empathy_contact_audio_call_menu_item_activated (GtkMenuItem *item,
345         EmpathyContact *contact)
346 {
347         empathy_call_new_with_streams (empathy_contact_get_id (contact),
348                 empathy_contact_get_account (contact),
349                 TRUE, FALSE,
350                 empathy_get_current_action_time ());
351 }
352
353 GtkWidget *
354 empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
355 {
356         GtkWidget *item;
357         GtkWidget *image;
358
359         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
360
361         item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
362         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
363                                               GTK_ICON_SIZE_MENU);
364         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
365         gtk_widget_set_sensitive (item, empathy_contact_can_voip_audio (contact) &&
366                                         !empathy_contact_is_user (contact));
367         gtk_widget_show (image);
368
369         g_signal_connect (item, "activate",
370                                   G_CALLBACK (empathy_contact_audio_call_menu_item_activated),
371                                   contact);
372
373         return item;
374 }
375
376 static void
377 empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
378         EmpathyContact *contact)
379 {
380         empathy_call_new_with_streams (empathy_contact_get_id (contact),
381                 empathy_contact_get_account (contact),
382                 TRUE, TRUE,
383                 empathy_get_current_action_time ());
384 }
385
386 GtkWidget *
387 empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
388 {
389         GtkWidget *item;
390         GtkWidget *image;
391
392         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
393
394         item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
395         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
396                                               GTK_ICON_SIZE_MENU);
397         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
398         gtk_widget_set_sensitive (item, empathy_contact_can_voip_video (contact) &&
399                                         !empathy_contact_is_user (contact));
400         gtk_widget_show (image);
401
402         g_signal_connect (item, "activate",
403                                   G_CALLBACK (empathy_contact_video_call_menu_item_activated),
404                                   contact);
405
406         return item;
407 }
408
409 static void
410 contact_log_menu_item_activate_cb (EmpathyContact *contact)
411 {
412         empathy_log_window_show (empathy_contact_get_account (contact),
413                                  empathy_contact_get_id (contact),
414                                  FALSE, NULL);
415 }
416
417 GtkWidget *
418 empathy_contact_log_menu_item_new (EmpathyContact *contact)
419 {
420         TplLogManager     *manager;
421         TplEntity         *entity;
422         gboolean           have_log;
423         GtkWidget         *item;
424         GtkWidget         *image;
425
426         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
427
428         manager = tpl_log_manager_dup_singleton ();
429         entity = tpl_entity_new_from_tp_contact (empathy_contact_get_tp_contact (contact),
430                                                  TPL_ENTITY_CONTACT);
431
432         have_log = tpl_log_manager_exists (manager,
433                                            empathy_contact_get_account (contact),
434                                            entity,
435                                            TPL_EVENT_MASK_TEXT);
436
437         g_object_unref (entity);
438         g_object_unref (manager);
439
440         item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
441         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
442                                               GTK_ICON_SIZE_MENU);
443         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
444         gtk_widget_set_sensitive (item, have_log);
445         gtk_widget_show (image);
446
447         g_signal_connect_swapped (item, "activate",
448                                   G_CALLBACK (contact_log_menu_item_activate_cb),
449                                   contact);
450
451         return item;
452 }
453
454 GtkWidget *
455 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
456 {
457         GtkWidget         *item;
458         GtkWidget         *image;
459
460         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
461
462         item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
463         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
464                                               GTK_ICON_SIZE_MENU);
465         gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact) &&
466                                         !empathy_contact_is_user (contact));
467         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
468         gtk_widget_show (image);
469
470         g_signal_connect_swapped (item, "activate",
471                                   G_CALLBACK (empathy_send_file_with_file_chooser),
472                                   contact);
473
474         return item;
475 }
476
477 GtkWidget *
478 empathy_contact_share_my_desktop_menu_item_new (EmpathyContact *contact)
479 {
480         GtkWidget         *item;
481         GtkWidget         *image;
482
483         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
484
485         item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
486         image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK,
487                                               GTK_ICON_SIZE_MENU);
488         gtk_widget_set_sensitive (item, empathy_contact_can_use_rfb_stream_tube (
489                 contact));
490         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
491         gtk_widget_show (image);
492
493         g_signal_connect_swapped (item, "activate",
494                                   G_CALLBACK (empathy_share_my_desktop_share_with_contact),
495                                   contact);
496
497         return item;
498 }
499
500 static void
501 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
502         EmpathyContact *contact)
503 {
504         EmpathyContactManager *manager;
505         EmpathyContactList *list;
506
507         manager = empathy_contact_manager_dup_singleton ();
508         list = EMPATHY_CONTACT_LIST (manager);
509
510         if (gtk_check_menu_item_get_active (item)) {
511                 empathy_contact_list_add_to_favourites (list, contact);
512         } else {
513                 empathy_contact_list_remove_from_favourites (list, contact);
514         }
515
516         g_object_unref (manager);
517 }
518
519 GtkWidget *
520 empathy_contact_favourite_menu_item_new (EmpathyContact *contact)
521 {
522         GtkWidget *item;
523         EmpathyContactManager *manager;
524
525         item = gtk_check_menu_item_new_with_label (_("Favorite"));
526
527         manager = empathy_contact_manager_dup_singleton ();
528         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
529                 empathy_contact_list_is_favourite (EMPATHY_CONTACT_LIST (manager),
530                                                    contact));
531
532         g_signal_connect (item, "toggled",
533                           G_CALLBACK (favourite_menu_item_toggled_cb),
534                           contact);
535
536         g_object_unref (manager);
537         return item;
538 }
539
540 static void
541 contact_info_menu_item_activate_cb (EmpathyContact *contact)
542 {
543         empathy_contact_information_dialog_show (contact, NULL);
544 }
545
546 GtkWidget *
547 empathy_contact_info_menu_item_new (EmpathyContact *contact)
548 {
549         GtkWidget *item;
550         GtkWidget *image;
551
552         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
553
554         item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
555         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
556                                               GTK_ICON_SIZE_MENU);
557         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
558         gtk_widget_show (image);
559
560         g_signal_connect_swapped (item, "activate",
561                                   G_CALLBACK (contact_info_menu_item_activate_cb),
562                                   contact);
563
564         return item;
565 }
566
567 static void
568 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
569 {
570         empathy_contact_edit_dialog_show (contact, NULL);
571 }
572
573 GtkWidget *
574 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
575 {
576         EmpathyContactManager *manager;
577         GtkWidget *item;
578         GtkWidget *image;
579         gboolean enable = FALSE;
580
581         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
582
583         if (empathy_contact_manager_initialized ()) {
584                 TpConnection *connection;
585                 EmpathyContactListFlags flags;
586
587                 manager = empathy_contact_manager_dup_singleton ();
588                 connection = empathy_contact_get_connection (contact);
589                 flags = empathy_contact_manager_get_flags_for_connection (
590                                 manager, connection);
591
592                 enable = (flags & EMPATHY_CONTACT_LIST_CAN_ALIAS ||
593                           flags & EMPATHY_CONTACT_LIST_CAN_GROUP);
594
595                 g_object_unref (manager);
596         }
597
598         item = gtk_image_menu_item_new_with_mnemonic (
599                                                      C_("Edit contact (contextual menu)",
600                                                         "_Edit"));
601         image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
602                                               GTK_ICON_SIZE_MENU);
603         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
604         gtk_widget_show (image);
605
606         gtk_widget_set_sensitive (item, enable);
607
608         g_signal_connect_swapped (item, "activate",
609                                   G_CALLBACK (contact_edit_menu_item_activate_cb),
610                                   contact);
611
612         return item;
613 }
614
615 typedef struct  {
616         EmpathyContact *contact;
617         EmpathyChatroom *chatroom;
618 } RoomSubMenuData;
619
620 static RoomSubMenuData *
621 room_sub_menu_data_new (EmpathyContact *contact,
622                         EmpathyChatroom *chatroom)
623 {
624         RoomSubMenuData *data;
625
626         data = g_slice_new (RoomSubMenuData);
627         data->contact = g_object_ref (contact);
628         data->chatroom = g_object_ref (chatroom);
629         return data;
630 }
631
632 static void
633 room_sub_menu_data_free (RoomSubMenuData *data)
634 {
635         g_object_unref (data->contact);
636         g_object_unref (data->chatroom);
637         g_slice_free (RoomSubMenuData, data);
638 }
639
640 static void
641 room_sub_menu_activate_cb (GtkWidget *item,
642                            RoomSubMenuData *data)
643 {
644         EmpathyTpChat *chat;
645
646         chat = empathy_chatroom_get_tp_chat (data->chatroom);
647         if (chat == NULL) {
648                 /* channel was invalidated. Ignoring */
649                 return;
650         }
651
652         /* send invitation */
653         empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat), data->contact,
654                 _("Inviting you to this room"));
655 }
656
657 static GtkWidget *
658 create_room_sub_menu (EmpathyContact *contact,
659                       EmpathyChatroom *chatroom)
660 {
661         GtkWidget *item;
662         RoomSubMenuData *data;
663
664         item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
665         data = room_sub_menu_data_new (contact, chatroom);
666         g_signal_connect_data (item, "activate",
667                                G_CALLBACK (room_sub_menu_activate_cb), data,
668                                (GClosureNotify) room_sub_menu_data_free, 0);
669
670         return item;
671 }
672
673 GtkWidget *
674 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
675 {
676         GtkWidget *item;
677         GtkWidget *image;
678         GtkWidget *room_item;
679         EmpathyChatroomManager *mgr;
680         GList *rooms, *l;
681         GtkWidget *submenu = NULL;
682
683         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
684
685         item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
686         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
687                                               GTK_ICON_SIZE_MENU);
688         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
689
690         if (empathy_contact_is_user (contact)) {
691                 gtk_widget_set_sensitive (item, FALSE);
692                 gtk_widget_show (image);
693                 return item;
694         }
695
696         mgr = empathy_chatroom_manager_dup_singleton (NULL);
697         rooms = empathy_chatroom_manager_get_chatrooms (mgr,
698                 empathy_contact_get_account (contact));
699
700         for (l = rooms; l != NULL; l = g_list_next (l)) {
701                 EmpathyChatroom *chatroom = l->data;
702
703                 if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
704                         if (G_UNLIKELY (submenu == NULL))
705                                 submenu = gtk_menu_new ();
706
707                         room_item = create_room_sub_menu (contact, chatroom);
708                         gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
709                         gtk_widget_show (room_item);
710                 }
711         }
712
713         if (submenu) {
714                 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
715         } else {
716                 gtk_widget_set_sensitive (item, FALSE);
717         }
718
719         gtk_widget_show (image);
720
721         g_object_unref (mgr);
722         g_list_free (rooms);
723
724         return item;
725 }
726