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-pkg-kit.h>
43 #include "empathy-account-selector-dialog.h"
44 #include "empathy-individual-menu.h"
45 #include "empathy-images.h"
46 #include "empathy-log-window.h"
47 #include "empathy-contact-dialogs.h"
48 #include "empathy-gtk-enum-types.h"
49 #include "empathy-individual-dialogs.h"
50 #include "empathy-individual-edit-dialog.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-share-my-desktop.h"
53 #include "empathy-call-utils.h"
54 #include "empathy-individual-store-channel.h"
55 #include "empathy-individual-information-dialog.h"
57 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
58 #include <libempathy/empathy-debug.h>
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu)
63 FolksIndividual *individual; /* owned */
64 EmpathyIndividualFeatureFlags features;
65 EmpathyIndividualStore *store; /* may be NULL */
66 } EmpathyIndividualMenuPriv;
74 G_DEFINE_TYPE (EmpathyIndividualMenu, empathy_individual_menu, GTK_TYPE_MENU);
76 static GtkWidget * empathy_individual_chat_menu_item_new (
77 FolksIndividual *individual);
78 static GtkWidget * empathy_individual_sms_menu_item_new (
79 FolksIndividual *individual);
80 static GtkWidget * empathy_individual_log_menu_item_new (
81 FolksIndividual *individual);
82 static GtkWidget * empathy_individual_info_menu_item_new (
83 FolksIndividual *individual);
84 static GtkWidget * empathy_individual_edit_menu_item_new (
85 FolksIndividual *individual);
86 static GtkWidget * empathy_individual_invite_menu_item_new (
87 FolksIndividual *individual,
88 EmpathyContact *contact);
89 static GtkWidget * empathy_individual_file_transfer_menu_item_new (
90 FolksIndividual *individual);
91 static GtkWidget * empathy_individual_share_my_desktop_menu_item_new (
92 FolksIndividual *individual);
93 static GtkWidget * empathy_individual_favourite_menu_item_new (
94 FolksIndividual *individual);
95 static GtkWidget * empathy_individual_add_menu_item_new (
96 EmpathyIndividualMenu *self,
97 FolksIndividual *individual);
98 static GtkWidget * empathy_individiual_block_menu_item_new (
99 FolksIndividual *individual);
102 individual_menu_add_personas (GtkMenuShell *menu,
103 FolksIndividual *individual,
104 EmpathyIndividualFeatureFlags features)
109 guint persona_count = 0;
112 g_return_if_fail (GTK_IS_MENU (menu));
113 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
114 g_return_if_fail (empathy_folks_individual_contains_contact (individual));
116 personas = folks_individual_get_personas (individual);
117 /* we'll re-use this iterator throughout */
118 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
120 /* Make sure we've got enough valid entries for these menu items to add
122 while (gee_iterator_next (iter))
124 FolksPersona *persona = gee_iterator_get (iter);
125 if (empathy_folks_persona_is_interesting (persona))
128 g_clear_object (&persona);
131 /* return early if these entries would add nothing beyond the "quick" items */
132 if (persona_count <= 1)
135 /* add a separator before the list of personas */
136 item = gtk_separator_menu_item_new ();
137 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
138 gtk_widget_show (item);
140 for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
143 GtkWidget *contact_item;
144 GtkWidget *contact_submenu;
145 TpContact *tp_contact;
146 EmpathyContact *contact;
147 TpfPersona *persona = gee_iterator_get (iter);
149 FolksPersonaStore *store;
150 const gchar *account;
152 /* Individual containing only persona */
153 FolksIndividual *single_individual;
155 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
158 tp_contact = tpf_persona_get_contact (persona);
159 if (tp_contact == NULL)
162 contact = empathy_contact_dup_from_tp_contact (tp_contact);
163 single_individual = empathy_create_individual_from_tp_contact (
166 store = folks_persona_get_store (FOLKS_PERSONA (persona));
167 account = folks_persona_store_get_display_name (store);
169 /* Translators: this is used in the context menu for a contact. The first
170 * parameter is a contact ID (e.g. foo@jabber.org) and the second is one
171 * of the user's account IDs (e.g. me@hotmail.com). */
172 label = g_strdup_printf (_("%s (%s)"),
173 folks_persona_get_display_id (FOLKS_PERSONA (persona)), account);
175 contact_item = gtk_image_menu_item_new_with_label (label);
176 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (contact_item),
178 contact_submenu = gtk_menu_new ();
179 gtk_menu_item_set_submenu (GTK_MENU_ITEM (contact_item), contact_submenu);
180 image = gtk_image_new_from_icon_name (
181 empathy_icon_name_for_contact (contact), GTK_ICON_SIZE_MENU);
182 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (contact_item), image);
183 gtk_widget_show (image);
186 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
188 action = empathy_individual_chat_menu_item_new (single_individual);
189 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
190 gtk_widget_show (action);
194 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
196 action = empathy_individual_sms_menu_item_new (single_individual);
197 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
198 gtk_widget_show (action);
201 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
204 action = empathy_individual_audio_call_menu_item_new (
206 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
207 gtk_widget_show (action);
210 action = empathy_individual_video_call_menu_item_new (
212 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
213 gtk_widget_show (action);
217 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
219 action = empathy_individual_log_menu_item_new (single_individual);
220 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
221 gtk_widget_show (action);
225 action = empathy_individual_invite_menu_item_new (NULL, contact);
226 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
227 gtk_widget_show (action);
230 action = empathy_individual_file_transfer_menu_item_new (
232 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
233 gtk_widget_show (action);
235 /* Share my desktop */
236 action = empathy_individual_share_my_desktop_menu_item_new (
238 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
239 gtk_widget_show (action);
242 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
243 (item = empathy_individiual_block_menu_item_new (single_individual))
247 sep = gtk_separator_menu_item_new ();
248 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), sep);
249 gtk_widget_show (sep);
251 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), item);
252 gtk_widget_show (item);
255 gtk_menu_shell_append (GTK_MENU_SHELL (menu), contact_item);
256 gtk_widget_show (contact_item);
259 g_object_unref (contact);
260 g_object_unref (single_individual);
263 g_clear_object (&persona);
266 g_clear_object (&iter);
270 empathy_individual_menu_init (EmpathyIndividualMenu *self)
272 EmpathyIndividualMenuPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
273 EMPATHY_TYPE_INDIVIDUAL_MENU, EmpathyIndividualMenuPriv);
279 find_phone_accounts (void)
281 TpAccountManager *am;
285 am = tp_account_manager_dup ();
286 g_return_val_if_fail (am != NULL, NULL);
288 accounts = tp_account_manager_get_valid_accounts (am);
289 for (l = accounts; l != NULL; l = g_list_next (l))
291 TpAccount *account = l->data;
293 if (tp_account_get_connection_status (account, NULL) !=
294 TP_CONNECTION_STATUS_CONNECTED)
297 if (!empathy_account_has_uri_scheme_tel (account))
300 found = g_list_prepend (found, g_object_ref (account));
303 g_list_free (accounts);
310 has_phone_account (void)
315 accounts = find_phone_accounts ();
316 result = (accounts != NULL);
318 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
324 call_phone_number (FolksPhoneFieldDetails *details,
327 DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details));
329 empathy_call_new_with_streams (
330 folks_phone_field_details_get_normalised (details),
331 account, TRUE, FALSE, empathy_get_current_action_time ());
335 display_call_phone_dialog (FolksPhoneFieldDetails *details,
341 dialog = empathy_account_selector_dialog_new (accounts);
343 gtk_window_set_title (GTK_WINDOW (dialog),
344 _("Select account to use to place the call"));
346 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
347 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
348 _("Call"), GTK_RESPONSE_OK,
351 response = gtk_dialog_run (GTK_DIALOG (dialog));
353 if (response == GTK_RESPONSE_OK)
357 account = empathy_account_selector_dialog_dup_selected (
358 EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog));
362 call_phone_number (details, account);
364 g_object_unref (account);
368 gtk_widget_destroy (dialog);
372 call_phone_number_cb (GtkMenuItem *item,
373 FolksPhoneFieldDetails *details)
377 accounts = find_phone_accounts ();
378 if (accounts == NULL)
380 DEBUG ("No phone aware account connected; can't call");
382 else if (g_list_length (accounts) == 1)
384 call_phone_number (details, accounts->data);
388 /* Ask which account to use */
389 display_call_phone_dialog (details, accounts);
392 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
396 find_phone_type (FolksPhoneFieldDetails *details)
398 GeeCollection *types;
401 types = folks_abstract_field_details_get_parameter_values (
402 FOLKS_ABSTRACT_FIELD_DETAILS (details), "type");
407 iter = gee_iterable_iterator (GEE_ITERABLE (types));
408 while (gee_iterator_next (iter))
410 const gchar *type = gee_iterator_get (iter);
412 if (!tp_strdiff (type, "CELL"))
414 else if (!tp_strdiff (type, "WORK"))
416 else if (!tp_strdiff (type, "HOME"))
424 add_phone_numbers (EmpathyIndividualMenu *self)
426 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
431 all_numbers = folks_phone_details_get_phone_numbers (
432 FOLKS_PHONE_DETAILS (priv->individual));
434 sensitive = has_phone_account ();
436 iter = gee_iterable_iterator (GEE_ITERABLE (all_numbers));
437 while (gee_iterator_next (iter))
439 FolksPhoneFieldDetails *details = gee_iterator_get (iter);
440 GtkWidget *item, *image;
444 type = find_phone_type (details);
448 tmp = g_strdup_printf ("Call %s (%s)",
449 folks_phone_field_details_get_normalised (details),
454 tmp = g_strdup_printf ("Call %s",
455 folks_phone_field_details_get_normalised (details));
458 item = gtk_image_menu_item_new_with_mnemonic (tmp);
461 g_signal_connect_data (item, "activate",
462 G_CALLBACK (call_phone_number_cb), g_object_ref (details),
463 (GClosureNotify) g_object_unref, 0);
465 gtk_widget_set_sensitive (item, sensitive);
467 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL,
469 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
470 gtk_widget_show (image);
472 gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
473 gtk_widget_show (item);
477 /* return a list of TpContact supporting the blocking iface */
479 get_contacts_supporting_blocking (FolksIndividual *individual)
483 GList *result = NULL;
485 personas = folks_individual_get_personas (individual);
487 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
488 while (gee_iterator_next (iter))
490 TpfPersona *persona = gee_iterator_get (iter);
494 if (!TPF_IS_PERSONA (persona))
497 contact = tpf_persona_get_contact (persona);
501 conn = tp_contact_get_connection (contact);
503 if (tp_proxy_has_interface_by_id (conn,
504 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
505 result = g_list_prepend (result, contact);
508 g_clear_object (&iter);
519 static GotAvatarCtx *
520 got_avatar_ctx_new (gboolean blocked,
523 GotAvatarCtx *ctx = g_slice_new0 (GotAvatarCtx);
525 ctx->blocked = blocked;
526 ctx->parent = parent != NULL ? g_object_ref (parent) : NULL;
531 got_avatar_ctx_free (GotAvatarCtx *ctx)
533 g_clear_object (&ctx->parent);
534 g_slice_free (GotAvatarCtx, ctx);
538 got_avatar (GObject *source_object,
539 GAsyncResult *result,
542 FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
543 GotAvatarCtx *ctx = user_data;
545 GError *error = NULL;
546 gboolean abusive = FALSE;
547 EmpathyIndividualManager *manager;
549 avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
554 DEBUG ("Could not get avatar: %s", error->message);
555 g_error_free (error);
559 /* confirm the user really wishes to block the contact */
560 if (!empathy_block_individual_dialog_show (GTK_WINDOW (ctx->parent),
561 individual, avatar, &abusive))
565 manager = empathy_individual_manager_dup_singleton ();
567 empathy_individual_manager_set_blocked (manager, individual,
568 ctx->blocked, abusive);
570 g_object_unref (manager);
573 g_clear_object (&avatar);
574 got_avatar_ctx_free (ctx);
578 empathy_individual_block_menu_item_toggled (GtkCheckMenuItem *item,
579 FolksIndividual *individual)
585 /* @item may be destroyed while the async call is running to get the things
586 * we need from it right now. */
587 blocked = gtk_check_menu_item_get_active (item);
589 parent = g_object_get_data (
590 G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
593 ctx = got_avatar_ctx_new (blocked, parent);
595 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
596 48, 48, NULL, got_avatar, ctx);
600 update_block_menu_item (GtkWidget *item,
601 FolksIndividual *individual)
604 gboolean is_blocked = TRUE;
606 contacts = get_contacts_supporting_blocking (individual);
608 if (contacts == NULL)
611 /* Check the menu item if all his personas are blocked */
612 for (l = contacts; l != NULL; l = g_list_next (l))
614 TpContact *contact = l->data;
616 if (!tp_contact_is_blocked (contact))
623 g_signal_handlers_block_by_func (item,
624 empathy_individual_block_menu_item_toggled, individual);
626 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), is_blocked);
628 g_signal_handlers_unblock_by_func (item,
629 empathy_individual_block_menu_item_toggled, individual);
631 g_list_free (contacts);
635 contact_blocked_changed_cb (TpContact *contact,
639 FolksIndividual *individual;
641 individual = g_object_get_data (G_OBJECT (item), "individual");
643 update_block_menu_item (item, individual);
647 empathy_individiual_block_menu_item_new (FolksIndividual *individual)
652 contacts = get_contacts_supporting_blocking (individual);
654 /* Can't block, no persona supports blocking */
655 if (contacts == NULL)
658 item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
660 g_object_set_data_full (G_OBJECT (item), "individual",
661 g_object_ref (individual), g_object_unref);
663 for (l = contacts; l != NULL; l = g_list_next (l))
665 TpContact *contact = l->data;
667 tp_g_signal_connect_object (contact, "notify::is-blocked",
668 G_CALLBACK (contact_blocked_changed_cb), item, 0);
671 g_signal_connect (item, "toggled",
672 G_CALLBACK (empathy_individual_block_menu_item_toggled), individual);
674 update_block_menu_item (item, individual);
676 g_list_free (contacts);
682 constructed (GObject *object)
684 EmpathyIndividualMenu *self = (EmpathyIndividualMenu *) object;
685 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
688 FolksIndividual *individual;
689 EmpathyIndividualFeatureFlags features;
692 shell = GTK_MENU_SHELL (object);
693 individual = priv->individual;
694 features = priv->features;
697 if (features & EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT)
699 item = empathy_individual_add_menu_item_new (self, individual);
702 gtk_menu_shell_append (GTK_MENU_SHELL (shell), item);
703 gtk_widget_show (item);
708 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
710 item = empathy_individual_chat_menu_item_new (individual);
713 gtk_menu_shell_append (shell, item);
714 gtk_widget_show (item);
719 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
721 item = empathy_individual_sms_menu_item_new (individual);
724 gtk_menu_shell_append (shell, item);
725 gtk_widget_show (item);
729 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
732 item = empathy_individual_audio_call_menu_item_new (individual);
733 gtk_menu_shell_append (shell, item);
734 gtk_widget_show (item);
737 item = empathy_individual_video_call_menu_item_new (individual);
738 gtk_menu_shell_append (shell, item);
739 gtk_widget_show (item);
742 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE)
743 add_phone_numbers (self);
746 item = empathy_individual_invite_menu_item_new (individual, NULL);
747 gtk_menu_shell_append (shell, item);
748 gtk_widget_show (item);
751 item = empathy_individual_file_transfer_menu_item_new (individual);
752 gtk_menu_shell_append (shell, item);
753 gtk_widget_show (item);
755 /* Share my desktop */
756 /* FIXME we should add the "Share my desktop" menu item if Vino is
757 a registered handler in MC5 */
758 item = empathy_individual_share_my_desktop_menu_item_new (individual);
759 gtk_menu_shell_append (shell, item);
760 gtk_widget_show (item);
762 /* Menu items to target specific contacts */
763 individual_menu_add_personas (GTK_MENU_SHELL (object), individual, features);
766 if (features & (EMPATHY_INDIVIDUAL_FEATURE_EDIT |
767 EMPATHY_INDIVIDUAL_FEATURE_INFO |
768 EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE))
770 item = gtk_separator_menu_item_new ();
771 gtk_menu_shell_append (shell, item);
772 gtk_widget_show (item);
776 if (features & EMPATHY_INDIVIDUAL_FEATURE_EDIT)
778 item = empathy_individual_edit_menu_item_new (individual);
779 gtk_menu_shell_append (shell, item);
780 gtk_widget_show (item);
784 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
786 item = empathy_individual_log_menu_item_new (individual);
787 gtk_menu_shell_append (shell, item);
788 gtk_widget_show (item);
792 if (features & EMPATHY_INDIVIDUAL_FEATURE_INFO)
794 item = empathy_individual_info_menu_item_new (individual);
795 gtk_menu_shell_append (shell, item);
796 gtk_widget_show (item);
799 /* Favorite checkbox */
800 if (features & EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE)
802 item = empathy_individual_favourite_menu_item_new (individual);
803 gtk_menu_shell_append (shell, item);
804 gtk_widget_show (item);
807 /* Separator & Block */
808 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
809 (item = empathy_individiual_block_menu_item_new (individual)) != NULL) {
812 sep = gtk_separator_menu_item_new ();
813 gtk_menu_shell_append (shell, sep);
814 gtk_widget_show (sep);
816 gtk_menu_shell_append (shell, item);
817 gtk_widget_show (item);
822 get_property (GObject *object,
827 EmpathyIndividualMenuPriv *priv;
829 priv = GET_PRIV (object);
833 case PROP_INDIVIDUAL:
834 g_value_set_object (value, priv->individual);
837 g_value_set_flags (value, priv->features);
840 g_value_set_object (value, priv->store);
843 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
849 set_property (GObject *object,
854 EmpathyIndividualMenuPriv *priv;
856 priv = GET_PRIV (object);
860 case PROP_INDIVIDUAL:
861 priv->individual = g_value_dup_object (value);
864 priv->features = g_value_get_flags (value);
867 priv->store = g_value_dup_object (value); /* read only */
870 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
876 dispose (GObject *object)
878 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
880 tp_clear_object (&priv->individual);
881 tp_clear_object (&priv->store);
883 G_OBJECT_CLASS (empathy_individual_menu_parent_class)->dispose (object);
887 empathy_individual_menu_class_init (EmpathyIndividualMenuClass *klass)
889 GObjectClass *object_class = G_OBJECT_CLASS (klass);
891 object_class->constructed = constructed;
892 object_class->get_property = get_property;
893 object_class->set_property = set_property;
894 object_class->dispose = dispose;
897 * EmpathyIndividualMenu:individual:
899 * The #FolksIndividual the menu is for.
901 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
902 g_param_spec_object ("individual",
904 "The #FolksIndividual the menu is for.",
905 FOLKS_TYPE_INDIVIDUAL,
906 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
909 * EmpathyIndividualMenu:features:
911 * A set of feature flags controlling which entries are shown.
913 g_object_class_install_property (object_class, PROP_FEATURES,
914 g_param_spec_flags ("features",
916 "A set of feature flags controlling which entries are shown.",
917 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS,
918 EMPATHY_INDIVIDUAL_FEATURE_NONE,
919 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
921 g_object_class_install_property (object_class, PROP_STORE,
922 g_param_spec_object ("store",
924 "The EmpathyIndividualStore to use to get contact owner",
925 EMPATHY_TYPE_INDIVIDUAL_STORE,
926 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
928 g_type_class_add_private (object_class, sizeof (EmpathyIndividualMenuPriv));
932 empathy_individual_menu_new (FolksIndividual *individual,
933 EmpathyIndividualFeatureFlags features,
934 EmpathyIndividualStore *store)
936 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
937 g_return_val_if_fail (store == NULL ||
938 EMPATHY_IS_INDIVIDUAL_STORE (store), NULL);
939 g_return_val_if_fail (features != EMPATHY_INDIVIDUAL_FEATURE_NONE, NULL);
941 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU,
942 "individual", individual,
943 "features", features,
948 /* Like menu_item_set_first_contact(), but always operates upon the given
949 * contact. If the contact is non-NULL, it is assumed that the menu entry should
952 menu_item_set_contact (GtkWidget *item,
953 EmpathyContact *contact,
954 GCallback activate_callback,
955 EmpathyActionType action_type)
957 gboolean can_do_action = FALSE;
960 can_do_action = empathy_contact_can_do_action (contact, action_type);
961 gtk_widget_set_sensitive (item, can_do_action);
963 if (can_do_action == TRUE)
965 /* We want to make sure that the EmpathyContact stays alive while the
966 * signal is connected. */
967 g_signal_connect_data (item, "activate", G_CALLBACK (activate_callback),
968 g_object_ref (contact), (GClosureNotify) g_object_unref, 0);
971 return can_do_action;
975 * Set the given menu @item to call @activate_callback using the TpContact
976 * (associated with @individual) with the highest availability who is also valid
977 * whenever @item is activated.
979 * @action_type is the type of action performed by the menu entry; this is used
980 * so that only contacts which can perform that action (e.g. are capable of
981 * receiving video calls) are selected, as appropriate.
984 menu_item_set_first_contact (GtkWidget *item,
985 FolksIndividual *individual,
986 GCallback activate_callback,
987 EmpathyActionType action_type)
989 EmpathyContact *best_contact;
991 best_contact = empathy_contact_dup_best_for_action (individual, action_type);
992 menu_item_set_contact (item, best_contact, G_CALLBACK (activate_callback),
994 tp_clear_object (&best_contact);
1000 empathy_individual_chat_menu_item_activated (GtkMenuItem *item,
1001 EmpathyContact *contact)
1003 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1005 empathy_chat_with_contact (contact, empathy_get_current_action_time ());
1009 empathy_individual_chat_menu_item_new (FolksIndividual *individual)
1014 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1015 empathy_folks_individual_contains_contact (individual), NULL);
1017 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
1018 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
1019 GTK_ICON_SIZE_MENU);
1020 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1021 gtk_widget_show (image);
1023 menu_item_set_first_contact (item, individual,
1024 G_CALLBACK (empathy_individual_chat_menu_item_activated),
1025 EMPATHY_ACTION_CHAT);
1031 empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
1032 EmpathyContact *contact)
1034 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1036 empathy_sms_contact_id (
1037 empathy_contact_get_account (contact),
1038 empathy_contact_get_id (contact),
1039 empathy_get_current_action_time (),
1044 empathy_individual_sms_menu_item_new (FolksIndividual *individual)
1049 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1050 empathy_folks_individual_contains_contact (individual), NULL);
1052 item = gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
1053 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
1054 GTK_ICON_SIZE_MENU);
1055 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1056 gtk_widget_show (image);
1058 menu_item_set_first_contact (item, individual,
1059 G_CALLBACK (empathy_individual_sms_menu_item_activated),
1060 EMPATHY_ACTION_SMS);
1066 empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item,
1067 EmpathyContact *contact)
1069 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1071 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1072 empathy_contact_get_account (contact),
1074 empathy_get_current_action_time ());
1078 empathy_individual_audio_call_menu_item_new (FolksIndividual *individual)
1083 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1085 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
1086 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP, GTK_ICON_SIZE_MENU);
1087 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1088 gtk_widget_show (image);
1090 menu_item_set_first_contact (item, individual,
1091 G_CALLBACK (empathy_individual_audio_call_menu_item_activated),
1092 EMPATHY_ACTION_AUDIO_CALL);
1098 empathy_individual_video_call_menu_item_activated (GtkMenuItem *item,
1099 EmpathyContact *contact)
1101 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1103 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1104 empathy_contact_get_account (contact),
1106 empathy_get_current_action_time ());
1110 empathy_individual_video_call_menu_item_new (FolksIndividual *individual)
1114 EmpathyCameraMonitor *monitor;
1116 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1118 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
1119 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
1120 GTK_ICON_SIZE_MENU);
1121 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1122 gtk_widget_show (image);
1124 menu_item_set_first_contact (item, individual,
1125 G_CALLBACK (empathy_individual_video_call_menu_item_activated),
1126 EMPATHY_ACTION_VIDEO_CALL);
1128 /* Only follow available cameras if the contact can do Video calls */
1129 if (gtk_widget_get_sensitive (item))
1131 monitor = empathy_camera_monitor_dup_singleton ();
1132 g_object_set_data_full (G_OBJECT (item),
1133 "monitor", monitor, g_object_unref);
1134 g_object_bind_property (monitor, "available", item, "sensitive",
1135 G_BINDING_SYNC_CREATE);
1142 empathy_individual_log_menu_item_activated (GtkMenuItem *item,
1143 EmpathyContact *contact)
1145 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1147 empathy_log_window_show (empathy_contact_get_account (contact),
1148 empathy_contact_get_id (contact), FALSE, NULL);
1152 empathy_individual_log_menu_item_new (FolksIndividual *individual)
1157 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1159 item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
1160 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG, GTK_ICON_SIZE_MENU);
1161 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1162 gtk_widget_show (image);
1164 menu_item_set_first_contact (item, individual,
1165 G_CALLBACK (empathy_individual_log_menu_item_activated),
1166 EMPATHY_ACTION_VIEW_LOGS);
1172 empathy_individual_file_transfer_menu_item_activated (GtkMenuItem *item,
1173 EmpathyContact *contact)
1175 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1177 empathy_send_file_with_file_chooser (contact);
1181 empathy_individual_file_transfer_menu_item_new (FolksIndividual *individual)
1186 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1188 item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
1189 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
1190 GTK_ICON_SIZE_MENU);
1191 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1192 gtk_widget_show (image);
1194 menu_item_set_first_contact (item, individual,
1195 G_CALLBACK (empathy_individual_file_transfer_menu_item_activated),
1196 EMPATHY_ACTION_SEND_FILE);
1202 empathy_individual_share_my_desktop_menu_item_activated (GtkMenuItem *item,
1203 EmpathyContact *contact)
1205 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1207 empathy_share_my_desktop_share_with_contact (contact);
1211 empathy_individual_share_my_desktop_menu_item_new (FolksIndividual *individual)
1216 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1218 item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
1219 image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU);
1220 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1221 gtk_widget_show (image);
1223 menu_item_set_first_contact (item, individual,
1224 G_CALLBACK (empathy_individual_share_my_desktop_menu_item_activated),
1225 EMPATHY_ACTION_SHARE_MY_DESKTOP);
1231 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
1232 FolksIndividual *individual)
1234 folks_favourite_details_set_is_favourite (
1235 FOLKS_FAVOURITE_DETAILS (individual),
1236 gtk_check_menu_item_get_active (item));
1240 empathy_individual_favourite_menu_item_new (FolksIndividual *individual)
1244 item = gtk_check_menu_item_new_with_label (_("Favorite"));
1246 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1247 folks_favourite_details_get_is_favourite (
1248 FOLKS_FAVOURITE_DETAILS (individual)));
1250 g_signal_connect (item, "toggled",
1251 G_CALLBACK (favourite_menu_item_toggled_cb), individual);
1257 show_gnome_contacts_error_dialog (void)
1261 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
1262 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1263 _("gnome-contacts not installed"));
1265 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1266 _("Please install gnome-contacts to access contacts details."));
1268 g_signal_connect_swapped (dialog, "response",
1269 G_CALLBACK (gtk_widget_destroy), dialog);
1271 gtk_widget_show (dialog);
1275 start_gnome_contacts (FolksIndividual *individual,
1276 gboolean try_installing);
1279 install_gnome_contacts_cb (GObject *source,
1280 GAsyncResult *result,
1283 FolksIndividual *individual = user_data;
1284 GError *error = NULL;
1286 if (!empathy_pkg_kit_install_packages_finish (result, &error))
1288 DEBUG ("Failed to install gnome-contacts: %s", error->message);
1289 g_error_free (error);
1291 show_gnome_contacts_error_dialog ();
1295 DEBUG ("gnome-contacts installed");
1297 start_gnome_contacts (individual, FALSE);
1300 g_object_unref (individual);
1304 start_gnome_contacts (FolksIndividual *individual,
1305 gboolean try_installing)
1307 GDesktopAppInfo *desktop_info;
1310 GError *error = NULL;
1311 GdkAppLaunchContext *context = NULL;
1312 GdkDisplay *display;
1314 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
1316 /* Start gnome-contacts */
1317 display = gdk_display_get_default ();
1318 context = gdk_display_get_app_launch_context (display);
1320 desktop_info = g_desktop_app_info_new ("gnome-contacts.desktop");
1321 if (desktop_info == NULL)
1325 const gchar *packages[] = { "gnome-contacts", NULL };
1327 DEBUG ("gnome-contacts not installed; try to install it");
1329 empathy_pkg_kit_install_packages_async (0, packages, NULL,
1330 NULL, install_gnome_contacts_cb, g_object_ref (individual));
1334 show_gnome_contacts_error_dialog ();
1340 /* glib doesn't have API to start a desktop file with args... (#637875) */
1341 cmd = g_strdup_printf ("%s -i %s", g_app_info_get_commandline (
1342 (GAppInfo *) desktop_info), folks_individual_get_id (individual));
1344 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1345 if (app_info == NULL)
1347 DEBUG ("Failed to create app_info: %s", error->message);
1348 g_error_free (error);
1352 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1355 g_critical ("Failed to start gnome-contacts: %s", error->message);
1356 g_error_free (error);
1359 g_object_unref (desktop_info);
1360 g_object_unref (app_info);
1364 individual_info_menu_item_activate_cb (GtkMenuItem *item,
1365 FolksIndividual *individual)
1367 EmpathyIndividualManager *mgr;
1369 mgr = empathy_individual_manager_dup_singleton ();
1371 /* Only use gnome-contacts if that's a 'real' individual we got from
1372 * Folks (and so the individual manager knows about it). If not that's a
1373 * MUC contact and we use the simple dialog. */
1374 if (empathy_individual_manager_lookup_member (mgr,
1375 folks_individual_get_id (individual)) != NULL)
1377 start_gnome_contacts (individual, TRUE);
1381 empathy_individual_information_dialog_show (individual, NULL);
1384 g_object_unref (mgr);
1388 empathy_individual_info_menu_item_new (FolksIndividual *individual)
1393 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1394 g_return_val_if_fail (empathy_folks_individual_contains_contact (individual),
1397 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
1398 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
1399 GTK_ICON_SIZE_MENU);
1400 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1401 gtk_widget_show (image);
1403 g_signal_connect (item, "activate",
1404 G_CALLBACK (individual_info_menu_item_activate_cb),
1411 individual_edit_menu_item_activate_cb (FolksIndividual *individual)
1413 empathy_individual_edit_dialog_show (individual, NULL);
1417 empathy_individual_edit_menu_item_new (FolksIndividual *individual)
1419 EmpathyIndividualManager *manager;
1422 gboolean enable = FALSE;
1423 EmpathyContact *contact;
1425 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1427 contact = empathy_contact_dup_from_folks_individual (individual);
1429 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1431 if (empathy_individual_manager_initialized ())
1433 TpConnection *connection;
1435 manager = empathy_individual_manager_dup_singleton ();
1436 connection = empathy_contact_get_connection (contact);
1438 enable = (empathy_connection_can_alias_personas (connection,
1440 empathy_connection_can_group_personas (connection, individual));
1442 g_object_unref (manager);
1445 item = gtk_image_menu_item_new_with_mnemonic (
1446 C_("Edit individual (contextual menu)", "_Edit"));
1447 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1448 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1449 gtk_widget_show (image);
1451 gtk_widget_set_sensitive (item, enable);
1453 g_signal_connect_swapped (item, "activate",
1454 G_CALLBACK (individual_edit_menu_item_activate_cb), individual);
1456 g_object_unref (contact);
1463 FolksIndividual *individual;
1464 EmpathyContact *contact;
1465 EmpathyChatroom *chatroom;
1468 static RoomSubMenuData *
1469 room_sub_menu_data_new (FolksIndividual *individual,
1470 EmpathyContact *contact,
1471 EmpathyChatroom *chatroom)
1473 RoomSubMenuData *data;
1475 data = g_slice_new0 (RoomSubMenuData);
1476 if (individual != NULL)
1477 data->individual = g_object_ref (individual);
1478 if (contact != NULL)
1479 data->contact = g_object_ref (contact);
1480 data->chatroom = g_object_ref (chatroom);
1486 room_sub_menu_data_free (RoomSubMenuData *data)
1488 tp_clear_object (&data->individual);
1489 tp_clear_object (&data->contact);
1490 g_object_unref (data->chatroom);
1491 g_slice_free (RoomSubMenuData, data);
1495 room_sub_menu_activate_cb (GtkWidget *item,
1496 RoomSubMenuData *data)
1498 EmpathyTpChat *chat;
1499 EmpathyChatroomManager *mgr;
1500 EmpathyContact *contact = NULL;
1502 chat = empathy_chatroom_get_tp_chat (data->chatroom);
1505 /* channel was invalidated. Ignoring */
1509 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1511 if (data->contact != NULL)
1512 contact = g_object_ref (data->contact);
1518 /* find the first of this Individual's contacts who can join this room */
1519 personas = folks_individual_get_personas (data->individual);
1521 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1522 while (gee_iterator_next (iter) && (contact == NULL))
1524 TpfPersona *persona = gee_iterator_get (iter);
1525 TpContact *tp_contact;
1528 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1530 tp_contact = tpf_persona_get_contact (persona);
1531 if (tp_contact != NULL)
1533 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1535 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1536 empathy_contact_get_account (contact));
1538 if (g_list_find (rooms, data->chatroom) == NULL)
1539 g_clear_object (&contact);
1541 /* if contact != NULL here, we've found our match */
1543 g_list_free (rooms);
1546 g_clear_object (&persona);
1548 g_clear_object (&iter);
1551 g_object_unref (mgr);
1553 if (contact == NULL)
1555 /* contact disappeared. Ignoring */
1559 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1561 /* send invitation */
1562 empathy_tp_chat_add (chat, contact, _("Inviting you to this room"));
1565 g_object_unref (contact);
1569 create_room_sub_menu (FolksIndividual *individual,
1570 EmpathyContact *contact,
1571 EmpathyChatroom *chatroom)
1574 RoomSubMenuData *data;
1576 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
1577 data = room_sub_menu_data_new (individual, contact, chatroom);
1578 g_signal_connect_data (item, "activate",
1579 G_CALLBACK (room_sub_menu_activate_cb), data,
1580 (GClosureNotify) room_sub_menu_data_free, 0);
1586 empathy_individual_invite_menu_item_new (FolksIndividual *individual,
1587 EmpathyContact *contact)
1591 GtkWidget *room_item;
1592 EmpathyChatroomManager *mgr;
1593 GList *rooms = NULL;
1594 GList *names = NULL;
1596 GtkWidget *submenu = NULL;
1597 /* map of chat room names to their objects; just a utility to remove
1598 * duplicates and to make construction of the alphabetized list easier */
1599 GHashTable *name_room_map;
1601 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) ||
1602 EMPATHY_IS_CONTACT (contact),
1605 name_room_map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
1608 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
1609 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
1610 GTK_ICON_SIZE_MENU);
1611 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1613 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1615 if (contact != NULL)
1617 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1618 empathy_contact_get_account (contact));
1625 /* find the first of this Individual's contacts who can join this room */
1626 personas = folks_individual_get_personas (individual);
1627 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1628 while (gee_iterator_next (iter))
1630 TpfPersona *persona = gee_iterator_get (iter);
1632 TpContact *tp_contact;
1633 EmpathyContact *contact_cur;
1635 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1637 tp_contact = tpf_persona_get_contact (persona);
1638 if (tp_contact != NULL)
1640 contact_cur = empathy_contact_dup_from_tp_contact (
1643 rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
1644 empathy_contact_get_account (contact_cur));
1645 rooms = g_list_concat (rooms, rooms_cur);
1647 g_object_unref (contact_cur);
1650 g_clear_object (&persona);
1652 g_clear_object (&iter);
1655 /* alphabetize the rooms */
1656 for (l = rooms; l != NULL; l = g_list_next (l))
1658 EmpathyChatroom *chatroom = l->data;
1661 if (empathy_chatroom_get_tp_chat (chatroom) != NULL)
1665 name = empathy_chatroom_get_name (chatroom);
1666 existed = (g_hash_table_lookup (name_room_map, name) != NULL);
1667 g_hash_table_insert (name_room_map, (gpointer) name,
1668 g_object_ref (chatroom));
1670 /* this will take care of duplicates in rooms */
1673 names = g_list_insert_sorted (names, (gpointer) name,
1674 (GCompareFunc) g_strcmp0);
1679 for (l = names; l != NULL; l = g_list_next (l))
1681 const gchar *name = l->data;
1682 EmpathyChatroom *chatroom;
1684 if (G_UNLIKELY (submenu == NULL))
1685 submenu = gtk_menu_new ();
1687 chatroom = g_hash_table_lookup (name_room_map, name);
1688 room_item = create_room_sub_menu (individual, contact, chatroom);
1689 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
1690 gtk_widget_show (room_item);
1694 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1696 gtk_widget_set_sensitive (item, FALSE);
1698 gtk_widget_show (image);
1700 g_hash_table_unref (name_room_map);
1701 g_object_unref (mgr);
1702 g_list_free (names);
1703 g_list_free (rooms);
1709 add_menu_item_activated (GtkMenuItem *item,
1710 TpContact *tp_contact)
1712 GtkWidget *toplevel;
1713 EmpathyContact *contact;
1715 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
1716 if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel))
1719 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1721 empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
1724 g_object_unref (contact);
1728 empathy_individual_add_menu_item_new (EmpathyIndividualMenu *self,
1729 FolksIndividual *individual)
1731 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
1732 GtkWidget *item, *image;
1735 TpContact *to_add = NULL;
1737 /* find the first of this Individual's personas which are not in our contact
1739 personas = folks_individual_get_personas (individual);
1740 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1741 while (gee_iterator_next (iter))
1743 TpfPersona *persona = gee_iterator_get (iter);
1747 if (!TPF_IS_PERSONA (persona))
1750 contact = tpf_persona_get_contact (persona);
1751 if (contact == NULL)
1754 /* be sure to use a not channel specific contact.
1755 * TODO: Ideally tp-glib should do this for us (fdo #42702)*/
1756 if (EMPATHY_IS_INDIVIDUAL_STORE_CHANNEL (priv->store))
1759 TpChannelGroupFlags flags;
1761 channel = empathy_individual_store_channel_get_channel (
1762 EMPATHY_INDIVIDUAL_STORE_CHANNEL (priv->store));
1764 flags = tp_channel_group_get_flags (channel);
1765 if ((flags & TP_CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES) != 0)
1767 /* Channel uses channel specific handles (thanks XMPP...) */
1768 contact = tp_channel_group_get_contact_owner (channel, contact);
1770 /* If we don't know the owner, we can't add the contact */
1771 if (contact == NULL)
1776 conn = tp_contact_get_connection (contact);
1780 /* No point to try adding a contact if the CM doesn't support it */
1781 if (!tp_connection_get_can_change_contact_list (conn))
1784 /* Can't add ourself */
1785 if (tp_connection_get_self_contact (conn) == contact)
1788 if (tp_contact_get_subscribe_state (contact) == TP_SUBSCRIPTION_STATE_YES)
1791 g_object_unref (persona);
1796 g_object_unref (persona);
1799 g_object_unref (iter);
1804 item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
1805 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
1806 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1808 g_signal_connect_data (item, "activate",
1809 G_CALLBACK (add_menu_item_activated),
1810 g_object_ref (to_add), (GClosureNotify) g_object_unref, 0);