* Philip Withnall <philip.withnall@collabora.co.uk>
*/
-#include <config.h>
+#include "config.h"
-#include <string.h>
-#include <stdlib.h>
-
-#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
-#include <telepathy-glib/util.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
-
#ifdef HAVE_LIBCHAMPLAIN
#include <champlain/champlain.h>
#include <champlain-gtk/champlain-gtk.h>
#endif
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-location.h>
-#include <libempathy/empathy-time.h>
+#include "empathy-utils.h"
+#include "empathy-location.h"
+#include "empathy-time.h"
#include "empathy-avatar-image.h"
+#include "empathy-contactinfo-utils.h"
#include "empathy-groups-widget.h"
#include "empathy-gtk-enum-types.h"
-#include "empathy-individual-widget.h"
-#include "empathy-string-parser.h"
#include "empathy-ui-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
/**
* SECTION:empathy-individual-widget
/* Location */
GtkWidget *vbox_location;
GtkWidget *subvbox_location;
- GtkWidget *table_location;
+ GtkWidget *grid_location;
GtkWidget *label_location;
#ifdef HAVE_LIBCHAMPLAIN
GtkWidget *viewport_map;
gtk_widget_show (priv->details_spinner);
}
-typedef struct
-{
- const gchar *field_name;
- const gchar *title;
- gboolean linkify;
-} InfoFieldData;
-
-static InfoFieldData info_field_data[] =
-{
- { "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 }
-};
-
-static InfoFieldData *
-find_info_field_data (const gchar *field_name)
-{
- guint i;
-
- for (i = 0; info_field_data[i].field_name != NULL; i++)
- {
- if (tp_strdiff (info_field_data[i].field_name, field_name) == FALSE)
- return info_field_data + i;
- }
- return NULL;
-}
-
-static gint
-contact_info_field_name_cmp (const gchar *name1,
- const gchar *name2)
-{
- guint i;
-
- if (tp_strdiff (name1, name2) == FALSE)
- return 0;
-
- /* We use the order of info_field_data */
- for (i = 0; info_field_data[i].field_name != NULL; i++)
- {
- if (tp_strdiff (info_field_data[i].field_name, name1) == FALSE)
- return -1;
- if (tp_strdiff (info_field_data[i].field_name, name2) == FALSE)
- return +1;
- }
-
- return g_strcmp0 (name1, name2);
-}
-
-static gint
-contact_info_field_cmp (TpContactInfoField *field1,
- TpContactInfoField *field2)
-{
- return contact_info_field_name_cmp (field1->field_name, field2->field_name);
-}
-
static void
client_types_notify_cb (TpContact *contact,
GParamSpec *pspec,
client_types_update (self);
}
+typedef struct {
+ EmpathyIndividualWidget *widget; /* weak */
+ TpContact *contact; /* owned */
+} DetailsData;
+
static void
update_weak_contact (EmpathyIndividualWidget *self)
{
presence_type_cur = folks_presence_details_get_presence_type (
presence);
- if (folks_presence_details_typecmp (
+ if (tp_contact == NULL || folks_presence_details_typecmp (
presence_type_cur, presence_type) > 0)
{
presence_type = presence_type_cur;
}
}
+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
details_update_show (EmpathyIndividualWidget *self,
TpContact *contact)
EmpathyIndividualWidgetPriv *priv = GET_PRIV (self);
GList *info, *l;
guint n_rows = 0;
+ GtkWidget *channels_label;
+ TpConnection *conn;
+ TpAccount *account;
- info = tp_contact_get_contact_info (contact);
- info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
+ info = tp_contact_dup_contact_info (contact);
+ 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;
+ gchar *title;
const gchar *value;
- GtkWidget *w;
+ EmpathyContactInfoFormatFunc format;
+ GtkWidget *title_widget, *value_widget;
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;
}
+ /* Skip empty field */
+ if (tp_str_empty (value))
+ continue;
+
/* Add Title */
- w = gtk_label_new (_(field_data->title));
- gtk_grid_attach (GTK_GRID (priv->grid_details),
- w, 0, n_rows, 1, 1);
- 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, TRUE);
+ title_widget = gtk_label_new (title);
/* Add Value */
- w = gtk_label_new (value);
- if (field_data->linkify == TRUE)
+ value_widget = gtk_label_new (value);
+
+ if (format != NULL)
{
gchar *markup;
- markup = empathy_add_link_markup (value);
- gtk_label_set_markup (GTK_LABEL (w), markup);
+ markup = format (field->field_value);
+ gtk_label_set_markup (GTK_LABEL (value_widget), markup);
g_free (markup);
}
- gtk_label_set_selectable (GTK_LABEL (w),
+ gtk_label_set_selectable (GTK_LABEL (value_widget),
(priv->flags & EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP) ? FALSE : TRUE);
- gtk_grid_attach (GTK_GRID (priv->grid_details),
- w, 1, n_rows, 1, 1);
- gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
- gtk_widget_show (w);
+ add_row (GTK_GRID (priv->grid_details), n_rows, title_widget,
+ value_widget);
+
+ n_rows++;
+ }
+
+ conn = tp_contact_get_connection (contact);
+ account = tp_connection_get_account (conn);
+
+ 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 (priv->grid_details), n_rows, title_widget,
+ channels_label);
n_rows++;
}
- g_list_free (info);
+
+ tp_contact_info_list_free (info);
return n_rows;
}
}
/* Prepare the location information table */
- if (priv->table_location != NULL)
- gtk_widget_destroy (priv->table_location);
+ if (priv->grid_location != NULL)
+ gtk_widget_destroy (priv->grid_location);
- priv->table_location = gtk_table_new (1, 2, FALSE);
+ priv->grid_location = gtk_grid_new ();
gtk_box_pack_start (GTK_BOX (priv->subvbox_location),
- priv->table_location, FALSE, FALSE, 5);
+ priv->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 (priv->table_location),
- label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
+ gtk_grid_attach (GTK_GRID (priv->grid_location),
+ label, 0, row, 1, 1);
gtk_widget_show (label);
if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
if (svalue != NULL)
{
label = gtk_label_new (svalue);
- gtk_table_attach_defaults (GTK_TABLE (priv->table_location),
- label, 1, 2, row, row + 1);
+ gtk_grid_attach (GTK_GRID (priv->grid_location),
+ label, 1, row, 1, 1);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
gtk_widget_show (label);
#ifdef HAVE_LIBCHAMPLAIN
if ((g_hash_table_lookup (location, EMPATHY_LOCATION_LAT) != NULL) &&
- (g_hash_table_lookup (location, EMPATHY_LOCATION_LON) != NULL) &&
- !(priv->flags & EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP))
+ (g_hash_table_lookup (location, EMPATHY_LOCATION_LON) != NULL))
{
/* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
* windows */
if (row > 0)
{
/* We can display some fields */
- gtk_widget_show (priv->table_location);
+ gtk_widget_show (priv->grid_location);
}
else if (display_map == FALSE)
{
types = tp_contact_get_client_types (priv->contact);
- if (types != NULL
- && g_strv_length ((gchar **) types) > 0
- && !tp_strdiff (types[0], "phone"))
+ if (empathy_client_types_contains_mobile_device ((GStrv) types))
{
gtk_widget_show (priv->hbox_client_types);
}
GtkWidget *status_label, *state_image;
const gchar *message;
gchar *markup_text = NULL;
+ FolksPresenceType presence;
+ gboolean visible = TRUE;
if (FOLKS_IS_INDIVIDUAL (folks_object))
grid = G_OBJECT (priv->individual_grid);
status_label = g_object_get_data (grid, "status-label");
state_image = g_object_get_data (grid, "state-image");
+ presence = folks_presence_details_get_presence_type (
+ FOLKS_PRESENCE_DETAILS (folks_object));
+ if (presence == FOLKS_PRESENCE_TYPE_UNKNOWN ||
+ presence == FOLKS_PRESENCE_TYPE_ERROR)
+ {
+ /* Don't display anything if we don't know the presence */
+ visible = FALSE;
+ goto out;
+ }
+
/* FIXME: Default messages should be moved into libfolks (bgo#627403) */
message = folks_presence_details_get_presence_message (
FOLKS_PRESENCE_DETAILS (folks_object));
if (EMP_STR_EMPTY (message))
{
- message = empathy_presence_get_default_message (
- folks_presence_details_get_presence_type (
- FOLKS_PRESENCE_DETAILS (folks_object)));
+ message = empathy_presence_get_default_message (presence);
}
if (message != NULL)
g_free (markup_text);
gtk_image_set_from_icon_name (GTK_IMAGE (state_image),
- empathy_icon_name_for_presence (
- folks_presence_details_get_presence_type (
- FOLKS_PRESENCE_DETAILS (folks_object))),
+ empathy_icon_name_for_presence (presence),
GTK_ICON_SIZE_BUTTON);
- gtk_widget_show (state_image);
+
+out:
+ gtk_widget_set_visible (status_label, visible);
+ gtk_widget_set_visible (state_image, visible);
}
static void
current_row++;
/* Presence */
- priv->hbox_presence = gtk_hbox_new (FALSE, 6);
+ priv->hbox_presence = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
/* Presence image */
image = gtk_image_new_from_stock (GTK_STOCK_MISSING_IMAGE,
gtk_widget_show (label);
/* Pack the protocol icon with the account name in an hbox */
- hbox = GTK_BOX (gtk_hbox_new (FALSE, 6));
+ hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
account_label = gtk_label_new (NULL);
gtk_label_set_selectable (GTK_LABEL (account_label),
gtk_widget_show (GTK_WIDGET (grid));
/* Pack a separator after the grid */
- separator = gtk_hseparator_new ();
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
g_object_set_data (G_OBJECT (grid), "separator", separator);
gtk_box_pack_start (GTK_BOX (priv->vbox_individual), separator, FALSE, FALSE,
0);
gtk_container_remove (GTK_CONTAINER (priv->vbox_individual),
GTK_WIDGET (priv->individual_grid));
+
+#ifdef HAVE_LIBCHAMPLAIN
+ if (priv->map_view_embed != NULL)
+ {
+ gtk_container_remove (GTK_CONTAINER (priv->viewport_map),
+ priv->map_view_embed);
+
+ priv->map_view_embed = NULL;
+ }
+#endif
+
priv->individual_grid = NULL;
}
}
else if (!was_showing_personas && will_show_personas)
{
- gboolean c;
-
/* Remove the old Individual grid */
individual_grid_destroy (self);
/* Set up all the Persona grids instead */
- for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
FolksPersona *persona = gee_iterator_get (iter);
add_persona (self, persona);
}
else if (was_showing_personas && !will_show_personas)
{
- gboolean c;
-
/* Remove all Personas */
- for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+ iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+ while (gee_iterator_next (iter))
{
FolksPersona *persona = gee_iterator_get (iter);
remove_persona (self, persona);
NULL);
g_free (filename);
- priv->table_location = NULL;
+ priv->grid_location = NULL;
gtk_box_pack_start (GTK_BOX (self), priv->vbox_individual_widget, TRUE, TRUE,
0);
{
EmpathyIndividualWidgetPriv *priv = GET_PRIV (object);
- g_hash_table_destroy (priv->persona_grids);
+ g_hash_table_unref (priv->persona_grids);
G_OBJECT_CLASS (empathy_individual_widget_parent_class)->finalize (object);
}