#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
#include <champlain/champlain.h>
#include <champlain-gtk/champlain-gtk.h>
#endif
#include <telepathy-glib/interfaces.h>
#include <libempathy/empathy-tp-contact-factory.h>
-#include <libempathy/empathy-contact-manager.h>
#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-location.h>
#include <libempathy/empathy-time.h>
#include <libempathy/empathy-utils.h>
#include "empathy-contact-widget.h"
+#include "empathy-contactinfo-utils.h"
#include "empathy-account-chooser.h"
#include "empathy-avatar-chooser.h"
#include "empathy-avatar-image.h"
+#include "empathy-groups-widget.h"
#include "empathy-ui-utils.h"
#include "empathy-string-parser.h"
-#include "empathy-kludge-label.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
#include <libempathy/empathy-debug.h>
/* Delay before updating the widget when the id entry changed (seconds) */
#define ID_CHANGED_TIMEOUT 1
+#define DATA_FIELD "contact-info-field"
+
typedef struct
{
- EmpathyContactManager *manager;
EmpathyContact *contact;
EmpathyContactWidgetFlags flags;
guint widget_id_timeout;
GtkWidget *vbox_contact_widget;
/* Contact */
- GtkWidget *hbox_contact;
GtkWidget *widget_avatar;
GtkWidget *widget_account;
GtkWidget *image_account;
GtkWidget *hbox_presence;
GtkWidget *image_state;
GtkWidget *label_status;
- GtkWidget *table_contact;
+ GtkWidget *grid_contact;
GtkWidget *vbox_avatar;
GtkWidget *favourite_checkbox;
+ GtkWidget *label_details;
/* Location */
GtkWidget *vbox_location;
GtkWidget *subvbox_location;
- GtkWidget *table_location;
+ GtkWidget *grid_location;
GtkWidget *label_location;
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
GtkWidget *viewport_map;
GtkWidget *map_view_embed;
ChamplainView *map_view;
#endif
/* Groups */
- GtkWidget *vbox_groups;
- GtkWidget *entry_group;
- GtkWidget *button_group;
- GtkWidget *treeview_groups;
+ GtkWidget *groups_widget;
/* Details */
GtkWidget *vbox_details;
- GtkWidget *table_details;
+ GtkWidget *grid_details;
GtkWidget *hbox_details_requested;
GtkWidget *spinner_details;
GList *details_to_set;
GCancellable *details_cancellable;
+ gboolean details_changed;
/* Client */
GtkWidget *vbox_client;
- GtkWidget *table_client;
+ GtkWidget *grid_client;
GtkWidget *hbox_client_requested;
} EmpathyContactWidget;
COL_COUNT
};
+static gboolean
+field_value_is_empty (TpContactInfoField *field)
+{
+ guint i;
+
+ if (field->field_value == NULL)
+ return TRUE;
+
+ /* Field is empty if all its values are empty */
+ for (i = 0; field->field_value[i] != NULL; i++)
+ {
+ if (!tp_str_empty (field->field_value[i]))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+set_contact_info_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+
+ if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
+ &error))
+ {
+ DEBUG ("SetContactInfo() failed: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ DEBUG ("SetContactInfo() succeeded");
+}
+
static void
contact_widget_save (EmpathyContactWidget *information)
{
TpContactInfoField *field = l->data;
next = l->next;
- if (field->field_value == NULL || EMP_STR_EMPTY (field->field_value[0]))
+ if (field_value_is_empty (field))
{
DEBUG ("Drop empty field: %s", field->field_name);
tp_contact_info_field_free (field);
if (information->details_to_set != NULL)
{
- tp_connection_set_contact_info_async (connection,
- information->details_to_set, NULL, NULL);
+ if (information->details_changed)
+ {
+ tp_connection_set_contact_info_async (connection,
+ information->details_to_set, set_contact_info_cb, NULL);
+ }
+
tp_contact_info_list_free (information->details_to_set);
information->details_to_set = NULL;
}
static void
contact_widget_details_changed_cb (GtkEntry *entry,
- TpContactInfoField *field)
+ EmpathyContactWidget *self)
{
const gchar *strv[] = { NULL, NULL };
+ TpContactInfoField *field;
+
+ self->details_changed = TRUE;
+
+ field = g_object_get_data ((GObject *) entry, DATA_FIELD);
+ g_assert (field != NULL);
strv[0] = gtk_entry_get_text (entry);
field->field_value = g_strdupv ((GStrv) strv);
}
-static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
-
-typedef struct
+static void
+contact_widget_bday_changed_cb (GtkCalendar *calendar,
+ EmpathyContactWidget *self)
{
- const gchar *field_name;
- const gchar *title;
- gboolean linkify;
-} InfoFieldData;
+ guint year, month, day;
+ GDate *date;
+ gchar tmp[255];
+ const gchar *strv[] = { NULL, NULL };
+ TpContactInfoField *field;
-static InfoFieldData info_field_datas[] =
-{
- { "fn", N_("Full name:"), FALSE },
- { "tel", N_("Phone number:"), FALSE },
- { "email", N_("E-mail address:"), TRUE },
- { "url", N_("Website:"), TRUE },
- { "bday", N_("Birthday:"), FALSE },
- { NULL, NULL }
-};
+ self->details_changed = TRUE;
-static InfoFieldData *
-find_info_field_data (const gchar *field_name)
-{
- guint i;
+ field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
+ g_assert (field != NULL);
- for (i = 0; info_field_datas[i].field_name != NULL; i++)
- {
- if (!tp_strdiff (info_field_datas[i].field_name, field_name))
- return info_field_datas + i;
- }
- return NULL;
+ gtk_calendar_get_date (calendar, &year, &month, &day);
+ date = g_date_new_dmy (day, month+1, year);
+
+ gtk_calendar_clear_marks (calendar);
+ gtk_calendar_mark_day (calendar, g_date_get_day (date));
+
+ g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
+ strv[0] = tmp;
+ if (field->field_value != NULL)
+ g_strfreev (field->field_value);
+ field->field_value = g_strdupv ((GStrv) strv);
+
+ g_date_free (date);
}
-static gint
-contact_info_field_name_cmp (const gchar *name1,
- const gchar *name2)
-{
- guint i;
+static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
- if (!tp_strdiff (name1, name2))
- return 0;
+static gboolean
+field_name_in_field_list (GList *list,
+ const gchar *name)
+{
+ GList *l;
- /* We use the order of info_field_datas */
- for (i = 0; info_field_datas[i].field_name != NULL; i++)
+ for (l = list; l != NULL; l = g_list_next (l))
{
- if (!tp_strdiff (info_field_datas[i].field_name, name1))
- return -1;
- if (!tp_strdiff (info_field_datas[i].field_name, name2))
- return +1;
+ TpContactInfoField *field = l->data;
+
+ if (!tp_strdiff (field->field_name, name))
+ return TRUE;
}
- return g_strcmp0 (name1, name2);
+ return FALSE;
}
-static gint
-contact_info_field_cmp (TpContactInfoField *field1,
- TpContactInfoField *field2)
+static TpContactInfoFieldSpec *
+get_spec_from_list (GList *list,
+ const gchar *name)
{
- return contact_info_field_name_cmp (field1->field_name, field2->field_name);
-}
+ GList *l;
-static gint
-contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
- TpContactInfoFieldSpec *spec2)
-{
- return contact_info_field_name_cmp (spec1->name, spec2->name);
+ for (l = list; l != NULL; l = g_list_next (l))
+ {
+ TpContactInfoFieldSpec *spec = l->data;
+
+ if (!tp_strdiff (spec->name, name))
+ return spec;
+ }
+
+ return NULL;
}
static guint
TpConnection *connection;
GList *specs, *l;
guint n_rows = 0;
+ GList *info;
+ const char **field_names = empathy_contact_info_get_field_names (NULL);
+ guint i;
g_assert (information->details_to_set == NULL);
+ information->details_changed = FALSE;
+
contact = empathy_contact_get_tp_contact (information->contact);
connection = tp_contact_get_connection (contact);
+ info = tp_contact_get_contact_info (contact);
+
specs = tp_connection_get_contact_info_supported_fields (connection);
- specs = g_list_sort (specs, (GCompareFunc) contact_info_field_spec_cmp);
- for (l = specs; l != NULL; l = l->next)
+
+ /* Look at the fields set in our vCard */
+ for (l = info; l != NULL; l = l->next)
{
- TpContactInfoFieldSpec *spec = l->data;
+ TpContactInfoField *field = l->data;
+
+ /* make a copy for the details_to_set list */
+ field = tp_contact_info_field_copy (field);
+ DEBUG ("Field %s is in our vCard", field->field_name);
+
+ information->details_to_set = g_list_prepend (information->details_to_set,
+ field);
+ }
+
+ /* Add fields which are supported but not in the vCard */
+ for (i = 0; field_names[i] != NULL; i++)
+ {
+ TpContactInfoFieldSpec *spec;
TpContactInfoField *field;
- InfoFieldData *field_data;
- GList *info, *ll;
- GStrv value = NULL;
+
+ /* Check if the field was in the vCard */
+ if (field_name_in_field_list (information->details_to_set,
+ field_names[i]))
+ continue;
+
+ /* Check if the CM supports the field */
+ spec = get_spec_from_list (specs, field_names[i]);
+ if (spec == NULL)
+ continue;
+
+ /* add an empty field so user can set a value */
+ field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
+
+ information->details_to_set = g_list_prepend (information->details_to_set,
+ field);
+ }
+
+ /* Add widgets for supported fields */
+ information->details_to_set = g_list_sort (information->details_to_set,
+ (GCompareFunc) empathy_contact_info_field_spec_cmp);
+
+ for (l = information->details_to_set; l != NULL; l= g_list_next (l))
+ {
+ TpContactInfoField *field = l->data;
GtkWidget *w;
+ TpContactInfoFieldSpec *spec;
+ gboolean has_field;
+ char *title;
- field_data = find_info_field_data (spec->name);
- if (field_data == NULL)
+ has_field = empathy_contact_info_lookup_field (field->field_name,
+ NULL, NULL);
+ if (!has_field)
{
- DEBUG ("Unhandled ContactInfo field spec: %s", spec->name);
+ /* Empathy doesn't display this field so we can't change it.
+ * But we put it in the details_to_set list so it won't be erased
+ * when calling SetContactInfo (bgo #630427) */
+ DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
continue;
}
- /* Search initial value */
- info = tp_contact_get_contact_info (contact);
- for (ll = info; ll != NULL; ll = ll->next)
+ spec = get_spec_from_list (specs, field->field_name);
+ /* We shouldn't have added the field to details_to_set if it's not
+ * supported by the CM */
+ g_assert (spec != NULL);
+
+ if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
{
- field = ll->data;
- if (!tp_strdiff (field->field_name, spec->name))
- {
- value = field->field_value;
- break;
- }
+ DEBUG ("Ignoring field '%s' due it to having the "
+ "Overwritten_By_Nickname flag", field->field_name);
+ continue;
}
- field = tp_contact_info_field_new (spec->name, spec->parameters, value);
- information->details_to_set = g_list_prepend (information->details_to_set,
- field);
-
/* Add Title */
- w = gtk_label_new (_(field_data->title));
- gtk_table_attach (GTK_TABLE (information->table_details),
- w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
+ title = empathy_contact_info_field_label (field->field_name,
+ field->parameters);
+ w = gtk_label_new (title);
+ g_free (title);
+
+ gtk_grid_attach (GTK_GRID (information->grid_details),
+ w, 0, n_rows, 1, 1);
+
gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
gtk_widget_show (w);
/* Add Value */
- w = gtk_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (w),
- field->field_value[0] ? field->field_value[0] : "");
- gtk_table_attach_defaults (GTK_TABLE (information->table_details),
- w, 1, 2, n_rows, n_rows + 1);
- gtk_widget_show (w);
+ if (!tp_strdiff (field->field_name, "bday"))
+ {
+ w = gtk_calendar_new ();
+ if (field->field_value[0])
+ {
+ GDate date;
+
+ g_date_set_parse (&date, field->field_value[0]);
+ if (g_date_valid (&date))
+ {
+ gtk_calendar_select_day (GTK_CALENDAR (w),
+ g_date_get_day (&date));
+ gtk_calendar_select_month (GTK_CALENDAR (w),
+ g_date_get_month (&date) - 1, g_date_get_year (&date));
+ gtk_calendar_mark_day (GTK_CALENDAR (w),
+ g_date_get_day (&date));
+ }
+ }
+
+ gtk_grid_attach (GTK_GRID (information->grid_details),
+ w, 1, n_rows, 1, 1);
+ gtk_widget_show (w);
+
+ g_object_set_data ((GObject *) w, DATA_FIELD, field);
+
+ g_signal_connect (w, "day-selected",
+ G_CALLBACK (contact_widget_bday_changed_cb), information);
+ g_signal_connect (w, "month-changed",
+ G_CALLBACK (contact_widget_bday_changed_cb), information);
+ }
+ else
+ {
+ w = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (w),
+ field->field_value[0] ? field->field_value[0] : "");
+ gtk_grid_attach (GTK_GRID (information->grid_details),
+ w, 1, n_rows, 1, 1);
+ gtk_widget_show (w);
- g_signal_connect (w, "changed",
- G_CALLBACK (contact_widget_details_changed_cb), field);
+ g_object_set_data ((GObject *) w, DATA_FIELD, field);
+
+ g_signal_connect (w, "changed",
+ G_CALLBACK (contact_widget_details_changed_cb), information);
+ }
n_rows++;
}
+
g_list_free (specs);
+ g_list_free (info);
return n_rows;
}
+static void
+add_row (GtkGrid *grid,
+ guint row,
+ GtkWidget *title,
+ GtkWidget *value)
+{
+ gtk_grid_attach (grid, title, 0, row, 1, 1);
+ gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
+ gtk_widget_show (title);
+
+ gtk_grid_attach (grid, value, 1, row, 1, 1);
+ gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
+ gtk_widget_show (value);
+}
+
static guint
contact_widget_details_update_show (EmpathyContactWidget *information)
{
TpContact *contact;
GList *info, *l;
guint n_rows = 0;
+ GtkWidget *channels_label;
+ TpAccount *account;
contact = empathy_contact_get_tp_contact (information->contact);
info = tp_contact_get_contact_info (contact);
- info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
+ info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
for (l = info; l != NULL; l = l->next)
{
TpContactInfoField *field = l->data;
- InfoFieldData *field_data;
const gchar *value;
- GtkWidget *w;
+ gchar *markup = NULL, *title;
+ GtkWidget *title_widget, *value_widget;
+ EmpathyContactInfoFormatFunc format;
if (field->field_value == NULL || field->field_value[0] == NULL)
continue;
value = field->field_value[0];
- field_data = find_info_field_data (field->field_name);
- if (field_data == NULL)
+ if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
{
DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
continue;
}
+ if (format != NULL)
+ {
+ markup = format (field->field_value);
+
+ if (markup == NULL)
+ {
+ DEBUG ("Invalid value for field '%s' (first element was '%s')",
+ field->field_name, field->field_value[0]);
+ continue;
+ }
+ }
+
/* Add Title */
- w = gtk_label_new (_(field_data->title));
- gtk_table_attach (GTK_TABLE (information->table_details),
- w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
- gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
- gtk_widget_show (w);
+ title = empathy_contact_info_field_label (field->field_name,
+ field->parameters);
+ title_widget = gtk_label_new (title);
+ g_free (title);
/* Add Value */
- w = gtk_label_new (value);
- if (field_data->linkify)
+ value_widget = gtk_label_new (value);
+ if (markup != NULL)
{
- gchar *markup;
-
- markup = empathy_add_link_markup (value);
- gtk_label_set_markup (GTK_LABEL (w), markup);
+ gtk_label_set_markup (GTK_LABEL (value_widget), markup);
g_free (markup);
}
if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
- gtk_label_set_selectable (GTK_LABEL (w), TRUE);
+ gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
- gtk_table_attach_defaults (GTK_TABLE (information->table_details),
- w, 1, 2, n_rows, n_rows + 1);
- gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
- gtk_widget_show (w);
+ add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
+ value_widget);
+
+ n_rows++;
+ }
+
+ account = empathy_contact_get_account (information->contact);
+
+ channels_label = empathy_contact_info_create_channel_list_label (account,
+ info, n_rows);
+
+ if (channels_label != NULL)
+ {
+ GtkWidget *title_widget;
+
+ title_widget = gtk_label_new (_("Channels:"));
+
+ add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
+ channels_label);
n_rows++;
}
+
g_list_free (info);
return n_rows;
{
guint n_rows;
- gtk_container_foreach (GTK_CONTAINER (information->table_details),
+ gtk_container_foreach (GTK_CONTAINER (information->grid_details),
(GtkCallback) gtk_widget_destroy, NULL);
if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
if (n_rows > 0)
{
gtk_widget_show (information->vbox_details);
- gtk_widget_show (information->table_details);
+ gtk_widget_show (information->grid_details);
}
else
{
G_CALLBACK (contact_widget_details_notify_cb), information);
}
- g_object_unref (information->details_cancellable);
- information->details_cancellable = NULL;
+ tp_clear_object (&information->details_cancellable);
}
static void
-contact_widget_details_feature_prepared_cb (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
+fetch_contact_information (EmpathyContactWidget *information,
+ TpConnection *connection)
{
- TpConnection *connection = TP_CONNECTION (object);
- EmpathyContactWidget *information = user_data;
TpContact *contact;
TpContactInfoFlags flags;
- if (!tp_proxy_prepare_finish (connection, res, NULL))
+ if (!tp_proxy_has_interface_by_id (connection,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
{
gtk_widget_hide (information->vbox_details);
return;
/* Request the contact's info */
gtk_widget_show (information->vbox_details);
gtk_widget_show (information->hbox_details_requested);
- gtk_widget_hide (information->table_details);
+ gtk_widget_hide (information->grid_details);
gtk_spinner_start (GTK_SPINNER (information->spinner_details));
contact = empathy_contact_get_tp_contact (information->contact);
if (tp_contact != NULL)
{
- GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
TpConnection *connection;
- /* First, make sure the CONTACT_INFO feature is ready on the connection */
connection = tp_contact_get_connection (tp_contact);
- tp_proxy_prepare_async (connection, features,
- contact_widget_details_feature_prepared_cb, information);
+
+ fetch_contact_information (information, connection);
}
}
}
static void
-contact_widget_cell_toggled (GtkCellRendererToggle *cell,
- gchar *path_string,
- EmpathyContactWidget *information)
+contact_widget_groups_update (EmpathyContactWidget *information)
{
- GtkTreeView *view;
- GtkTreeModel *model;
- GtkListStore *store;
- GtkTreePath *path;
- GtkTreeIter iter;
- gboolean was_enabled;
- gchar *group;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- model = gtk_tree_view_get_model (view);
- store = GTK_LIST_STORE (model);
-
- path = gtk_tree_path_new_from_string (path_string);
-
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter,
- COL_ENABLED, &was_enabled,
- COL_NAME, &group,
- -1);
-
- gtk_list_store_set (store, &iter, COL_ENABLED, !was_enabled, -1);
- gtk_tree_path_free (path);
-
- if (group != NULL)
+ if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
+ information->contact != NULL)
{
- FolksIndividual *individual = folks_individual_dup_from_empathy_contact (
- information->contact);
+ FolksPersona *persona =
+ empathy_contact_get_persona (information->contact);
- if (individual != NULL)
+ if (FOLKS_IS_GROUP_DETAILS (persona))
{
- folks_groups_change_group (FOLKS_GROUPS (individual), group,
- !was_enabled);
- g_object_unref (individual);
- }
-
- g_free (group);
- }
-}
-
-static void
-contact_widget_model_populate_columns (EmpathyContactWidget *information)
-{
- GtkTreeView *view;
- GtkTreeModel *model;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- guint col_offset;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- model = gtk_tree_view_get_model (view);
-
- renderer = gtk_cell_renderer_toggle_new ();
- g_signal_connect (renderer, "toggled",
- G_CALLBACK (contact_widget_cell_toggled), information);
-
- column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
- "active", COL_ENABLED, NULL);
-
- gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
- gtk_tree_view_column_set_fixed_width (column, 50);
- gtk_tree_view_append_column (view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- col_offset = gtk_tree_view_insert_column_with_attributes (view,
- -1, _("Group"),
- renderer,
- "text", COL_NAME,
- /* "editable", COL_EDITABLE, */
- NULL);
-
- g_object_set_data (G_OBJECT (renderer),
- "column", GINT_TO_POINTER (COL_NAME));
+ empathy_groups_widget_set_group_details (
+ EMPATHY_GROUPS_WIDGET (information->groups_widget),
+ FOLKS_GROUP_DETAILS (persona));
+ gtk_widget_show (information->groups_widget);
- column = gtk_tree_view_get_column (view, col_offset - 1);
- gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
- gtk_tree_view_column_set_resizable (column,FALSE);
- gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
-}
-
-static void
-contact_widget_model_setup (EmpathyContactWidget *information)
-{
- GtkTreeView *view;
- GtkListStore *store;
- GtkTreeSelection *selection;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
-
- store = gtk_list_store_new (COL_COUNT,
- G_TYPE_STRING, /* name */
- G_TYPE_BOOLEAN, /* enabled */
- G_TYPE_BOOLEAN); /* editable */
-
- gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
-
- selection = gtk_tree_view_get_selection (view);
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
-
- contact_widget_model_populate_columns (information);
-
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
- COL_NAME, GTK_SORT_ASCENDING);
-
- g_object_unref (store);
-}
-
-static void
-contact_widget_groups_populate_data (EmpathyContactWidget *information)
-{
- GtkTreeView *view;
- GtkListStore *store;
- GtkTreeIter iter;
- GList *my_groups, *l;
- GList *all_groups;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
- gtk_list_store_clear (store);
-
- all_groups = empathy_contact_list_get_all_groups (
- EMPATHY_CONTACT_LIST (information->manager));
- my_groups = empathy_contact_list_get_groups (
- EMPATHY_CONTACT_LIST (information->manager),
- information->contact);
-
- for (l = all_groups; l; l = l->next)
- {
- const gchar *group_str;
- gboolean enabled;
-
- group_str = l->data;
-
- enabled = g_list_find_custom (my_groups,
- group_str, (GCompareFunc) strcmp) != NULL;
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COL_NAME, group_str,
- COL_EDITABLE, TRUE,
- COL_ENABLED, enabled,
- -1);
- }
-
- g_list_foreach (all_groups, (GFunc) g_free, NULL);
- g_list_foreach (my_groups, (GFunc) g_free, NULL);
- g_list_free (all_groups);
- g_list_free (my_groups);
-}
-
-static gboolean
-contact_widget_model_find_name_foreach (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- FindName *data)
-{
- gchar *name;
-
- gtk_tree_model_get (model, iter,
- COL_NAME, &name,
- -1);
-
- if (!name)
- return FALSE;
-
- if (data->name && strcmp (data->name, name) == 0)
- {
- data->found = TRUE;
- data->found_iter = *iter;
-
- g_free (name);
-
- return TRUE;
- }
-
- g_free (name);
-
- return FALSE;
-}
-
-static gboolean
-contact_widget_model_find_name (EmpathyContactWidget *information,
- const gchar *name,
- GtkTreeIter *iter)
-{
- GtkTreeView *view;
- GtkTreeModel *model;
- FindName data;
-
- if (EMP_STR_EMPTY (name))
- return FALSE;
-
- data.information = information;
- data.name = name;
- data.found = FALSE;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- model = gtk_tree_view_get_model (view);
-
- gtk_tree_model_foreach (model,
- (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
- &data);
-
- if (data.found == TRUE)
- {
- *iter = data.found_iter;
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-contact_widget_entry_group_changed_cb (GtkEditable *editable,
- EmpathyContactWidget *information)
-{
- GtkTreeIter iter;
- const gchar *group;
-
- group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
-
- if (contact_widget_model_find_name (information, group, &iter))
- gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
- else
- gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
- !EMP_STR_EMPTY (group));
-}
-
-static void
-contact_widget_entry_group_activate_cb (GtkEntry *entry,
- EmpathyContactWidget *information)
-{
- gtk_widget_activate (GTK_WIDGET (information->button_group));
-}
-
-static void
-contact_widget_button_group_clicked_cb (GtkButton *button,
- EmpathyContactWidget *information)
-{
- GtkTreeView *view;
- GtkListStore *store;
- GtkTreeIter iter;
- FolksIndividual *individual;
- const gchar *group;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
-
- group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COL_NAME, group,
- COL_ENABLED, TRUE,
- -1);
-
- individual = folks_individual_dup_from_empathy_contact (information->contact);
-
- if (individual != NULL)
- {
- folks_groups_change_group (FOLKS_GROUPS (individual), group, TRUE);
- g_object_unref (individual);
+ return;
+ }
}
-}
-
-static void
-contact_widget_groups_notify_cb (EmpathyContactWidget *information)
-{
- /* FIXME: not implemented */
-}
-static void
-contact_widget_groups_setup (EmpathyContactWidget *information)
-{
- if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
- {
- contact_widget_model_setup (information);
- }
-}
-
-static void
-contact_widget_groups_update (EmpathyContactWidget *information)
-{
- if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
- information->contact)
- {
- g_signal_connect_swapped (information->contact, "notify::groups",
- G_CALLBACK (contact_widget_groups_notify_cb), information);
- contact_widget_groups_populate_data (information);
-
- gtk_widget_show (information->vbox_groups);
- }
- else
- gtk_widget_hide (information->vbox_groups);
+ /* In case of failure */
+ gtk_widget_hide (information->groups_widget);
}
/* Converts the Location's GHashTable's key to a user readable string */
{
GHashTable *location;
GValue *value;
+#ifdef HAVE_LIBCHAMPLAIN
gdouble lat = 0.0, lon = 0.0;
gboolean has_position = TRUE;
+#endif
GtkWidget *label;
guint row = 0;
static const gchar* ordered_geolocation_keys[] = {
return;
}
- value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
- if (value == NULL)
- has_position = FALSE;
- else
- lat = g_value_get_double (value);
-
- value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
- if (value == NULL)
- has_position = FALSE;
- else
- lon = g_value_get_double (value);
-
value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
if (value == NULL)
{
gchar *user_date;
gchar *text;
gint64 stamp;
- time_t time_;
+ gchar *tmp;
stamp = g_value_get_int64 (value);
- time_ = stamp;
- user_date = empathy_time_to_string_relative (time_);
+ user_date = empathy_time_to_string_relative (stamp);
- text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
+ tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
+ /* translators: format is "Location, $date" */
+ text = g_strdup_printf (_("%s, %s"), tmp, user_date);
+ g_free (tmp);
gtk_label_set_markup (GTK_LABEL (information->label_location), text);
g_free (user_date);
g_free (text);
}
- /* Prepare the location information table */
- if (information->table_location != NULL)
+ /* Prepare the location information grid */
+ if (information->grid_location != NULL)
{
- gtk_widget_destroy (information->table_location);
+ gtk_widget_destroy (information->grid_location);
}
- information->table_location = gtk_table_new (1, 2, FALSE);
+ information->grid_location = gtk_grid_new ();
gtk_box_pack_start (GTK_BOX (information->subvbox_location),
- information->table_location, FALSE, FALSE, 5);
+ information->grid_location, FALSE, FALSE, 5);
for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
label = gtk_label_new (user_label);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
- gtk_table_attach (GTK_TABLE (information->table_location),
- label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
+ gtk_grid_attach (GTK_GRID (information->grid_location),
+ label, 0, row, 1, 1);
gtk_widget_show (label);
if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
}
else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
{
- time_t time_;
+ gint64 time_;
time_ = g_value_get_int64 (value);
svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
if (svalue != NULL)
{
label = gtk_label_new (svalue);
- gtk_table_attach_defaults (GTK_TABLE (information->table_location),
- label, 1, 2, row, row + 1);
+ gtk_grid_attach (GTK_GRID (information->grid_location),
+ label, 1, row, 1, 1);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
gtk_widget_show (label);
row++;
}
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
if (has_position &&
!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
{
if (row > 0)
{
/* We can display some fields */
- gtk_widget_show (information->table_location);
+ gtk_widget_show (information->grid_location);
}
else if (!display_map)
{
return;
}
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
if (display_map)
{
ClutterActor *marker;
- ChamplainLayer *layer;
+ ChamplainMarkerLayer *layer;
information->map_view_embed = gtk_champlain_embed_new ();
information->map_view = gtk_champlain_embed_get_view (
gtk_container_add (GTK_CONTAINER (information->viewport_map),
information->map_view_embed);
g_object_set (G_OBJECT (information->map_view),
- "show-license", TRUE,
- "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
+ "kinetic-mode", TRUE,
"zoom-level", 10,
NULL);
- layer = champlain_layer_new ();
- champlain_view_add_layer (information->map_view, layer);
+ layer = champlain_marker_layer_new ();
+ champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
- marker = champlain_marker_new_with_text (
- empathy_contact_get_name (information->contact), NULL, NULL, NULL);
- champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
- clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
+ marker = champlain_label_new_with_text (
+ empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
+ champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
+ champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
champlain_view_center_on (information->map_view, lat, lon);
gtk_widget_show_all (information->viewport_map);
empathy_contact_get_avatar (information->contact) == NULL)
return;
- menu = gtk_menu_new ();
+ menu = empathy_context_menu_new (parent);
/* Add "Save as..." entry */
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
button, event_time);
- g_object_ref_sink (menu);
- g_object_unref (menu);
}
static gboolean
}
}
+/* Update all the contact info fields having the
+* Overwritten_By_Nickname flag to the new alias. This avoid accidentally
+* reseting the alias when calling SetContactInfo(). See bgo #644298 for
+* details. */
static void
-set_alias_on_account (TpAccount *account,
- const gchar *alias)
+update_nickname_in_contact_info (EmpathyContactWidget *self,
+ TpConnection *connection,
+ const gchar *nickname)
{
- DEBUG ("Set Account.Nickname to %s", alias);
+ GList *specs, *l;
+
+ specs = tp_connection_get_contact_info_supported_fields (connection);
+
+ for (l = self->details_to_set; l != NULL; l= g_list_next (l))
+ {
+ TpContactInfoField *field = l->data;
+ TpContactInfoFieldSpec *spec;
+
+ spec = get_spec_from_list (specs, field->field_name);
+ /* We shouldn't have added the field to details_to_set if it's not
+ * supported by the CM */
+ g_assert (spec != NULL);
+
+ if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
+ {
+ const gchar *strv[] = { nickname, NULL };
- tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
+ DEBUG ("Updating field '%s' to '%s' as it has the "
+ "Overwritten_By_Nickname flag and Account.Nickname has "
+ "been updated", field->field_name, nickname);
+
+ if (field->field_value != NULL)
+ g_strfreev (field->field_value);
+ field->field_value = g_strdupv ((GStrv) strv);
+ }
+ }
+
+ g_list_free (specs);
}
static gboolean
if (empathy_contact_is_user (information->contact))
{
TpAccount * account;
+ const gchar *current_nickname;
account = empathy_contact_get_account (information->contact);
- set_alias_on_account (account, alias);
- }
- else
- {
- FolksIndividual *individual =
- folks_individual_dup_from_empathy_contact (information->contact);
+ current_nickname = tp_account_get_nickname (account);
- if (individual != NULL)
+ if (tp_strdiff (current_nickname, alias))
{
- folks_alias_set_alias (FOLKS_ALIAS (individual), alias);
- g_object_unref (individual);
+ DEBUG ("Set Account.Nickname to %s", alias);
+
+ tp_account_set_nickname_async (account, alias, set_nickname_cb,
+ NULL);
+
+ update_nickname_in_contact_info (information,
+ empathy_contact_get_connection (information->contact), alias);
}
}
+ else
+ {
+ empathy_contact_set_alias (information->contact, alias);
+ }
}
return FALSE;
{
if (GTK_IS_ENTRY (information->widget_alias))
gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
- empathy_contact_get_name (information->contact));
+ empathy_contact_get_alias (information->contact));
else
gtk_label_set_label (GTK_LABEL (information->widget_alias),
- empathy_contact_get_name (information->contact));
+ empathy_contact_get_alias (information->contact));
}
static void
gtk_widget_show (information->image_state);
}
-static void
-contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
- EmpathyContact *contact,
- gboolean is_favourite,
- EmpathyContactWidget *information)
-{
- if (contact != information->contact)
- return;
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
- information->favourite_checkbox), is_favourite);
-}
-
static void
contact_widget_remove_contact (EmpathyContactWidget *information)
{
contact_widget_presence_notify_cb, information);
g_signal_handlers_disconnect_by_func (information->contact,
contact_widget_avatar_notify_cb, information);
- g_signal_handlers_disconnect_by_func (information->contact,
- contact_widget_groups_notify_cb, information);
tp_contact = empathy_contact_get_tp_contact (information->contact);
if (tp_contact != NULL)
if (information->details_cancellable != NULL)
{
g_cancellable_cancel (information->details_cancellable);
- g_object_unref (information->details_cancellable);
- information->details_cancellable = NULL;
+ tp_clear_object (&information->details_cancellable);
}
}
contact_widget_presence_notify_cb (information);
contact_widget_avatar_notify_cb (information);
- if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
- {
- FolksIndividual *individual =
- folks_individual_dup_from_empathy_contact (information->contact);
-
- if (individual != NULL)
- {
- gboolean is_favourite = folks_favourite_get_is_favourite (
- FOLKS_FAVOURITE (individual));
- contact_widget_favourites_changed_cb (information->manager,
- information->contact, is_favourite, information);
-
- g_object_unref (individual);
- }
- }
-
gtk_widget_show (information->label_alias);
gtk_widget_show (information->widget_alias);
- gtk_widget_show (information->hbox_presence);
gtk_widget_show (information->widget_avatar);
+
+ gtk_widget_set_visible (information->hbox_presence,
+ !(information->flags & EMPATHY_CONTACT_WIDGET_NO_STATUS));
+
+ if (empathy_contact_is_user (information->contact))
+ gtk_label_set_text (GTK_LABEL (information->label_details),
+ _("Personal Details"));
+ else
+ gtk_label_set_text (GTK_LABEL (information->label_details),
+ _("Contact Details"));
}
else
{
return FALSE;
}
-static void
-favourite_toggled_cb (GtkToggleButton *button,
- EmpathyContactWidget *information)
-{
- FolksIndividual *individual = folks_individual_dup_from_empathy_contact (
- information->contact);
-
- if (individual != NULL)
- {
- gboolean active = gtk_toggle_button_get_active (button);
- folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), active);
- g_object_unref (individual);
- }
-}
-
static void
contact_widget_contact_setup (EmpathyContactWidget *information)
{
- /* Setup label_status as a KludgeLabel */
- information->label_status = empathy_kludge_label_new ("");
+ information->label_status = gtk_label_new ("");
gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
PANGO_WRAP_WORD_CHAR);
gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
TRUE);
+ gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
else
{
/* Pack the protocol icon with the account name in an hbox */
- information->widget_account = gtk_hbox_new (FALSE, 6);
+ information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
information->label_account = gtk_label_new (NULL);
if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
gtk_box_pack_start (GTK_BOX (information->widget_account),
information->label_account, FALSE, TRUE, 0);
}
- gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
- information->widget_account,
- 1, 2, 0, 1);
+
+ gtk_grid_attach (GTK_GRID (information->grid_contact),
+ information->widget_account,
+ 1, 0, 1, 1);
+
gtk_widget_show (information->widget_account);
/* Set up avatar chooser/display */
}
gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
}
- gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
- information->widget_id,
- 1, 2, 1, 2);
+
+ gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
+ 1, 1, 1, 1);
+
gtk_widget_show (information->widget_id);
/* Setup alias label/entry */
}
gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
}
- gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
- information->widget_alias,
- 1, 2, 2, 3);
+
+ gtk_grid_attach (GTK_GRID (information->grid_contact),
+ information->widget_alias, 1, 2, 1, 1);
+
if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
}
gtk_widget_show (information->widget_alias);
-
- /* Favorite */
- if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
- {
- information->favourite_checkbox = gtk_check_button_new_with_label (
- _("Favorite"));
-
- g_signal_connect (information->favourite_checkbox, "toggled",
- G_CALLBACK (favourite_toggled_cb), information);
-
- gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
- information->favourite_checkbox, 0, 2, 3, 4);
-
- information->fav_sig_id = g_signal_connect (information->manager,
- "favourites-changed",
- G_CALLBACK (contact_widget_favourites_changed_cb), information);
-
- gtk_widget_show (information->favourite_checkbox);
- }
}
static void
g_source_remove (information->widget_id_timeout);
}
- if (information->fav_sig_id != 0)
- g_signal_handler_disconnect (information->manager, information->fav_sig_id);
-
- g_object_unref (information->manager);
-
g_slice_free (EmpathyContactWidget, information);
}
"libempathy-gtk");
gui = empathy_builder_get_file (filename,
"vbox_contact_widget", &information->vbox_contact_widget,
- "hbox_contact", &information->hbox_contact,
"hbox_presence", &information->hbox_presence,
"label_alias", &information->label_alias,
"image_state", &information->image_state,
- "table_contact", &information->table_contact,
+ "grid_contact", &information->grid_contact,
"vbox_avatar", &information->vbox_avatar,
"vbox_location", &information->vbox_location,
"subvbox_location", &information->subvbox_location,
"label_location", &information->label_location,
-#if HAVE_LIBCHAMPLAIN
+#ifdef HAVE_LIBCHAMPLAIN
"viewport_map", &information->viewport_map,
#endif
- "vbox_groups", &information->vbox_groups,
- "entry_group", &information->entry_group,
- "button_group", &information->button_group,
- "treeview_groups", &information->treeview_groups,
+ "groups_widget", &information->groups_widget,
"vbox_details", &information->vbox_details,
- "table_details", &information->table_details,
+ "grid_details", &information->grid_details,
"hbox_details_requested", &information->hbox_details_requested,
"vbox_client", &information->vbox_client,
- "table_client", &information->table_client,
+ "grid_client", &information->grid_client,
"hbox_client_requested", &information->hbox_client_requested,
+ "label_details", &information->label_details,
NULL);
g_free (filename);
empathy_builder_connect (gui, information,
"vbox_contact_widget", "destroy", contact_widget_destroy_cb,
- "entry_group", "changed", contact_widget_entry_group_changed_cb,
- "entry_group", "activate", contact_widget_entry_group_activate_cb,
- "button_group", "clicked", contact_widget_button_group_clicked_cb,
NULL);
- information->table_location = NULL;
+ information->grid_location = NULL;
g_object_set_data (G_OBJECT (information->vbox_contact_widget),
"EmpathyContactWidget",
information);
- information->manager = empathy_contact_manager_dup_singleton ();
-
/* Create widgets */
contact_widget_contact_setup (information);
- contact_widget_groups_setup (information);
contact_widget_details_setup (information);
contact_widget_client_setup (information);