1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2009 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>
28 #include <glib/gi18n-lib.h>
30 #ifdef HAVE_LIBCHAMPLAIN
31 #include <champlain/champlain.h>
32 #include <champlain-gtk/champlain-gtk.h>
35 #include <telepathy-glib/account.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-glib/interfaces.h>
39 #include <libempathy/empathy-tp-contact-factory.h>
40 #include <libempathy/empathy-contact-manager.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-location.h>
43 #include <libempathy/empathy-request-util.h>
44 #include <libempathy/empathy-time.h>
45 #include <libempathy/empathy-utils.h>
47 #include "empathy-contact-widget.h"
48 #include "empathy-account-chooser.h"
49 #include "empathy-avatar-chooser.h"
50 #include "empathy-avatar-image.h"
51 #include "empathy-groups-widget.h"
52 #include "empathy-ui-utils.h"
53 #include "empathy-string-parser.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
56 #include <libempathy/empathy-debug.h>
59 * SECTION:empathy-contact-widget
60 * @title:EmpathyContactWidget
61 * @short_description: A widget used to display and edit details about a contact
62 * @include: libempathy-empathy-contact-widget.h
64 * #EmpathyContactWidget is a widget which displays appropriate widgets
65 * with details about a contact, also allowing changing these details,
70 * EmpathyContactWidget:
71 * @parent: parent object
73 * Widget which displays appropriate widgets with details about a contact,
74 * also allowing changing these details, if desired.
77 /* Delay before updating the widget when the id entry changed (seconds) */
78 #define ID_CHANGED_TIMEOUT 1
80 #define DATA_FIELD "contact-info-field"
84 EmpathyContactManager *manager;
85 EmpathyContact *contact;
86 EmpathyContactWidgetFlags flags;
87 guint widget_id_timeout;
90 GtkWidget *vbox_contact_widget;
93 GtkWidget *hbox_contact;
94 GtkWidget *widget_avatar;
95 GtkWidget *widget_account;
96 GtkWidget *image_account;
97 GtkWidget *label_account;
99 GtkWidget *widget_alias;
100 GtkWidget *label_alias;
101 GtkWidget *hbox_presence;
102 GtkWidget *image_state;
103 GtkWidget *label_status;
104 GtkWidget *table_contact;
105 GtkWidget *vbox_avatar;
106 GtkWidget *favourite_checkbox;
109 GtkWidget *vbox_location;
110 GtkWidget *subvbox_location;
111 GtkWidget *table_location;
112 GtkWidget *label_location;
113 #ifdef HAVE_LIBCHAMPLAIN
114 GtkWidget *viewport_map;
115 GtkWidget *map_view_embed;
116 ChamplainView *map_view;
120 GtkWidget *groups_widget;
123 GtkWidget *vbox_details;
124 GtkWidget *table_details;
125 GtkWidget *hbox_details_requested;
126 GtkWidget *spinner_details;
127 GList *details_to_set;
128 GCancellable *details_cancellable;
129 gboolean details_changed;
132 GtkWidget *vbox_client;
133 GtkWidget *table_client;
134 GtkWidget *hbox_client_requested;
135 } EmpathyContactWidget;
139 EmpathyContactWidget *information;
142 GtkTreeIter found_iter;
154 field_value_is_empty (TpContactInfoField *field)
158 if (field->field_value == NULL)
161 /* Field is empty if all its values are empty */
162 for (i = 0; field->field_value[i] != NULL; i++)
164 if (!tp_str_empty (field->field_value[i]))
172 set_contact_info_cb (GObject *source,
173 GAsyncResult *result,
176 GError *error = NULL;
178 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
181 DEBUG ("SetContactInfo() failed: %s", error->message);
182 g_error_free (error);
186 DEBUG ("SetContactInfo() succeeded");
190 contact_widget_save (EmpathyContactWidget *information)
192 TpConnection *connection;
195 connection = empathy_contact_get_connection (information->contact);
197 /* Remove empty fields */
198 for (l = information->details_to_set; l != NULL; l = next)
200 TpContactInfoField *field = l->data;
203 if (field_value_is_empty (field))
205 DEBUG ("Drop empty field: %s", field->field_name);
206 tp_contact_info_field_free (field);
207 information->details_to_set =
208 g_list_delete_link (information->details_to_set, l);
212 if (information->details_to_set != NULL)
214 if (information->details_changed)
216 tp_connection_set_contact_info_async (connection,
217 information->details_to_set, set_contact_info_cb, NULL);
220 tp_contact_info_list_free (information->details_to_set);
221 information->details_to_set = NULL;
226 contact_widget_details_setup (EmpathyContactWidget *information)
228 gtk_widget_hide (information->vbox_details);
230 information->spinner_details = gtk_spinner_new ();
231 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
232 information->spinner_details, TRUE, TRUE, 0);
233 gtk_widget_show (information->spinner_details);
237 contact_widget_details_changed_cb (GtkEntry *entry,
238 EmpathyContactWidget *self)
240 const gchar *strv[] = { NULL, NULL };
241 TpContactInfoField *field;
243 self->details_changed = TRUE;
245 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
246 g_assert (field != NULL);
248 strv[0] = gtk_entry_get_text (entry);
250 if (field->field_value != NULL)
251 g_strfreev (field->field_value);
252 field->field_value = g_strdupv ((GStrv) strv);
256 contact_widget_bday_changed_cb (GtkCalendar *calendar,
257 EmpathyContactWidget *self)
259 guint year, month, day;
262 const gchar *strv[] = { NULL, NULL };
263 TpContactInfoField *field;
265 self->details_changed = TRUE;
267 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
268 g_assert (field != NULL);
270 gtk_calendar_get_date (calendar, &year, &month, &day);
271 date = g_date_new_dmy (day, month+1, year);
273 gtk_calendar_clear_marks (calendar);
274 gtk_calendar_mark_day (calendar, g_date_get_day (date));
276 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
278 if (field->field_value != NULL)
279 g_strfreev (field->field_value);
280 field->field_value = g_strdupv ((GStrv) strv);
285 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
287 typedef gchar * (* FieldFormatFunc) (GStrv);
291 const gchar *field_name;
293 FieldFormatFunc format;
297 linkify_first_value (GStrv values)
299 return empathy_add_link_markup (values[0]);
303 format_idle_time (GStrv values)
305 const gchar *value = values[0];
306 int duration = strtol (value, NULL, 10);
311 return empathy_duration_to_string (duration);
314 static InfoFieldData info_field_datas[] =
316 { "fn", N_("Full name:"), NULL },
317 { "tel", N_("Phone number:"), NULL },
318 { "email", N_("E-mail address:"), linkify_first_value },
319 { "url", N_("Website:"), linkify_first_value },
320 { "bday", N_("Birthday:"), NULL },
322 /* Note to translators: this is the caption for a string of the form "5
323 * minutes ago", and refers to the time since the contact last interacted
324 * with their IM client.
326 { "x-idle-time", N_("Last seen:"), format_idle_time },
330 static InfoFieldData *
331 find_info_field_data (const gchar *field_name)
335 for (i = 0; info_field_datas[i].field_name != NULL; i++)
337 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
338 return info_field_datas + i;
344 contact_info_field_name_cmp (const gchar *name1,
349 if (!tp_strdiff (name1, name2))
352 /* We use the order of info_field_datas */
353 for (i = 0; info_field_datas[i].field_name != NULL; i++)
355 if (!tp_strdiff (info_field_datas[i].field_name, name1))
357 if (!tp_strdiff (info_field_datas[i].field_name, name2))
361 return g_strcmp0 (name1, name2);
365 contact_info_field_cmp (TpContactInfoField *field1,
366 TpContactInfoField *field2)
368 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
372 field_name_in_field_list (GList *list,
377 for (l = list; l != NULL; l = g_list_next (l))
379 TpContactInfoField *field = l->data;
381 if (!tp_strdiff (field->field_name, name))
388 static TpContactInfoFieldSpec *
389 get_spec_from_list (GList *list,
394 for (l = list; l != NULL; l = g_list_next (l))
396 TpContactInfoFieldSpec *spec = l->data;
398 if (!tp_strdiff (spec->name, name))
406 contact_widget_details_update_edit (EmpathyContactWidget *information)
409 TpConnection *connection;
415 g_assert (information->details_to_set == NULL);
417 information->details_changed = FALSE;
419 contact = empathy_contact_get_tp_contact (information->contact);
420 connection = tp_contact_get_connection (contact);
422 info = tp_contact_get_contact_info (contact);
424 specs = tp_connection_get_contact_info_supported_fields (connection);
426 /* Look at the fields set in our vCard */
427 for (l = info; l != NULL; l = l->next)
429 TpContactInfoField *field = l->data;
431 /* make a copy for the details_to_set list */
432 field = tp_contact_info_field_copy (field);
433 DEBUG ("Field %s is in our vCard", field->field_name);
435 information->details_to_set = g_list_prepend (information->details_to_set,
439 /* Add fields which are supported but not in the vCard */
440 for (i = 0; info_field_datas[i].field_name != NULL; i++)
442 TpContactInfoFieldSpec *spec;
443 TpContactInfoField *field;
445 /* Check if the field was in the vCard */
446 if (field_name_in_field_list (information->details_to_set,
447 info_field_datas[i].field_name))
450 /* Check if the CM supports the field */
451 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
455 /* add an empty field so user can set a value */
456 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
458 information->details_to_set = g_list_prepend (information->details_to_set,
462 /* Add widgets for supported fields */
463 information->details_to_set = g_list_sort (information->details_to_set,
464 (GCompareFunc) contact_info_field_cmp);
466 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
468 TpContactInfoField *field = l->data;
469 InfoFieldData *field_data;
471 TpContactInfoFieldSpec *spec;
473 field_data = find_info_field_data (field->field_name);
474 if (field_data == NULL)
476 /* Empathy doesn't display this field so we can't change it.
477 * But we put it in the details_to_set list so it won't be erased
478 * when calling SetContactInfo (bgo #630427) */
479 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
483 spec = get_spec_from_list (specs, field->field_name);
484 /* We shouldn't have added the field to details_to_set if it's not
485 * supported by the CM */
486 g_assert (spec != NULL);
488 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
490 DEBUG ("Ignoring field '%s' due it to having the "
491 "Overwritten_By_Nickname flag", field->field_name);
496 w = gtk_label_new (_(field_data->title));
497 gtk_table_attach (GTK_TABLE (information->table_details),
498 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
499 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
503 if (!tp_strdiff (field->field_name, "bday"))
505 w = gtk_calendar_new ();
506 if (field->field_value[0])
510 g_date_set_parse (&date, field->field_value[0]);
511 if (g_date_valid (&date))
513 gtk_calendar_select_day (GTK_CALENDAR (w),
514 g_date_get_day (&date));
515 gtk_calendar_select_month (GTK_CALENDAR (w),
516 g_date_get_month (&date) - 1, g_date_get_year (&date));
517 gtk_calendar_mark_day (GTK_CALENDAR (w),
518 g_date_get_day (&date));
521 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
522 w, 1, 2, n_rows, n_rows + 1);
525 g_object_set_data ((GObject *) w, DATA_FIELD, field);
527 g_signal_connect (w, "day-selected-double-click",
528 G_CALLBACK (contact_widget_bday_changed_cb), information);
529 g_signal_connect (w, "month-changed",
530 G_CALLBACK (contact_widget_bday_changed_cb), information);
534 w = gtk_entry_new ();
535 gtk_entry_set_text (GTK_ENTRY (w),
536 field->field_value[0] ? field->field_value[0] : "");
537 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
538 w, 1, 2, n_rows, n_rows + 1);
541 g_object_set_data ((GObject *) w, DATA_FIELD, field);
543 g_signal_connect (w, "changed",
544 G_CALLBACK (contact_widget_details_changed_cb), information);
557 channel_name_activated_cb (
560 EmpathyContactWidget *information)
562 TpAccount *account = empathy_contact_get_account (information->contact);
564 empathy_join_muc (account, uri, empathy_get_current_action_time ());
570 EmpathyContactWidget *information,
575 GString *label_markup = g_string_new ("");
578 w = gtk_label_new (_("Channels:"));
579 gtk_table_attach (GTK_TABLE (information->table_details),
580 w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
581 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
584 for (i = 0; i < channels->len; i++)
586 const gchar *channel_name = g_ptr_array_index (channels, i);
587 /* We abuse the URI of the link to hold the channel name. It seems to
588 * be okay to just use it essentially verbatim, rather than trying to
589 * ensure it's actually a valid URI. g_string_append_uri_escaped()
590 * escapes way more than we actually need to; so we're just using
591 * g_markup_escape_text directly.
593 gchar *escaped = g_markup_escape_text (channel_name, -1);
596 g_string_append (label_markup, ", ");
598 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
599 escaped, channel_name);
603 w = gtk_label_new (NULL);
604 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
605 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
606 g_signal_connect (w, "activate-link",
607 (GCallback) channel_name_activated_cb, information);
608 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
609 w, 1, 2, row, row + 1);
610 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
613 g_string_free (label_markup, TRUE);
617 contact_widget_details_update_show (EmpathyContactWidget *information)
622 GPtrArray *channels = g_ptr_array_new ();
624 contact = empathy_contact_get_tp_contact (information->contact);
625 info = tp_contact_get_contact_info (contact);
626 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
627 for (l = info; l != NULL; l = l->next)
629 TpContactInfoField *field = l->data;
630 InfoFieldData *field_data;
632 gchar *markup = NULL;
635 if (field->field_value == NULL || field->field_value[0] == NULL)
638 value = field->field_value[0];
640 if (!tp_strdiff (field->field_name, "x-irc-channel"))
642 g_ptr_array_add (channels, (gpointer) field->field_value[0]);
646 field_data = find_info_field_data (field->field_name);
647 if (field_data == NULL)
649 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
653 if (field_data->format != NULL)
655 markup = field_data->format (field->field_value);
659 DEBUG ("Invalid value for field '%s' (first element was '%s')",
660 field->field_name, field->field_value[0]);
666 w = gtk_label_new (_(field_data->title));
667 gtk_table_attach (GTK_TABLE (information->table_details),
668 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
669 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
673 w = gtk_label_new (value);
676 gtk_label_set_markup (GTK_LABEL (w), markup);
680 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
681 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
683 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
684 w, 1, 2, n_rows, n_rows + 1);
685 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
692 if (channels->len > 0)
694 add_channel_list (information, channels, n_rows);
698 g_ptr_array_unref (channels);
703 contact_widget_details_notify_cb (EmpathyContactWidget *information)
707 gtk_container_foreach (GTK_CONTAINER (information->table_details),
708 (GtkCallback) gtk_widget_destroy, NULL);
710 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
711 n_rows = contact_widget_details_update_edit (information);
713 n_rows = contact_widget_details_update_show (information);
717 gtk_widget_show (information->vbox_details);
718 gtk_widget_show (information->table_details);
722 gtk_widget_hide (information->vbox_details);
725 gtk_widget_hide (information->hbox_details_requested);
726 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
730 contact_widget_details_request_cb (GObject *object,
734 TpContact *contact = TP_CONTACT (object);
735 EmpathyContactWidget *information = user_data;
736 GError *error = NULL;
738 if (!tp_contact_request_contact_info_finish (contact, res, &error))
740 /* If the request got cancelled it could mean the contact widget is
741 * destroyed, so we should not dereference information */
742 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
744 g_clear_error (&error);
748 gtk_widget_hide (information->vbox_details);
749 g_clear_error (&error);
753 contact_widget_details_notify_cb (information);
756 /* If we are going to edit ContactInfo, we don't want live updates */
757 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
759 g_signal_connect_swapped (contact, "notify::contact-info",
760 G_CALLBACK (contact_widget_details_notify_cb), information);
763 tp_clear_object (&information->details_cancellable);
767 contact_widget_details_feature_prepared_cb (GObject *object,
771 TpConnection *connection = TP_CONNECTION (object);
772 EmpathyContactWidget *information = user_data;
774 TpContactInfoFlags flags;
776 if (!tp_proxy_prepare_finish (connection, res, NULL))
778 gtk_widget_hide (information->vbox_details);
782 /* If we want to edit info, but connection does not support that, stop */
783 flags = tp_connection_get_contact_info_flags (connection);
784 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
785 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
787 gtk_widget_hide (information->vbox_details);
791 /* Request the contact's info */
792 gtk_widget_show (information->vbox_details);
793 gtk_widget_show (information->hbox_details_requested);
794 gtk_widget_hide (information->table_details);
795 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
797 contact = empathy_contact_get_tp_contact (information->contact);
798 g_assert (information->details_cancellable == NULL);
799 information->details_cancellable = g_cancellable_new ();
800 tp_contact_request_contact_info_async (contact,
801 information->details_cancellable, contact_widget_details_request_cb,
806 contact_widget_details_update (EmpathyContactWidget *information)
808 TpContact *tp_contact = NULL;
810 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
811 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
814 gtk_widget_hide (information->vbox_details);
816 if (information->contact != NULL)
817 tp_contact = empathy_contact_get_tp_contact (information->contact);
819 if (tp_contact != NULL)
821 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
822 TpConnection *connection;
824 /* First, make sure the CONTACT_INFO feature is ready on the connection */
825 connection = tp_contact_get_connection (tp_contact);
826 tp_proxy_prepare_async (connection, features,
827 contact_widget_details_feature_prepared_cb, information);
832 contact_widget_client_update (EmpathyContactWidget *information)
834 /* FIXME: Needs new telepathy spec */
838 contact_widget_client_setup (EmpathyContactWidget *information)
840 /* FIXME: Needs new telepathy spec */
841 gtk_widget_hide (information->vbox_client);
845 contact_widget_groups_update (EmpathyContactWidget *information)
847 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
848 information->contact != NULL)
850 FolksPersona *persona =
851 empathy_contact_get_persona (information->contact);
853 if (FOLKS_IS_GROUP_DETAILS (persona))
855 empathy_groups_widget_set_group_details (
856 EMPATHY_GROUPS_WIDGET (information->groups_widget),
857 FOLKS_GROUP_DETAILS (persona));
858 gtk_widget_show (information->groups_widget);
864 /* In case of failure */
865 gtk_widget_hide (information->groups_widget);
868 /* Converts the Location's GHashTable's key to a user readable string */
870 location_key_to_label (const gchar *key)
872 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
873 return _("Country ISO Code:");
874 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
875 return _("Country:");
876 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
878 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
880 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
882 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
883 return _("Postal Code:");
884 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
886 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
887 return _("Building:");
888 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
890 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
892 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
894 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
895 return _("Description:");
896 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
898 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
899 return _("Accuracy Level:");
900 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
902 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
903 return _("Vertical Error (meters):");
904 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
905 return _("Horizontal Error (meters):");
906 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
908 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
909 return _("Bearing:");
910 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
911 return _("Climb Speed:");
912 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
913 return _("Last Updated on:");
914 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
915 return _("Longitude:");
916 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
917 return _("Latitude:");
918 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
919 return _("Altitude:");
922 DEBUG ("Unexpected Location key: %s", key);
928 contact_widget_location_update (EmpathyContactWidget *information)
930 GHashTable *location;
932 #ifdef HAVE_LIBCHAMPLAIN
933 gdouble lat = 0.0, lon = 0.0;
934 gboolean has_position = TRUE;
938 static const gchar* ordered_geolocation_keys[] = {
939 EMPATHY_LOCATION_TEXT,
940 EMPATHY_LOCATION_URI,
941 EMPATHY_LOCATION_DESCRIPTION,
942 EMPATHY_LOCATION_BUILDING,
943 EMPATHY_LOCATION_FLOOR,
944 EMPATHY_LOCATION_ROOM,
945 EMPATHY_LOCATION_STREET,
946 EMPATHY_LOCATION_AREA,
947 EMPATHY_LOCATION_LOCALITY,
948 EMPATHY_LOCATION_REGION,
949 EMPATHY_LOCATION_COUNTRY,
954 gboolean display_map = FALSE;
956 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
958 gtk_widget_hide (information->vbox_location);
962 location = empathy_contact_get_location (information->contact);
963 if (location == NULL || g_hash_table_size (location) == 0)
965 gtk_widget_hide (information->vbox_location);
969 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
972 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
973 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
983 stamp = g_value_get_int64 (value);
985 user_date = empathy_time_to_string_relative (stamp);
987 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
988 /* translators: format is "Location, $date" */
989 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
991 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
997 /* Prepare the location information table */
998 if (information->table_location != NULL)
1000 gtk_widget_destroy (information->table_location);
1003 information->table_location = gtk_table_new (1, 2, FALSE);
1004 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
1005 information->table_location, FALSE, FALSE, 5);
1008 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
1010 const gchar* user_label;
1012 char *svalue = NULL;
1014 gvalue = g_hash_table_lookup (location, (gpointer) skey);
1018 user_label = location_key_to_label (skey);
1020 label = gtk_label_new (user_label);
1021 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1022 gtk_table_attach (GTK_TABLE (information->table_location),
1023 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1024 gtk_widget_show (label);
1026 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1029 dvalue = g_value_get_double (gvalue);
1030 svalue = g_strdup_printf ("%f", dvalue);
1032 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1034 svalue = g_value_dup_string (gvalue);
1036 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1040 time_ = g_value_get_int64 (value);
1041 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1046 label = gtk_label_new (svalue);
1047 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1048 label, 1, 2, row, row + 1);
1049 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1050 gtk_widget_show (label);
1052 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1053 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1060 #ifdef HAVE_LIBCHAMPLAIN
1062 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1064 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1072 /* We can display some fields */
1073 gtk_widget_show (information->table_location);
1075 else if (!display_map)
1077 /* Can't display either fields or map */
1078 gtk_widget_hide (information->vbox_location);
1082 #ifdef HAVE_LIBCHAMPLAIN
1085 ClutterActor *marker;
1086 ChamplainMarkerLayer *layer;
1088 information->map_view_embed = gtk_champlain_embed_new ();
1089 information->map_view = gtk_champlain_embed_get_view (
1090 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1092 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1093 information->map_view_embed);
1094 g_object_set (G_OBJECT (information->map_view),
1095 "kinetic-mode", TRUE,
1099 layer = champlain_marker_layer_new ();
1100 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1102 marker = champlain_label_new_with_text (
1103 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1104 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1105 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1107 champlain_view_center_on (information->map_view, lat, lon);
1108 gtk_widget_show_all (information->viewport_map);
1112 gtk_widget_show (information->vbox_location);
1116 save_avatar_menu_activate_cb (GtkWidget *widget,
1117 EmpathyContactWidget *information)
1120 EmpathyAvatar *avatar;
1121 gchar *ext = NULL, *filename;
1123 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1125 GTK_FILE_CHOOSER_ACTION_SAVE,
1126 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1127 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1130 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1133 /* look for the avatar extension */
1134 avatar = empathy_contact_get_avatar (information->contact);
1135 if (avatar->format != NULL)
1139 splitted = g_strsplit (avatar->format, "/", 2);
1140 if (splitted[0] != NULL && splitted[1] != NULL)
1141 ext = g_strdup (splitted[1]);
1143 g_strfreev (splitted);
1147 /* Avatar was loaded from the cache so was converted to PNG */
1148 ext = g_strdup ("png");
1155 id = tp_escape_as_identifier (empathy_contact_get_id (
1156 information->contact));
1158 filename = g_strdup_printf ("%s.%s", id, ext);
1159 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1166 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1168 GError *error = NULL;
1170 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1172 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1175 GtkWidget *error_dialog;
1177 error_dialog = gtk_message_dialog_new (NULL, 0,
1178 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1179 _("Unable to save avatar"));
1181 gtk_message_dialog_format_secondary_text (
1182 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1184 g_signal_connect (error_dialog, "response",
1185 G_CALLBACK (gtk_widget_destroy), NULL);
1187 gtk_window_present (GTK_WINDOW (error_dialog));
1189 g_clear_error (&error);
1195 gtk_widget_destroy (dialog);
1199 popup_avatar_menu (EmpathyContactWidget *information,
1201 GdkEventButton *event)
1203 GtkWidget *menu, *item;
1204 gint button, event_time;
1206 if (information->contact == NULL ||
1207 empathy_contact_get_avatar (information->contact) == NULL)
1210 menu = empathy_context_menu_new (parent);
1212 /* Add "Save as..." entry */
1213 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1214 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1215 gtk_widget_show (item);
1217 g_signal_connect (item, "activate",
1218 G_CALLBACK (save_avatar_menu_activate_cb), information);
1222 button = event->button;
1223 event_time = event->time;
1228 event_time = gtk_get_current_event_time ();
1231 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1232 button, event_time);
1236 widget_avatar_popup_menu_cb (GtkWidget *widget,
1237 EmpathyContactWidget *information)
1239 popup_avatar_menu (information, widget, NULL);
1245 widget_avatar_button_press_event_cb (GtkWidget *widget,
1246 GdkEventButton *event,
1247 EmpathyContactWidget *information)
1249 /* Ignore double-clicks and triple-clicks */
1250 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1252 popup_avatar_menu (information, widget, event);
1260 set_avatar_cb (GObject *source,
1264 GError *error = NULL;
1266 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1267 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1268 g_error_free (error);
1273 set_avatar_on_account (TpAccount *account,
1276 const gchar *mime_type)
1278 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1279 tp_proxy_get_object_path (account));
1281 tp_account_set_avatar_async (account, (const guchar *) data, size,
1282 mime_type, set_avatar_cb, NULL);
1286 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1287 EmpathyContactWidget *information)
1291 const gchar *mime_type;
1294 empathy_avatar_chooser_get_image_data (
1295 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1296 &data, &size, &mime_type);
1298 account = empathy_contact_get_account (information->contact);
1299 set_avatar_on_account (account, data, size, mime_type);
1303 set_nickname_cb (GObject *source,
1307 GError *error = NULL;
1309 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1311 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1312 g_error_free (error);
1316 /* Update all the contact info fields having the
1317 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1318 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1321 update_nickname_in_contact_info (EmpathyContactWidget *self,
1322 TpConnection *connection,
1323 const gchar *nickname)
1327 specs = tp_connection_get_contact_info_supported_fields (connection);
1329 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1331 TpContactInfoField *field = l->data;
1332 TpContactInfoFieldSpec *spec;
1334 spec = get_spec_from_list (specs, field->field_name);
1335 /* We shouldn't have added the field to details_to_set if it's not
1336 * supported by the CM */
1337 g_assert (spec != NULL);
1339 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1341 const gchar *strv[] = { nickname, NULL };
1343 DEBUG ("Updating field '%s' to '%s' as it has the "
1344 "Overwritten_By_Nickname flag and Account.Nickname has "
1345 "been updated", field->field_name, nickname);
1347 if (field->field_value != NULL)
1348 g_strfreev (field->field_value);
1349 field->field_value = g_strdupv ((GStrv) strv);
1353 g_list_free (specs);
1357 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1358 GdkEventFocus *event,
1359 EmpathyContactWidget *information)
1361 if (information->contact)
1365 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1367 if (empathy_contact_is_user (information->contact))
1369 TpAccount * account;
1370 const gchar *current_nickname;
1372 account = empathy_contact_get_account (information->contact);
1373 current_nickname = tp_account_get_nickname (account);
1375 if (tp_strdiff (current_nickname, alias))
1377 DEBUG ("Set Account.Nickname to %s", alias);
1379 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1382 update_nickname_in_contact_info (information,
1383 empathy_contact_get_connection (information->contact), alias);
1388 empathy_contact_set_alias (information->contact, alias);
1396 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1397 EmpathyAvatarChooser *avatar_chooser)
1401 account = empathy_account_chooser_get_account (account_chooser);
1402 if (account == NULL)
1405 empathy_avatar_chooser_set_account (avatar_chooser, account);
1409 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1411 EmpathyAvatar *avatar = NULL;
1413 if (information->contact)
1414 avatar = empathy_contact_get_avatar (information->contact);
1416 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1418 g_signal_handlers_block_by_func (information->widget_avatar,
1419 contact_widget_avatar_changed_cb,
1421 empathy_avatar_chooser_set (
1422 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1423 g_signal_handlers_unblock_by_func (information->widget_avatar,
1424 contact_widget_avatar_changed_cb, information);
1427 empathy_avatar_image_set (
1428 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1432 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1434 if (GTK_IS_ENTRY (information->widget_alias))
1435 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1436 empathy_contact_get_alias (information->contact));
1438 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1439 empathy_contact_get_alias (information->contact));
1443 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1445 const gchar *status;
1446 gchar *markup_text = NULL;
1448 status = empathy_contact_get_status (information->contact);
1450 markup_text = empathy_add_link_markup (status);
1451 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1452 g_free (markup_text);
1454 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1455 empathy_icon_name_for_contact (information->contact),
1456 GTK_ICON_SIZE_BUTTON);
1457 gtk_widget_show (information->image_state);
1461 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1462 EmpathyContact *contact,
1463 gboolean is_favourite,
1464 EmpathyContactWidget *information)
1466 if (contact != information->contact)
1469 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1470 information->favourite_checkbox), is_favourite);
1474 contact_widget_remove_contact (EmpathyContactWidget *information)
1476 if (information->contact)
1478 TpContact *tp_contact;
1480 contact_widget_save (information);
1482 g_signal_handlers_disconnect_by_func (information->contact,
1483 contact_widget_name_notify_cb, information);
1484 g_signal_handlers_disconnect_by_func (information->contact,
1485 contact_widget_presence_notify_cb, information);
1486 g_signal_handlers_disconnect_by_func (information->contact,
1487 contact_widget_avatar_notify_cb, information);
1489 tp_contact = empathy_contact_get_tp_contact (information->contact);
1490 if (tp_contact != NULL)
1492 g_signal_handlers_disconnect_by_func (tp_contact,
1493 contact_widget_details_notify_cb, information);
1496 g_object_unref (information->contact);
1497 information->contact = NULL;
1500 if (information->details_cancellable != NULL)
1502 g_cancellable_cancel (information->details_cancellable);
1503 tp_clear_object (&information->details_cancellable);
1507 static void contact_widget_change_contact (EmpathyContactWidget *information);
1510 contact_widget_contact_update (EmpathyContactWidget *information)
1512 TpAccount *account = NULL;
1513 const gchar *id = NULL;
1515 /* Connect and get info from new contact */
1516 if (information->contact)
1518 g_signal_connect_swapped (information->contact, "notify::name",
1519 G_CALLBACK (contact_widget_name_notify_cb), information);
1520 g_signal_connect_swapped (information->contact, "notify::presence",
1521 G_CALLBACK (contact_widget_presence_notify_cb), information);
1522 g_signal_connect_swapped (information->contact,
1523 "notify::presence-message",
1524 G_CALLBACK (contact_widget_presence_notify_cb), information);
1525 g_signal_connect_swapped (information->contact, "notify::avatar",
1526 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1528 account = empathy_contact_get_account (information->contact);
1529 id = empathy_contact_get_id (information->contact);
1532 /* Update account widget */
1533 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1537 g_signal_handlers_block_by_func (information->widget_account,
1538 contact_widget_change_contact,
1540 empathy_account_chooser_set_account (
1541 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1542 g_signal_handlers_unblock_by_func (information->widget_account,
1543 contact_widget_change_contact, information);
1552 name = tp_account_get_display_name (account);
1553 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1555 name = tp_account_get_icon_name (account);
1556 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1557 name, GTK_ICON_SIZE_MENU);
1561 /* Update id widget */
1562 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1563 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1565 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1567 /* Update other widgets */
1568 if (information->contact)
1570 contact_widget_name_notify_cb (information);
1571 contact_widget_presence_notify_cb (information);
1572 contact_widget_avatar_notify_cb (information);
1574 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1576 FolksPersona *persona = empathy_contact_get_persona (
1577 information->contact);
1579 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1581 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1582 FOLKS_FAVOURITE_DETAILS (persona));
1583 contact_widget_favourites_changed_cb (information->manager,
1584 information->contact, is_favourite, information);
1588 gtk_widget_show (information->label_alias);
1589 gtk_widget_show (information->widget_alias);
1590 gtk_widget_show (information->hbox_presence);
1591 gtk_widget_show (information->widget_avatar);
1595 gtk_widget_hide (information->label_alias);
1596 gtk_widget_hide (information->widget_alias);
1597 gtk_widget_hide (information->hbox_presence);
1598 gtk_widget_hide (information->widget_avatar);
1603 contact_widget_set_contact (EmpathyContactWidget *information,
1604 EmpathyContact *contact)
1606 if (contact == information->contact)
1609 contact_widget_remove_contact (information);
1611 information->contact = g_object_ref (contact);
1613 /* set the selected account to be the account this contact came from */
1614 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1615 empathy_account_chooser_set_account (
1616 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1617 empathy_contact_get_account (contact));
1620 /* Update information for widgets */
1621 contact_widget_contact_update (information);
1622 contact_widget_groups_update (information);
1623 contact_widget_details_update (information);
1624 contact_widget_client_update (information);
1625 contact_widget_location_update (information);
1629 contact_widget_got_contact_cb (TpConnection *connection,
1630 EmpathyContact *contact,
1631 const GError *error,
1633 GObject *weak_object)
1635 EmpathyContactWidget *information = user_data;
1639 DEBUG ("Error: %s", error->message);
1643 contact_widget_set_contact (information, contact);
1647 contact_widget_change_contact (EmpathyContactWidget *information)
1649 TpConnection *connection;
1651 connection = empathy_account_chooser_get_connection (
1652 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1656 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1660 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1661 if (!EMP_STR_EMPTY (id))
1663 empathy_tp_contact_factory_get_from_id (connection, id,
1664 contact_widget_got_contact_cb, information, NULL,
1665 G_OBJECT (information->vbox_contact_widget));
1670 empathy_tp_contact_factory_get_from_handle (connection,
1671 tp_connection_get_self_handle (connection),
1672 contact_widget_got_contact_cb, information, NULL,
1673 G_OBJECT (information->vbox_contact_widget));
1678 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1680 contact_widget_change_contact (self);
1685 contact_widget_id_changed_cb (GtkEntry *entry,
1686 EmpathyContactWidget *self)
1688 if (self->widget_id_timeout != 0)
1690 g_source_remove (self->widget_id_timeout);
1693 self->widget_id_timeout =
1694 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1695 (GSourceFunc) contact_widget_id_activate_timeout, self);
1699 contact_widget_id_focus_out_cb (GtkWidget *widget,
1700 GdkEventFocus *event,
1701 EmpathyContactWidget *information)
1703 contact_widget_change_contact (information);
1708 favourite_toggled_cb (GtkToggleButton *button,
1709 EmpathyContactWidget *information)
1711 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1713 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1715 gboolean active = gtk_toggle_button_get_active (button);
1716 folks_favourite_details_set_is_favourite (
1717 FOLKS_FAVOURITE_DETAILS (persona), active);
1722 contact_widget_contact_setup (EmpathyContactWidget *information)
1724 information->label_status = gtk_label_new ("");
1725 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1726 PANGO_WRAP_WORD_CHAR);
1727 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1730 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1731 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1733 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1734 information->label_status, TRUE, TRUE, 0);
1735 gtk_widget_show (information->label_status);
1737 /* Setup account label/chooser */
1738 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1740 information->widget_account = empathy_account_chooser_new ();
1742 g_signal_connect_swapped (information->widget_account, "changed",
1743 G_CALLBACK (contact_widget_change_contact),
1748 /* Pack the protocol icon with the account name in an hbox */
1749 information->widget_account = gtk_hbox_new (FALSE, 6);
1751 information->label_account = gtk_label_new (NULL);
1752 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1753 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1755 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1756 gtk_widget_show (information->label_account);
1758 information->image_account = gtk_image_new ();
1759 gtk_widget_show (information->image_account);
1761 gtk_box_pack_start (GTK_BOX (information->widget_account),
1762 information->image_account, FALSE, FALSE, 0);
1763 gtk_box_pack_start (GTK_BOX (information->widget_account),
1764 information->label_account, FALSE, TRUE, 0);
1766 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1767 information->widget_account,
1769 gtk_widget_show (information->widget_account);
1771 /* Set up avatar chooser/display */
1772 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1774 information->widget_avatar = empathy_avatar_chooser_new ();
1775 g_signal_connect (information->widget_avatar, "changed",
1776 G_CALLBACK (contact_widget_avatar_changed_cb),
1778 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1780 g_signal_connect (information->widget_account, "changed",
1781 G_CALLBACK (update_avatar_chooser_account_cb),
1782 information->widget_avatar);
1783 update_avatar_chooser_account_cb (
1784 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1785 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1790 information->widget_avatar = empathy_avatar_image_new ();
1792 g_signal_connect (information->widget_avatar, "popup-menu",
1793 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1794 g_signal_connect (information->widget_avatar, "button-press-event",
1795 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1798 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1799 information->widget_avatar,
1802 gtk_widget_show (information->widget_avatar);
1804 /* Setup id label/entry */
1805 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1807 information->widget_id = gtk_entry_new ();
1808 g_signal_connect (information->widget_id, "focus-out-event",
1809 G_CALLBACK (contact_widget_id_focus_out_cb),
1811 g_signal_connect (information->widget_id, "changed",
1812 G_CALLBACK (contact_widget_id_changed_cb),
1817 information->widget_id = gtk_label_new (NULL);
1818 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1819 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1821 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1823 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1824 information->widget_id,
1826 gtk_widget_show (information->widget_id);
1828 /* Setup alias label/entry */
1829 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1831 information->widget_alias = gtk_entry_new ();
1833 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1834 g_signal_connect (information->widget_alias, "focus-out-event",
1835 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1838 /* Make return activate the window default (the Close button) */
1839 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1844 information->widget_alias = gtk_label_new (NULL);
1845 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1846 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1848 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1850 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1851 information->widget_alias,
1853 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1854 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1856 gtk_widget_show (information->widget_alias);
1859 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1861 information->favourite_checkbox = gtk_check_button_new_with_label (
1864 g_signal_connect (information->favourite_checkbox, "toggled",
1865 G_CALLBACK (favourite_toggled_cb), information);
1867 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1868 information->favourite_checkbox, 0, 2, 3, 4);
1870 information->fav_sig_id = g_signal_connect (information->manager,
1871 "favourites-changed",
1872 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1874 gtk_widget_show (information->favourite_checkbox);
1879 contact_widget_destroy_cb (GtkWidget *widget,
1880 EmpathyContactWidget *information)
1882 contact_widget_remove_contact (information);
1884 if (information->widget_id_timeout != 0)
1886 g_source_remove (information->widget_id_timeout);
1889 if (information->fav_sig_id != 0)
1890 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1892 g_object_unref (information->manager);
1894 g_slice_free (EmpathyContactWidget, information);
1898 * empathy_contact_widget_new:
1899 * @contact: an #EmpathyContact
1900 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1902 * Creates a new #EmpathyContactWidget.
1904 * Return value: a new #EmpathyContactWidget
1907 empathy_contact_widget_new (EmpathyContact *contact,
1908 EmpathyContactWidgetFlags flags)
1910 EmpathyContactWidget *information;
1914 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1916 information = g_slice_new0 (EmpathyContactWidget);
1917 information->flags = flags;
1919 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1921 gui = empathy_builder_get_file (filename,
1922 "vbox_contact_widget", &information->vbox_contact_widget,
1923 "hbox_contact", &information->hbox_contact,
1924 "hbox_presence", &information->hbox_presence,
1925 "label_alias", &information->label_alias,
1926 "image_state", &information->image_state,
1927 "table_contact", &information->table_contact,
1928 "vbox_avatar", &information->vbox_avatar,
1929 "vbox_location", &information->vbox_location,
1930 "subvbox_location", &information->subvbox_location,
1931 "label_location", &information->label_location,
1932 #ifdef HAVE_LIBCHAMPLAIN
1933 "viewport_map", &information->viewport_map,
1935 "groups_widget", &information->groups_widget,
1936 "vbox_details", &information->vbox_details,
1937 "table_details", &information->table_details,
1938 "hbox_details_requested", &information->hbox_details_requested,
1939 "vbox_client", &information->vbox_client,
1940 "table_client", &information->table_client,
1941 "hbox_client_requested", &information->hbox_client_requested,
1945 empathy_builder_connect (gui, information,
1946 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1948 information->table_location = NULL;
1950 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1951 "EmpathyContactWidget",
1954 information->manager = empathy_contact_manager_dup_singleton ();
1956 /* Create widgets */
1957 contact_widget_contact_setup (information);
1958 contact_widget_details_setup (information);
1959 contact_widget_client_setup (information);
1961 if (contact != NULL)
1962 contact_widget_set_contact (information, contact);
1963 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1964 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1965 contact_widget_change_contact (information);
1967 return empathy_builder_unref_and_keep_widget (gui,
1968 information->vbox_contact_widget);
1972 * empathy_contact_widget_get_contact:
1973 * @widget: an #EmpathyContactWidget
1975 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1977 * Returns: the #EmpathyContact associated with @widget
1980 empathy_contact_widget_get_contact (GtkWidget *widget)
1982 EmpathyContactWidget *information;
1984 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1986 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1990 return information->contact;
1994 empathy_contact_widget_get_alias (GtkWidget *widget)
1996 EmpathyContactWidget *information;
1998 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2000 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2004 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
2008 * empathy_contact_widget_set_contact:
2009 * @widget: an #EmpathyContactWidget
2010 * @contact: a different #EmpathyContact
2012 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
2015 empathy_contact_widget_set_contact (GtkWidget *widget,
2016 EmpathyContact *contact)
2018 EmpathyContactWidget *information;
2020 g_return_if_fail (GTK_IS_WIDGET (widget));
2021 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
2023 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2027 contact_widget_set_contact (information, contact);
2031 * empathy_contact_widget_set_account_filter:
2032 * @widget: an #EmpathyContactWidget
2033 * @filter: a #EmpathyAccountChooserFilterFunc
2034 * @user_data: user data to pass to @filter, or %NULL
2036 * Set a filter on the #EmpathyAccountChooser included in the
2037 * #EmpathyContactWidget.
2040 empathy_contact_widget_set_account_filter (
2042 EmpathyAccountChooserFilterFunc filter,
2045 EmpathyContactWidget *information;
2046 EmpathyAccountChooser *chooser;
2048 g_return_if_fail (GTK_IS_WIDGET (widget));
2050 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2054 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2056 empathy_account_chooser_set_filter (chooser, filter, user_data);