1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2008-2010 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>
20 * Travis Reitter <travis.reitter@collabora.co.uk>
27 #include <glib/gi18n-lib.h>
29 #include <gio/gdesktopappinfo.h>
31 #include <telepathy-glib/util.h>
33 #include <folks/folks.h>
34 #include <folks/folks-telepathy.h>
36 #include <libempathy/empathy-camera-monitor.h>
37 #include <libempathy/empathy-request-util.h>
38 #include <libempathy/empathy-individual-manager.h>
39 #include <libempathy/empathy-chatroom-manager.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-pkg-kit.h>
44 #include "empathy-account-selector-dialog.h"
45 #include "empathy-individual-menu.h"
46 #include "empathy-images.h"
47 #include "empathy-log-window.h"
48 #include "empathy-contact-dialogs.h"
49 #include "empathy-gtk-enum-types.h"
50 #include "empathy-individual-dialogs.h"
51 #include "empathy-individual-edit-dialog.h"
52 #include "empathy-ui-utils.h"
53 #include "empathy-share-my-desktop.h"
54 #include "empathy-linking-dialog.h"
55 #include "empathy-call-utils.h"
56 #include "empathy-individual-store-channel.h"
58 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
59 #include <libempathy/empathy-debug.h>
61 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu)
64 FolksIndividual *individual; /* owned */
65 EmpathyIndividualFeatureFlags features;
66 EmpathyIndividualStore *store; /* may be NULL */
67 } EmpathyIndividualMenuPriv;
76 SIGNAL_LINK_CONTACTS_ACTIVATED,
80 static guint signals[LAST_SIGNAL];
82 G_DEFINE_TYPE (EmpathyIndividualMenu, empathy_individual_menu, GTK_TYPE_MENU);
84 static GtkWidget * empathy_individual_chat_menu_item_new (
85 FolksIndividual *individual);
86 static GtkWidget * empathy_individual_sms_menu_item_new (
87 FolksIndividual *individual);
88 static GtkWidget * empathy_individual_log_menu_item_new (
89 FolksIndividual *individual);
90 static GtkWidget * empathy_individual_info_menu_item_new (
91 FolksIndividual *individual);
92 static GtkWidget * empathy_individual_edit_menu_item_new (
93 FolksIndividual *individual);
94 static GtkWidget * empathy_individual_link_menu_item_new (
95 FolksIndividual *individual);
96 static GtkWidget * empathy_individual_invite_menu_item_new (
97 FolksIndividual *individual,
98 EmpathyContact *contact);
99 static GtkWidget * empathy_individual_file_transfer_menu_item_new (
100 FolksIndividual *individual);
101 static GtkWidget * empathy_individual_share_my_desktop_menu_item_new (
102 FolksIndividual *individual);
103 static GtkWidget * empathy_individual_favourite_menu_item_new (
104 FolksIndividual *individual);
105 static GtkWidget * empathy_individual_add_menu_item_new (
106 EmpathyIndividualMenu *self,
107 FolksIndividual *individual);
108 static GtkWidget * empathy_individiual_block_menu_item_new (
109 FolksIndividual *individual);
112 individual_menu_add_personas (GtkMenuShell *menu,
113 FolksIndividual *individual,
114 EmpathyIndividualFeatureFlags features)
119 guint persona_count = 0;
122 g_return_if_fail (GTK_IS_MENU (menu));
123 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
124 g_return_if_fail (empathy_folks_individual_contains_contact (individual));
126 personas = folks_individual_get_personas (individual);
127 /* we'll re-use this iterator throughout */
128 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
130 /* Make sure we've got enough valid entries for these menu items to add
132 while (gee_iterator_next (iter))
134 FolksPersona *persona = gee_iterator_get (iter);
135 if (empathy_folks_persona_is_interesting (persona))
138 g_clear_object (&persona);
141 /* return early if these entries would add nothing beyond the "quick" items */
142 if (persona_count <= 1)
145 /* add a separator before the list of personas */
146 item = gtk_separator_menu_item_new ();
147 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
148 gtk_widget_show (item);
150 for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
153 GtkWidget *contact_item;
154 GtkWidget *contact_submenu;
155 TpContact *tp_contact;
156 EmpathyContact *contact;
157 TpfPersona *persona = gee_iterator_get (iter);
159 FolksPersonaStore *store;
160 const gchar *account;
162 /* Individual containing only persona */
163 FolksIndividual *single_individual;
165 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
168 tp_contact = tpf_persona_get_contact (persona);
169 if (tp_contact == NULL)
172 contact = empathy_contact_dup_from_tp_contact (tp_contact);
173 single_individual = empathy_create_individual_from_tp_contact (
176 store = folks_persona_get_store (FOLKS_PERSONA (persona));
177 account = folks_persona_store_get_display_name (store);
179 /* Translators: this is used in the context menu for a contact. The first
180 * parameter is a contact ID (e.g. foo@jabber.org) and the second is one
181 * of the user's account IDs (e.g. me@hotmail.com). */
182 label = g_strdup_printf (_("%s (%s)"),
183 folks_persona_get_display_id (FOLKS_PERSONA (persona)), account);
185 contact_item = gtk_image_menu_item_new_with_label (label);
186 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (contact_item),
188 contact_submenu = gtk_menu_new ();
189 gtk_menu_item_set_submenu (GTK_MENU_ITEM (contact_item), contact_submenu);
190 image = gtk_image_new_from_icon_name (
191 empathy_icon_name_for_contact (contact), GTK_ICON_SIZE_MENU);
192 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (contact_item), image);
193 gtk_widget_show (image);
196 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
198 action = empathy_individual_chat_menu_item_new (single_individual);
199 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
200 gtk_widget_show (action);
204 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
206 action = empathy_individual_sms_menu_item_new (single_individual);
207 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
208 gtk_widget_show (action);
211 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
214 action = empathy_individual_audio_call_menu_item_new (
216 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
217 gtk_widget_show (action);
220 action = empathy_individual_video_call_menu_item_new (
222 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
223 gtk_widget_show (action);
227 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
229 action = empathy_individual_log_menu_item_new (single_individual);
230 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
231 gtk_widget_show (action);
235 action = empathy_individual_invite_menu_item_new (NULL, contact);
236 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
237 gtk_widget_show (action);
240 action = empathy_individual_file_transfer_menu_item_new (
242 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
243 gtk_widget_show (action);
245 /* Share my desktop */
246 action = empathy_individual_share_my_desktop_menu_item_new (
248 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
249 gtk_widget_show (action);
252 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
253 (item = empathy_individiual_block_menu_item_new (single_individual))
257 sep = gtk_separator_menu_item_new ();
258 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), sep);
259 gtk_widget_show (sep);
261 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), item);
262 gtk_widget_show (item);
265 gtk_menu_shell_append (GTK_MENU_SHELL (menu), contact_item);
266 gtk_widget_show (contact_item);
269 g_object_unref (contact);
270 g_object_unref (single_individual);
273 g_clear_object (&persona);
276 g_clear_object (&iter);
280 individual_link_menu_item_activate_cb (EmpathyIndividualMenu *self)
282 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
285 dialog = empathy_linking_dialog_show (priv->individual, NULL);
286 g_signal_emit (self, signals[SIGNAL_LINK_CONTACTS_ACTIVATED], 0, dialog);
290 empathy_individual_menu_init (EmpathyIndividualMenu *self)
292 EmpathyIndividualMenuPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
293 EMPATHY_TYPE_INDIVIDUAL_MENU, EmpathyIndividualMenuPriv);
299 find_phone_accounts (void)
301 TpAccountManager *am;
305 am = tp_account_manager_dup ();
306 g_return_val_if_fail (am != NULL, NULL);
308 accounts = tp_account_manager_get_valid_accounts (am);
309 for (l = accounts; l != NULL; l = g_list_next (l))
311 TpAccount *account = l->data;
313 if (tp_account_get_connection_status (account, NULL) !=
314 TP_CONNECTION_STATUS_CONNECTED)
317 if (!empathy_account_has_uri_scheme_tel (account))
320 found = g_list_prepend (found, g_object_ref (account));
323 g_list_free (accounts);
330 has_phone_account (void)
335 accounts = find_phone_accounts ();
336 result = (accounts != NULL);
338 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
344 call_phone_number (FolksPhoneFieldDetails *details,
347 DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details));
349 empathy_call_new_with_streams (
350 folks_phone_field_details_get_normalised (details),
351 account, TRUE, FALSE, empathy_get_current_action_time ());
355 display_call_phone_dialog (FolksPhoneFieldDetails *details,
361 dialog = empathy_account_selector_dialog_new (accounts);
363 gtk_window_set_title (GTK_WINDOW (dialog),
364 _("Select account to use to place the call"));
366 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
367 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
368 _("Call"), GTK_RESPONSE_OK,
371 response = gtk_dialog_run (GTK_DIALOG (dialog));
373 if (response == GTK_RESPONSE_OK)
377 account = empathy_account_selector_dialog_dup_selected (
378 EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog));
382 call_phone_number (details, account);
384 g_object_unref (account);
388 gtk_widget_destroy (dialog);
392 call_phone_number_cb (GtkMenuItem *item,
393 FolksPhoneFieldDetails *details)
397 accounts = find_phone_accounts ();
398 if (accounts == NULL)
400 DEBUG ("No phone aware account connected; can't call");
402 else if (g_list_length (accounts) == 1)
404 call_phone_number (details, accounts->data);
408 /* Ask which account to use */
409 display_call_phone_dialog (details, accounts);
412 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
416 find_phone_type (FolksPhoneFieldDetails *details)
418 GeeCollection *types;
421 types = folks_abstract_field_details_get_parameter_values (
422 FOLKS_ABSTRACT_FIELD_DETAILS (details), "type");
427 iter = gee_iterable_iterator (GEE_ITERABLE (types));
428 while (gee_iterator_next (iter))
430 const gchar *type = gee_iterator_get (iter);
432 if (!tp_strdiff (type, "CELL"))
434 else if (!tp_strdiff (type, "WORK"))
436 else if (!tp_strdiff (type, "HOME"))
444 add_phone_numbers (EmpathyIndividualMenu *self)
446 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
451 all_numbers = folks_phone_details_get_phone_numbers (
452 FOLKS_PHONE_DETAILS (priv->individual));
454 sensitive = has_phone_account ();
456 iter = gee_iterable_iterator (GEE_ITERABLE (all_numbers));
457 while (gee_iterator_next (iter))
459 FolksPhoneFieldDetails *details = gee_iterator_get (iter);
460 GtkWidget *item, *image;
464 type = find_phone_type (details);
468 tmp = g_strdup_printf ("Call %s (%s)",
469 folks_phone_field_details_get_normalised (details),
474 tmp = g_strdup_printf ("Call %s",
475 folks_phone_field_details_get_normalised (details));
478 item = gtk_image_menu_item_new_with_mnemonic (tmp);
481 g_signal_connect_data (item, "activate",
482 G_CALLBACK (call_phone_number_cb), g_object_ref (details),
483 (GClosureNotify) g_object_unref, 0);
485 gtk_widget_set_sensitive (item, sensitive);
487 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL,
489 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
490 gtk_widget_show (image);
492 gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
493 gtk_widget_show (item);
497 /* return a list of TpContact supporting the blocking iface */
499 get_contacts_supporting_blocking (FolksIndividual *individual)
503 GList *result = NULL;
505 personas = folks_individual_get_personas (individual);
507 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
508 while (gee_iterator_next (iter))
510 TpfPersona *persona = gee_iterator_get (iter);
514 if (!TPF_IS_PERSONA (persona))
517 contact = tpf_persona_get_contact (persona);
521 conn = tp_contact_get_connection (contact);
523 if (tp_proxy_has_interface_by_id (conn,
524 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
525 result = g_list_prepend (result, contact);
528 g_clear_object (&iter);
539 static GotAvatarCtx *
540 got_avatar_ctx_new (gboolean blocked,
543 GotAvatarCtx *ctx = g_slice_new0 (GotAvatarCtx);
545 ctx->blocked = blocked;
546 ctx->parent = parent != NULL ? g_object_ref (parent) : NULL;
551 got_avatar_ctx_free (GotAvatarCtx *ctx)
553 g_clear_object (&ctx->parent);
554 g_slice_free (GotAvatarCtx, ctx);
558 got_avatar (GObject *source_object,
559 GAsyncResult *result,
562 FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
563 GotAvatarCtx *ctx = user_data;
565 GError *error = NULL;
566 gboolean abusive = FALSE;
567 EmpathyIndividualManager *manager;
569 avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
574 DEBUG ("Could not get avatar: %s", error->message);
575 g_error_free (error);
579 /* confirm the user really wishes to block the contact */
580 if (!empathy_block_individual_dialog_show (GTK_WINDOW (ctx->parent),
581 individual, avatar, &abusive))
585 manager = empathy_individual_manager_dup_singleton ();
587 empathy_individual_manager_set_blocked (manager, individual,
588 ctx->blocked, abusive);
590 g_object_unref (manager);
593 g_clear_object (&avatar);
594 got_avatar_ctx_free (ctx);
598 empathy_individual_block_menu_item_toggled (GtkCheckMenuItem *item,
599 FolksIndividual *individual)
605 /* @item may be destroyed while the async call is running to get the things
606 * we need from it right now. */
607 blocked = gtk_check_menu_item_get_active (item);
609 parent = g_object_get_data (
610 G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
613 ctx = got_avatar_ctx_new (blocked, parent);
615 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
616 48, 48, NULL, got_avatar, ctx);
620 update_block_menu_item (GtkWidget *item,
621 FolksIndividual *individual)
624 gboolean is_blocked = TRUE;
626 contacts = get_contacts_supporting_blocking (individual);
628 if (contacts == NULL)
631 /* Check the menu item if all his personas are blocked */
632 for (l = contacts; l != NULL; l = g_list_next (l))
634 TpContact *contact = l->data;
636 if (!tp_contact_is_blocked (contact))
643 g_signal_handlers_block_by_func (item,
644 empathy_individual_block_menu_item_toggled, individual);
646 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), is_blocked);
648 g_signal_handlers_unblock_by_func (item,
649 empathy_individual_block_menu_item_toggled, individual);
651 g_list_free (contacts);
655 contact_blocked_changed_cb (TpContact *contact,
659 FolksIndividual *individual;
661 individual = g_object_get_data (G_OBJECT (item), "individual");
663 update_block_menu_item (item, individual);
667 empathy_individiual_block_menu_item_new (FolksIndividual *individual)
672 contacts = get_contacts_supporting_blocking (individual);
674 /* Can't block, no persona supports blocking */
675 if (contacts == NULL)
678 item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
680 g_object_set_data_full (G_OBJECT (item), "individual",
681 g_object_ref (individual), g_object_unref);
683 for (l = contacts; l != NULL; l = g_list_next (l))
685 TpContact *contact = l->data;
687 tp_g_signal_connect_object (contact, "notify::is-blocked",
688 G_CALLBACK (contact_blocked_changed_cb), item, 0);
691 g_signal_connect (item, "toggled",
692 G_CALLBACK (empathy_individual_block_menu_item_toggled), individual);
694 update_block_menu_item (item, individual);
696 g_list_free (contacts);
702 constructed (GObject *object)
704 EmpathyIndividualMenu *self = (EmpathyIndividualMenu *) object;
705 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
708 FolksIndividual *individual;
709 EmpathyIndividualFeatureFlags features;
712 shell = GTK_MENU_SHELL (object);
713 individual = priv->individual;
714 features = priv->features;
717 if (features & EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT)
719 item = empathy_individual_add_menu_item_new (self, individual);
722 gtk_menu_shell_append (GTK_MENU_SHELL (shell), item);
723 gtk_widget_show (item);
728 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
730 item = empathy_individual_chat_menu_item_new (individual);
733 gtk_menu_shell_append (shell, item);
734 gtk_widget_show (item);
739 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
741 item = empathy_individual_sms_menu_item_new (individual);
744 gtk_menu_shell_append (shell, item);
745 gtk_widget_show (item);
749 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
752 item = empathy_individual_audio_call_menu_item_new (individual);
753 gtk_menu_shell_append (shell, item);
754 gtk_widget_show (item);
757 item = empathy_individual_video_call_menu_item_new (individual);
758 gtk_menu_shell_append (shell, item);
759 gtk_widget_show (item);
762 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE)
763 add_phone_numbers (self);
766 item = empathy_individual_invite_menu_item_new (individual, NULL);
767 gtk_menu_shell_append (shell, item);
768 gtk_widget_show (item);
771 item = empathy_individual_file_transfer_menu_item_new (individual);
772 gtk_menu_shell_append (shell, item);
773 gtk_widget_show (item);
775 /* Share my desktop */
776 /* FIXME we should add the "Share my desktop" menu item if Vino is
777 a registered handler in MC5 */
778 item = empathy_individual_share_my_desktop_menu_item_new (individual);
779 gtk_menu_shell_append (shell, item);
780 gtk_widget_show (item);
782 /* Menu items to target specific contacts */
783 individual_menu_add_personas (GTK_MENU_SHELL (object), individual, features);
786 if (features & (EMPATHY_INDIVIDUAL_FEATURE_EDIT |
787 EMPATHY_INDIVIDUAL_FEATURE_INFO |
788 EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE |
789 EMPATHY_INDIVIDUAL_FEATURE_LINK))
791 item = gtk_separator_menu_item_new ();
792 gtk_menu_shell_append (shell, item);
793 gtk_widget_show (item);
797 if (features & EMPATHY_INDIVIDUAL_FEATURE_EDIT)
799 item = empathy_individual_edit_menu_item_new (individual);
800 gtk_menu_shell_append (shell, item);
801 gtk_widget_show (item);
805 if (features & EMPATHY_INDIVIDUAL_FEATURE_LINK)
807 item = empathy_individual_link_menu_item_new (individual);
808 gtk_menu_shell_append (shell, item);
810 g_signal_connect_swapped (item, "activate",
811 (GCallback) individual_link_menu_item_activate_cb, object);
813 gtk_widget_show (item);
817 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
819 item = empathy_individual_log_menu_item_new (individual);
820 gtk_menu_shell_append (shell, item);
821 gtk_widget_show (item);
825 if (features & EMPATHY_INDIVIDUAL_FEATURE_INFO)
827 item = empathy_individual_info_menu_item_new (individual);
828 gtk_menu_shell_append (shell, item);
829 gtk_widget_show (item);
832 /* Favorite checkbox */
833 if (features & EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE)
835 item = empathy_individual_favourite_menu_item_new (individual);
836 gtk_menu_shell_append (shell, item);
837 gtk_widget_show (item);
840 /* Separator & Block */
841 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
842 (item = empathy_individiual_block_menu_item_new (individual)) != NULL) {
845 sep = gtk_separator_menu_item_new ();
846 gtk_menu_shell_append (shell, sep);
847 gtk_widget_show (sep);
849 gtk_menu_shell_append (shell, item);
850 gtk_widget_show (item);
855 get_property (GObject *object,
860 EmpathyIndividualMenuPriv *priv;
862 priv = GET_PRIV (object);
866 case PROP_INDIVIDUAL:
867 g_value_set_object (value, priv->individual);
870 g_value_set_flags (value, priv->features);
873 g_value_set_object (value, priv->store);
876 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
882 set_property (GObject *object,
887 EmpathyIndividualMenuPriv *priv;
889 priv = GET_PRIV (object);
893 case PROP_INDIVIDUAL:
894 priv->individual = g_value_dup_object (value);
897 priv->features = g_value_get_flags (value);
900 priv->store = g_value_dup_object (value); /* read only */
903 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
909 dispose (GObject *object)
911 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
913 tp_clear_object (&priv->individual);
914 tp_clear_object (&priv->store);
916 G_OBJECT_CLASS (empathy_individual_menu_parent_class)->dispose (object);
920 empathy_individual_menu_class_init (EmpathyIndividualMenuClass *klass)
922 GObjectClass *object_class = G_OBJECT_CLASS (klass);
924 object_class->constructed = constructed;
925 object_class->get_property = get_property;
926 object_class->set_property = set_property;
927 object_class->dispose = dispose;
930 * EmpathyIndividualMenu:individual:
932 * The #FolksIndividual the menu is for.
934 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
935 g_param_spec_object ("individual",
937 "The #FolksIndividual the menu is for.",
938 FOLKS_TYPE_INDIVIDUAL,
939 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
942 * EmpathyIndividualMenu:features:
944 * A set of feature flags controlling which entries are shown.
946 g_object_class_install_property (object_class, PROP_FEATURES,
947 g_param_spec_flags ("features",
949 "A set of feature flags controlling which entries are shown.",
950 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS,
951 EMPATHY_INDIVIDUAL_FEATURE_NONE,
952 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
954 g_object_class_install_property (object_class, PROP_STORE,
955 g_param_spec_object ("store",
957 "The EmpathyIndividualStore to use to get contact owner",
958 EMPATHY_TYPE_INDIVIDUAL_STORE,
959 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
961 signals[SIGNAL_LINK_CONTACTS_ACTIVATED] =
962 g_signal_new ("link-contacts-activated", G_OBJECT_CLASS_TYPE (klass),
963 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
964 g_cclosure_marshal_generic,
965 G_TYPE_NONE, 1, EMPATHY_TYPE_LINKING_DIALOG);
967 g_type_class_add_private (object_class, sizeof (EmpathyIndividualMenuPriv));
971 empathy_individual_menu_new (FolksIndividual *individual,
972 EmpathyIndividualFeatureFlags features,
973 EmpathyIndividualStore *store)
975 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
976 g_return_val_if_fail (store == NULL ||
977 EMPATHY_IS_INDIVIDUAL_STORE (store), NULL);
978 g_return_val_if_fail (features != EMPATHY_INDIVIDUAL_FEATURE_NONE, NULL);
980 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU,
981 "individual", individual,
982 "features", features,
987 /* Like menu_item_set_first_contact(), but always operates upon the given
988 * contact. If the contact is non-NULL, it is assumed that the menu entry should
991 menu_item_set_contact (GtkWidget *item,
992 EmpathyContact *contact,
993 GCallback activate_callback,
994 EmpathyActionType action_type)
996 gboolean can_do_action = FALSE;
999 can_do_action = empathy_contact_can_do_action (contact, action_type);
1000 gtk_widget_set_sensitive (item, can_do_action);
1002 if (can_do_action == TRUE)
1004 /* We want to make sure that the EmpathyContact stays alive while the
1005 * signal is connected. */
1006 g_signal_connect_data (item, "activate", G_CALLBACK (activate_callback),
1007 g_object_ref (contact), (GClosureNotify) g_object_unref, 0);
1010 return can_do_action;
1014 * Set the given menu @item to call @activate_callback using the TpContact
1015 * (associated with @individual) with the highest availability who is also valid
1016 * whenever @item is activated.
1018 * @action_type is the type of action performed by the menu entry; this is used
1019 * so that only contacts which can perform that action (e.g. are capable of
1020 * receiving video calls) are selected, as appropriate.
1023 menu_item_set_first_contact (GtkWidget *item,
1024 FolksIndividual *individual,
1025 GCallback activate_callback,
1026 EmpathyActionType action_type)
1028 EmpathyContact *best_contact;
1030 best_contact = empathy_contact_dup_best_for_action (individual, action_type);
1031 menu_item_set_contact (item, best_contact, G_CALLBACK (activate_callback),
1033 tp_clear_object (&best_contact);
1039 empathy_individual_chat_menu_item_activated (GtkMenuItem *item,
1040 EmpathyContact *contact)
1042 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1044 empathy_chat_with_contact (contact, empathy_get_current_action_time ());
1048 empathy_individual_chat_menu_item_new (FolksIndividual *individual)
1053 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1054 empathy_folks_individual_contains_contact (individual), NULL);
1056 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
1057 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
1058 GTK_ICON_SIZE_MENU);
1059 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1060 gtk_widget_show (image);
1062 menu_item_set_first_contact (item, individual,
1063 G_CALLBACK (empathy_individual_chat_menu_item_activated),
1064 EMPATHY_ACTION_CHAT);
1070 empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
1071 EmpathyContact *contact)
1073 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1075 empathy_sms_contact_id (
1076 empathy_contact_get_account (contact),
1077 empathy_contact_get_id (contact),
1078 empathy_get_current_action_time (),
1083 empathy_individual_sms_menu_item_new (FolksIndividual *individual)
1088 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1089 empathy_folks_individual_contains_contact (individual), NULL);
1091 item = gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
1092 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
1093 GTK_ICON_SIZE_MENU);
1094 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1095 gtk_widget_show (image);
1097 menu_item_set_first_contact (item, individual,
1098 G_CALLBACK (empathy_individual_sms_menu_item_activated),
1099 EMPATHY_ACTION_SMS);
1105 empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item,
1106 EmpathyContact *contact)
1108 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1110 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1111 empathy_contact_get_account (contact),
1113 empathy_get_current_action_time ());
1117 empathy_individual_audio_call_menu_item_new (FolksIndividual *individual)
1122 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1124 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
1125 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP, GTK_ICON_SIZE_MENU);
1126 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1127 gtk_widget_show (image);
1129 menu_item_set_first_contact (item, individual,
1130 G_CALLBACK (empathy_individual_audio_call_menu_item_activated),
1131 EMPATHY_ACTION_AUDIO_CALL);
1137 empathy_individual_video_call_menu_item_activated (GtkMenuItem *item,
1138 EmpathyContact *contact)
1140 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1142 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1143 empathy_contact_get_account (contact),
1145 empathy_get_current_action_time ());
1149 empathy_individual_video_call_menu_item_new (FolksIndividual *individual)
1153 EmpathyCameraMonitor *monitor;
1155 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1157 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
1158 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
1159 GTK_ICON_SIZE_MENU);
1160 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1161 gtk_widget_show (image);
1163 menu_item_set_first_contact (item, individual,
1164 G_CALLBACK (empathy_individual_video_call_menu_item_activated),
1165 EMPATHY_ACTION_VIDEO_CALL);
1167 /* Only follow available cameras if the contact can do Video calls */
1168 if (gtk_widget_get_sensitive (item))
1170 monitor = empathy_camera_monitor_dup_singleton ();
1171 g_object_set_data_full (G_OBJECT (item),
1172 "monitor", monitor, g_object_unref);
1173 g_object_bind_property (monitor, "available", item, "sensitive",
1174 G_BINDING_SYNC_CREATE);
1181 empathy_individual_log_menu_item_activated (GtkMenuItem *item,
1182 EmpathyContact *contact)
1184 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1186 empathy_log_window_show (empathy_contact_get_account (contact),
1187 empathy_contact_get_id (contact), FALSE, NULL);
1191 empathy_individual_log_menu_item_new (FolksIndividual *individual)
1196 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1198 item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
1199 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG, GTK_ICON_SIZE_MENU);
1200 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1201 gtk_widget_show (image);
1203 menu_item_set_first_contact (item, individual,
1204 G_CALLBACK (empathy_individual_log_menu_item_activated),
1205 EMPATHY_ACTION_VIEW_LOGS);
1211 empathy_individual_file_transfer_menu_item_activated (GtkMenuItem *item,
1212 EmpathyContact *contact)
1214 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1216 empathy_send_file_with_file_chooser (contact);
1220 empathy_individual_file_transfer_menu_item_new (FolksIndividual *individual)
1225 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1227 item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
1228 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
1229 GTK_ICON_SIZE_MENU);
1230 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1231 gtk_widget_show (image);
1233 menu_item_set_first_contact (item, individual,
1234 G_CALLBACK (empathy_individual_file_transfer_menu_item_activated),
1235 EMPATHY_ACTION_SEND_FILE);
1241 empathy_individual_share_my_desktop_menu_item_activated (GtkMenuItem *item,
1242 EmpathyContact *contact)
1244 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1246 empathy_share_my_desktop_share_with_contact (contact);
1250 empathy_individual_share_my_desktop_menu_item_new (FolksIndividual *individual)
1255 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1257 item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
1258 image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU);
1259 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1260 gtk_widget_show (image);
1262 menu_item_set_first_contact (item, individual,
1263 G_CALLBACK (empathy_individual_share_my_desktop_menu_item_activated),
1264 EMPATHY_ACTION_SHARE_MY_DESKTOP);
1270 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
1271 FolksIndividual *individual)
1273 folks_favourite_details_set_is_favourite (
1274 FOLKS_FAVOURITE_DETAILS (individual),
1275 gtk_check_menu_item_get_active (item));
1279 empathy_individual_favourite_menu_item_new (FolksIndividual *individual)
1283 item = gtk_check_menu_item_new_with_label (_("Favorite"));
1285 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1286 folks_favourite_details_get_is_favourite (
1287 FOLKS_FAVOURITE_DETAILS (individual)));
1289 g_signal_connect (item, "toggled",
1290 G_CALLBACK (favourite_menu_item_toggled_cb), individual);
1296 show_gnome_contacts_error_dialog (void)
1300 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
1301 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1302 _("gnome-contacts not installed"));
1304 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1305 _("Please install gnome-contacts to access contacts details."));
1307 g_signal_connect_swapped (dialog, "response",
1308 G_CALLBACK (gtk_widget_destroy), dialog);
1310 gtk_widget_show (dialog);
1314 start_gnome_contacts (FolksIndividual *individual,
1315 gboolean try_installing);
1318 install_gnome_contacts_cb (GObject *source,
1319 GAsyncResult *result,
1322 FolksIndividual *individual = user_data;
1323 GError *error = NULL;
1325 if (!empathy_pkg_kit_install_packages_finish (result, &error))
1327 DEBUG ("Failed to install gnome-contacts: %s", error->message);
1328 g_error_free (error);
1330 show_gnome_contacts_error_dialog ();
1334 DEBUG ("gnome-contacts installed");
1336 start_gnome_contacts (individual, FALSE);
1339 g_object_unref (individual);
1343 start_gnome_contacts (FolksIndividual *individual,
1344 gboolean try_installing)
1346 GDesktopAppInfo *desktop_info;
1349 GError *error = NULL;
1350 GdkAppLaunchContext *context = NULL;
1351 GdkDisplay *display;
1353 /* Start gnome-contacts */
1354 display = gdk_display_get_default ();
1355 context = gdk_display_get_app_launch_context (display);
1357 desktop_info = g_desktop_app_info_new ("gnome-contacts.desktop");
1358 if (desktop_info == NULL)
1362 const gchar *packages[] = { "gnome-contacts", NULL };
1364 DEBUG ("gnome-contacts not installed; try to install it");
1366 empathy_pkg_kit_install_packages_async (0, packages, NULL,
1367 NULL, install_gnome_contacts_cb, g_object_ref (individual));
1371 show_gnome_contacts_error_dialog ();
1377 /* glib doesn't have API to start a desktop file with args... (#637875) */
1378 cmd = g_strdup_printf ("%s -i %s", g_app_info_get_commandline (
1379 (GAppInfo *) desktop_info), folks_individual_get_id (individual));
1381 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1382 if (app_info == NULL)
1384 DEBUG ("Failed to create app_info: %s", error->message);
1385 g_error_free (error);
1389 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1392 g_critical ("Failed to start gnome-contacts: %s", error->message);
1393 g_error_free (error);
1396 g_object_unref (desktop_info);
1397 g_object_unref (app_info);
1401 individual_info_menu_item_activate_cb (FolksIndividual *individual)
1403 start_gnome_contacts (individual, TRUE);
1407 empathy_individual_info_menu_item_new (FolksIndividual *individual)
1412 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1413 g_return_val_if_fail (empathy_folks_individual_contains_contact (individual),
1416 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
1417 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
1418 GTK_ICON_SIZE_MENU);
1419 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1420 gtk_widget_show (image);
1422 g_signal_connect (item, "activate",
1423 G_CALLBACK (individual_info_menu_item_activate_cb),
1430 individual_edit_menu_item_activate_cb (FolksIndividual *individual)
1432 empathy_individual_edit_dialog_show (individual, NULL);
1436 empathy_individual_edit_menu_item_new (FolksIndividual *individual)
1438 EmpathyIndividualManager *manager;
1441 gboolean enable = FALSE;
1442 EmpathyContact *contact;
1444 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1446 contact = empathy_contact_dup_from_folks_individual (individual);
1448 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1450 if (empathy_individual_manager_initialized ())
1452 TpConnection *connection;
1454 manager = empathy_individual_manager_dup_singleton ();
1455 connection = empathy_contact_get_connection (contact);
1457 enable = (empathy_connection_can_alias_personas (connection,
1459 empathy_connection_can_group_personas (connection, individual));
1461 g_object_unref (manager);
1464 item = gtk_image_menu_item_new_with_mnemonic (
1465 C_("Edit individual (contextual menu)", "_Edit"));
1466 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1467 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1468 gtk_widget_show (image);
1470 gtk_widget_set_sensitive (item, enable);
1472 g_signal_connect_swapped (item, "activate",
1473 G_CALLBACK (individual_edit_menu_item_activate_cb), individual);
1475 g_object_unref (contact);
1481 empathy_individual_link_menu_item_new (FolksIndividual *individual)
1484 /*GtkWidget *image;*/
1486 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1488 item = gtk_image_menu_item_new_with_mnemonic (
1489 /* Translators: this is a verb meaning "to connect two contacts together
1490 * to form a meta-contact". */
1491 C_("Link individual (contextual menu)", "_Link Contacts…"));
1493 /*image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1494 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1495 gtk_widget_show (image);*/
1497 /* Only allow trusted Individuals to be linked */
1498 gtk_widget_set_sensitive (item,
1499 folks_individual_get_trust_level (individual) ==
1500 FOLKS_TRUST_LEVEL_PERSONAS);
1507 FolksIndividual *individual;
1508 EmpathyContact *contact;
1509 EmpathyChatroom *chatroom;
1512 static RoomSubMenuData *
1513 room_sub_menu_data_new (FolksIndividual *individual,
1514 EmpathyContact *contact,
1515 EmpathyChatroom *chatroom)
1517 RoomSubMenuData *data;
1519 data = g_slice_new0 (RoomSubMenuData);
1520 if (individual != NULL)
1521 data->individual = g_object_ref (individual);
1522 if (contact != NULL)
1523 data->contact = g_object_ref (contact);
1524 data->chatroom = g_object_ref (chatroom);
1530 room_sub_menu_data_free (RoomSubMenuData *data)
1532 tp_clear_object (&data->individual);
1533 tp_clear_object (&data->contact);
1534 g_object_unref (data->chatroom);
1535 g_slice_free (RoomSubMenuData, data);
1539 room_sub_menu_activate_cb (GtkWidget *item,
1540 RoomSubMenuData *data)
1542 EmpathyTpChat *chat;
1543 EmpathyChatroomManager *mgr;
1544 EmpathyContact *contact = NULL;
1546 chat = empathy_chatroom_get_tp_chat (data->chatroom);
1549 /* channel was invalidated. Ignoring */
1553 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1555 if (data->contact != NULL)
1556 contact = g_object_ref (data->contact);
1562 /* find the first of this Individual's contacts who can join this room */
1563 personas = folks_individual_get_personas (data->individual);
1565 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1566 while (gee_iterator_next (iter) && (contact == NULL))
1568 TpfPersona *persona = gee_iterator_get (iter);
1569 TpContact *tp_contact;
1572 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1574 tp_contact = tpf_persona_get_contact (persona);
1575 if (tp_contact != NULL)
1577 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1579 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1580 empathy_contact_get_account (contact));
1582 if (g_list_find (rooms, data->chatroom) == NULL)
1583 g_clear_object (&contact);
1585 /* if contact != NULL here, we've found our match */
1587 g_list_free (rooms);
1590 g_clear_object (&persona);
1592 g_clear_object (&iter);
1595 g_object_unref (mgr);
1597 if (contact == NULL)
1599 /* contact disappeared. Ignoring */
1603 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1605 /* send invitation */
1606 empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat),
1607 contact, _("Inviting you to this room"));
1610 g_object_unref (contact);
1614 create_room_sub_menu (FolksIndividual *individual,
1615 EmpathyContact *contact,
1616 EmpathyChatroom *chatroom)
1619 RoomSubMenuData *data;
1621 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
1622 data = room_sub_menu_data_new (individual, contact, chatroom);
1623 g_signal_connect_data (item, "activate",
1624 G_CALLBACK (room_sub_menu_activate_cb), data,
1625 (GClosureNotify) room_sub_menu_data_free, 0);
1631 empathy_individual_invite_menu_item_new (FolksIndividual *individual,
1632 EmpathyContact *contact)
1636 GtkWidget *room_item;
1637 EmpathyChatroomManager *mgr;
1638 GList *rooms = NULL;
1639 GList *names = NULL;
1641 GtkWidget *submenu = NULL;
1642 /* map of chat room names to their objects; just a utility to remove
1643 * duplicates and to make construction of the alphabetized list easier */
1644 GHashTable *name_room_map;
1646 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) ||
1647 EMPATHY_IS_CONTACT (contact),
1650 name_room_map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
1653 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
1654 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
1655 GTK_ICON_SIZE_MENU);
1656 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1658 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1660 if (contact != NULL)
1662 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1663 empathy_contact_get_account (contact));
1670 /* find the first of this Individual's contacts who can join this room */
1671 personas = folks_individual_get_personas (individual);
1672 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1673 while (gee_iterator_next (iter))
1675 TpfPersona *persona = gee_iterator_get (iter);
1677 TpContact *tp_contact;
1678 EmpathyContact *contact_cur;
1680 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1682 tp_contact = tpf_persona_get_contact (persona);
1683 if (tp_contact != NULL)
1685 contact_cur = empathy_contact_dup_from_tp_contact (
1688 rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
1689 empathy_contact_get_account (contact_cur));
1690 rooms = g_list_concat (rooms, rooms_cur);
1692 g_object_unref (contact_cur);
1695 g_clear_object (&persona);
1697 g_clear_object (&iter);
1700 /* alphabetize the rooms */
1701 for (l = rooms; l != NULL; l = g_list_next (l))
1703 EmpathyChatroom *chatroom = l->data;
1706 if (empathy_chatroom_get_tp_chat (chatroom) != NULL)
1710 name = empathy_chatroom_get_name (chatroom);
1711 existed = (g_hash_table_lookup (name_room_map, name) != NULL);
1712 g_hash_table_insert (name_room_map, (gpointer) name,
1713 g_object_ref (chatroom));
1715 /* this will take care of duplicates in rooms */
1718 names = g_list_insert_sorted (names, (gpointer) name,
1719 (GCompareFunc) g_strcmp0);
1724 for (l = names; l != NULL; l = g_list_next (l))
1726 const gchar *name = l->data;
1727 EmpathyChatroom *chatroom;
1729 if (G_UNLIKELY (submenu == NULL))
1730 submenu = gtk_menu_new ();
1732 chatroom = g_hash_table_lookup (name_room_map, name);
1733 room_item = create_room_sub_menu (individual, contact, chatroom);
1734 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
1735 gtk_widget_show (room_item);
1739 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1741 gtk_widget_set_sensitive (item, FALSE);
1743 gtk_widget_show (image);
1745 g_hash_table_unref (name_room_map);
1746 g_object_unref (mgr);
1747 g_list_free (names);
1748 g_list_free (rooms);
1754 add_menu_item_activated (GtkMenuItem *item,
1755 TpContact *tp_contact)
1757 GtkWidget *toplevel;
1758 EmpathyContact *contact;
1760 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
1761 if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel))
1764 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1766 empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
1769 g_object_unref (contact);
1773 empathy_individual_add_menu_item_new (EmpathyIndividualMenu *self,
1774 FolksIndividual *individual)
1776 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
1777 GtkWidget *item, *image;
1780 TpContact *to_add = NULL;
1782 /* find the first of this Individual's personas which are not in our contact
1784 personas = folks_individual_get_personas (individual);
1785 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1786 while (gee_iterator_next (iter))
1788 TpfPersona *persona = gee_iterator_get (iter);
1792 if (!TPF_IS_PERSONA (persona))
1795 contact = tpf_persona_get_contact (persona);
1796 if (contact == NULL)
1799 /* be sure to use a not channel specific contact.
1800 * TODO: Ideally tp-glib should do this for us (fdo #42702)*/
1801 if (EMPATHY_IS_INDIVIDUAL_STORE_CHANNEL (priv->store))
1804 TpChannelGroupFlags flags;
1806 channel = empathy_individual_store_channel_get_channel (
1807 EMPATHY_INDIVIDUAL_STORE_CHANNEL (priv->store));
1809 flags = tp_channel_group_get_flags (channel);
1810 if ((flags & TP_CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES) != 0)
1812 /* Channel uses channel specific handles (thanks XMPP...) */
1813 contact = tp_channel_group_get_contact_owner (channel, contact);
1815 /* If we don't know the owner, we can't add the contact */
1816 if (contact == NULL)
1821 conn = tp_contact_get_connection (contact);
1825 /* No point to try adding a contact if the CM doesn't support it */
1826 if (!tp_connection_get_can_change_contact_list (conn))
1829 /* Can't add ourself */
1830 if (tp_connection_get_self_contact (conn) == contact)
1833 if (tp_contact_get_subscribe_state (contact) == TP_SUBSCRIPTION_STATE_YES)
1836 g_object_unref (persona);
1841 g_object_unref (persona);
1844 g_object_unref (iter);
1849 item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
1850 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
1851 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1853 g_signal_connect_data (item, "activate",
1854 G_CALLBACK (add_menu_item_activated),
1855 g_object_ref (to_add), (GClosureNotify) g_object_unref, 0);