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-call-utils.h"
55 #include "empathy-individual-store-channel.h"
56 #include "empathy-individual-information-dialog.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;
75 G_DEFINE_TYPE (EmpathyIndividualMenu, empathy_individual_menu, GTK_TYPE_MENU);
77 static GtkWidget * empathy_individual_chat_menu_item_new (
78 FolksIndividual *individual);
79 static GtkWidget * empathy_individual_sms_menu_item_new (
80 FolksIndividual *individual);
81 static GtkWidget * empathy_individual_log_menu_item_new (
82 FolksIndividual *individual);
83 static GtkWidget * empathy_individual_info_menu_item_new (
84 FolksIndividual *individual);
85 static GtkWidget * empathy_individual_edit_menu_item_new (
86 FolksIndividual *individual);
87 static GtkWidget * empathy_individual_invite_menu_item_new (
88 FolksIndividual *individual,
89 EmpathyContact *contact);
90 static GtkWidget * empathy_individual_file_transfer_menu_item_new (
91 FolksIndividual *individual);
92 static GtkWidget * empathy_individual_share_my_desktop_menu_item_new (
93 FolksIndividual *individual);
94 static GtkWidget * empathy_individual_favourite_menu_item_new (
95 FolksIndividual *individual);
96 static GtkWidget * empathy_individual_add_menu_item_new (
97 EmpathyIndividualMenu *self,
98 FolksIndividual *individual);
99 static GtkWidget * empathy_individiual_block_menu_item_new (
100 FolksIndividual *individual);
103 individual_menu_add_personas (GtkMenuShell *menu,
104 FolksIndividual *individual,
105 EmpathyIndividualFeatureFlags features)
110 guint persona_count = 0;
113 g_return_if_fail (GTK_IS_MENU (menu));
114 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
115 g_return_if_fail (empathy_folks_individual_contains_contact (individual));
117 personas = folks_individual_get_personas (individual);
118 /* we'll re-use this iterator throughout */
119 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
121 /* Make sure we've got enough valid entries for these menu items to add
123 while (gee_iterator_next (iter))
125 FolksPersona *persona = gee_iterator_get (iter);
126 if (empathy_folks_persona_is_interesting (persona))
129 g_clear_object (&persona);
132 /* return early if these entries would add nothing beyond the "quick" items */
133 if (persona_count <= 1)
136 /* add a separator before the list of personas */
137 item = gtk_separator_menu_item_new ();
138 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
139 gtk_widget_show (item);
141 for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
144 GtkWidget *contact_item;
145 GtkWidget *contact_submenu;
146 TpContact *tp_contact;
147 EmpathyContact *contact;
148 TpfPersona *persona = gee_iterator_get (iter);
150 FolksPersonaStore *store;
151 const gchar *account;
153 /* Individual containing only persona */
154 FolksIndividual *single_individual;
156 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
159 tp_contact = tpf_persona_get_contact (persona);
160 if (tp_contact == NULL)
163 contact = empathy_contact_dup_from_tp_contact (tp_contact);
164 single_individual = empathy_create_individual_from_tp_contact (
167 store = folks_persona_get_store (FOLKS_PERSONA (persona));
168 account = folks_persona_store_get_display_name (store);
170 /* Translators: this is used in the context menu for a contact. The first
171 * parameter is a contact ID (e.g. foo@jabber.org) and the second is one
172 * of the user's account IDs (e.g. me@hotmail.com). */
173 label = g_strdup_printf (_("%s (%s)"),
174 folks_persona_get_display_id (FOLKS_PERSONA (persona)), account);
176 contact_item = gtk_image_menu_item_new_with_label (label);
177 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (contact_item),
179 contact_submenu = gtk_menu_new ();
180 gtk_menu_item_set_submenu (GTK_MENU_ITEM (contact_item), contact_submenu);
181 image = gtk_image_new_from_icon_name (
182 empathy_icon_name_for_contact (contact), GTK_ICON_SIZE_MENU);
183 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (contact_item), image);
184 gtk_widget_show (image);
187 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
189 action = empathy_individual_chat_menu_item_new (single_individual);
190 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
191 gtk_widget_show (action);
195 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
197 action = empathy_individual_sms_menu_item_new (single_individual);
198 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
199 gtk_widget_show (action);
202 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
205 action = empathy_individual_audio_call_menu_item_new (
207 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
208 gtk_widget_show (action);
211 action = empathy_individual_video_call_menu_item_new (
213 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
214 gtk_widget_show (action);
218 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
220 action = empathy_individual_log_menu_item_new (single_individual);
221 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
222 gtk_widget_show (action);
226 action = empathy_individual_invite_menu_item_new (NULL, contact);
227 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
228 gtk_widget_show (action);
231 action = empathy_individual_file_transfer_menu_item_new (
233 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
234 gtk_widget_show (action);
236 /* Share my desktop */
237 action = empathy_individual_share_my_desktop_menu_item_new (
239 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
240 gtk_widget_show (action);
243 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
244 (item = empathy_individiual_block_menu_item_new (single_individual))
248 sep = gtk_separator_menu_item_new ();
249 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), sep);
250 gtk_widget_show (sep);
252 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), item);
253 gtk_widget_show (item);
256 gtk_menu_shell_append (GTK_MENU_SHELL (menu), contact_item);
257 gtk_widget_show (contact_item);
260 g_object_unref (contact);
261 g_object_unref (single_individual);
264 g_clear_object (&persona);
267 g_clear_object (&iter);
271 empathy_individual_menu_init (EmpathyIndividualMenu *self)
273 EmpathyIndividualMenuPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
274 EMPATHY_TYPE_INDIVIDUAL_MENU, EmpathyIndividualMenuPriv);
280 find_phone_accounts (void)
282 TpAccountManager *am;
286 am = tp_account_manager_dup ();
287 g_return_val_if_fail (am != NULL, NULL);
289 accounts = tp_account_manager_get_valid_accounts (am);
290 for (l = accounts; l != NULL; l = g_list_next (l))
292 TpAccount *account = l->data;
294 if (tp_account_get_connection_status (account, NULL) !=
295 TP_CONNECTION_STATUS_CONNECTED)
298 if (!empathy_account_has_uri_scheme_tel (account))
301 found = g_list_prepend (found, g_object_ref (account));
304 g_list_free (accounts);
311 has_phone_account (void)
316 accounts = find_phone_accounts ();
317 result = (accounts != NULL);
319 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
325 call_phone_number (FolksPhoneFieldDetails *details,
328 DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details));
330 empathy_call_new_with_streams (
331 folks_phone_field_details_get_normalised (details),
332 account, TRUE, FALSE, empathy_get_current_action_time ());
336 display_call_phone_dialog (FolksPhoneFieldDetails *details,
342 dialog = empathy_account_selector_dialog_new (accounts);
344 gtk_window_set_title (GTK_WINDOW (dialog),
345 _("Select account to use to place the call"));
347 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
348 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
349 _("Call"), GTK_RESPONSE_OK,
352 response = gtk_dialog_run (GTK_DIALOG (dialog));
354 if (response == GTK_RESPONSE_OK)
358 account = empathy_account_selector_dialog_dup_selected (
359 EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog));
363 call_phone_number (details, account);
365 g_object_unref (account);
369 gtk_widget_destroy (dialog);
373 call_phone_number_cb (GtkMenuItem *item,
374 FolksPhoneFieldDetails *details)
378 accounts = find_phone_accounts ();
379 if (accounts == NULL)
381 DEBUG ("No phone aware account connected; can't call");
383 else if (g_list_length (accounts) == 1)
385 call_phone_number (details, accounts->data);
389 /* Ask which account to use */
390 display_call_phone_dialog (details, accounts);
393 g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
397 find_phone_type (FolksPhoneFieldDetails *details)
399 GeeCollection *types;
402 types = folks_abstract_field_details_get_parameter_values (
403 FOLKS_ABSTRACT_FIELD_DETAILS (details), "type");
408 iter = gee_iterable_iterator (GEE_ITERABLE (types));
409 while (gee_iterator_next (iter))
411 const gchar *type = gee_iterator_get (iter);
413 if (!tp_strdiff (type, "CELL"))
415 else if (!tp_strdiff (type, "WORK"))
417 else if (!tp_strdiff (type, "HOME"))
425 add_phone_numbers (EmpathyIndividualMenu *self)
427 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
432 all_numbers = folks_phone_details_get_phone_numbers (
433 FOLKS_PHONE_DETAILS (priv->individual));
435 sensitive = has_phone_account ();
437 iter = gee_iterable_iterator (GEE_ITERABLE (all_numbers));
438 while (gee_iterator_next (iter))
440 FolksPhoneFieldDetails *details = gee_iterator_get (iter);
441 GtkWidget *item, *image;
445 type = find_phone_type (details);
449 tmp = g_strdup_printf ("Call %s (%s)",
450 folks_phone_field_details_get_normalised (details),
455 tmp = g_strdup_printf ("Call %s",
456 folks_phone_field_details_get_normalised (details));
459 item = gtk_image_menu_item_new_with_mnemonic (tmp);
462 g_signal_connect_data (item, "activate",
463 G_CALLBACK (call_phone_number_cb), g_object_ref (details),
464 (GClosureNotify) g_object_unref, 0);
466 gtk_widget_set_sensitive (item, sensitive);
468 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL,
470 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
471 gtk_widget_show (image);
473 gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
474 gtk_widget_show (item);
478 /* return a list of TpContact supporting the blocking iface */
480 get_contacts_supporting_blocking (FolksIndividual *individual)
484 GList *result = NULL;
486 personas = folks_individual_get_personas (individual);
488 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
489 while (gee_iterator_next (iter))
491 TpfPersona *persona = gee_iterator_get (iter);
495 if (!TPF_IS_PERSONA (persona))
498 contact = tpf_persona_get_contact (persona);
502 conn = tp_contact_get_connection (contact);
504 if (tp_proxy_has_interface_by_id (conn,
505 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
506 result = g_list_prepend (result, contact);
509 g_clear_object (&iter);
520 static GotAvatarCtx *
521 got_avatar_ctx_new (gboolean blocked,
524 GotAvatarCtx *ctx = g_slice_new0 (GotAvatarCtx);
526 ctx->blocked = blocked;
527 ctx->parent = parent != NULL ? g_object_ref (parent) : NULL;
532 got_avatar_ctx_free (GotAvatarCtx *ctx)
534 g_clear_object (&ctx->parent);
535 g_slice_free (GotAvatarCtx, ctx);
539 got_avatar (GObject *source_object,
540 GAsyncResult *result,
543 FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
544 GotAvatarCtx *ctx = user_data;
546 GError *error = NULL;
547 gboolean abusive = FALSE;
548 EmpathyIndividualManager *manager;
550 avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
555 DEBUG ("Could not get avatar: %s", error->message);
556 g_error_free (error);
560 /* confirm the user really wishes to block the contact */
561 if (!empathy_block_individual_dialog_show (GTK_WINDOW (ctx->parent),
562 individual, avatar, &abusive))
566 manager = empathy_individual_manager_dup_singleton ();
568 empathy_individual_manager_set_blocked (manager, individual,
569 ctx->blocked, abusive);
571 g_object_unref (manager);
574 g_clear_object (&avatar);
575 got_avatar_ctx_free (ctx);
579 empathy_individual_block_menu_item_toggled (GtkCheckMenuItem *item,
580 FolksIndividual *individual)
586 /* @item may be destroyed while the async call is running to get the things
587 * we need from it right now. */
588 blocked = gtk_check_menu_item_get_active (item);
590 parent = g_object_get_data (
591 G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
594 ctx = got_avatar_ctx_new (blocked, parent);
596 empathy_pixbuf_avatar_from_individual_scaled_async (individual,
597 48, 48, NULL, got_avatar, ctx);
601 update_block_menu_item (GtkWidget *item,
602 FolksIndividual *individual)
605 gboolean is_blocked = TRUE;
607 contacts = get_contacts_supporting_blocking (individual);
609 if (contacts == NULL)
612 /* Check the menu item if all his personas are blocked */
613 for (l = contacts; l != NULL; l = g_list_next (l))
615 TpContact *contact = l->data;
617 if (!tp_contact_is_blocked (contact))
624 g_signal_handlers_block_by_func (item,
625 empathy_individual_block_menu_item_toggled, individual);
627 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), is_blocked);
629 g_signal_handlers_unblock_by_func (item,
630 empathy_individual_block_menu_item_toggled, individual);
632 g_list_free (contacts);
636 contact_blocked_changed_cb (TpContact *contact,
640 FolksIndividual *individual;
642 individual = g_object_get_data (G_OBJECT (item), "individual");
644 update_block_menu_item (item, individual);
648 empathy_individiual_block_menu_item_new (FolksIndividual *individual)
653 contacts = get_contacts_supporting_blocking (individual);
655 /* Can't block, no persona supports blocking */
656 if (contacts == NULL)
659 item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
661 g_object_set_data_full (G_OBJECT (item), "individual",
662 g_object_ref (individual), g_object_unref);
664 for (l = contacts; l != NULL; l = g_list_next (l))
666 TpContact *contact = l->data;
668 tp_g_signal_connect_object (contact, "notify::is-blocked",
669 G_CALLBACK (contact_blocked_changed_cb), item, 0);
672 g_signal_connect (item, "toggled",
673 G_CALLBACK (empathy_individual_block_menu_item_toggled), individual);
675 update_block_menu_item (item, individual);
677 g_list_free (contacts);
683 constructed (GObject *object)
685 EmpathyIndividualMenu *self = (EmpathyIndividualMenu *) object;
686 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
689 FolksIndividual *individual;
690 EmpathyIndividualFeatureFlags features;
693 shell = GTK_MENU_SHELL (object);
694 individual = priv->individual;
695 features = priv->features;
698 if (features & EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT)
700 item = empathy_individual_add_menu_item_new (self, individual);
703 gtk_menu_shell_append (GTK_MENU_SHELL (shell), item);
704 gtk_widget_show (item);
709 if (features & EMPATHY_INDIVIDUAL_FEATURE_CHAT)
711 item = empathy_individual_chat_menu_item_new (individual);
714 gtk_menu_shell_append (shell, item);
715 gtk_widget_show (item);
720 if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
722 item = empathy_individual_sms_menu_item_new (individual);
725 gtk_menu_shell_append (shell, item);
726 gtk_widget_show (item);
730 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
733 item = empathy_individual_audio_call_menu_item_new (individual);
734 gtk_menu_shell_append (shell, item);
735 gtk_widget_show (item);
738 item = empathy_individual_video_call_menu_item_new (individual);
739 gtk_menu_shell_append (shell, item);
740 gtk_widget_show (item);
743 if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE)
744 add_phone_numbers (self);
747 item = empathy_individual_invite_menu_item_new (individual, NULL);
748 gtk_menu_shell_append (shell, item);
749 gtk_widget_show (item);
752 item = empathy_individual_file_transfer_menu_item_new (individual);
753 gtk_menu_shell_append (shell, item);
754 gtk_widget_show (item);
756 /* Share my desktop */
757 /* FIXME we should add the "Share my desktop" menu item if Vino is
758 a registered handler in MC5 */
759 item = empathy_individual_share_my_desktop_menu_item_new (individual);
760 gtk_menu_shell_append (shell, item);
761 gtk_widget_show (item);
763 /* Menu items to target specific contacts */
764 individual_menu_add_personas (GTK_MENU_SHELL (object), individual, features);
767 if (features & (EMPATHY_INDIVIDUAL_FEATURE_EDIT |
768 EMPATHY_INDIVIDUAL_FEATURE_INFO |
769 EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE))
771 item = gtk_separator_menu_item_new ();
772 gtk_menu_shell_append (shell, item);
773 gtk_widget_show (item);
777 if (features & EMPATHY_INDIVIDUAL_FEATURE_EDIT)
779 item = empathy_individual_edit_menu_item_new (individual);
780 gtk_menu_shell_append (shell, item);
781 gtk_widget_show (item);
785 if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
787 item = empathy_individual_log_menu_item_new (individual);
788 gtk_menu_shell_append (shell, item);
789 gtk_widget_show (item);
793 if (features & EMPATHY_INDIVIDUAL_FEATURE_INFO)
795 item = empathy_individual_info_menu_item_new (individual);
796 gtk_menu_shell_append (shell, item);
797 gtk_widget_show (item);
800 /* Favorite checkbox */
801 if (features & EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE)
803 item = empathy_individual_favourite_menu_item_new (individual);
804 gtk_menu_shell_append (shell, item);
805 gtk_widget_show (item);
808 /* Separator & Block */
809 if (features & EMPATHY_INDIVIDUAL_FEATURE_BLOCK &&
810 (item = empathy_individiual_block_menu_item_new (individual)) != NULL) {
813 sep = gtk_separator_menu_item_new ();
814 gtk_menu_shell_append (shell, sep);
815 gtk_widget_show (sep);
817 gtk_menu_shell_append (shell, item);
818 gtk_widget_show (item);
823 get_property (GObject *object,
828 EmpathyIndividualMenuPriv *priv;
830 priv = GET_PRIV (object);
834 case PROP_INDIVIDUAL:
835 g_value_set_object (value, priv->individual);
838 g_value_set_flags (value, priv->features);
841 g_value_set_object (value, priv->store);
844 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
850 set_property (GObject *object,
855 EmpathyIndividualMenuPriv *priv;
857 priv = GET_PRIV (object);
861 case PROP_INDIVIDUAL:
862 priv->individual = g_value_dup_object (value);
865 priv->features = g_value_get_flags (value);
868 priv->store = g_value_dup_object (value); /* read only */
871 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
877 dispose (GObject *object)
879 EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
881 tp_clear_object (&priv->individual);
882 tp_clear_object (&priv->store);
884 G_OBJECT_CLASS (empathy_individual_menu_parent_class)->dispose (object);
888 empathy_individual_menu_class_init (EmpathyIndividualMenuClass *klass)
890 GObjectClass *object_class = G_OBJECT_CLASS (klass);
892 object_class->constructed = constructed;
893 object_class->get_property = get_property;
894 object_class->set_property = set_property;
895 object_class->dispose = dispose;
898 * EmpathyIndividualMenu:individual:
900 * The #FolksIndividual the menu is for.
902 g_object_class_install_property (object_class, PROP_INDIVIDUAL,
903 g_param_spec_object ("individual",
905 "The #FolksIndividual the menu is for.",
906 FOLKS_TYPE_INDIVIDUAL,
907 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
910 * EmpathyIndividualMenu:features:
912 * A set of feature flags controlling which entries are shown.
914 g_object_class_install_property (object_class, PROP_FEATURES,
915 g_param_spec_flags ("features",
917 "A set of feature flags controlling which entries are shown.",
918 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS,
919 EMPATHY_INDIVIDUAL_FEATURE_NONE,
920 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
922 g_object_class_install_property (object_class, PROP_STORE,
923 g_param_spec_object ("store",
925 "The EmpathyIndividualStore to use to get contact owner",
926 EMPATHY_TYPE_INDIVIDUAL_STORE,
927 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
929 g_type_class_add_private (object_class, sizeof (EmpathyIndividualMenuPriv));
933 empathy_individual_menu_new (FolksIndividual *individual,
934 EmpathyIndividualFeatureFlags features,
935 EmpathyIndividualStore *store)
937 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
938 g_return_val_if_fail (store == NULL ||
939 EMPATHY_IS_INDIVIDUAL_STORE (store), NULL);
940 g_return_val_if_fail (features != EMPATHY_INDIVIDUAL_FEATURE_NONE, NULL);
942 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU,
943 "individual", individual,
944 "features", features,
949 /* Like menu_item_set_first_contact(), but always operates upon the given
950 * contact. If the contact is non-NULL, it is assumed that the menu entry should
953 menu_item_set_contact (GtkWidget *item,
954 EmpathyContact *contact,
955 GCallback activate_callback,
956 EmpathyActionType action_type)
958 gboolean can_do_action = FALSE;
961 can_do_action = empathy_contact_can_do_action (contact, action_type);
962 gtk_widget_set_sensitive (item, can_do_action);
964 if (can_do_action == TRUE)
966 /* We want to make sure that the EmpathyContact stays alive while the
967 * signal is connected. */
968 g_signal_connect_data (item, "activate", G_CALLBACK (activate_callback),
969 g_object_ref (contact), (GClosureNotify) g_object_unref, 0);
972 return can_do_action;
976 * Set the given menu @item to call @activate_callback using the TpContact
977 * (associated with @individual) with the highest availability who is also valid
978 * whenever @item is activated.
980 * @action_type is the type of action performed by the menu entry; this is used
981 * so that only contacts which can perform that action (e.g. are capable of
982 * receiving video calls) are selected, as appropriate.
985 menu_item_set_first_contact (GtkWidget *item,
986 FolksIndividual *individual,
987 GCallback activate_callback,
988 EmpathyActionType action_type)
990 EmpathyContact *best_contact;
992 best_contact = empathy_contact_dup_best_for_action (individual, action_type);
993 menu_item_set_contact (item, best_contact, G_CALLBACK (activate_callback),
995 tp_clear_object (&best_contact);
1001 empathy_individual_chat_menu_item_activated (GtkMenuItem *item,
1002 EmpathyContact *contact)
1004 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1006 empathy_chat_with_contact (contact, empathy_get_current_action_time ());
1010 empathy_individual_chat_menu_item_new (FolksIndividual *individual)
1015 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1016 empathy_folks_individual_contains_contact (individual), NULL);
1018 item = gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
1019 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
1020 GTK_ICON_SIZE_MENU);
1021 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1022 gtk_widget_show (image);
1024 menu_item_set_first_contact (item, individual,
1025 G_CALLBACK (empathy_individual_chat_menu_item_activated),
1026 EMPATHY_ACTION_CHAT);
1032 empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
1033 EmpathyContact *contact)
1035 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1037 empathy_sms_contact_id (
1038 empathy_contact_get_account (contact),
1039 empathy_contact_get_id (contact),
1040 empathy_get_current_action_time (),
1045 empathy_individual_sms_menu_item_new (FolksIndividual *individual)
1050 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) &&
1051 empathy_folks_individual_contains_contact (individual), NULL);
1053 item = gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
1054 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
1055 GTK_ICON_SIZE_MENU);
1056 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1057 gtk_widget_show (image);
1059 menu_item_set_first_contact (item, individual,
1060 G_CALLBACK (empathy_individual_sms_menu_item_activated),
1061 EMPATHY_ACTION_SMS);
1067 empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item,
1068 EmpathyContact *contact)
1070 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1072 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1073 empathy_contact_get_account (contact),
1075 empathy_get_current_action_time ());
1079 empathy_individual_audio_call_menu_item_new (FolksIndividual *individual)
1084 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1086 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
1087 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP, GTK_ICON_SIZE_MENU);
1088 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1089 gtk_widget_show (image);
1091 menu_item_set_first_contact (item, individual,
1092 G_CALLBACK (empathy_individual_audio_call_menu_item_activated),
1093 EMPATHY_ACTION_AUDIO_CALL);
1099 empathy_individual_video_call_menu_item_activated (GtkMenuItem *item,
1100 EmpathyContact *contact)
1102 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1104 empathy_call_new_with_streams (empathy_contact_get_id (contact),
1105 empathy_contact_get_account (contact),
1107 empathy_get_current_action_time ());
1111 empathy_individual_video_call_menu_item_new (FolksIndividual *individual)
1115 EmpathyCameraMonitor *monitor;
1117 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1119 item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
1120 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
1121 GTK_ICON_SIZE_MENU);
1122 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1123 gtk_widget_show (image);
1125 menu_item_set_first_contact (item, individual,
1126 G_CALLBACK (empathy_individual_video_call_menu_item_activated),
1127 EMPATHY_ACTION_VIDEO_CALL);
1129 /* Only follow available cameras if the contact can do Video calls */
1130 if (gtk_widget_get_sensitive (item))
1132 monitor = empathy_camera_monitor_dup_singleton ();
1133 g_object_set_data_full (G_OBJECT (item),
1134 "monitor", monitor, g_object_unref);
1135 g_object_bind_property (monitor, "available", item, "sensitive",
1136 G_BINDING_SYNC_CREATE);
1143 empathy_individual_log_menu_item_activated (GtkMenuItem *item,
1144 EmpathyContact *contact)
1146 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1148 empathy_log_window_show (empathy_contact_get_account (contact),
1149 empathy_contact_get_id (contact), FALSE, NULL);
1153 empathy_individual_log_menu_item_new (FolksIndividual *individual)
1158 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1160 item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
1161 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG, GTK_ICON_SIZE_MENU);
1162 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1163 gtk_widget_show (image);
1165 menu_item_set_first_contact (item, individual,
1166 G_CALLBACK (empathy_individual_log_menu_item_activated),
1167 EMPATHY_ACTION_VIEW_LOGS);
1173 empathy_individual_file_transfer_menu_item_activated (GtkMenuItem *item,
1174 EmpathyContact *contact)
1176 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1178 empathy_send_file_with_file_chooser (contact);
1182 empathy_individual_file_transfer_menu_item_new (FolksIndividual *individual)
1187 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1189 item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
1190 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
1191 GTK_ICON_SIZE_MENU);
1192 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1193 gtk_widget_show (image);
1195 menu_item_set_first_contact (item, individual,
1196 G_CALLBACK (empathy_individual_file_transfer_menu_item_activated),
1197 EMPATHY_ACTION_SEND_FILE);
1203 empathy_individual_share_my_desktop_menu_item_activated (GtkMenuItem *item,
1204 EmpathyContact *contact)
1206 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1208 empathy_share_my_desktop_share_with_contact (contact);
1212 empathy_individual_share_my_desktop_menu_item_new (FolksIndividual *individual)
1217 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1219 item = gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
1220 image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU);
1221 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1222 gtk_widget_show (image);
1224 menu_item_set_first_contact (item, individual,
1225 G_CALLBACK (empathy_individual_share_my_desktop_menu_item_activated),
1226 EMPATHY_ACTION_SHARE_MY_DESKTOP);
1232 favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
1233 FolksIndividual *individual)
1235 folks_favourite_details_set_is_favourite (
1236 FOLKS_FAVOURITE_DETAILS (individual),
1237 gtk_check_menu_item_get_active (item));
1241 empathy_individual_favourite_menu_item_new (FolksIndividual *individual)
1245 item = gtk_check_menu_item_new_with_label (_("Favorite"));
1247 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1248 folks_favourite_details_get_is_favourite (
1249 FOLKS_FAVOURITE_DETAILS (individual)));
1251 g_signal_connect (item, "toggled",
1252 G_CALLBACK (favourite_menu_item_toggled_cb), individual);
1258 show_gnome_contacts_error_dialog (void)
1262 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
1263 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1264 _("gnome-contacts not installed"));
1266 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1267 _("Please install gnome-contacts to access contacts details."));
1269 g_signal_connect_swapped (dialog, "response",
1270 G_CALLBACK (gtk_widget_destroy), dialog);
1272 gtk_widget_show (dialog);
1276 start_gnome_contacts (FolksIndividual *individual,
1277 gboolean try_installing);
1280 install_gnome_contacts_cb (GObject *source,
1281 GAsyncResult *result,
1284 FolksIndividual *individual = user_data;
1285 GError *error = NULL;
1287 if (!empathy_pkg_kit_install_packages_finish (result, &error))
1289 DEBUG ("Failed to install gnome-contacts: %s", error->message);
1290 g_error_free (error);
1292 show_gnome_contacts_error_dialog ();
1296 DEBUG ("gnome-contacts installed");
1298 start_gnome_contacts (individual, FALSE);
1301 g_object_unref (individual);
1305 start_gnome_contacts (FolksIndividual *individual,
1306 gboolean try_installing)
1308 GDesktopAppInfo *desktop_info;
1311 GError *error = NULL;
1312 GdkAppLaunchContext *context = NULL;
1313 GdkDisplay *display;
1315 g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
1317 /* Start gnome-contacts */
1318 display = gdk_display_get_default ();
1319 context = gdk_display_get_app_launch_context (display);
1321 desktop_info = g_desktop_app_info_new ("gnome-contacts.desktop");
1322 if (desktop_info == NULL)
1326 const gchar *packages[] = { "gnome-contacts", NULL };
1328 DEBUG ("gnome-contacts not installed; try to install it");
1330 empathy_pkg_kit_install_packages_async (0, packages, NULL,
1331 NULL, install_gnome_contacts_cb, g_object_ref (individual));
1335 show_gnome_contacts_error_dialog ();
1341 /* glib doesn't have API to start a desktop file with args... (#637875) */
1342 cmd = g_strdup_printf ("%s -i %s", g_app_info_get_commandline (
1343 (GAppInfo *) desktop_info), folks_individual_get_id (individual));
1345 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1346 if (app_info == NULL)
1348 DEBUG ("Failed to create app_info: %s", error->message);
1349 g_error_free (error);
1353 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
1356 g_critical ("Failed to start gnome-contacts: %s", error->message);
1357 g_error_free (error);
1360 g_object_unref (desktop_info);
1361 g_object_unref (app_info);
1365 individual_info_menu_item_activate_cb (GtkMenuItem *item,
1366 FolksIndividual *individual)
1368 EmpathyIndividualManager *mgr;
1370 mgr = empathy_individual_manager_dup_singleton ();
1372 /* Only use gnome-contacts if that's a 'real' individual we got from
1373 * Folks (and so the individual manager knows about it). If not that's a
1374 * MUC contact and we use the simple dialog. */
1375 if (empathy_individual_manager_lookup_member (mgr,
1376 folks_individual_get_id (individual)) != NULL)
1378 start_gnome_contacts (individual, TRUE);
1382 empathy_individual_information_dialog_show (individual, NULL);
1385 g_object_unref (mgr);
1389 empathy_individual_info_menu_item_new (FolksIndividual *individual)
1394 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1395 g_return_val_if_fail (empathy_folks_individual_contains_contact (individual),
1398 item = gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
1399 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION,
1400 GTK_ICON_SIZE_MENU);
1401 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1402 gtk_widget_show (image);
1404 g_signal_connect (item, "activate",
1405 G_CALLBACK (individual_info_menu_item_activate_cb),
1412 individual_edit_menu_item_activate_cb (FolksIndividual *individual)
1414 empathy_individual_edit_dialog_show (individual, NULL);
1418 empathy_individual_edit_menu_item_new (FolksIndividual *individual)
1420 EmpathyIndividualManager *manager;
1423 gboolean enable = FALSE;
1424 EmpathyContact *contact;
1426 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
1428 contact = empathy_contact_dup_from_folks_individual (individual);
1430 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
1432 if (empathy_individual_manager_initialized ())
1434 TpConnection *connection;
1436 manager = empathy_individual_manager_dup_singleton ();
1437 connection = empathy_contact_get_connection (contact);
1439 enable = (empathy_connection_can_alias_personas (connection,
1441 empathy_connection_can_group_personas (connection, individual));
1443 g_object_unref (manager);
1446 item = gtk_image_menu_item_new_with_mnemonic (
1447 C_("Edit individual (contextual menu)", "_Edit"));
1448 image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
1449 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1450 gtk_widget_show (image);
1452 gtk_widget_set_sensitive (item, enable);
1454 g_signal_connect_swapped (item, "activate",
1455 G_CALLBACK (individual_edit_menu_item_activate_cb), individual);
1457 g_object_unref (contact);
1464 FolksIndividual *individual;
1465 EmpathyContact *contact;
1466 EmpathyChatroom *chatroom;
1469 static RoomSubMenuData *
1470 room_sub_menu_data_new (FolksIndividual *individual,
1471 EmpathyContact *contact,
1472 EmpathyChatroom *chatroom)
1474 RoomSubMenuData *data;
1476 data = g_slice_new0 (RoomSubMenuData);
1477 if (individual != NULL)
1478 data->individual = g_object_ref (individual);
1479 if (contact != NULL)
1480 data->contact = g_object_ref (contact);
1481 data->chatroom = g_object_ref (chatroom);
1487 room_sub_menu_data_free (RoomSubMenuData *data)
1489 tp_clear_object (&data->individual);
1490 tp_clear_object (&data->contact);
1491 g_object_unref (data->chatroom);
1492 g_slice_free (RoomSubMenuData, data);
1496 room_sub_menu_activate_cb (GtkWidget *item,
1497 RoomSubMenuData *data)
1499 EmpathyTpChat *chat;
1500 EmpathyChatroomManager *mgr;
1501 EmpathyContact *contact = NULL;
1503 chat = empathy_chatroom_get_tp_chat (data->chatroom);
1506 /* channel was invalidated. Ignoring */
1510 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1512 if (data->contact != NULL)
1513 contact = g_object_ref (data->contact);
1519 /* find the first of this Individual's contacts who can join this room */
1520 personas = folks_individual_get_personas (data->individual);
1522 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1523 while (gee_iterator_next (iter) && (contact == NULL))
1525 TpfPersona *persona = gee_iterator_get (iter);
1526 TpContact *tp_contact;
1529 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1531 tp_contact = tpf_persona_get_contact (persona);
1532 if (tp_contact != NULL)
1534 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1536 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1537 empathy_contact_get_account (contact));
1539 if (g_list_find (rooms, data->chatroom) == NULL)
1540 g_clear_object (&contact);
1542 /* if contact != NULL here, we've found our match */
1544 g_list_free (rooms);
1547 g_clear_object (&persona);
1549 g_clear_object (&iter);
1552 g_object_unref (mgr);
1554 if (contact == NULL)
1556 /* contact disappeared. Ignoring */
1560 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1562 /* send invitation */
1563 empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat),
1564 contact, _("Inviting you to this room"));
1567 g_object_unref (contact);
1571 create_room_sub_menu (FolksIndividual *individual,
1572 EmpathyContact *contact,
1573 EmpathyChatroom *chatroom)
1576 RoomSubMenuData *data;
1578 item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
1579 data = room_sub_menu_data_new (individual, contact, chatroom);
1580 g_signal_connect_data (item, "activate",
1581 G_CALLBACK (room_sub_menu_activate_cb), data,
1582 (GClosureNotify) room_sub_menu_data_free, 0);
1588 empathy_individual_invite_menu_item_new (FolksIndividual *individual,
1589 EmpathyContact *contact)
1593 GtkWidget *room_item;
1594 EmpathyChatroomManager *mgr;
1595 GList *rooms = NULL;
1596 GList *names = NULL;
1598 GtkWidget *submenu = NULL;
1599 /* map of chat room names to their objects; just a utility to remove
1600 * duplicates and to make construction of the alphabetized list easier */
1601 GHashTable *name_room_map;
1603 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) ||
1604 EMPATHY_IS_CONTACT (contact),
1607 name_room_map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
1610 item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
1611 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
1612 GTK_ICON_SIZE_MENU);
1613 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1615 mgr = empathy_chatroom_manager_dup_singleton (NULL);
1617 if (contact != NULL)
1619 rooms = empathy_chatroom_manager_get_chatrooms (mgr,
1620 empathy_contact_get_account (contact));
1627 /* find the first of this Individual's contacts who can join this room */
1628 personas = folks_individual_get_personas (individual);
1629 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1630 while (gee_iterator_next (iter))
1632 TpfPersona *persona = gee_iterator_get (iter);
1634 TpContact *tp_contact;
1635 EmpathyContact *contact_cur;
1637 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
1639 tp_contact = tpf_persona_get_contact (persona);
1640 if (tp_contact != NULL)
1642 contact_cur = empathy_contact_dup_from_tp_contact (
1645 rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
1646 empathy_contact_get_account (contact_cur));
1647 rooms = g_list_concat (rooms, rooms_cur);
1649 g_object_unref (contact_cur);
1652 g_clear_object (&persona);
1654 g_clear_object (&iter);
1657 /* alphabetize the rooms */
1658 for (l = rooms; l != NULL; l = g_list_next (l))
1660 EmpathyChatroom *chatroom = l->data;
1663 if (empathy_chatroom_get_tp_chat (chatroom) != NULL)
1667 name = empathy_chatroom_get_name (chatroom);
1668 existed = (g_hash_table_lookup (name_room_map, name) != NULL);
1669 g_hash_table_insert (name_room_map, (gpointer) name,
1670 g_object_ref (chatroom));
1672 /* this will take care of duplicates in rooms */
1675 names = g_list_insert_sorted (names, (gpointer) name,
1676 (GCompareFunc) g_strcmp0);
1681 for (l = names; l != NULL; l = g_list_next (l))
1683 const gchar *name = l->data;
1684 EmpathyChatroom *chatroom;
1686 if (G_UNLIKELY (submenu == NULL))
1687 submenu = gtk_menu_new ();
1689 chatroom = g_hash_table_lookup (name_room_map, name);
1690 room_item = create_room_sub_menu (individual, contact, chatroom);
1691 gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
1692 gtk_widget_show (room_item);
1696 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
1698 gtk_widget_set_sensitive (item, FALSE);
1700 gtk_widget_show (image);
1702 g_hash_table_unref (name_room_map);
1703 g_object_unref (mgr);
1704 g_list_free (names);
1705 g_list_free (rooms);
1711 add_menu_item_activated (GtkMenuItem *item,
1712 TpContact *tp_contact)
1714 GtkWidget *toplevel;
1715 EmpathyContact *contact;
1717 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
1718 if (!gtk_widget_is_toplevel (toplevel) || !GTK_IS_WINDOW (toplevel))
1721 contact = empathy_contact_dup_from_tp_contact (tp_contact);
1723 empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
1726 g_object_unref (contact);
1730 empathy_individual_add_menu_item_new (EmpathyIndividualMenu *self,
1731 FolksIndividual *individual)
1733 EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
1734 GtkWidget *item, *image;
1737 TpContact *to_add = NULL;
1739 /* find the first of this Individual's personas which are not in our contact
1741 personas = folks_individual_get_personas (individual);
1742 iter = gee_iterable_iterator (GEE_ITERABLE (personas));
1743 while (gee_iterator_next (iter))
1745 TpfPersona *persona = gee_iterator_get (iter);
1749 if (!TPF_IS_PERSONA (persona))
1752 contact = tpf_persona_get_contact (persona);
1753 if (contact == NULL)
1756 /* be sure to use a not channel specific contact.
1757 * TODO: Ideally tp-glib should do this for us (fdo #42702)*/
1758 if (EMPATHY_IS_INDIVIDUAL_STORE_CHANNEL (priv->store))
1761 TpChannelGroupFlags flags;
1763 channel = empathy_individual_store_channel_get_channel (
1764 EMPATHY_INDIVIDUAL_STORE_CHANNEL (priv->store));
1766 flags = tp_channel_group_get_flags (channel);
1767 if ((flags & TP_CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES) != 0)
1769 /* Channel uses channel specific handles (thanks XMPP...) */
1770 contact = tp_channel_group_get_contact_owner (channel, contact);
1772 /* If we don't know the owner, we can't add the contact */
1773 if (contact == NULL)
1778 conn = tp_contact_get_connection (contact);
1782 /* No point to try adding a contact if the CM doesn't support it */
1783 if (!tp_connection_get_can_change_contact_list (conn))
1786 /* Can't add ourself */
1787 if (tp_connection_get_self_contact (conn) == contact)
1790 if (tp_contact_get_subscribe_state (contact) == TP_SUBSCRIPTION_STATE_YES)
1793 g_object_unref (persona);
1798 g_object_unref (persona);
1801 g_object_unref (iter);
1806 item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
1807 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
1808 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1810 g_signal_connect_data (item, "activate",
1811 G_CALLBACK (add_menu_item_activated),
1812 g_object_ref (to_add), (GClosureNotify) g_object_unref, 0);