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>
24 #include "empathy-individual-menu.h"
26 #include <glib/gi18n-lib.h>
27 #include <tp-account-widgets/tpaw-camera-monitor.h>
28 #include <telepathy-glib/telepathy-glib-dbus.h>
30 #include "empathy-account-selector-dialog.h"
31 #include "empathy-call-utils.h"
32 #include "empathy-chatroom-manager.h"
33 #include "empathy-gtk-enum-types.h"
34 #include "empathy-images.h"
35 #include "empathy-individual-dialogs.h"
36 #include "empathy-individual-dialogs.h"
37 #include "empathy-individual-edit-dialog.h"
38 #include "empathy-individual-information-dialog.h"
39 #include "empathy-individual-manager.h"
40 #include "empathy-individual-store-channel.h"
41 #include "empathy-log-window.h"
42 #include "empathy-request-util.h"
43 #include "empathy-share-my-desktop.h"
44 #include "empathy-ui-utils.h"
45 #include "empathy-utils.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
48 #include "empathy-debug.h"
50 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu)
53 gchar
*active_group
; /* may be NULL */
54 FolksIndividual
*individual
; /* owned */
55 EmpathyIndividualFeatureFlags features
;
56 EmpathyIndividualStore
*store
; /* may be NULL */
57 } EmpathyIndividualMenuPriv
;
60 PROP_ACTIVE_GROUP
= 1,
71 static guint signals
[LAST_SIGNAL
] = { 0 };
73 G_DEFINE_TYPE (EmpathyIndividualMenu
, empathy_individual_menu
, GTK_TYPE_MENU
);
75 static GtkWidget
* empathy_individual_chat_menu_item_new (
76 EmpathyIndividualMenu
*self
, FolksIndividual
*individual
);
77 static GtkWidget
* empathy_individual_sms_menu_item_new (
78 EmpathyIndividualMenu
*self
, FolksIndividual
*individual
);
79 static GtkWidget
* empathy_individual_log_menu_item_new (
80 FolksIndividual
*individual
);
81 static GtkWidget
* empathy_individual_info_menu_item_new (
82 FolksIndividual
*individual
);
83 static GtkWidget
* empathy_individual_edit_menu_item_new (
84 FolksIndividual
*individual
);
85 static GtkWidget
* empathy_individual_invite_menu_item_new (
86 FolksIndividual
*individual
,
87 EmpathyContact
*contact
);
88 static GtkWidget
* empathy_individual_file_transfer_menu_item_new (
89 EmpathyIndividualMenu
*self
, FolksIndividual
*individual
);
90 static GtkWidget
* empathy_individual_share_my_desktop_menu_item_new (
91 EmpathyIndividualMenu
*self
, FolksIndividual
*individual
);
92 static GtkWidget
* empathy_individual_favourite_menu_item_new (
93 FolksIndividual
*individual
);
94 static GtkWidget
* empathy_individual_add_menu_item_new (
95 EmpathyIndividualMenu
*self
,
96 FolksIndividual
*individual
);
97 static GtkWidget
* empathy_individiual_block_menu_item_new (
98 FolksIndividual
*individual
);
99 static GtkWidget
* empathy_individiual_remove_menu_item_new (
100 EmpathyIndividualMenu
*self
);
103 individual_menu_add_personas (EmpathyIndividualMenu
*self
,
105 FolksIndividual
*individual
,
106 EmpathyIndividualFeatureFlags features
)
111 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 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
142 while (gee_iterator_next (iter
))
145 GtkWidget
*contact_item
;
146 GtkWidget
*contact_submenu
;
147 TpContact
*tp_contact
;
148 EmpathyContact
*contact
;
149 TpfPersona
*persona
= gee_iterator_get (iter
);
151 FolksPersonaStore
*store
;
152 const gchar
*account
;
154 /* Individual containing only persona */
155 FolksIndividual
*single_individual
;
157 if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona
)))
160 tp_contact
= tpf_persona_get_contact (persona
);
161 if (tp_contact
== NULL
)
164 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
165 single_individual
= empathy_create_individual_from_tp_contact (
168 /* Pretty hacky. Creating single_individual had a side effect to change
169 * persona.individual from individual to single_individual which is not
170 * what we want so we set it back. See bgo#684971 for details. */
171 g_object_set (persona
, "individual", individual
, NULL
);
173 store
= folks_persona_get_store (FOLKS_PERSONA (persona
));
174 account
= folks_persona_store_get_display_name (store
);
176 /* Translators: this is used in the context menu for a contact. The first
177 * parameter is a contact ID (e.g. foo@jabber.org) and the second is one
178 * of the user's account IDs (e.g. me@hotmail.com). */
179 label
= g_strdup_printf (_("%s (%s)"),
180 folks_persona_get_display_id (FOLKS_PERSONA (persona
)), account
);
182 contact_item
= gtk_image_menu_item_new_with_label (label
);
183 gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (contact_item
),
185 contact_submenu
= gtk_menu_new ();
186 gtk_menu_item_set_submenu (GTK_MENU_ITEM (contact_item
), contact_submenu
);
187 image
= gtk_image_new_from_icon_name (
188 empathy_icon_name_for_contact (contact
), GTK_ICON_SIZE_MENU
);
189 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (contact_item
), image
);
190 gtk_widget_show (image
);
193 if (features
& EMPATHY_INDIVIDUAL_FEATURE_CHAT
)
195 action
= empathy_individual_chat_menu_item_new (self
,
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 (self
,
206 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
207 gtk_widget_show (action
);
210 if (features
& EMPATHY_INDIVIDUAL_FEATURE_CALL
)
213 action
= empathy_individual_audio_call_menu_item_new (
214 self
, single_individual
);
215 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
216 gtk_widget_show (action
);
219 action
= empathy_individual_video_call_menu_item_new (
220 self
, single_individual
);
221 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
222 gtk_widget_show (action
);
226 if (features
& EMPATHY_INDIVIDUAL_FEATURE_LOG
)
228 action
= empathy_individual_log_menu_item_new (single_individual
);
229 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
230 gtk_widget_show (action
);
234 action
= empathy_individual_invite_menu_item_new (NULL
, contact
);
235 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
236 gtk_widget_show (action
);
239 if (features
& EMPATHY_INDIVIDUAL_FEATURE_FILE_TRANSFER
)
241 action
= empathy_individual_file_transfer_menu_item_new (
242 self
, single_individual
);
243 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
244 gtk_widget_show (action
);
247 /* Share my desktop */
248 action
= empathy_individual_share_my_desktop_menu_item_new (
249 self
, single_individual
);
250 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), action
);
251 gtk_widget_show (action
);
254 if (features
& EMPATHY_INDIVIDUAL_FEATURE_BLOCK
&&
255 (item
= empathy_individiual_block_menu_item_new (single_individual
))
259 sep
= gtk_separator_menu_item_new ();
260 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), sep
);
261 gtk_widget_show (sep
);
263 gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu
), item
);
264 gtk_widget_show (item
);
267 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), contact_item
);
268 gtk_widget_show (contact_item
);
271 g_object_unref (contact
);
272 g_object_unref (single_individual
);
275 g_clear_object (&persona
);
279 g_clear_object (&iter
);
283 empathy_individual_menu_init (EmpathyIndividualMenu
*self
)
285 EmpathyIndividualMenuPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
286 EMPATHY_TYPE_INDIVIDUAL_MENU
, EmpathyIndividualMenuPriv
);
292 find_phone_accounts (void)
294 TpAccountManager
*am
;
298 am
= tp_account_manager_dup ();
299 g_return_val_if_fail (am
!= NULL
, NULL
);
301 accounts
= tp_account_manager_dup_valid_accounts (am
);
302 for (l
= accounts
; l
!= NULL
; l
= g_list_next (l
))
304 TpAccount
*account
= l
->data
;
306 if (tp_account_get_connection_status (account
, NULL
) !=
307 TP_CONNECTION_STATUS_CONNECTED
)
310 if (!tp_account_associated_with_uri_scheme (account
, "tel"))
313 found
= g_list_prepend (found
, g_object_ref (account
));
316 g_list_free_full (accounts
, g_object_unref
);
323 has_phone_account (void)
328 accounts
= find_phone_accounts ();
329 result
= (accounts
!= NULL
);
331 g_list_free_full (accounts
, (GDestroyNotify
) g_object_unref
);
337 call_phone_number (FolksPhoneFieldDetails
*details
,
340 DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details
));
342 empathy_call_new_with_streams (
343 folks_phone_field_details_get_normalised (details
),
344 account
, TRUE
, FALSE
, empathy_get_current_action_time ());
348 display_call_phone_dialog (FolksPhoneFieldDetails
*details
,
354 dialog
= empathy_account_selector_dialog_new (accounts
);
356 gtk_window_set_title (GTK_WINDOW (dialog
),
357 _("Select account to use to place the call"));
359 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
360 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
361 _("Call"), GTK_RESPONSE_OK
,
364 response
= gtk_dialog_run (GTK_DIALOG (dialog
));
366 if (response
== GTK_RESPONSE_OK
)
370 account
= empathy_account_selector_dialog_dup_selected (
371 EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog
));
375 call_phone_number (details
, account
);
377 g_object_unref (account
);
381 gtk_widget_destroy (dialog
);
385 call_phone_number_cb (GtkMenuItem
*item
,
386 FolksPhoneFieldDetails
*details
)
390 accounts
= find_phone_accounts ();
391 if (accounts
== NULL
)
393 DEBUG ("No phone aware account connected; can't call");
395 else if (g_list_length (accounts
) == 1)
397 call_phone_number (details
, accounts
->data
);
401 /* Ask which account to use */
402 display_call_phone_dialog (details
, accounts
);
405 g_list_free_full (accounts
, (GDestroyNotify
) g_object_unref
);
409 find_phone_type (FolksPhoneFieldDetails
*details
)
411 GeeCollection
*types
;
414 types
= folks_abstract_field_details_get_parameter_values (
415 FOLKS_ABSTRACT_FIELD_DETAILS (details
), "type");
420 iter
= gee_iterable_iterator (GEE_ITERABLE (types
));
421 while (gee_iterator_next (iter
))
423 const gchar
*type
= gee_iterator_get (iter
);
425 if (!tp_strdiff (type
, "CELL"))
427 else if (!tp_strdiff (type
, "WORK"))
429 else if (!tp_strdiff (type
, "HOME"))
437 add_phone_numbers (EmpathyIndividualMenu
*self
)
439 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (self
);
444 all_numbers
= folks_phone_details_get_phone_numbers (
445 FOLKS_PHONE_DETAILS (priv
->individual
));
447 sensitive
= has_phone_account ();
449 iter
= gee_iterable_iterator (GEE_ITERABLE (all_numbers
));
450 while (gee_iterator_next (iter
))
452 FolksPhoneFieldDetails
*details
= gee_iterator_get (iter
);
453 GtkWidget
*item
, *image
;
457 type
= find_phone_type (details
);
461 /* translators: first argument is a phone number like +32123456 and
462 * the second one is something like 'home' or 'work'. */
463 tmp
= g_strdup_printf (_("Call %s (%s)"),
464 folks_phone_field_details_get_normalised (details
),
469 /* translators: argument is a phone number like +32123456 */
470 tmp
= g_strdup_printf (_("Call %s"),
471 folks_phone_field_details_get_normalised (details
));
474 item
= gtk_image_menu_item_new_with_mnemonic (tmp
);
477 g_signal_connect_data (item
, "activate",
478 G_CALLBACK (call_phone_number_cb
), g_object_ref (details
),
479 (GClosureNotify
) g_object_unref
, 0);
481 gtk_widget_set_sensitive (item
, sensitive
);
483 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL
,
485 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
486 gtk_widget_show (image
);
488 gtk_menu_shell_append (GTK_MENU_SHELL (self
), item
);
489 gtk_widget_show (item
);
492 g_object_unref (iter
);
495 /* return a list of TpContact supporting the blocking iface */
497 get_contacts_supporting_blocking (FolksIndividual
*individual
)
501 GList
*result
= NULL
;
503 personas
= folks_individual_get_personas (individual
);
505 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
506 while (gee_iterator_next (iter
))
508 TpfPersona
*persona
= gee_iterator_get (iter
);
512 if (!TPF_IS_PERSONA (persona
))
515 contact
= tpf_persona_get_contact (persona
);
519 conn
= tp_contact_get_connection (contact
);
521 if (tp_proxy_has_interface_by_id (conn
,
522 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING
))
523 result
= g_list_prepend (result
, contact
);
526 g_clear_object (&iter
);
537 static GotAvatarCtx
*
538 got_avatar_ctx_new (gboolean blocked
,
541 GotAvatarCtx
*ctx
= g_slice_new0 (GotAvatarCtx
);
543 ctx
->blocked
= blocked
;
544 ctx
->parent
= parent
!= NULL
? g_object_ref (parent
) : NULL
;
549 got_avatar_ctx_free (GotAvatarCtx
*ctx
)
551 g_clear_object (&ctx
->parent
);
552 g_slice_free (GotAvatarCtx
, ctx
);
556 got_avatar (GObject
*source_object
,
557 GAsyncResult
*result
,
560 FolksIndividual
*individual
= FOLKS_INDIVIDUAL (source_object
);
561 GotAvatarCtx
*ctx
= user_data
;
563 GError
*error
= NULL
;
564 gboolean abusive
= FALSE
;
565 EmpathyIndividualManager
*manager
;
567 avatar
= empathy_pixbuf_avatar_from_individual_scaled_finish (individual
,
572 DEBUG ("Could not get avatar: %s", error
->message
);
573 g_error_free (error
);
577 /* confirm the user really wishes to block the contact */
578 if (!empathy_block_individual_dialog_show (GTK_WINDOW (ctx
->parent
),
579 individual
, avatar
, &abusive
))
583 manager
= empathy_individual_manager_dup_singleton ();
585 empathy_individual_manager_set_blocked (manager
, individual
,
586 ctx
->blocked
, abusive
);
588 g_object_unref (manager
);
591 g_clear_object (&avatar
);
592 got_avatar_ctx_free (ctx
);
596 empathy_individual_block_menu_item_toggled (GtkCheckMenuItem
*item
,
597 FolksIndividual
*individual
)
603 /* @item may be destroyed while the async call is running to get the things
604 * we need from it right now. */
605 blocked
= gtk_check_menu_item_get_active (item
);
607 parent
= g_object_get_data (
608 G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item
))),
611 ctx
= got_avatar_ctx_new (blocked
, parent
);
613 empathy_pixbuf_avatar_from_individual_scaled_async (individual
,
614 48, 48, NULL
, got_avatar
, ctx
);
618 update_block_menu_item (GtkWidget
*item
,
619 FolksIndividual
*individual
)
622 gboolean is_blocked
= TRUE
;
624 contacts
= get_contacts_supporting_blocking (individual
);
626 if (contacts
== NULL
)
629 /* Check the menu item if all his personas are blocked */
630 for (l
= contacts
; l
!= NULL
; l
= g_list_next (l
))
632 TpContact
*contact
= l
->data
;
634 if (!tp_contact_is_blocked (contact
))
641 g_signal_handlers_block_by_func (item
,
642 empathy_individual_block_menu_item_toggled
, individual
);
644 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item
), is_blocked
);
646 g_signal_handlers_unblock_by_func (item
,
647 empathy_individual_block_menu_item_toggled
, individual
);
649 g_list_free (contacts
);
653 contact_blocked_changed_cb (TpContact
*contact
,
657 FolksIndividual
*individual
;
659 individual
= g_object_get_data (G_OBJECT (item
), "individual");
661 update_block_menu_item (item
, individual
);
665 empathy_individiual_block_menu_item_new (FolksIndividual
*individual
)
670 contacts
= get_contacts_supporting_blocking (individual
);
672 /* Can't block, no persona supports blocking */
673 if (contacts
== NULL
)
676 item
= gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
678 g_object_set_data_full (G_OBJECT (item
), "individual",
679 g_object_ref (individual
), g_object_unref
);
681 for (l
= contacts
; l
!= NULL
; l
= g_list_next (l
))
683 TpContact
*contact
= l
->data
;
685 tp_g_signal_connect_object (contact
, "notify::is-blocked",
686 G_CALLBACK (contact_blocked_changed_cb
), item
, 0);
689 g_signal_connect (item
, "toggled",
690 G_CALLBACK (empathy_individual_block_menu_item_toggled
), individual
);
692 update_block_menu_item (item
, individual
);
694 g_list_free (contacts
);
701 REMOVE_DIALOG_RESPONSE_CANCEL
= 0,
702 REMOVE_DIALOG_RESPONSE_DELETE
,
703 REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK
,
704 REMOVE_DIALOG_RESPONSE_REMOVE_FROM_GROUP
708 remove_dialog_show (const gchar
*message
,
709 const gchar
*secondary_text
,
710 gboolean show_remove_from_group
,
711 gboolean block_button
,
713 const gchar
*active_group
)
718 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
719 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_NONE
, "%s", message
);
723 GtkWidget
*image
= gtk_image_new_from_pixbuf (avatar
);
724 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog
), image
);
725 gtk_widget_show (image
);
728 if (show_remove_from_group
)
731 gchar
*button_text
= g_strdup_printf (_("Remove from _Group \'%s\'"),
734 /* gtk_dialog_add_button() doesn't allow us to pass a string with a
735 * mnemonic so we have to create the button manually. */
736 button
= gtk_button_new_with_mnemonic (button_text
);
737 g_free (button_text
);
739 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
,
740 REMOVE_DIALOG_RESPONSE_REMOVE_FROM_GROUP
);
742 gtk_widget_show (button
);
749 /* gtk_dialog_add_button() doesn't allow us to pass a string with a
750 * mnemonic so we have to create the button manually. */
751 button
= gtk_button_new_with_mnemonic (
752 _("Delete and _Block"));
754 gtk_dialog_add_action_widget (GTK_DIALOG (dialog
), button
,
755 REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK
);
757 gtk_widget_show (button
);
760 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
761 GTK_STOCK_CANCEL
, REMOVE_DIALOG_RESPONSE_CANCEL
,
762 GTK_STOCK_DELETE
, REMOVE_DIALOG_RESPONSE_DELETE
, NULL
);
763 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog
),
764 "%s", secondary_text
);
766 gtk_widget_show (dialog
);
768 res
= gtk_dialog_run (GTK_DIALOG (dialog
));
769 gtk_widget_destroy (dialog
);
775 individual_removed_from_group_cb (GObject
*source_object
,
779 GError
*error
= NULL
;
780 FolksIndividual
*individual
= FOLKS_INDIVIDUAL (source_object
);
782 folks_group_details_change_group_finish (
783 FOLKS_GROUP_DETAILS (individual
), res
, &error
);
786 DEBUG ("Individual could not be removed from group: %s",
788 g_error_free (error
);
793 remove_got_avatar (GObject
*source_object
,
794 GAsyncResult
*result
,
797 FolksIndividual
*individual
= FOLKS_INDIVIDUAL (source_object
);
798 EmpathyIndividualMenu
*self
= EMPATHY_INDIVIDUAL_MENU (user_data
);
799 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (self
);
801 EmpathyIndividualManager
*manager
;
804 guint persona_count
= 0;
806 GError
*error
= NULL
;
808 gboolean show_remove_from_group
;
811 avatar
= empathy_pixbuf_avatar_from_individual_scaled_finish (individual
,
816 DEBUG ("Could not get avatar: %s", error
->message
);
817 g_error_free (error
);
820 /* We couldn't retrieve the avatar, but that isn't a fatal error,
821 * so we still display the remove dialog. */
823 groups
= folks_group_details_get_groups (FOLKS_GROUP_DETAILS (individual
));
824 show_remove_from_group
=
825 gee_collection_get_size (GEE_COLLECTION (groups
)) > 1;
827 personas
= folks_individual_get_personas (individual
);
829 persona_count
= gee_collection_get_size (GEE_COLLECTION (personas
));
831 /* If we have more than one TpfPersona, display a different message
832 * ensuring the user knows that *all* of the meta-contacts' personas will
835 if (persona_count
< 2)
837 /* Not a meta-contact */
840 _("Do you really want to remove the contact '%s'?"),
841 folks_alias_details_get_alias (
842 FOLKS_ALIAS_DETAILS (individual
)));
849 _("Do you really want to remove the linked contact '%s'? "
850 "Note that this will remove all the contacts which make up "
851 "this linked contact."),
852 folks_alias_details_get_alias (
853 FOLKS_ALIAS_DETAILS (individual
)));
857 manager
= empathy_individual_manager_dup_singleton ();
858 can_block
= empathy_individual_manager_supports_blocking (manager
,
860 res
= remove_dialog_show (_("Removing contact"), text
,
861 show_remove_from_group
, can_block
, avatar
, priv
->active_group
);
863 if (res
== REMOVE_DIALOG_RESPONSE_REMOVE_FROM_GROUP
)
865 folks_group_details_change_group (FOLKS_GROUP_DETAILS (individual
),
866 priv
->active_group
, false, individual_removed_from_group_cb
, NULL
);
870 if (res
== REMOVE_DIALOG_RESPONSE_DELETE
||
871 res
== REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK
)
875 if (res
== REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK
)
877 if (!empathy_block_individual_dialog_show (NULL
, individual
,
881 empathy_individual_manager_set_blocked (manager
, individual
,
885 empathy_individual_manager_remove (manager
, individual
, "");
890 g_object_unref (manager
);
891 g_object_unref (self
);
895 remove_activate_cb (GtkMenuItem
*menuitem
,
896 EmpathyIndividualMenu
*self
)
898 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (self
);
900 empathy_pixbuf_avatar_from_individual_scaled_async (priv
->individual
,
901 48, 48, NULL
, remove_got_avatar
, g_object_ref (self
));
905 empathy_individiual_remove_menu_item_new (EmpathyIndividualMenu
*self
)
909 gboolean can_remove
= FALSE
;
910 GtkWidget
*item
, *image
;
911 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (self
);
913 /* If any of the Individual's personas can be removed, add an option to
914 * remove. This will act as a best-effort option. If any Personas cannot be
915 * removed from the server, then this option will just be inactive upon
916 * subsequent menu openings */
917 personas
= folks_individual_get_personas (priv
->individual
);
918 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
919 while (!can_remove
&& gee_iterator_next (iter
))
921 FolksPersona
*persona
= gee_iterator_get (iter
);
922 FolksPersonaStore
*store
= folks_persona_get_store (persona
);
923 FolksMaybeBool maybe_can_remove
=
924 folks_persona_store_get_can_remove_personas (store
);
926 if (maybe_can_remove
== FOLKS_MAYBE_BOOL_TRUE
)
929 g_clear_object (&persona
);
931 g_clear_object (&iter
);
936 item
= gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
937 image
= gtk_image_new_from_icon_name (GTK_STOCK_REMOVE
,
939 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
941 g_signal_connect (item
, "activate",
942 G_CALLBACK (remove_activate_cb
), self
);
948 constructed (GObject
*object
)
950 EmpathyIndividualMenu
*self
= EMPATHY_INDIVIDUAL_MENU (object
);
951 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (object
);
954 FolksIndividual
*individual
;
955 EmpathyIndividualFeatureFlags features
;
958 shell
= GTK_MENU_SHELL (object
);
959 individual
= priv
->individual
;
960 features
= priv
->features
;
963 if (features
& EMPATHY_INDIVIDUAL_FEATURE_ADD_CONTACT
)
965 item
= empathy_individual_add_menu_item_new (self
, individual
);
968 gtk_menu_shell_append (GTK_MENU_SHELL (shell
), item
);
969 gtk_widget_show (item
);
974 if (features
& EMPATHY_INDIVIDUAL_FEATURE_CHAT
)
976 item
= empathy_individual_chat_menu_item_new (self
, individual
);
979 gtk_menu_shell_append (shell
, item
);
980 gtk_widget_show (item
);
985 if (features
& EMPATHY_INDIVIDUAL_FEATURE_SMS
)
987 item
= empathy_individual_sms_menu_item_new (self
, individual
);
990 gtk_menu_shell_append (shell
, item
);
991 gtk_widget_show (item
);
995 if (features
& EMPATHY_INDIVIDUAL_FEATURE_CALL
)
998 item
= empathy_individual_audio_call_menu_item_new (self
, individual
);
999 gtk_menu_shell_append (shell
, item
);
1000 gtk_widget_show (item
);
1003 item
= empathy_individual_video_call_menu_item_new (self
, individual
);
1004 gtk_menu_shell_append (shell
, item
);
1005 gtk_widget_show (item
);
1008 if (features
& EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE
)
1009 add_phone_numbers (self
);
1012 item
= empathy_individual_invite_menu_item_new (individual
, NULL
);
1013 gtk_menu_shell_append (shell
, item
);
1014 gtk_widget_show (item
);
1017 if (features
& EMPATHY_INDIVIDUAL_FEATURE_FILE_TRANSFER
)
1019 item
= empathy_individual_file_transfer_menu_item_new (self
, individual
);
1020 gtk_menu_shell_append (shell
, item
);
1021 gtk_widget_show (item
);
1024 /* Share my desktop */
1025 /* FIXME we should add the "Share my desktop" menu item if Vino is
1026 a registered handler in MC5 */
1027 item
= empathy_individual_share_my_desktop_menu_item_new (self
, individual
);
1028 gtk_menu_shell_append (shell
, item
);
1029 gtk_widget_show (item
);
1031 /* Menu items to target specific contacts */
1032 individual_menu_add_personas (self
, GTK_MENU_SHELL (object
),
1033 individual
, features
);
1036 if (features
& (EMPATHY_INDIVIDUAL_FEATURE_EDIT
|
1037 EMPATHY_INDIVIDUAL_FEATURE_INFO
|
1038 EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE
))
1040 item
= gtk_separator_menu_item_new ();
1041 gtk_menu_shell_append (shell
, item
);
1042 gtk_widget_show (item
);
1046 if (features
& EMPATHY_INDIVIDUAL_FEATURE_EDIT
)
1048 item
= empathy_individual_edit_menu_item_new (individual
);
1049 gtk_menu_shell_append (shell
, item
);
1050 gtk_widget_show (item
);
1054 if (features
& EMPATHY_INDIVIDUAL_FEATURE_LOG
)
1056 item
= empathy_individual_log_menu_item_new (individual
);
1057 gtk_menu_shell_append (shell
, item
);
1058 gtk_widget_show (item
);
1062 if (features
& EMPATHY_INDIVIDUAL_FEATURE_INFO
)
1064 item
= empathy_individual_info_menu_item_new (individual
);
1065 gtk_menu_shell_append (shell
, item
);
1066 gtk_widget_show (item
);
1069 /* Favorite checkbox */
1070 if (features
& EMPATHY_INDIVIDUAL_FEATURE_FAVOURITE
)
1072 item
= empathy_individual_favourite_menu_item_new (individual
);
1073 gtk_menu_shell_append (shell
, item
);
1074 gtk_widget_show (item
);
1077 /* Separator & Block */
1078 if (features
& EMPATHY_INDIVIDUAL_FEATURE_BLOCK
&&
1079 (item
= empathy_individiual_block_menu_item_new (individual
)) != NULL
) {
1082 sep
= gtk_separator_menu_item_new ();
1083 gtk_menu_shell_append (shell
, sep
);
1084 gtk_widget_show (sep
);
1086 gtk_menu_shell_append (shell
, item
);
1087 gtk_widget_show (item
);
1090 /* Separator & Remove */
1091 if (features
& EMPATHY_INDIVIDUAL_FEATURE_REMOVE
&&
1092 (item
= empathy_individiual_remove_menu_item_new (self
)) != NULL
) {
1095 sep
= gtk_separator_menu_item_new ();
1096 gtk_menu_shell_append (shell
, sep
);
1097 gtk_widget_show (sep
);
1099 gtk_menu_shell_append (shell
, item
);
1100 gtk_widget_show (item
);
1105 get_property (GObject
*object
,
1110 EmpathyIndividualMenuPriv
*priv
;
1112 priv
= GET_PRIV (object
);
1116 case PROP_ACTIVE_GROUP
:
1117 g_value_set_string (value
, priv
->active_group
);
1119 case PROP_INDIVIDUAL
:
1120 g_value_set_object (value
, priv
->individual
);
1123 g_value_set_flags (value
, priv
->features
);
1126 g_value_set_object (value
, priv
->store
);
1129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
1135 set_property (GObject
*object
,
1137 const GValue
*value
,
1140 EmpathyIndividualMenuPriv
*priv
;
1142 priv
= GET_PRIV (object
);
1146 case PROP_ACTIVE_GROUP
:
1147 g_assert (priv
->active_group
== NULL
); /* construct only */
1148 priv
->active_group
= g_value_dup_string (value
);
1150 case PROP_INDIVIDUAL
:
1151 priv
->individual
= g_value_dup_object (value
);
1154 priv
->features
= g_value_get_flags (value
);
1157 priv
->store
= g_value_dup_object (value
); /* read only */
1160 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
1166 dispose (GObject
*object
)
1168 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (object
);
1170 tp_clear_object (&priv
->individual
);
1171 tp_clear_object (&priv
->store
);
1173 G_OBJECT_CLASS (empathy_individual_menu_parent_class
)->dispose (object
);
1177 finalize (GObject
*object
)
1179 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (object
);
1181 g_free (priv
->active_group
);
1183 G_OBJECT_CLASS (empathy_individual_menu_parent_class
)->finalize (object
);
1187 empathy_individual_menu_class_init (EmpathyIndividualMenuClass
*klass
)
1189 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1191 object_class
->constructed
= constructed
;
1192 object_class
->get_property
= get_property
;
1193 object_class
->set_property
= set_property
;
1194 object_class
->dispose
= dispose
;
1195 object_class
->finalize
= finalize
;
1198 * gchar *:active-group:
1200 * The group the selected roster-contact widget belongs, or NULL.
1202 g_object_class_install_property (object_class
, PROP_ACTIVE_GROUP
,
1203 g_param_spec_string ("active-group",
1205 "The group the selected roster-contact widget belongs, or NULL",
1207 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
));
1210 * EmpathyIndividualMenu:individual:
1212 * The #FolksIndividual the menu is for.
1214 g_object_class_install_property (object_class
, PROP_INDIVIDUAL
,
1215 g_param_spec_object ("individual",
1217 "The #FolksIndividual the menu is for.",
1218 FOLKS_TYPE_INDIVIDUAL
,
1219 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
));
1222 * EmpathyIndividualMenu:features:
1224 * A set of feature flags controlling which entries are shown.
1226 g_object_class_install_property (object_class
, PROP_FEATURES
,
1227 g_param_spec_flags ("features",
1229 "A set of feature flags controlling which entries are shown.",
1230 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS
,
1231 EMPATHY_INDIVIDUAL_FEATURE_NONE
,
1232 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
));
1234 g_object_class_install_property (object_class
, PROP_STORE
,
1235 g_param_spec_object ("store",
1237 "The EmpathyIndividualStore to use to get contact owner",
1238 EMPATHY_TYPE_INDIVIDUAL_STORE
,
1239 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
));
1241 signals
[MENU_ITEM_ACTIVATED
] =
1242 g_signal_new ("menu-item-activated",
1243 G_TYPE_FROM_CLASS (klass
),
1247 g_cclosure_marshal_generic
,
1251 g_type_class_add_private (object_class
, sizeof (EmpathyIndividualMenuPriv
));
1255 empathy_individual_menu_new (FolksIndividual
*individual
,
1256 const gchar
*active_group
,
1257 EmpathyIndividualFeatureFlags features
,
1258 EmpathyIndividualStore
*store
)
1260 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1261 g_return_val_if_fail (store
== NULL
||
1262 EMPATHY_IS_INDIVIDUAL_STORE (store
), NULL
);
1263 g_return_val_if_fail (features
!= EMPATHY_INDIVIDUAL_FEATURE_NONE
, NULL
);
1265 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU
,
1266 "active-group", active_group
,
1267 "individual", individual
,
1268 "features", features
,
1273 /* Like menu_item_set_first_contact(), but always operates upon the given
1274 * contact. If the contact is non-NULL, it is assumed that the menu entry should
1277 menu_item_set_contact (GtkWidget
*item
,
1278 EmpathyContact
*contact
,
1279 GCallback activate_callback
,
1280 EmpathyActionType action_type
)
1282 gboolean can_do_action
= FALSE
;
1284 if (contact
!= NULL
)
1285 can_do_action
= empathy_contact_can_do_action (contact
, action_type
);
1286 gtk_widget_set_sensitive (item
, can_do_action
);
1288 if (can_do_action
== TRUE
)
1290 /* We want to make sure that the EmpathyContact stays alive while the
1291 * signal is connected. */
1292 g_signal_connect_data (item
, "activate", G_CALLBACK (activate_callback
),
1293 g_object_ref (contact
), (GClosureNotify
) g_object_unref
, 0);
1296 return can_do_action
;
1300 * Set the given menu @item to call @activate_callback using the TpContact
1301 * (associated with @individual) with the highest availability who is also valid
1302 * whenever @item is activated.
1304 * @action_type is the type of action performed by the menu entry; this is used
1305 * so that only contacts which can perform that action (e.g. are capable of
1306 * receiving video calls) are selected, as appropriate.
1309 menu_item_set_first_contact (GtkWidget
*item
,
1310 FolksIndividual
*individual
,
1311 GCallback activate_callback
,
1312 EmpathyActionType action_type
)
1314 EmpathyContact
*best_contact
;
1316 best_contact
= empathy_contact_dup_best_for_action (individual
, action_type
);
1317 menu_item_set_contact (item
, best_contact
, G_CALLBACK (activate_callback
),
1319 tp_clear_object (&best_contact
);
1325 emit_menu_item_activated (GtkMenuItem
*item
)
1327 EmpathyIndividualMenu
*self
;
1329 self
= EMPATHY_INDIVIDUAL_MENU (g_object_get_data (G_OBJECT (item
),
1330 "individual-menu"));
1331 g_signal_emit (self
, signals
[MENU_ITEM_ACTIVATED
], 0);
1335 empathy_individual_chat_menu_item_activated (GtkMenuItem
*item
,
1336 EmpathyContact
*contact
)
1338 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1340 empathy_chat_with_contact (contact
, empathy_get_current_action_time ());
1342 emit_menu_item_activated (item
);
1346 empathy_individual_chat_menu_item_new (EmpathyIndividualMenu
*self
,
1347 FolksIndividual
*individual
)
1352 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
) &&
1353 empathy_folks_individual_contains_contact (individual
), NULL
);
1355 item
= gtk_image_menu_item_new_with_mnemonic (_("_Chat"));
1356 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE
,
1357 GTK_ICON_SIZE_MENU
);
1358 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1359 gtk_widget_show (image
);
1361 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1362 menu_item_set_first_contact (item
, individual
,
1363 G_CALLBACK (empathy_individual_chat_menu_item_activated
),
1364 EMPATHY_ACTION_CHAT
);
1370 empathy_individual_sms_menu_item_activated (GtkMenuItem
*item
,
1371 EmpathyContact
*contact
)
1373 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1375 empathy_sms_contact_id (
1376 empathy_contact_get_account (contact
),
1377 empathy_contact_get_id (contact
),
1378 empathy_get_current_action_time (),
1381 emit_menu_item_activated (item
);
1385 empathy_individual_sms_menu_item_new (EmpathyIndividualMenu
*self
,
1386 FolksIndividual
*individual
)
1391 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
) &&
1392 empathy_folks_individual_contains_contact (individual
), NULL
);
1394 item
= gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
1395 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS
,
1396 GTK_ICON_SIZE_MENU
);
1397 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1398 gtk_widget_show (image
);
1400 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1401 menu_item_set_first_contact (item
, individual
,
1402 G_CALLBACK (empathy_individual_sms_menu_item_activated
),
1403 EMPATHY_ACTION_SMS
);
1409 empathy_individual_audio_call_menu_item_activated (GtkMenuItem
*item
,
1410 EmpathyContact
*contact
)
1412 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1414 empathy_call_new_with_streams (empathy_contact_get_id (contact
),
1415 empathy_contact_get_account (contact
),
1417 empathy_get_current_action_time ());
1419 emit_menu_item_activated (item
);
1423 empathy_individual_audio_call_menu_item_new (EmpathyIndividualMenu
*self
,
1424 FolksIndividual
*individual
)
1429 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1431 item
= gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio Call"));
1432 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP
, GTK_ICON_SIZE_MENU
);
1433 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1434 gtk_widget_show (image
);
1436 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1437 menu_item_set_first_contact (item
, individual
,
1438 G_CALLBACK (empathy_individual_audio_call_menu_item_activated
),
1439 EMPATHY_ACTION_AUDIO_CALL
);
1445 empathy_individual_video_call_menu_item_activated (GtkMenuItem
*item
,
1446 EmpathyContact
*contact
)
1448 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1450 empathy_call_new_with_streams (empathy_contact_get_id (contact
),
1451 empathy_contact_get_account (contact
),
1453 empathy_get_current_action_time ());
1455 emit_menu_item_activated (item
);
1459 empathy_individual_video_call_menu_item_new (EmpathyIndividualMenu
*self
,
1460 FolksIndividual
*individual
)
1464 TpawCameraMonitor
*monitor
;
1466 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1468 item
= gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
1469 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL
,
1470 GTK_ICON_SIZE_MENU
);
1471 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1472 gtk_widget_show (image
);
1474 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1475 menu_item_set_first_contact (item
, individual
,
1476 G_CALLBACK (empathy_individual_video_call_menu_item_activated
),
1477 EMPATHY_ACTION_VIDEO_CALL
);
1479 /* Only follow available cameras if the contact can do Video calls */
1480 if (gtk_widget_get_sensitive (item
))
1482 monitor
= tpaw_camera_monitor_dup_singleton ();
1483 g_object_set_data_full (G_OBJECT (item
),
1484 "monitor", monitor
, g_object_unref
);
1485 g_object_bind_property (monitor
, "available", item
, "sensitive",
1486 G_BINDING_SYNC_CREATE
);
1493 empathy_individual_log_menu_item_activated (GtkMenuItem
*item
,
1494 EmpathyContact
*contact
)
1496 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1498 empathy_log_window_show (empathy_contact_get_account (contact
),
1499 empathy_contact_get_id (contact
), FALSE
, NULL
);
1503 empathy_individual_log_menu_item_new (FolksIndividual
*individual
)
1508 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1510 item
= gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
1511 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG
, GTK_ICON_SIZE_MENU
);
1512 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1513 gtk_widget_show (image
);
1515 menu_item_set_first_contact (item
, individual
,
1516 G_CALLBACK (empathy_individual_log_menu_item_activated
),
1517 EMPATHY_ACTION_VIEW_LOGS
);
1523 empathy_individual_file_transfer_menu_item_activated (GtkMenuItem
*item
,
1524 EmpathyContact
*contact
)
1526 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1528 empathy_send_file_with_file_chooser (contact
);
1530 emit_menu_item_activated (item
);
1534 empathy_individual_file_transfer_menu_item_new (EmpathyIndividualMenu
*self
,
1535 FolksIndividual
*individual
)
1540 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1542 item
= gtk_image_menu_item_new_with_mnemonic (_("Send File"));
1543 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND
,
1544 GTK_ICON_SIZE_MENU
);
1545 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1546 gtk_widget_show (image
);
1548 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1549 menu_item_set_first_contact (item
, individual
,
1550 G_CALLBACK (empathy_individual_file_transfer_menu_item_activated
),
1551 EMPATHY_ACTION_SEND_FILE
);
1557 empathy_individual_share_my_desktop_menu_item_activated (GtkMenuItem
*item
,
1558 EmpathyContact
*contact
)
1560 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1562 empathy_share_my_desktop_share_with_contact (contact
);
1564 emit_menu_item_activated (item
);
1568 empathy_individual_share_my_desktop_menu_item_new (EmpathyIndividualMenu
*self
,
1569 FolksIndividual
*individual
)
1574 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1576 item
= gtk_image_menu_item_new_with_mnemonic (_("Share My Desktop"));
1577 image
= gtk_image_new_from_icon_name (GTK_STOCK_NETWORK
, GTK_ICON_SIZE_MENU
);
1578 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1579 gtk_widget_show (image
);
1581 g_object_set_data (G_OBJECT (item
), "individual-menu", self
);
1582 menu_item_set_first_contact (item
, individual
,
1583 G_CALLBACK (empathy_individual_share_my_desktop_menu_item_activated
),
1584 EMPATHY_ACTION_SHARE_MY_DESKTOP
);
1590 favourite_menu_item_toggled_cb (GtkCheckMenuItem
*item
,
1591 FolksIndividual
*individual
)
1593 folks_favourite_details_set_is_favourite (
1594 FOLKS_FAVOURITE_DETAILS (individual
),
1595 gtk_check_menu_item_get_active (item
));
1599 empathy_individual_favourite_menu_item_new (FolksIndividual
*individual
)
1603 item
= gtk_check_menu_item_new_with_label (_("Favorite"));
1605 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item
),
1606 folks_favourite_details_get_is_favourite (
1607 FOLKS_FAVOURITE_DETAILS (individual
)));
1609 g_signal_connect (item
, "toggled",
1610 G_CALLBACK (favourite_menu_item_toggled_cb
), individual
);
1616 individual_info_menu_item_activate_cb (GtkMenuItem
*item
,
1617 FolksIndividual
*individual
)
1619 empathy_display_individual_info (individual
);
1623 empathy_individual_info_menu_item_new (FolksIndividual
*individual
)
1628 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1629 g_return_val_if_fail (empathy_folks_individual_contains_contact (individual
),
1632 item
= gtk_image_menu_item_new_with_mnemonic (_("Infor_mation"));
1633 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_CONTACT_INFORMATION
,
1634 GTK_ICON_SIZE_MENU
);
1635 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1636 gtk_widget_show (image
);
1638 g_signal_connect (item
, "activate",
1639 G_CALLBACK (individual_info_menu_item_activate_cb
),
1646 individual_edit_menu_item_activate_cb (FolksIndividual
*individual
)
1648 empathy_individual_edit_dialog_show (individual
, NULL
);
1652 empathy_individual_edit_menu_item_new (FolksIndividual
*individual
)
1654 EmpathyIndividualManager
*manager
;
1657 gboolean enable
= FALSE
;
1658 EmpathyContact
*contact
;
1660 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
), NULL
);
1662 contact
= empathy_contact_dup_from_folks_individual (individual
);
1664 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact
), NULL
);
1666 if (empathy_individual_manager_initialized ())
1668 TpConnection
*connection
;
1670 manager
= empathy_individual_manager_dup_singleton ();
1671 connection
= empathy_contact_get_connection (contact
);
1673 enable
= (empathy_connection_can_alias_personas (connection
,
1675 empathy_connection_can_group_personas (connection
, individual
));
1677 g_object_unref (manager
);
1680 item
= gtk_image_menu_item_new_with_mnemonic (
1681 C_("Edit individual (contextual menu)", "_Edit"));
1682 image
= gtk_image_new_from_icon_name (GTK_STOCK_EDIT
, GTK_ICON_SIZE_MENU
);
1683 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1684 gtk_widget_show (image
);
1686 gtk_widget_set_sensitive (item
, enable
);
1688 g_signal_connect_swapped (item
, "activate",
1689 G_CALLBACK (individual_edit_menu_item_activate_cb
), individual
);
1691 g_object_unref (contact
);
1698 FolksIndividual
*individual
;
1699 EmpathyContact
*contact
;
1700 EmpathyChatroom
*chatroom
;
1703 static RoomSubMenuData
*
1704 room_sub_menu_data_new (FolksIndividual
*individual
,
1705 EmpathyContact
*contact
,
1706 EmpathyChatroom
*chatroom
)
1708 RoomSubMenuData
*data
;
1710 data
= g_slice_new0 (RoomSubMenuData
);
1711 if (individual
!= NULL
)
1712 data
->individual
= g_object_ref (individual
);
1713 if (contact
!= NULL
)
1714 data
->contact
= g_object_ref (contact
);
1715 data
->chatroom
= g_object_ref (chatroom
);
1721 room_sub_menu_data_free (RoomSubMenuData
*data
)
1723 tp_clear_object (&data
->individual
);
1724 tp_clear_object (&data
->contact
);
1725 g_object_unref (data
->chatroom
);
1726 g_slice_free (RoomSubMenuData
, data
);
1730 room_sub_menu_activate_cb (GtkWidget
*item
,
1731 RoomSubMenuData
*data
)
1733 EmpathyTpChat
*chat
;
1734 EmpathyChatroomManager
*mgr
;
1735 EmpathyContact
*contact
= NULL
;
1737 chat
= empathy_chatroom_get_tp_chat (data
->chatroom
);
1740 /* channel was invalidated. Ignoring */
1744 mgr
= empathy_chatroom_manager_dup_singleton (NULL
);
1746 if (data
->contact
!= NULL
)
1747 contact
= g_object_ref (data
->contact
);
1753 /* find the first of this Individual's contacts who can join this room */
1754 personas
= folks_individual_get_personas (data
->individual
);
1756 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
1757 while (gee_iterator_next (iter
) && (contact
== NULL
))
1759 TpfPersona
*persona
= gee_iterator_get (iter
);
1760 TpContact
*tp_contact
;
1763 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona
)))
1765 tp_contact
= tpf_persona_get_contact (persona
);
1766 if (tp_contact
!= NULL
)
1768 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
1770 rooms
= empathy_chatroom_manager_get_chatrooms (mgr
,
1771 empathy_contact_get_account (contact
));
1773 if (g_list_find (rooms
, data
->chatroom
) == NULL
)
1774 g_clear_object (&contact
);
1776 /* if contact != NULL here, we've found our match */
1778 g_list_free (rooms
);
1781 g_clear_object (&persona
);
1783 g_clear_object (&iter
);
1786 g_object_unref (mgr
);
1788 if (contact
== NULL
)
1790 /* contact disappeared. Ignoring */
1794 g_return_if_fail (EMPATHY_IS_CONTACT (contact
));
1796 /* send invitation */
1797 empathy_tp_chat_add (chat
, contact
, _("Inviting you to this room"));
1800 g_object_unref (contact
);
1804 create_room_sub_menu (FolksIndividual
*individual
,
1805 EmpathyContact
*contact
,
1806 EmpathyChatroom
*chatroom
)
1809 RoomSubMenuData
*data
;
1811 item
= gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom
));
1812 data
= room_sub_menu_data_new (individual
, contact
, chatroom
);
1813 g_signal_connect_data (item
, "activate",
1814 G_CALLBACK (room_sub_menu_activate_cb
), data
,
1815 (GClosureNotify
) room_sub_menu_data_free
, 0);
1821 empathy_individual_invite_menu_item_new (FolksIndividual
*individual
,
1822 EmpathyContact
*contact
)
1826 GtkWidget
*room_item
;
1827 EmpathyChatroomManager
*mgr
;
1828 GList
*rooms
= NULL
;
1829 GList
*names
= NULL
;
1831 GtkWidget
*submenu
= NULL
;
1832 /* map of chat room names to their objects; just a utility to remove
1833 * duplicates and to make construction of the alphabetized list easier */
1834 GHashTable
*name_room_map
;
1836 g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual
) ||
1837 EMPATHY_IS_CONTACT (contact
),
1840 name_room_map
= g_hash_table_new_full (g_str_hash
, g_str_equal
, NULL
,
1843 item
= gtk_image_menu_item_new_with_mnemonic (_("_Invite to Chat Room"));
1844 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE
,
1845 GTK_ICON_SIZE_MENU
);
1846 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
1848 mgr
= empathy_chatroom_manager_dup_singleton (NULL
);
1850 if (contact
!= NULL
)
1852 rooms
= empathy_chatroom_manager_get_chatrooms (mgr
,
1853 empathy_contact_get_account (contact
));
1860 /* find the first of this Individual's contacts who can join this room */
1861 personas
= folks_individual_get_personas (individual
);
1862 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
1863 while (gee_iterator_next (iter
))
1865 TpfPersona
*persona
= gee_iterator_get (iter
);
1867 TpContact
*tp_contact
;
1868 EmpathyContact
*contact_cur
;
1870 if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona
)))
1872 tp_contact
= tpf_persona_get_contact (persona
);
1873 if (tp_contact
!= NULL
)
1875 contact_cur
= empathy_contact_dup_from_tp_contact (
1878 rooms_cur
= empathy_chatroom_manager_get_chatrooms (mgr
,
1879 empathy_contact_get_account (contact_cur
));
1880 rooms
= g_list_concat (rooms
, rooms_cur
);
1882 g_object_unref (contact_cur
);
1885 g_clear_object (&persona
);
1887 g_clear_object (&iter
);
1890 /* alphabetize the rooms */
1891 for (l
= rooms
; l
!= NULL
; l
= g_list_next (l
))
1893 EmpathyChatroom
*chatroom
= l
->data
;
1896 if (empathy_chatroom_get_tp_chat (chatroom
) != NULL
)
1900 name
= empathy_chatroom_get_name (chatroom
);
1901 existed
= (g_hash_table_lookup (name_room_map
, name
) != NULL
);
1902 g_hash_table_insert (name_room_map
, (gpointer
) name
,
1903 g_object_ref (chatroom
));
1905 /* this will take care of duplicates in rooms */
1908 names
= g_list_insert_sorted (names
, (gpointer
) name
,
1909 (GCompareFunc
) g_strcmp0
);
1914 for (l
= names
; l
!= NULL
; l
= g_list_next (l
))
1916 const gchar
*name
= l
->data
;
1917 EmpathyChatroom
*chatroom
;
1919 if (G_UNLIKELY (submenu
== NULL
))
1920 submenu
= gtk_menu_new ();
1922 chatroom
= g_hash_table_lookup (name_room_map
, name
);
1923 room_item
= create_room_sub_menu (individual
, contact
, chatroom
);
1924 gtk_menu_shell_append ((GtkMenuShell
*) submenu
, room_item
);
1925 gtk_widget_show (room_item
);
1929 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item
), submenu
);
1931 gtk_widget_set_sensitive (item
, FALSE
);
1933 gtk_widget_show (image
);
1935 g_hash_table_unref (name_room_map
);
1936 g_object_unref (mgr
);
1937 g_list_free (names
);
1938 g_list_free (rooms
);
1944 add_menu_item_activated (GtkMenuItem
*item
,
1945 TpContact
*tp_contact
)
1947 GtkWidget
*toplevel
;
1948 FolksIndividual
*individual
;
1950 toplevel
= gtk_widget_get_toplevel (GTK_WIDGET (item
));
1951 if (!gtk_widget_is_toplevel (toplevel
) || !GTK_IS_WINDOW (toplevel
))
1954 individual
= empathy_ensure_individual_from_tp_contact (tp_contact
);
1956 empathy_new_individual_dialog_show_with_individual (GTK_WINDOW (toplevel
),
1959 g_object_unref (individual
);
1963 empathy_individual_add_menu_item_new (EmpathyIndividualMenu
*self
,
1964 FolksIndividual
*individual
)
1966 EmpathyIndividualMenuPriv
*priv
= GET_PRIV (self
);
1967 GtkWidget
*item
, *image
;
1970 TpContact
*to_add
= NULL
;
1972 /* find the first of this Individual's personas which are not in our contact
1974 personas
= folks_individual_get_personas (individual
);
1975 iter
= gee_iterable_iterator (GEE_ITERABLE (personas
));
1976 while (gee_iterator_next (iter
))
1978 TpfPersona
*persona
= gee_iterator_get (iter
);
1982 if (!TPF_IS_PERSONA (persona
))
1985 contact
= tpf_persona_get_contact (persona
);
1986 if (contact
== NULL
)
1989 /* be sure to use a not channel specific contact.
1990 * TODO: Ideally tp-glib should do this for us (fdo #42702)*/
1991 if (EMPATHY_IS_INDIVIDUAL_STORE_CHANNEL (priv
->store
))
1994 TpChannelGroupFlags flags
;
1996 channel
= empathy_individual_store_channel_get_channel (
1997 EMPATHY_INDIVIDUAL_STORE_CHANNEL (priv
->store
));
1999 flags
= tp_channel_group_get_flags (channel
);
2000 if ((flags
& TP_CHANNEL_GROUP_FLAG_CHANNEL_SPECIFIC_HANDLES
) != 0)
2002 /* Channel uses channel specific handles (thanks XMPP...) */
2003 contact
= tp_channel_group_get_contact_owner (channel
, contact
);
2005 /* If we don't know the owner, we can't add the contact */
2006 if (contact
== NULL
)
2011 conn
= tp_contact_get_connection (contact
);
2015 /* No point to try adding a contact if the CM doesn't support it */
2016 if (!tp_connection_get_can_change_contact_list (conn
))
2019 /* Can't add ourself */
2020 if (tp_connection_get_self_contact (conn
) == contact
)
2023 if (tp_contact_get_subscribe_state (contact
) == TP_SUBSCRIPTION_STATE_YES
)
2026 g_object_unref (persona
);
2031 g_object_unref (persona
);
2034 g_object_unref (iter
);
2039 item
= gtk_image_menu_item_new_with_mnemonic (_("_Add Contact…"));
2040 image
= gtk_image_new_from_icon_name (GTK_STOCK_ADD
, GTK_ICON_SIZE_MENU
);
2041 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
2043 g_signal_connect_data (item
, "activate",
2044 G_CALLBACK (add_menu_item_activated
),
2045 g_object_ref (to_add
), (GClosureNotify
) g_object_unref
, 0);