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