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_invite_menu_item_new (
95 FolksIndividual *individual,
96 EmpathyContact *contact);
97 static GtkWidget * empathy_individual_file_transfer_menu_item_new (
98 FolksIndividual *individual);
99 static GtkWidget * empathy_individual_share_my_desktop_menu_item_new (
100 FolksIndividual *individual);
101 static GtkWidget * empathy_individual_favourite_menu_item_new (
102 FolksIndividual *individual);
103 static GtkWidget * empathy_individual_add_menu_item_new (
104 EmpathyIndividualMenu *self,
105 FolksIndividual *individual);
106 static GtkWidget * empathy_individiual_block_menu_item_new (
107 FolksIndividual *individual);
110 individual_menu_add_personas (GtkMenuShell *menu,
111 FolksIndividual *individual,
112 EmpathyIndividualFeatureFlags features)
117 guint persona_count = 0;
120 g_return_if_fail (GTK_IS_MENU (menu));
121 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
122 g_return_if_fail (empathy_folks_individual_contains_contact (individual));
124 personas = folks_individual_get_personas (individual);
125 /* we'll re-use this iterator throughout */
126 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
128 /* Make sure we've got enough valid entries for these menu items to add
130 while (gee_iterator_next (iter))
132 FolksPersona *persona = gee_iterator_get (iter);
133 if (empathy_folks_persona_is_interesting (persona))
136 g_clear_object (&persona);
139 /* return early if these entries would add nothing beyond the "quick" items */
140 if (persona_count <= 1)
143 /* add a separator before the list of personas */
144 item = gtk_separator_menu_item_new ();
145 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
146 gtk_widget_show (item);
148 for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
151 GtkWidget *contact_item;
152 GtkWidget *contact_submenu;
153 TpContact *tp_contact;
154 EmpathyContact *contact;
155 TpfPersona *persona = gee_iterator_get (iter);
157 FolksPersonaStore *store;
158 const gchar *account;
160 /* Individual containing only persona */
161 FolksIndividual *single_individual;
163 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
166 tp_contact = tpf_persona_get_contact (persona);
167 if (tp_contact == NULL)
170 contact = empathy_contact_dup_from_tp_contact (tp_contact);
171 single_individual = empathy_create_individual_from_tp_contact (
174 store = folks_persona_get_store (FOLKS_PERSONA (persona));
175 account = folks_persona_store_get_display_name (store);
177 /* Translators: this is used in the context menu for a contact. The first
178 * parameter is a contact ID (e.g. foo@jabber.org) and the second is one
179 * of the user's account IDs (e.g. me@hotmail.com). */
180 label = g_strdup_printf (_("%s (%s)"),
181 folks_persona_get_display_id (FOLKS_PERSONA (persona)), account);
183 contact_item = gtk_image_menu_item_new_with_label (label);
184 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (contact_item),
186 contact_submenu = gtk_menu_new ();
187 gtk_menu_item_set_submenu (GTK_MENU_ITEM (contact_item), contact_submenu);
188 image = gtk_image_new_from_icon_name (
189 empathy_icon_name_for_contact (contact), GTK_ICON_SIZE_MENU);
190 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (contact_item), image);
191 gtk_widget_show (image);
194 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
196 action = empathy_individual_chat_menu_item_new (single_individual);
197 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
198 gtk_widget_show (action);
202 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
204 action = empathy_individual_sms_menu_item_new (single_individual);
205 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
206 gtk_widget_show (action);
209 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
212 action = empathy_individual_audio_call_menu_item_new (
214 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
215 gtk_widget_show (action);
218 action = empathy_individual_video_call_menu_item_new (
220 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
221 gtk_widget_show (action);
225 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
227 action = empathy_individual_log_menu_item_new (single_individual);
228 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
229 gtk_widget_show (action);
233 action = empathy_individual_invite_menu_item_new (NULL, contact);
234 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
235 gtk_widget_show (action);
238 action = empathy_individual_file_transfer_menu_item_new (
240 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
241 gtk_widget_show (action);
243 /* Share my desktop */
244 action = empathy_individual_share_my_desktop_menu_item_new (
246 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
247 gtk_widget_show (action);
250 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
251 (item = empathy_individiual_block_menu_item_new (single_individual))
255 sep = gtk_separator_menu_item_new ();
256 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), sep);
257 gtk_widget_show (sep);
259 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), item);
260 gtk_widget_show (item);
263 gtk_menu_shell_append (GTK_MENU_SHELL (menu), contact_item);
264 gtk_widget_show (contact_item);
267 g_object_unref (contact);
268 g_object_unref (single_individual);
271 g_clear_object (&persona);
274 g_clear_object (&iter);
278 empathy_individual_menu_init (EmpathyIndividualMenu *self)
280 EmpathyIndividualMenuPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
281 EMPATHY_TYPE_INDIVIDUAL_MENU, EmpathyIndividualMenuPriv);
287 find_phone_accounts (void)
289 TpAccountManager *am;
293 am = tp_account_manager_dup ();
294 g_return_val_if_fail (am != NULL, NULL);
296 accounts = tp_account_manager_get_valid_accounts (am);
297 for (l = accounts; l != NULL; l = g_list_next (l))
299 TpAccount *account = l->data;
301 if (tp_account_get_connection_status (account, NULL) !=
302 TP_CONNECTION_STATUS_CONNECTED)
305 if (!empathy_account_has_uri_scheme_tel (account))
308 found = g_list_prepend (found, g_object_ref (account));
311 g_list_free (accounts);
318 has_phone_account (void)
323 accounts = find_phone_accounts ();
324 result = (accounts != NULL);
326 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
332 call_phone_number (FolksPhoneFieldDetails *details,
335 DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details));
337 empathy_call_new_with_streams (
338 folks_phone_field_details_get_normalised (details),
339 account, TRUE, FALSE, empathy_get_current_action_time ());
343 display_call_phone_dialog (FolksPhoneFieldDetails *details,
349 dialog = empathy_account_selector_dialog_new (accounts);
351 gtk_window_set_title (GTK_WINDOW (dialog),
352 _("Select account to use to place the call"));
354 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
355 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
356 _("Call"), GTK_RESPONSE_OK,
359 response = gtk_dialog_run (GTK_DIALOG (dialog));
361 if (response == GTK_RESPONSE_OK)
365 account = empathy_account_selector_dialog_dup_selected (
366 EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog));
370 call_phone_number (details, account);
372 g_object_unref (account);
376 gtk_widget_destroy (dialog);
380 call_phone_number_cb (GtkMenuItem *item,
381 FolksPhoneFieldDetails *details)
385 accounts = find_phone_accounts ();
386 if (accounts == NULL)
388 DEBUG ("No phone aware account connected; can't call");
390 else if (g_list_length (accounts) == 1)
392 call_phone_number (details, accounts->data);
396 /* Ask which account to use */
397 display_call_phone_dialog (details, accounts);
400 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
404 find_phone_type (FolksPhoneFieldDetails *details)
406 GeeCollection *types;
409 types = folks_abstract_field_details_get_parameter_values (
410 FOLKS_ABSTRACT_FIELD_DETAILS (details), "type");
415 iter = gee_iterable_iterator (GEE_ITERABLE (types));
416 while (gee_iterator_next (iter))
418 const gchar *type = gee_iterator_get (iter);
420 if (!tp_strdiff (type, "CELL"))
422 else if (!tp_strdiff (type, "WORK"))
424 else if (!tp_strdiff (type, "HOME"))
432 add_phone_numbers (EmpathyIndividualMenu *self)
434 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
439 all_numbers = folks_phone_details_get_phone_numbers (
440 FOLKS_PHONE_DETAILS (priv->individual));
442 sensitive = has_phone_account ();
444 iter = gee_iterable_iterator (GEE_ITERABLE (all_numbers));
445 while (gee_iterator_next (iter))
447 FolksPhoneFieldDetails *details = gee_iterator_get (iter);
448 GtkWidget *item, *image;
452 type = find_phone_type (details);
456 tmp = g_strdup_printf ("Call %s (%s)",
457 folks_phone_field_details_get_normalised (details),
462 tmp = g_strdup_printf ("Call %s",
463 folks_phone_field_details_get_normalised (details));
466 item = gtk_image_menu_item_new_with_mnemonic (tmp);
469 g_signal_connect_data (item, "activate",
470 G_CALLBACK (call_phone_number_cb), g_object_ref (details),
471 (GClosureNotify) g_object_unref, 0);
473 gtk_widget_set_sensitive (item, sensitive);
475 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL,
477 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
478 gtk_widget_show (image);
480 gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
481 gtk_widget_show (item);
485 /* return a list of TpContact supporting the blocking iface */
487 get_contacts_supporting_blocking (FolksIndividual *individual)
491 GList *result = NULL;
493 personas = folks_individual_get_personas (individual);
495 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
496 while (gee_iterator_next (iter))
498 TpfPersona *persona = gee_iterator_get (iter);
502 if (!TPF_IS_PERSONA (persona))
505 contact = tpf_persona_get_contact (persona);
509 conn = tp_contact_get_connection (contact);
511 if (tp_proxy_has_interface_by_id (conn,
512 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
513 result = g_list_prepend (result, contact);
516 g_clear_object (&iter);
527 static GotAvatarCtx *
528 got_avatar_ctx_new (gboolean blocked,
531 GotAvatarCtx *ctx = g_slice_new0 (GotAvatarCtx);
533 ctx->blocked = blocked;
534 ctx->parent = parent != NULL ? g_object_ref (parent) : NULL;
539 got_avatar_ctx_free (GotAvatarCtx *ctx)
541 g_clear_object (&ctx->parent);
542 g_slice_free (GotAvatarCtx, ctx);
546 got_avatar (GObject *source_object,
547 GAsyncResult *result,
550 FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
551 GotAvatarCtx *ctx = user_data;
553 GError *error = NULL;
554 gboolean abusive = FALSE;
555 EmpathyIndividualManager *manager;
557 avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
562 DEBUG ("Could not get avatar: %s", error->message);
563 g_error_free (error);
567 /* confirm the user really wishes to block the contact */
568 if (!empathy_block_individual_dialog_show (GTK_WINDOW (ctx->parent),
569 individual, avatar, &abusive))
573 manager = empathy_individual_manager_dup_singleton ();
575 empathy_individual_manager_set_blocked (manager, individual,
576 ctx->blocked, abusive);
578 g_object_unref (manager);
581 g_clear_object (&avatar);
582 got_avatar_ctx_free (ctx);
586 empathy_individual_block_menu_item_toggled (GtkCheckMenuItem *item,
587 FolksIndividual *individual)
593 /* @item may be destroyed while the async call is running to get the things
594 * we need from it right now. */
595 blocked = gtk_check_menu_item_get_active (item);
597 parent = g_object_get_data (
598 G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
601 ctx = got_avatar_ctx_new (blocked, parent);
603 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
604 48, 48, NULL, got_avatar, ctx);
608 update_block_menu_item (GtkWidget *item,
609 FolksIndividual *individual)
612 gboolean is_blocked = TRUE;
614 contacts = get_contacts_supporting_blocking (individual);
616 if (contacts == NULL)
619 /* Check the menu item if all his personas are blocked */
620 for (l = contacts; l != NULL; l = g_list_next (l))
622 TpContact *contact = l->data;
624 if (!tp_contact_is_blocked (contact))
631 g_signal_handlers_block_by_func (item,
632 empathy_individual_block_menu_item_toggled, individual);
634 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), is_blocked);
636 g_signal_handlers_unblock_by_func (item,
637 empathy_individual_block_menu_item_toggled, individual);
639 g_list_free (contacts);
643 contact_blocked_changed_cb (TpContact *contact,
647 FolksIndividual *individual;
649 individual = g_object_get_data (G_OBJECT (item), "individual");
651 update_block_menu_item (item, individual);
655 empathy_individiual_block_menu_item_new (FolksIndividual *individual)
660 contacts = get_contacts_supporting_blocking (individual);
662 /* Can't block, no persona supports blocking */
663 if (contacts == NULL)
666 item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
668 g_object_set_data_full (G_OBJECT (item), "individual",
669 g_object_ref (individual), g_object_unref);
671 for (l = contacts; l != NULL; l = g_list_next (l))
673 TpContact *contact = l->data;
675 tp_g_signal_connect_object (contact, "notify::is-blocked",
676 G_CALLBACK (contact_blocked_changed_cb), item, 0);
679 g_signal_connect (item, "toggled",
680 G_CALLBACK (empathy_individual_block_menu_item_toggled), individual);
682 update_block_menu_item (item, individual);
684 g_list_free (contacts);
690 constructed (GObject *object)
692 EmpathyIndividualMenu *self = (EmpathyIndividualMenu *) object;
693 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
696 FolksIndividual *individual;
697 EmpathyIndividualFeatureFlags features;
700 shell = GTK_MENU_SHELL (object);
701 individual = priv->individual;
702 features = priv->features;
705 if (features & EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT)
707 item = empathy_individual_add_menu_item_new (self, individual);
710 gtk_menu_shell_append (GTK_MENU_SHELL (shell), item);
711 gtk_widget_show (item);
716 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
718 item = empathy_individual_chat_menu_item_new (individual);
721 gtk_menu_shell_append (shell, item);
722 gtk_widget_show (item);
727 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
729 item = empathy_individual_sms_menu_item_new (individual);
732 gtk_menu_shell_append (shell, item);
733 gtk_widget_show (item);
737 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
740 item = empathy_individual_audio_call_menu_item_new (individual);
741 gtk_menu_shell_append (shell, item);
742 gtk_widget_show (item);
745 item = empathy_individual_video_call_menu_item_new (individual);
746 gtk_menu_shell_append (shell, item);
747 gtk_widget_show (item);
750 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE)
751 add_phone_numbers (self);
754 item = empathy_individual_invite_menu_item_new (individual, NULL);
755 gtk_menu_shell_append (shell, item);
756 gtk_widget_show (item);
759 item = empathy_individual_file_transfer_menu_item_new (individual);
760 gtk_menu_shell_append (shell, item);
761 gtk_widget_show (item);
763 /* Share my desktop */
764 /* FIXME we should add the "Share my desktop" menu item if Vino is
765 a registered handler in MC5 */
766 item = empathy_individual_share_my_desktop_menu_item_new (individual);
767 gtk_menu_shell_append (shell, item);
768 gtk_widget_show (item);
770 /* Menu items to target specific contacts */
771 individual_menu_add_personas (GTK_MENU_SHELL (object), individual, features);
774 if (features & (EMPATHY_INDIVIDUAL_FEATURE_EDIT |
775 EMPATHY_INDIVIDUAL_FEATURE_INFO |
776 EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE))
778 item = gtk_separator_menu_item_new ();
779 gtk_menu_shell_append (shell, item);
780 gtk_widget_show (item);
784 if (features & EMPATHY_INDIVIDUAL_FEATURE_EDIT)
786 item = empathy_individual_edit_menu_item_new (individual);
787 gtk_menu_shell_append (shell, item);
788 gtk_widget_show (item);
792 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
794 item = empathy_individual_log_menu_item_new (individual);
795 gtk_menu_shell_append (shell, item);
796 gtk_widget_show (item);
800 if (features & EMPATHY_INDIVIDUAL_FEATURE_INFO)
802 item = empathy_individual_info_menu_item_new (individual);
803 gtk_menu_shell_append (shell, item);
804 gtk_widget_show (item);
807 /* Favorite checkbox */
808 if (features & EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE)
810 item = empathy_individual_favourite_menu_item_new (individual);
811 gtk_menu_shell_append (shell, item);
812 gtk_widget_show (item);
815 /* Separator & Block */
816 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
817 (item = empathy_individiual_block_menu_item_new (individual)) != NULL) {
820 sep = gtk_separator_menu_item_new ();
821 gtk_menu_shell_append (shell, sep);
822 gtk_widget_show (sep);
824 gtk_menu_shell_append (shell, item);
825 gtk_widget_show (item);
830 get_property (GObject *object,
835 EmpathyIndividualMenuPriv *priv;
837 priv = GET_PRIV (object);
841 case PROP_INDIVIDUAL:
842 g_value_set_object (value, priv->individual);
845 g_value_set_flags (value, priv->features);
848 g_value_set_object (value, priv->store);
851 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
857 set_property (GObject *object,
862 EmpathyIndividualMenuPriv *priv;
864 priv = GET_PRIV (object);
868 case PROP_INDIVIDUAL:
869 priv->individual = g_value_dup_object (value);
872 priv->features = g_value_get_flags (value);
875 priv->store = g_value_dup_object (value); /* read only */
878 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
884 dispose (GObject *object)
886 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
888 tp_clear_object (&priv->individual);
889 tp_clear_object (&priv->store);
891 G_OBJECT_CLASS (empathy_individual_menu_parent_class)->dispose (object);
895 empathy_individual_menu_class_init (EmpathyIndividualMenuClass *klass)
897 GObjectClass *object_class = G_OBJECT_CLASS (klass);
899 object_class->constructed = constructed;
900 object_class->get_property = get_property;
901 object_class->set_property = set_property;
902 object_class->dispose = dispose;
905 * EmpathyIndividualMenu:individual:
907 * The #FolksIndividual the menu is for.
909 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
910 g_param_spec_object ("individual",
912 "The #FolksIndividual the menu is for.",
913 FOLKS_TYPE_INDIVIDUAL,
914 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
917 * EmpathyIndividualMenu:features:
919 * A set of feature flags controlling which entries are shown.
921 g_object_class_install_property (object_class, PROP_FEATURES,
922 g_param_spec_flags ("features",
924 "A set of feature flags controlling which entries are shown.",
925 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS,
926 EMPATHY_INDIVIDUAL_FEATURE_NONE,
927 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
929 g_object_class_install_property (object_class, PROP_STORE,
930 g_param_spec_object ("store",
932 "The EmpathyIndividualStore to use to get contact owner",
933 EMPATHY_TYPE_INDIVIDUAL_STORE,
934 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
936 signals[SIGNAL_LINK_CONTACTS_ACTIVATED] =
937 g_signal_new ("link-contacts-activated", G_OBJECT_CLASS_TYPE (klass),
938 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
939 g_cclosure_marshal_generic,
940 G_TYPE_NONE, 1, EMPATHY_TYPE_LINKING_DIALOG);
942 g_type_class_add_private (object_class, sizeof (EmpathyIndividualMenuPriv));
946 empathy_individual_menu_new (FolksIndividual *individual,
947 EmpathyIndividualFeatureFlags features,
948 EmpathyIndividualStore *store)
950 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
951 g_return_val_if_fail (store == NULL ||
952 EMPATHY_IS_INDIVIDUAL_STORE (store), NULL);
953 g_return_val_if_fail (features != EMPATHY_INDIVIDUAL_FEATURE_NONE, NULL);
955 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU,
956 "individual", individual,
957 "features", features,
962 /* Like menu_item_set_first_contact(), but always operates upon the given
963 * contact. If the contact is non-NULL, it is assumed that the menu entry should
966 menu_item_set_contact (GtkWidget *item,
967 EmpathyContact *contact,
968 GCallback activate_callback,
969 EmpathyActionType action_type)
971 gboolean can_do_action = FALSE;
974 can_do_action = empathy_contact_can_do_action (contact, action_type);
975 gtk_widget_set_sensitive (item, can_do_action);
977 if (can_do_action == TRUE)
979 /* We want to make sure that the EmpathyContact stays alive while the
980 * signal is connected. */
981 g_signal_connect_data (item, "activate", G_CALLBACK (activate_callback),
982 g_object_ref (contact), (GClosureNotify) g_object_unref, 0);
985 return can_do_action;
989 * Set the given menu @item to call @activate_callback using the TpContact
990 * (associated with @individual) with the highest availability who is also valid
991 * whenever @item is activated.
993 * @action_type is the type of action performed by the menu entry; this is used
994 * so that only contacts which can perform that action (e.g. are capable of
995 * receiving video calls) are selected, as appropriate.
998 menu_item_set_first_contact (GtkWidget *item,
999 FolksIndividual *individual,
1000 GCallback activate_callback,
1001 EmpathyActionType action_type)
1003 EmpathyContact *best_contact;
1005 best_contact = empathy_contact_dup_best_for_action (individual, action_type);
1006 menu_item_set_contact (item, best_contact, G_CALLBACK (activate_callback),
1008 tp_clear_object (&best_contact);
1014 empathy_individual_chat_menu_item_activated (GtkMenuItem *item,
1015 EmpathyContact *contact)
1017 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1019 empathy_chat_with_contact (contact, empathy_get_current_action_time ());
1023 empathy_individual_chat_menu_item_new (FolksIndividual *individual)
1028 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1029 empathy_folks_individual_contains_contact (individual), NULL);
1031 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
1032 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
1033 GTK_ICON_SIZE_MENU);
1034 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1035 gtk_widget_show (image);
1037 menu_item_set_first_contact (item, individual,
1038 G_CALLBACK (empathy_individual_chat_menu_item_activated),
1039 EMPATHY_ACTION_CHAT);
1045 empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
1046 EmpathyContact *contact)
1048 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1050 empathy_sms_contact_id (
1051 empathy_contact_get_account (contact),
1052 empathy_contact_get_id (contact),
1053 empathy_get_current_action_time (),
1058 empathy_individual_sms_menu_item_new (FolksIndividual *individual)
1063 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1064 empathy_folks_individual_contains_contact (individual), NULL);
1066 item = gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
1067 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
1068 GTK_ICON_SIZE_MENU);
1069 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1070 gtk_widget_show (image);
1072 menu_item_set_first_contact (item, individual,
1073 G_CALLBACK (empathy_individual_sms_menu_item_activated),
1074 EMPATHY_ACTION_SMS);
1080 empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item,
1081 EmpathyContact *contact)
1083 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1085 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1086 empathy_contact_get_account (contact),
1088 empathy_get_current_action_time ());
1092 empathy_individual_audio_call_menu_item_new (FolksIndividual *individual)
1097 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1099 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
1100 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP, GTK_ICON_SIZE_MENU);
1101 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1102 gtk_widget_show (image);
1104 menu_item_set_first_contact (item, individual,
1105 G_CALLBACK (empathy_individual_audio_call_menu_item_activated),
1106 EMPATHY_ACTION_AUDIO_CALL);
1112 empathy_individual_video_call_menu_item_activated (GtkMenuItem *item,
1113 EmpathyContact *contact)
1115 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1117 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1118 empathy_contact_get_account (contact),
1120 empathy_get_current_action_time ());
1124 empathy_individual_video_call_menu_item_new (FolksIndividual *individual)
1128 EmpathyCameraMonitor *monitor;
1130 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1132 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
1133 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
1134 GTK_ICON_SIZE_MENU);
1135 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1136 gtk_widget_show (image);
1138 menu_item_set_first_contact (item, individual,
1139 G_CALLBACK (empathy_individual_video_call_menu_item_activated),
1140 EMPATHY_ACTION_VIDEO_CALL);
1142 /* Only follow available cameras if the contact can do Video calls */
1143 if (gtk_widget_get_sensitive (item))
1145 monitor = empathy_camera_monitor_dup_singleton ();
1146 g_object_set_data_full (G_OBJECT (item),
1147 "monitor", monitor, g_object_unref);
1148 g_object_bind_property (monitor, "available", item, "sensitive",
1149 G_BINDING_SYNC_CREATE);
1156 empathy_individual_log_menu_item_activated (GtkMenuItem *item,
1157 EmpathyContact *contact)
1159 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1161 empathy_log_window_show (empathy_contact_get_account (contact),
1162 empathy_contact_get_id (contact), FALSE, NULL);
1166 empathy_individual_log_menu_item_new (FolksIndividual *individual)
1171 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1173 item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
1174 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG, GTK_ICON_SIZE_MENU);
1175 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1176 gtk_widget_show (image);
1178 menu_item_set_first_contact (item, individual,
1179 G_CALLBACK (empathy_individual_log_menu_item_activated),
1180 EMPATHY_ACTION_VIEW_LOGS);
1186 empathy_individual_file_transfer_menu_item_activated (GtkMenuItem *item,
1187 EmpathyContact *contact)
1189 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1191 empathy_send_file_with_file_chooser (contact);
1195 empathy_individual_file_transfer_menu_item_new (FolksIndividual *individual)
1200 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1202 item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
1203 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
1204 GTK_ICON_SIZE_MENU);
1205 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1206 gtk_widget_show (image);
1208 menu_item_set_first_contact (item, individual,
1209 G_CALLBACK (empathy_individual_file_transfer_menu_item_activated),
1210 EMPATHY_ACTION_SEND_FILE);
1216 empathy_individual_share_my_desktop_menu_item_activated (GtkMenuItem *item,
1217 EmpathyContact *contact)
1219 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1221 empathy_share_my_desktop_share_with_contact (contact);
1225 empathy_individual_share_my_desktop_menu_item_new (FolksIndividual *individual)
1230 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1232 item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
1233 image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU);
1234 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1235 gtk_widget_show (image);
1237 menu_item_set_first_contact (item, individual,
1238 G_CALLBACK (empathy_individual_share_my_desktop_menu_item_activated),
1239 EMPATHY_ACTION_SHARE_MY_DESKTOP);
1245 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
1246 FolksIndividual *individual)
1248 folks_favourite_details_set_is_favourite (
1249 FOLKS_FAVOURITE_DETAILS (individual),
1250 gtk_check_menu_item_get_active (item));
1254 empathy_individual_favourite_menu_item_new (FolksIndividual *individual)
1258 item = gtk_check_menu_item_new_with_label (_("Favorite"));
1260 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1261 folks_favourite_details_get_is_favourite (
1262 FOLKS_FAVOURITE_DETAILS (individual)));
1264 g_signal_connect (item, "toggled",
1265 G_CALLBACK (favourite_menu_item_toggled_cb), individual);
1271 show_gnome_contacts_error_dialog (void)
1275 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
1276 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1277 _("gnome-contacts not installed"));
1279 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1280 _("Please install gnome-contacts to access contacts details."));
1282 g_signal_connect_swapped (dialog, "response",
1283 G_CALLBACK (gtk_widget_destroy), dialog);
1285 gtk_widget_show (dialog);
1289 start_gnome_contacts (FolksIndividual *individual,
1290 gboolean try_installing);
1293 install_gnome_contacts_cb (GObject *source,
1294 GAsyncResult *result,
1297 FolksIndividual *individual = user_data;
1298 GError *error = NULL;
1300 if (!empathy_pkg_kit_install_packages_finish (result, &error))
1302 DEBUG ("Failed to install gnome-contacts: %s", error->message);
1303 g_error_free (error);
1305 show_gnome_contacts_error_dialog ();
1309 DEBUG ("gnome-contacts installed");
1311 start_gnome_contacts (individual, FALSE);
1314 g_object_unref (individual);
1318 start_gnome_contacts (FolksIndividual *individual,
1319 gboolean try_installing)
1321 GDesktopAppInfo *desktop_info;
1324 GError *error = NULL;
1325 GdkAppLaunchContext *context = NULL;
1326 GdkDisplay *display;
1328 /* Start gnome-contacts */
1329 display = gdk_display_get_default ();
1330 context = gdk_display_get_app_launch_context (display);
1332 desktop_info = g_desktop_app_info_new ("gnome-contacts.desktop");
1333 if (desktop_info == NULL)
1337 const gchar *packages[] = { "gnome-contacts", NULL };
1339 DEBUG ("gnome-contacts not installed; try to install it");
1341 empathy_pkg_kit_install_packages_async (0, packages, NULL,
1342 NULL, install_gnome_contacts_cb, g_object_ref (individual));
1346 show_gnome_contacts_error_dialog ();
1352 /* glib doesn't have API to start a desktop file with args... (#637875) */
1353 cmd = g_strdup_printf ("%s -i %s", g_app_info_get_commandline (
1354 (GAppInfo *) desktop_info), folks_individual_get_id (individual));
1356 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1357 if (app_info == NULL)
1359 DEBUG ("Failed to create app_info: %s", error->message);
1360 g_error_free (error);
1364 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1367 g_critical ("Failed to start gnome-contacts: %s", error->message);
1368 g_error_free (error);
1371 g_object_unref (desktop_info);
1372 g_object_unref (app_info);
1376 individual_info_menu_item_activate_cb (FolksIndividual *individual)
1378 start_gnome_contacts (individual, TRUE);
1382 empathy_individual_info_menu_item_new (FolksIndividual *individual)
1387 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1388 g_return_val_if_fail (empathy_folks_individual_contains_contact (individual),
1391 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
1392 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
1393 GTK_ICON_SIZE_MENU);
1394 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1395 gtk_widget_show (image);
1397 g_signal_connect (item, "activate",
1398 G_CALLBACK (individual_info_menu_item_activate_cb),
1405 individual_edit_menu_item_activate_cb (FolksIndividual *individual)
1407 empathy_individual_edit_dialog_show (individual, NULL);
1411 empathy_individual_edit_menu_item_new (FolksIndividual *individual)
1413 EmpathyIndividualManager *manager;
1416 gboolean enable = FALSE;
1417 EmpathyContact *contact;
1419 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1421 contact = empathy_contact_dup_from_folks_individual (individual);
1423 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1425 if (empathy_individual_manager_initialized ())
1427 TpConnection *connection;
1429 manager = empathy_individual_manager_dup_singleton ();
1430 connection = empathy_contact_get_connection (contact);
1432 enable = (empathy_connection_can_alias_personas (connection,
1434 empathy_connection_can_group_personas (connection, individual));
1436 g_object_unref (manager);
1439 item = gtk_image_menu_item_new_with_mnemonic (
1440 C_("Edit individual (contextual menu)", "_Edit"));
1441 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1442 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1443 gtk_widget_show (image);
1445 gtk_widget_set_sensitive (item, enable);
1447 g_signal_connect_swapped (item, "activate",
1448 G_CALLBACK (individual_edit_menu_item_activate_cb), individual);
1450 g_object_unref (contact);
1457 FolksIndividual *individual;
1458 EmpathyContact *contact;
1459 EmpathyChatroom *chatroom;
1462 static RoomSubMenuData *
1463 room_sub_menu_data_new (FolksIndividual *individual,
1464 EmpathyContact *contact,
1465 EmpathyChatroom *chatroom)
1467 RoomSubMenuData *data;
1469 data = g_slice_new0 (RoomSubMenuData);
1470 if (individual != NULL)
1471 data->individual = g_object_ref (individual);
1472 if (contact != NULL)
1473 data->contact = g_object_ref (contact);
1474 data->chatroom = g_object_ref (chatroom);
1480 room_sub_menu_data_free (RoomSubMenuData *data)
1482 tp_clear_object (&data->individual);
1483 tp_clear_object (&data->contact);
1484 g_object_unref (data->chatroom);
1485 g_slice_free (RoomSubMenuData, data);
1489 room_sub_menu_activate_cb (GtkWidget *item,
1490 RoomSubMenuData *data)
1492 EmpathyTpChat *chat;
1493 EmpathyChatroomManager *mgr;
1494 EmpathyContact *contact = NULL;
1496 chat = empathy_chatroom_get_tp_chat (data->chatroom);
1499 /* channel was invalidated. Ignoring */
1503 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1505 if (data->contact != NULL)
1506 contact = g_object_ref (data->contact);
1512 /* find the first of this Individual's contacts who can join this room */
1513 personas = folks_individual_get_personas (data->individual);
1515 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1516 while (gee_iterator_next (iter) && (contact == NULL))
1518 TpfPersona *persona = gee_iterator_get (iter);
1519 TpContact *tp_contact;
1522 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1524 tp_contact = tpf_persona_get_contact (persona);
1525 if (tp_contact != NULL)
1527 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1529 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1530 empathy_contact_get_account (contact));
1532 if (g_list_find (rooms, data->chatroom) == NULL)
1533 g_clear_object (&contact);
1535 /* if contact != NULL here, we've found our match */
1537 g_list_free (rooms);
1540 g_clear_object (&persona);
1542 g_clear_object (&iter);
1545 g_object_unref (mgr);
1547 if (contact == NULL)
1549 /* contact disappeared. Ignoring */
1553 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1555 /* send invitation */
1556 empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat),
1557 contact, _("Inviting you to this room"));
1560 g_object_unref (contact);
1564 create_room_sub_menu (FolksIndividual *individual,
1565 EmpathyContact *contact,
1566 EmpathyChatroom *chatroom)
1569 RoomSubMenuData *data;
1571 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
1572 data = room_sub_menu_data_new (individual, contact, chatroom);
1573 g_signal_connect_data (item, "activate",
1574 G_CALLBACK (room_sub_menu_activate_cb), data,
1575 (GClosureNotify) room_sub_menu_data_free, 0);
1581 empathy_individual_invite_menu_item_new (FolksIndividual *individual,
1582 EmpathyContact *contact)
1586 GtkWidget *room_item;
1587 EmpathyChatroomManager *mgr;
1588 GList *rooms = NULL;
1589 GList *names = NULL;
1591 GtkWidget *submenu = NULL;
1592 /* map of chat room names to their objects; just a utility to remove
1593 * duplicates and to make construction of the alphabetized list easier */
1594 GHashTable *name_room_map;
1596 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) ||
1597 EMPATHY_IS_CONTACT (contact),
1600 name_room_map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
1603 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
1604 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
1605 GTK_ICON_SIZE_MENU);
1606 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1608 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1610 if (contact != NULL)
1612 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1613 empathy_contact_get_account (contact));
1620 /* find the first of this Individual's contacts who can join this room */
1621 personas = folks_individual_get_personas (individual);
1622 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1623 while (gee_iterator_next (iter))
1625 TpfPersona *persona = gee_iterator_get (iter);
1627 TpContact *tp_contact;
1628 EmpathyContact *contact_cur;
1630 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1632 tp_contact = tpf_persona_get_contact (persona);
1633 if (tp_contact != NULL)
1635 contact_cur = empathy_contact_dup_from_tp_contact (
1638 rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
1639 empathy_contact_get_account (contact_cur));
1640 rooms = g_list_concat (rooms, rooms_cur);
1642 g_object_unref (contact_cur);
1645 g_clear_object (&persona);
1647 g_clear_object (&iter);
1650 /* alphabetize the rooms */
1651 for (l = rooms; l != NULL; l = g_list_next (l))
1653 EmpathyChatroom *chatroom = l->data;
1656 if (empathy_chatroom_get_tp_chat (chatroom) != NULL)
1660 name = empathy_chatroom_get_name (chatroom);
1661 existed = (g_hash_table_lookup (name_room_map, name) != NULL);
1662 g_hash_table_insert (name_room_map, (gpointer) name,
1663 g_object_ref (chatroom));
1665 /* this will take care of duplicates in rooms */
1668 names = g_list_insert_sorted (names, (gpointer) name,
1669 (GCompareFunc) g_strcmp0);
1674 for (l = names; l != NULL; l = g_list_next (l))
1676 const gchar *name = l->data;
1677 EmpathyChatroom *chatroom;
1679 if (G_UNLIKELY (submenu == NULL))
1680 submenu = gtk_menu_new ();
1682 chatroom = g_hash_table_lookup (name_room_map, name);
1683 room_item = create_room_sub_menu (individual, contact, chatroom);
1684 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
1685 gtk_widget_show (room_item);
1689 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1691 gtk_widget_set_sensitive (item, FALSE);
1693 gtk_widget_show (image);
1695 g_hash_table_unref (name_room_map);
1696 g_object_unref (mgr);
1697 g_list_free (names);
1698 g_list_free (rooms);
1704 add_menu_item_activated (GtkMenuItem *item,
1705 TpContact *tp_contact)
1707 GtkWidget *toplevel;
1708 EmpathyContact *contact;
1710 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
1711 if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel))
1714 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1716 empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
1719 g_object_unref (contact);
1723 empathy_individual_add_menu_item_new (EmpathyIndividualMenu *self,
1724 FolksIndividual *individual)
1726 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
1727 GtkWidget *item, *image;
1730 TpContact *to_add = NULL;
1732 /* find the first of this Individual's personas which are not in our contact
1734 personas = folks_individual_get_personas (individual);
1735 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1736 while (gee_iterator_next (iter))
1738 TpfPersona *persona = gee_iterator_get (iter);
1742 if (!TPF_IS_PERSONA (persona))
1745 contact = tpf_persona_get_contact (persona);
1746 if (contact == NULL)
1749 /* be sure to use a not channel specific contact.
1750 * TODO: Ideally tp-glib should do this for us (fdo #42702)*/
1751 if (EMPATHY_IS_INDIVIDUAL_STORE_CHANNEL (priv->store))
1754 TpChannelGroupFlags flags;
1756 channel = empathy_individual_store_channel_get_channel (
1757 EMPATHY_INDIVIDUAL_STORE_CHANNEL (priv->store));
1759 flags = tp_channel_group_get_flags (channel);
1760 if ((flags & TP_CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES) != 0)
1762 /* Channel uses channel specific handles (thanks XMPP...) */
1763 contact = tp_channel_group_get_contact_owner (channel, contact);
1765 /* If we don't know the owner, we can't add the contact */
1766 if (contact == NULL)
1771 conn = tp_contact_get_connection (contact);
1775 /* No point to try adding a contact if the CM doesn't support it */
1776 if (!tp_connection_get_can_change_contact_list (conn))
1779 /* Can't add ourself */
1780 if (tp_connection_get_self_contact (conn) == contact)
1783 if (tp_contact_get_subscribe_state (contact) == TP_SUBSCRIPTION_STATE_YES)
1786 g_object_unref (persona);
1791 g_object_unref (persona);
1794 g_object_unref (iter);
1799 item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
1800 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
1801 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1803 g_signal_connect_data (item, "activate",
1804 G_CALLBACK (add_menu_item_activated),
1805 g_object_ref (to_add), (GClosureNotify) g_object_unref, 0);