#include <folks/folks.h>
#include <folks/folks-telepathy.h>
-#include <libempathy/empathy-call-factory.h>
-#include <libempathy/empathy-dispatcher.h>
+#include <libempathy/empathy-camera-monitor.h>
+#include <libempathy/empathy-request-util.h>
#include <libempathy/empathy-individual-manager.h>
#include <libempathy/empathy-chatroom-manager.h>
#include <libempathy/empathy-utils.h>
+#include "empathy-account-selector-dialog.h"
#include "empathy-individual-menu.h"
#include "empathy-images.h"
#include "empathy-log-window.h"
#include "empathy-ui-utils.h"
#include "empathy-share-my-desktop.h"
#include "empathy-linking-dialog.h"
+#include "empathy-call-utils.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
+#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu)
EmpathyIndividualFeatureFlags features)
{
GtkWidget *item;
- GList *personas, *l;
+ GeeSet *personas;
+ GeeIterator *iter;
guint persona_count = 0;
+ gboolean c;
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (FOLKS_IS_INDIVIDUAL (individual));
g_return_if_fail (empathy_folks_individual_contains_contact (individual));
personas = folks_individual_get_personas (individual);
+ /* we'll re-use this iterator throughout */
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
/* Make sure we've got enough valid entries for these menu items to add
* functionality */
- for (l = personas; l != NULL; l = l->next)
+ while (gee_iterator_next (iter))
{
- if (!TPF_IS_PERSONA (l->data))
- continue;
+ FolksPersona *persona = gee_iterator_get (iter);
+ if (empathy_folks_persona_is_interesting (persona))
+ persona_count++;
- persona_count++;
+ g_clear_object (&persona);
}
/* return early if these entries would add nothing beyond the "quick" items */
gtk_widget_show (item);
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = l->next)
+ for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
{
GtkWidget *image;
GtkWidget *contact_item;
GtkWidget *contact_submenu;
TpContact *tp_contact;
EmpathyContact *contact;
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
gchar *label;
FolksPersonaStore *store;
const gchar *account;
GtkWidget *action;
- if (!TPF_IS_PERSONA (persona))
- continue;
+ if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ goto while_finish;
tp_contact = tpf_persona_get_contact (persona);
+ if (tp_contact == NULL)
+ goto while_finish;
+
contact = empathy_contact_dup_from_tp_contact (tp_contact);
store = folks_persona_get_store (FOLKS_PERSONA (persona));
gtk_widget_show (action);
}
+ /* SMS */
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
+ {
+ action = empathy_individual_sms_menu_item_new (NULL, contact);
+ gtk_menu_shell_append (GTK_MENU_SHELL (contact_submenu), action);
+ gtk_widget_show (action);
+ }
+
if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
{
/* Audio Call */
g_free (label);
g_object_unref (contact);
+
+while_finish:
+ g_clear_object (&persona);
}
+
+ g_clear_object (&iter);
}
static void
self->priv = priv;
}
+static GList *
+find_phone_accounts (void)
+{
+ TpAccountManager *am;
+ GList *accounts, *l;
+ GList *found = NULL;
+
+ am = tp_account_manager_dup ();
+ g_return_val_if_fail (am != NULL, NULL);
+
+ accounts = tp_account_manager_get_valid_accounts (am);
+ for (l = accounts; l != NULL; l = g_list_next (l))
+ {
+ TpAccount *account = l->data;
+
+ if (tp_account_get_connection_status (account, NULL) !=
+ TP_CONNECTION_STATUS_CONNECTED)
+ continue;
+
+ if (!empathy_account_has_uri_scheme_tel (account))
+ continue;
+
+ found = g_list_prepend (found, g_object_ref (account));
+ }
+
+ g_list_free (accounts);
+ g_object_unref (am);
+
+ return found;
+}
+
+static gboolean
+has_phone_account (void)
+{
+ GList *accounts;
+ gboolean result;
+
+ accounts = find_phone_accounts ();
+ result = (accounts != NULL);
+
+ g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
+
+ return result;
+}
+
+static void
+call_phone_number (FolksPhoneFieldDetails *details,
+ TpAccount *account)
+{
+ DEBUG ("Try to call %s", folks_phone_field_details_get_normalised (details));
+
+ empathy_call_new_with_streams (
+ folks_phone_field_details_get_normalised (details),
+ account, TRUE, FALSE, empathy_get_current_action_time ());
+}
+
+static void
+display_call_phone_dialog (FolksPhoneFieldDetails *details,
+ GList *accounts)
+{
+ GtkWidget *dialog;
+ gint response;
+
+ dialog = empathy_account_selector_dialog_new (accounts);
+
+ gtk_window_set_title (GTK_WINDOW (dialog),
+ _("Select account to use to place the call"));
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ _("Call"), GTK_RESPONSE_OK,
+ NULL);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ TpAccount *account;
+
+ account = empathy_account_selector_dialog_dup_selected (
+ EMPATHY_ACCOUNT_SELECTOR_DIALOG (dialog));
+
+ if (account != NULL)
+ {
+ call_phone_number (details, account);
+
+ g_object_unref (account);
+ }
+ }
+
+ gtk_widget_destroy (dialog);
+}
+
+static void
+call_phone_number_cb (GtkMenuItem *item,
+ FolksPhoneFieldDetails *details)
+{
+ GList *accounts;
+
+ accounts = find_phone_accounts ();
+ if (accounts == NULL)
+ {
+ DEBUG ("No phone aware account connected; can't call");
+ }
+ else if (g_list_length (accounts) == 1)
+ {
+ call_phone_number (details, accounts->data);
+ }
+ else
+ {
+ /* Ask which account to use */
+ display_call_phone_dialog (details, accounts);
+ }
+
+ g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
+}
+
+static const gchar *
+find_phone_type (FolksPhoneFieldDetails *details)
+{
+ GeeCollection *types;
+ GeeIterator *iter;
+
+ types = folks_abstract_field_details_get_parameter_values (
+ FOLKS_ABSTRACT_FIELD_DETAILS (details), "type");
+
+ if (types == NULL)
+ return NULL;
+
+ iter = gee_iterable_iterator (GEE_ITERABLE (types));
+ while (gee_iterator_next (iter))
+ {
+ const gchar *type = gee_iterator_get (iter);
+
+ if (!tp_strdiff (type, "CELL"))
+ return _("Mobile");
+ else if (!tp_strdiff (type, "WORK"))
+ return _("Work");
+ else if (!tp_strdiff (type, "HOME"))
+ return _("HOME");
+ }
+
+ return NULL;
+}
+
+static void
+add_phone_numbers (EmpathyIndividualMenu *self)
+{
+ EmpathyIndividualMenuPriv *priv = GET_PRIV (self);
+ GeeSet *all_numbers;
+ GeeIterator *iter;
+ gboolean sensitive;
+
+ all_numbers = folks_phone_details_get_phone_numbers (
+ FOLKS_PHONE_DETAILS (priv->individual));
+
+ sensitive = has_phone_account ();
+
+ iter = gee_iterable_iterator (GEE_ITERABLE (all_numbers));
+ while (gee_iterator_next (iter))
+ {
+ FolksPhoneFieldDetails *details = gee_iterator_get (iter);
+ GtkWidget *item, *image;
+ gchar *tmp;
+ const gchar *type;
+
+ type = find_phone_type (details);
+
+ if (type != NULL)
+ {
+ tmp = g_strdup_printf ("Call %s (%s)",
+ folks_phone_field_details_get_normalised (details),
+ type);
+ }
+ else
+ {
+ tmp = g_strdup_printf ("Call %s",
+ folks_phone_field_details_get_normalised (details));
+ }
+
+ item = gtk_image_menu_item_new_with_mnemonic (tmp);
+ g_free (tmp);
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (call_phone_number_cb), g_object_ref (details),
+ (GClosureNotify) g_object_unref, 0);
+
+ gtk_widget_set_sensitive (item, sensitive);
+
+ image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_CALL,
+ GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ gtk_widget_show (image);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (self), item);
+ gtk_widget_show (item);
+ }
+}
+
static void
constructed (GObject *object)
{
+ EmpathyIndividualMenu *self = (EmpathyIndividualMenu *) object;
EmpathyIndividualMenuPriv *priv = GET_PRIV (object);
GtkMenuShell *shell;
GtkWidget *item;
}
}
+ /* SMS */
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_SMS)
+ {
+ item = empathy_individual_sms_menu_item_new (individual, NULL);
+ if (item != NULL)
+ {
+ gtk_menu_shell_append (shell, item);
+ gtk_widget_show (item);
+ }
+ }
+
if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL)
{
/* Audio Call */
gtk_widget_show (item);
}
- /* Log */
- if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
- {
- item = empathy_individual_log_menu_item_new (individual, NULL);
- gtk_menu_shell_append (shell, item);
- gtk_widget_show (item);
- }
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_CALL_PHONE)
+ add_phone_numbers (self);
/* Invite */
item = empathy_individual_invite_menu_item_new (individual, NULL);
gtk_widget_show (item);
}
+ /* Log */
+ if (features & EMPATHY_INDIVIDUAL_FEATURE_LOG)
+ {
+ item = empathy_individual_log_menu_item_new (individual, NULL);
+ gtk_menu_shell_append (shell, item);
+ gtk_widget_show (item);
+ }
+
/* Info */
if (features & EMPATHY_INDIVIDUAL_FEATURE_INFO)
{
if (can_do_action == TRUE)
{
- g_signal_connect (item, "activate", G_CALLBACK (activate_callback),
- contact);
+ /* We want to make sure that the EmpathyContact stays alive while the
+ * signal is connected. */
+ g_signal_connect_data (item, "activate", G_CALLBACK (activate_callback),
+ g_object_ref (contact), (GClosureNotify) g_object_unref, 0);
}
return can_do_action;
{
g_return_if_fail (EMPATHY_IS_CONTACT (contact));
- empathy_dispatcher_chat_with_contact (contact, gtk_get_current_event_time ());
+ empathy_chat_with_contact (contact, empathy_get_current_action_time ());
}
GtkWidget *
return item;
}
+static void
+empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
+ EmpathyContact *contact)
+{
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+ empathy_sms_contact_id (
+ empathy_contact_get_account (contact),
+ empathy_contact_get_id (contact),
+ empathy_get_current_action_time ());
+}
+
+GtkWidget *
+empathy_individual_sms_menu_item_new (FolksIndividual *individual,
+ EmpathyContact *contact)
+{
+ GtkWidget *item;
+ GtkWidget *image;
+
+ g_return_val_if_fail ((FOLKS_IS_INDIVIDUAL (individual) &&
+ empathy_folks_individual_contains_contact (individual)) ||
+ EMPATHY_IS_CONTACT (contact),
+ NULL);
+
+ item = gtk_image_menu_item_new_with_mnemonic (_("_SMS"));
+ image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_SMS,
+ GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ gtk_widget_show (image);
+
+ if (contact != NULL)
+ {
+ menu_item_set_contact (item, contact,
+ G_CALLBACK (empathy_individual_sms_menu_item_activated),
+ EMPATHY_ACTION_SMS);
+ }
+ else
+ {
+ menu_item_set_first_contact (item, individual,
+ G_CALLBACK (empathy_individual_sms_menu_item_activated),
+ EMPATHY_ACTION_SMS);
+ }
+
+ return item;
+}
+
static void
empathy_individual_audio_call_menu_item_activated (GtkMenuItem *item,
EmpathyContact *contact)
{
g_return_if_fail (EMPATHY_IS_CONTACT (contact));
- empathy_call_factory_new_call_with_streams (contact, TRUE, FALSE,
- gtk_get_current_event_time (), NULL);
+ empathy_call_new_with_streams (empathy_contact_get_id (contact),
+ empathy_contact_get_account (contact),
+ TRUE, FALSE,
+ empathy_get_current_action_time ());
}
GtkWidget *
{
g_return_if_fail (EMPATHY_IS_CONTACT (contact));
- empathy_call_factory_new_call_with_streams (contact, TRUE, TRUE,
- gtk_get_current_event_time (), NULL);
+ empathy_call_new_with_streams (empathy_contact_get_id (contact),
+ empathy_contact_get_account (contact),
+ TRUE, TRUE,
+ empathy_get_current_action_time ());
}
GtkWidget *
{
GtkWidget *item;
GtkWidget *image;
+ EmpathyCameraMonitor *monitor;
g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual) ||
EMPATHY_IS_CONTACT (contact),
EMPATHY_ACTION_VIDEO_CALL);
}
+ /* Only follow available cameras if the contact can do Video calls */
+ if (gtk_widget_get_sensitive (item))
+ {
+ monitor = empathy_camera_monitor_dup_singleton ();
+ g_object_set_data_full (G_OBJECT (item),
+ "monitor", monitor, g_object_unref);
+ g_object_bind_property (monitor, "available", item, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ }
+
return item;
}
favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
FolksIndividual *individual)
{
- folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual),
+ folks_favourite_details_set_is_favourite (
+ FOLKS_FAVOURITE_DETAILS (individual),
gtk_check_menu_item_get_active (item));
}
item = gtk_check_menu_item_new_with_label (_("Favorite"));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
- folks_favourite_get_is_favourite (FOLKS_FAVOURITE (individual)));
+ folks_favourite_details_get_is_favourite (
+ FOLKS_FAVOURITE_DETAILS (individual)));
g_signal_connect (item, "toggled",
G_CALLBACK (favourite_menu_item_toggled_cb), individual);
if (empathy_individual_manager_initialized ())
{
TpConnection *connection;
- EmpathyIndividualManagerFlags flags;
manager = empathy_individual_manager_dup_singleton ();
connection = empathy_contact_get_connection (contact);
- flags = empathy_individual_manager_get_flags_for_connection (
- manager, connection);
- enable = (flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_ALIAS ||
- flags & EMPATHY_INDIVIDUAL_MANAGER_CAN_GROUP);
+ enable = (empathy_connection_can_alias_personas (connection,
+ individual) &&
+ empathy_connection_can_group_personas (connection, individual));
g_object_unref (manager);
}
EmpathyTpChat *chat;
EmpathyChatroomManager *mgr;
EmpathyContact *contact = NULL;
- GList *personas, *l;
chat = empathy_chatroom_get_tp_chat (data->chatroom);
if (chat == NULL)
contact = g_object_ref (data->contact);
else
{
+ GeeSet *personas;
+ GeeIterator *iter;
+
/* find the first of this Individual's contacts who can join this room */
personas = folks_individual_get_personas (data->individual);
- for (l = personas; l != NULL && contact == NULL; l = g_list_next (l))
+
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter) && (contact == NULL))
{
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
TpContact *tp_contact;
GList *rooms;
- if (!TPF_IS_PERSONA (persona))
- continue;
-
- tp_contact = tpf_persona_get_contact (persona);
- contact = empathy_contact_dup_from_tp_contact (tp_contact);
+ if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ if (tp_contact != NULL)
+ {
+ contact = empathy_contact_dup_from_tp_contact (tp_contact);
- rooms = empathy_chatroom_manager_get_chatrooms (mgr,
- empathy_contact_get_account (contact));
+ rooms = empathy_chatroom_manager_get_chatrooms (mgr,
+ empathy_contact_get_account (contact));
- if (g_list_find (rooms, data->chatroom) == NULL)
- tp_clear_object (&contact);
+ if (g_list_find (rooms, data->chatroom) == NULL)
+ g_clear_object (&contact);
- /* if contact != NULL here, we've found our match */
+ /* if contact != NULL here, we've found our match */
- g_list_free (rooms);
+ g_list_free (rooms);
+ }
+ }
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
g_object_unref (mgr);
GtkWidget *image;
GtkWidget *room_item;
EmpathyChatroomManager *mgr;
- GList *personas;
GList *rooms = NULL;
GList *names = NULL;
GList *l;
}
else
{
- /* collect the rooms from amongst all accounts for this Individual */
+ GeeSet *personas;
+ GeeIterator *iter;
+
+ /* find the first of this Individual's contacts who can join this room */
personas = folks_individual_get_personas (individual);
- for (l = personas; l != NULL; l = g_list_next (l))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
- TpfPersona *persona = l->data;
+ TpfPersona *persona = gee_iterator_get (iter);
GList *rooms_cur;
TpContact *tp_contact;
EmpathyContact *contact_cur;
- if (!TPF_IS_PERSONA (persona))
- continue;
-
- tp_contact = tpf_persona_get_contact (persona);
- contact_cur = empathy_contact_dup_from_tp_contact (tp_contact);
-
- rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
- empathy_contact_get_account (contact_cur));
- rooms = g_list_concat (rooms, rooms_cur);
-
- g_object_unref (contact_cur);
+ if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
+ {
+ tp_contact = tpf_persona_get_contact (persona);
+ if (tp_contact != NULL)
+ {
+ contact_cur = empathy_contact_dup_from_tp_contact (
+ tp_contact);
+
+ rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
+ empathy_contact_get_account (contact_cur));
+ rooms = g_list_concat (rooms, rooms_cur);
+
+ g_object_unref (contact_cur);
+ }
+ }
+ g_clear_object (&persona);
}
+ g_clear_object (&iter);
}
/* alphabetize the rooms */