]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-menu.c
Move empathy_call_* util functions to libempathy-gtk
[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         /* Log */
90         if (features & EMPATHY_CONTACT_FEATURE_LOG) {
91                 item = empathy_contact_log_menu_item_new (contact);
92                 gtk_menu_shell_append (shell, item);
93                 gtk_widget_show (item);
94         }
95
96         /* Invite */
97         item = empathy_contact_invite_menu_item_new (contact);
98         gtk_menu_shell_append (shell, item);
99         gtk_widget_show (item);
100
101         /* File transfer */
102         if (features & EMPATHY_CONTACT_FEATURE_FT) {
103                 item = empathy_contact_file_transfer_menu_item_new (contact);
104                 gtk_menu_shell_append (shell, item);
105                 gtk_widget_show (item);
106         }
107
108         /* Share my desktop */
109         /* FIXME we should add the "Share my desktop" menu item if Vino is
110         a registered handler in MC5 */
111         item = empathy_contact_share_my_desktop_menu_item_new (contact);
112         gtk_menu_shell_append (shell, item);
113         gtk_widget_show (item);
114
115         /* Separator */
116         if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
117                         EMPATHY_CONTACT_FEATURE_INFO |
118                         EMPATHY_CONTACT_FEATURE_FAVOURITE)) {
119                 item = gtk_separator_menu_item_new ();
120                 gtk_menu_shell_append (shell, item);
121                 gtk_widget_show (item);
122         }
123
124         /* Edit */
125         if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
126                 item = empathy_contact_edit_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 (contact, TRUE, FALSE,
348                 empathy_get_current_action_time ());
349 }
350
351 GtkWidget *
352 empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
353 {
354         GtkWidget *item;
355         GtkWidget *image;
356
357         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
358
359         item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
360         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
361                                               GTK_ICON_SIZE_MENU);
362         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
363         gtk_widget_set_sensitive (item, empathy_contact_can_voip_audio (contact) &&
364                                         !empathy_contact_is_user (contact));
365         gtk_widget_show (image);
366
367         g_signal_connect (item, "activate",
368                                   G_CALLBACK (empathy_contact_audio_call_menu_item_activated),
369                                   contact);
370
371         return item;
372 }
373
374 static void
375 empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
376         EmpathyContact *contact)
377 {
378         empathy_call_new_with_streams (contact, TRUE, TRUE,
379                 empathy_get_current_action_time ());
380 }
381
382 GtkWidget *
383 empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
384 {
385         GtkWidget *item;
386         GtkWidget *image;
387
388         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
389
390         item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
391         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
392                                               GTK_ICON_SIZE_MENU);
393         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
394         gtk_widget_set_sensitive (item, empathy_contact_can_voip_video (contact) &&
395                                         !empathy_contact_is_user (contact));
396         gtk_widget_show (image);
397
398         g_signal_connect (item, "activate",
399                                   G_CALLBACK (empathy_contact_video_call_menu_item_activated),
400                                   contact);
401
402         return item;
403 }
404
405 static void
406 contact_log_menu_item_activate_cb (EmpathyContact *contact)
407 {
408         empathy_log_window_show (empathy_contact_get_account (contact),
409                                  empathy_contact_get_id (contact),
410                                  FALSE, NULL);
411 }
412
413 GtkWidget *
414 empathy_contact_log_menu_item_new (EmpathyContact *contact)
415 {
416         TplLogManager     *manager;
417         TplEntity         *entity;
418         gboolean           have_log;
419         GtkWidget         *item;
420         GtkWidget         *image;
421
422         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
423
424         manager = tpl_log_manager_dup_singleton ();
425         entity = tpl_entity_new_from_tp_contact (empathy_contact_get_tp_contact (contact),
426                                                  TPL_ENTITY_CONTACT);
427
428         have_log = tpl_log_manager_exists (manager,
429                                            empathy_contact_get_account (contact),
430                                            entity,
431                                            TPL_EVENT_MASK_TEXT);
432
433         g_object_unref (entity);
434         g_object_unref (manager);
435
436         item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
437         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
438                                               GTK_ICON_SIZE_MENU);
439         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
440         gtk_widget_set_sensitive (item, have_log);
441         gtk_widget_show (image);
442
443         g_signal_connect_swapped (item, "activate",
444                                   G_CALLBACK (contact_log_menu_item_activate_cb),
445                                   contact);
446
447         return item;
448 }
449
450 GtkWidget *
451 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
452 {
453         GtkWidget         *item;
454         GtkWidget         *image;
455
456         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
457
458         item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
459         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
460                                               GTK_ICON_SIZE_MENU);
461         gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact) &&
462                                         !empathy_contact_is_user (contact));
463         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
464         gtk_widget_show (image);
465
466         g_signal_connect_swapped (item, "activate",
467                                   G_CALLBACK (empathy_send_file_with_file_chooser),
468                                   contact);
469
470         return item;
471 }
472
473 GtkWidget *
474 empathy_contact_share_my_desktop_menu_item_new (EmpathyContact *contact)
475 {
476         GtkWidget         *item;
477         GtkWidget         *image;
478
479         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
480
481         item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
482         image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK,
483                                               GTK_ICON_SIZE_MENU);
484         gtk_widget_set_sensitive (item, empathy_contact_can_use_rfb_stream_tube (
485                 contact));
486         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
487         gtk_widget_show (image);
488
489         g_signal_connect_swapped (item, "activate",
490                                   G_CALLBACK (empathy_share_my_desktop_share_with_contact),
491                                   contact);
492
493         return item;
494 }
495
496 static void
497 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
498         EmpathyContact *contact)
499 {
500         EmpathyContactManager *manager;
501         EmpathyContactList *list;
502
503         manager = empathy_contact_manager_dup_singleton ();
504         list = EMPATHY_CONTACT_LIST (manager);
505
506         if (gtk_check_menu_item_get_active (item)) {
507                 empathy_contact_list_add_to_favourites (list, contact);
508         } else {
509                 empathy_contact_list_remove_from_favourites (list, contact);
510         }
511
512         g_object_unref (manager);
513 }
514
515 GtkWidget *
516 empathy_contact_favourite_menu_item_new (EmpathyContact *contact)
517 {
518         GtkWidget *item;
519         EmpathyContactManager *manager;
520
521         item = gtk_check_menu_item_new_with_label (_("Favorite"));
522
523         manager = empathy_contact_manager_dup_singleton ();
524         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
525                 empathy_contact_list_is_favourite (EMPATHY_CONTACT_LIST (manager),
526                                                    contact));
527
528         g_signal_connect (item, "toggled",
529                           G_CALLBACK (favourite_menu_item_toggled_cb),
530                           contact);
531
532         g_object_unref (manager);
533         return item;
534 }
535
536 static void
537 contact_info_menu_item_activate_cb (EmpathyContact *contact)
538 {
539         empathy_contact_information_dialog_show (contact, NULL);
540 }
541
542 GtkWidget *
543 empathy_contact_info_menu_item_new (EmpathyContact *contact)
544 {
545         GtkWidget *item;
546         GtkWidget *image;
547
548         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
549
550         item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
551         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
552                                               GTK_ICON_SIZE_MENU);
553         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
554         gtk_widget_show (image);
555
556         g_signal_connect_swapped (item, "activate",
557                                   G_CALLBACK (contact_info_menu_item_activate_cb),
558                                   contact);
559
560         return item;
561 }
562
563 static void
564 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
565 {
566         empathy_contact_edit_dialog_show (contact, NULL);
567 }
568
569 GtkWidget *
570 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
571 {
572         EmpathyContactManager *manager;
573         GtkWidget *item;
574         GtkWidget *image;
575         gboolean enable = FALSE;
576
577         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
578
579         if (empathy_contact_manager_initialized ()) {
580                 TpConnection *connection;
581                 EmpathyContactListFlags flags;
582
583                 manager = empathy_contact_manager_dup_singleton ();
584                 connection = empathy_contact_get_connection (contact);
585                 flags = empathy_contact_manager_get_flags_for_connection (
586                                 manager, connection);
587
588                 enable = (flags & EMPATHY_CONTACT_LIST_CAN_ALIAS ||
589                           flags & EMPATHY_CONTACT_LIST_CAN_GROUP);
590
591                 g_object_unref (manager);
592         }
593
594         item = gtk_image_menu_item_new_with_mnemonic (
595                                                      C_("Edit contact (contextual menu)",
596                                                         "_Edit"));
597         image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
598                                               GTK_ICON_SIZE_MENU);
599         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
600         gtk_widget_show (image);
601
602         gtk_widget_set_sensitive (item, enable);
603
604         g_signal_connect_swapped (item, "activate",
605                                   G_CALLBACK (contact_edit_menu_item_activate_cb),
606                                   contact);
607
608         return item;
609 }
610
611 typedef struct  {
612         EmpathyContact *contact;
613         EmpathyChatroom *chatroom;
614 } RoomSubMenuData;
615
616 static RoomSubMenuData *
617 room_sub_menu_data_new (EmpathyContact *contact,
618                         EmpathyChatroom *chatroom)
619 {
620         RoomSubMenuData *data;
621
622         data = g_slice_new (RoomSubMenuData);
623         data->contact = g_object_ref (contact);
624         data->chatroom = g_object_ref (chatroom);
625         return data;
626 }
627
628 static void
629 room_sub_menu_data_free (RoomSubMenuData *data)
630 {
631         g_object_unref (data->contact);
632         g_object_unref (data->chatroom);
633         g_slice_free (RoomSubMenuData, data);
634 }
635
636 static void
637 room_sub_menu_activate_cb (GtkWidget *item,
638                            RoomSubMenuData *data)
639 {
640         EmpathyTpChat *chat;
641
642         chat = empathy_chatroom_get_tp_chat (data->chatroom);
643         if (chat == NULL) {
644                 /* channel was invalidated. Ignoring */
645                 return;
646         }
647
648         /* send invitation */
649         empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat), data->contact,
650                 _("Inviting you to this room"));
651 }
652
653 static GtkWidget *
654 create_room_sub_menu (EmpathyContact *contact,
655                       EmpathyChatroom *chatroom)
656 {
657         GtkWidget *item;
658         RoomSubMenuData *data;
659
660         item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
661         data = room_sub_menu_data_new (contact, chatroom);
662         g_signal_connect_data (item, "activate",
663                                G_CALLBACK (room_sub_menu_activate_cb), data,
664                                (GClosureNotify) room_sub_menu_data_free, 0);
665
666         return item;
667 }
668
669 GtkWidget *
670 empathy_contact_invite_menu_item_new (EmpathyContact *contact)
671 {
672         GtkWidget *item;
673         GtkWidget *image;
674         GtkWidget *room_item;
675         EmpathyChatroomManager *mgr;
676         GList *rooms, *l;
677         GtkWidget *submenu = NULL;
678
679         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
680
681         item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
682         image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
683                                               GTK_ICON_SIZE_MENU);
684         gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
685
686         if (empathy_contact_is_user (contact)) {
687                 gtk_widget_set_sensitive (item, FALSE);
688                 gtk_widget_show (image);
689                 return item;
690         }
691
692         mgr = empathy_chatroom_manager_dup_singleton (NULL);
693         rooms = empathy_chatroom_manager_get_chatrooms (mgr,
694                 empathy_contact_get_account (contact));
695
696         for (l = rooms; l != NULL; l = g_list_next (l)) {
697                 EmpathyChatroom *chatroom = l->data;
698
699                 if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
700                         if (G_UNLIKELY (submenu == NULL))
701                                 submenu = gtk_menu_new ();
702
703                         room_item = create_room_sub_menu (contact, chatroom);
704                         gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
705                         gtk_widget_show (room_item);
706                 }
707         }
708
709         if (submenu) {
710                 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
711         } else {
712                 gtk_widget_set_sensitive (item, FALSE);
713         }
714
715         gtk_widget_show (image);
716
717         g_object_unref (mgr);
718         g_list_free (rooms);
719
720         return item;
721 }
722