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-time.h>
44 #include <libempathy/empathy-utils.h>
46 #include "empathy-contact-widget.h"
47 #include "empathy-account-chooser.h"
48 #include "empathy-avatar-chooser.h"
49 #include "empathy-avatar-image.h"
50 #include "empathy-groups-widget.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-string-parser.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
55 #include <libempathy/empathy-debug.h>
58 * SECTION:empathy-contact-widget
59 * @title:EmpathyContactWidget
60 * @short_description: A widget used to display and edit details about a contact
61 * @include: libempathy-empathy-contact-widget.h
63 * #EmpathyContactWidget is a widget which displays appropriate widgets
64 * with details about a contact, also allowing changing these details,
69 * EmpathyContactWidget:
70 * @parent: parent object
72 * Widget which displays appropriate widgets with details about a contact,
73 * also allowing changing these details, if desired.
76 /* Delay before updating the widget when the id entry changed (seconds) */
77 #define ID_CHANGED_TIMEOUT 1
79 #define DATA_FIELD "contact-info-field"
83 EmpathyContactManager *manager;
84 EmpathyContact *contact;
85 EmpathyContactWidgetFlags flags;
86 guint widget_id_timeout;
89 GtkWidget *vbox_contact_widget;
92 GtkWidget *hbox_contact;
93 GtkWidget *widget_avatar;
94 GtkWidget *widget_account;
95 GtkWidget *image_account;
96 GtkWidget *label_account;
98 GtkWidget *widget_alias;
99 GtkWidget *label_alias;
100 GtkWidget *hbox_presence;
101 GtkWidget *image_state;
102 GtkWidget *label_status;
103 GtkWidget *table_contact;
104 GtkWidget *vbox_avatar;
105 GtkWidget *favourite_checkbox;
108 GtkWidget *vbox_location;
109 GtkWidget *subvbox_location;
110 GtkWidget *table_location;
111 GtkWidget *label_location;
112 #ifdef HAVE_LIBCHAMPLAIN
113 GtkWidget *viewport_map;
114 GtkWidget *map_view_embed;
115 ChamplainView *map_view;
119 GtkWidget *groups_widget;
122 GtkWidget *vbox_details;
123 GtkWidget *table_details;
124 GtkWidget *hbox_details_requested;
125 GtkWidget *spinner_details;
126 GList *details_to_set;
127 GCancellable *details_cancellable;
128 gboolean details_changed;
131 GtkWidget *vbox_client;
132 GtkWidget *table_client;
133 GtkWidget *hbox_client_requested;
134 } EmpathyContactWidget;
138 EmpathyContactWidget *information;
141 GtkTreeIter found_iter;
153 field_value_is_empty (TpContactInfoField *field)
157 if (field->field_value == NULL)
160 /* Field is empty if all its values are empty */
161 for (i = 0; field->field_value[i] != NULL; i++)
163 if (!tp_str_empty (field->field_value[i]))
171 set_contact_info_cb (GObject *source,
172 GAsyncResult *result,
175 GError *error = NULL;
177 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
180 DEBUG ("SetContactInfo() failed: %s", error->message);
181 g_error_free (error);
185 DEBUG ("SetContactInfo() succeeded");
189 contact_widget_save (EmpathyContactWidget *information)
191 TpConnection *connection;
194 connection = empathy_contact_get_connection (information->contact);
196 /* Remove empty fields */
197 for (l = information->details_to_set; l != NULL; l = next)
199 TpContactInfoField *field = l->data;
202 if (field_value_is_empty (field))
204 DEBUG ("Drop empty field: %s", field->field_name);
205 tp_contact_info_field_free (field);
206 information->details_to_set =
207 g_list_delete_link (information->details_to_set, l);
211 if (information->details_to_set != NULL)
213 if (information->details_changed)
215 tp_connection_set_contact_info_async (connection,
216 information->details_to_set, set_contact_info_cb, NULL);
219 tp_contact_info_list_free (information->details_to_set);
220 information->details_to_set = NULL;
225 contact_widget_details_setup (EmpathyContactWidget *information)
227 gtk_widget_hide (information->vbox_details);
229 information->spinner_details = gtk_spinner_new ();
230 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
231 information->spinner_details, TRUE, TRUE, 0);
232 gtk_widget_show (information->spinner_details);
236 contact_widget_details_changed_cb (GtkEntry *entry,
237 EmpathyContactWidget *self)
239 const gchar *strv[] = { NULL, NULL };
240 TpContactInfoField *field;
242 self->details_changed = TRUE;
244 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
245 g_assert (field != NULL);
247 strv[0] = gtk_entry_get_text (entry);
249 if (field->field_value != NULL)
250 g_strfreev (field->field_value);
251 field->field_value = g_strdupv ((GStrv) strv);
255 contact_widget_bday_changed_cb (GtkCalendar *calendar,
256 EmpathyContactWidget *self)
258 guint year, month, day;
261 const gchar *strv[] = { NULL, NULL };
262 TpContactInfoField *field;
264 self->details_changed = TRUE;
266 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
267 g_assert (field != NULL);
269 gtk_calendar_get_date (calendar, &year, &month, &day);
270 date = g_date_new_dmy (day, month+1, year);
272 gtk_calendar_clear_marks (calendar);
273 gtk_calendar_mark_day (calendar, g_date_get_day (date));
275 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
277 if (field->field_value != NULL)
278 g_strfreev (field->field_value);
279 field->field_value = g_strdupv ((GStrv) strv);
284 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
286 typedef gchar * (* FieldFormatFunc) (GStrv);
290 const gchar *field_name;
292 FieldFormatFunc format;
296 linkify_first_value (GStrv values)
298 return empathy_add_link_markup (values[0]);
301 static InfoFieldData info_field_datas[] =
303 { "fn", N_("Full name:"), NULL },
304 { "tel", N_("Phone number:"), NULL },
305 { "email", N_("E-mail address:"), linkify_first_value },
306 { "url", N_("Website:"), linkify_first_value },
307 { "bday", N_("Birthday:"), NULL },
311 static InfoFieldData *
312 find_info_field_data (const gchar *field_name)
316 for (i = 0; info_field_datas[i].field_name != NULL; i++)
318 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
319 return info_field_datas + i;
325 contact_info_field_name_cmp (const gchar *name1,
330 if (!tp_strdiff (name1, name2))
333 /* We use the order of info_field_datas */
334 for (i = 0; info_field_datas[i].field_name != NULL; i++)
336 if (!tp_strdiff (info_field_datas[i].field_name, name1))
338 if (!tp_strdiff (info_field_datas[i].field_name, name2))
342 return g_strcmp0 (name1, name2);
346 contact_info_field_cmp (TpContactInfoField *field1,
347 TpContactInfoField *field2)
349 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
353 field_name_in_field_list (GList *list,
358 for (l = list; l != NULL; l = g_list_next (l))
360 TpContactInfoField *field = l->data;
362 if (!tp_strdiff (field->field_name, name))
369 static TpContactInfoFieldSpec *
370 get_spec_from_list (GList *list,
375 for (l = list; l != NULL; l = g_list_next (l))
377 TpContactInfoFieldSpec *spec = l->data;
379 if (!tp_strdiff (spec->name, name))
387 contact_widget_details_update_edit (EmpathyContactWidget *information)
390 TpConnection *connection;
396 g_assert (information->details_to_set == NULL);
398 information->details_changed = FALSE;
400 contact = empathy_contact_get_tp_contact (information->contact);
401 connection = tp_contact_get_connection (contact);
403 info = tp_contact_get_contact_info (contact);
405 specs = tp_connection_get_contact_info_supported_fields (connection);
407 /* Look at the fields set in our vCard */
408 for (l = info; l != NULL; l = l->next)
410 TpContactInfoField *field = l->data;
412 /* make a copy for the details_to_set list */
413 field = tp_contact_info_field_copy (field);
414 DEBUG ("Field %s is in our vCard", field->field_name);
416 information->details_to_set = g_list_prepend (information->details_to_set,
420 /* Add fields which are supported but not in the vCard */
421 for (i = 0; info_field_datas[i].field_name != NULL; i++)
423 TpContactInfoFieldSpec *spec;
424 TpContactInfoField *field;
426 /* Check if the field was in the vCard */
427 if (field_name_in_field_list (information->details_to_set,
428 info_field_datas[i].field_name))
431 /* Check if the CM supports the field */
432 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
436 /* add an empty field so user can set a value */
437 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
439 information->details_to_set = g_list_prepend (information->details_to_set,
443 /* Add widgets for supported fields */
444 information->details_to_set = g_list_sort (information->details_to_set,
445 (GCompareFunc) contact_info_field_cmp);
447 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
449 TpContactInfoField *field = l->data;
450 InfoFieldData *field_data;
452 TpContactInfoFieldSpec *spec;
454 field_data = find_info_field_data (field->field_name);
455 if (field_data == NULL)
457 /* Empathy doesn't display this field so we can't change it.
458 * But we put it in the details_to_set list so it won't be erased
459 * when calling SetContactInfo (bgo #630427) */
460 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
464 spec = get_spec_from_list (specs, field->field_name);
465 /* We shouldn't have added the field to details_to_set if it's not
466 * supported by the CM */
467 g_assert (spec != NULL);
469 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
471 DEBUG ("Ignoring field '%s' due it to having the "
472 "Overwritten_By_Nickname flag", field->field_name);
477 w = gtk_label_new (_(field_data->title));
478 gtk_table_attach (GTK_TABLE (information->table_details),
479 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
480 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
484 if (!tp_strdiff (field->field_name, "bday"))
486 w = gtk_calendar_new ();
487 if (field->field_value[0])
491 g_date_set_parse (&date, field->field_value[0]);
492 if (g_date_valid (&date))
494 gtk_calendar_select_day (GTK_CALENDAR (w),
495 g_date_get_day (&date));
496 gtk_calendar_select_month (GTK_CALENDAR (w),
497 g_date_get_month (&date) - 1, g_date_get_year (&date));
498 gtk_calendar_mark_day (GTK_CALENDAR (w),
499 g_date_get_day (&date));
502 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
503 w, 1, 2, n_rows, n_rows + 1);
506 g_object_set_data ((GObject *) w, DATA_FIELD, field);
508 g_signal_connect (w, "day-selected-double-click",
509 G_CALLBACK (contact_widget_bday_changed_cb), information);
510 g_signal_connect (w, "month-changed",
511 G_CALLBACK (contact_widget_bday_changed_cb), information);
515 w = gtk_entry_new ();
516 gtk_entry_set_text (GTK_ENTRY (w),
517 field->field_value[0] ? field->field_value[0] : "");
518 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
519 w, 1, 2, n_rows, n_rows + 1);
522 g_object_set_data ((GObject *) w, DATA_FIELD, field);
524 g_signal_connect (w, "changed",
525 G_CALLBACK (contact_widget_details_changed_cb), information);
538 channel_name_activated_cb (
541 EmpathyContactWidget *information)
543 TpAccount *account = empathy_contact_get_account (information->contact);
545 empathy_join_muc (account, uri, empathy_get_current_action_time ());
551 EmpathyContactWidget *information,
556 GString *label_markup = g_string_new ("");
559 w = gtk_label_new (_("Channels:"));
560 gtk_table_attach (GTK_TABLE (information->table_details),
561 w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
562 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
565 for (i = 0; i < channels->len; i++)
567 const gchar *channel_name = g_ptr_array_index (channels, i);
568 /* We abuse the URI of the link to hold the channel name. It seems to
569 * be okay to just use it essentially verbatim, rather than trying to
570 * ensure it's actually a valid URI. g_string_append_uri_escaped()
571 * escapes way more than we actually need to; so we're just using
572 * g_markup_escape_text directly.
574 gchar *escaped = g_markup_escape_text (channel_name, -1);
577 g_string_append (label_markup, ", ");
579 g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
580 escaped, channel_name);
584 w = gtk_label_new (NULL);
585 gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
586 gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
587 g_signal_connect (w, "activate-link",
588 (GCallback) channel_name_activated_cb, information);
589 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
590 w, 1, 2, row, row + 1);
591 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
594 g_string_free (label_markup, TRUE);
598 contact_widget_details_update_show (EmpathyContactWidget *information)
603 GPtrArray *channels = g_ptr_array_new ();
605 contact = empathy_contact_get_tp_contact (information->contact);
606 info = tp_contact_get_contact_info (contact);
607 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
608 for (l = info; l != NULL; l = l->next)
610 TpContactInfoField *field = l->data;
611 InfoFieldData *field_data;
613 gchar *markup = NULL;
616 if (field->field_value == NULL || field->field_value[0] == NULL)
619 value = field->field_value[0];
621 if (!tp_strdiff (field->field_name, "x-irc-channel"))
623 g_ptr_array_add (channels, (gpointer) field->field_value[0]);
627 field_data = find_info_field_data (field->field_name);
628 if (field_data == NULL)
630 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
634 if (field_data->format != NULL)
636 markup = field_data->format (field->field_value);
640 DEBUG ("Invalid value for field '%s' (first element was '%s')",
641 field->field_name, field->field_value[0]);
647 w = gtk_label_new (_(field_data->title));
648 gtk_table_attach (GTK_TABLE (information->table_details),
649 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
650 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
654 w = gtk_label_new (value);
657 gtk_label_set_markup (GTK_LABEL (w), markup);
661 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
662 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
664 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
665 w, 1, 2, n_rows, n_rows + 1);
666 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
673 if (channels->len > 0)
675 add_channel_list (information, channels, n_rows);
679 g_ptr_array_unref (channels);
684 contact_widget_details_notify_cb (EmpathyContactWidget *information)
688 gtk_container_foreach (GTK_CONTAINER (information->table_details),
689 (GtkCallback) gtk_widget_destroy, NULL);
691 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
692 n_rows = contact_widget_details_update_edit (information);
694 n_rows = contact_widget_details_update_show (information);
698 gtk_widget_show (information->vbox_details);
699 gtk_widget_show (information->table_details);
703 gtk_widget_hide (information->vbox_details);
706 gtk_widget_hide (information->hbox_details_requested);
707 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
711 contact_widget_details_request_cb (GObject *object,
715 TpContact *contact = TP_CONTACT (object);
716 EmpathyContactWidget *information = user_data;
717 GError *error = NULL;
719 if (!tp_contact_request_contact_info_finish (contact, res, &error))
721 /* If the request got cancelled it could mean the contact widget is
722 * destroyed, so we should not dereference information */
723 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
725 g_clear_error (&error);
729 gtk_widget_hide (information->vbox_details);
730 g_clear_error (&error);
734 contact_widget_details_notify_cb (information);
737 /* If we are going to edit ContactInfo, we don't want live updates */
738 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
740 g_signal_connect_swapped (contact, "notify::contact-info",
741 G_CALLBACK (contact_widget_details_notify_cb), information);
744 tp_clear_object (&information->details_cancellable);
748 contact_widget_details_feature_prepared_cb (GObject *object,
752 TpConnection *connection = TP_CONNECTION (object);
753 EmpathyContactWidget *information = user_data;
755 TpContactInfoFlags flags;
757 if (!tp_proxy_prepare_finish (connection, res, NULL))
759 gtk_widget_hide (information->vbox_details);
763 /* If we want to edit info, but connection does not support that, stop */
764 flags = tp_connection_get_contact_info_flags (connection);
765 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
766 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
768 gtk_widget_hide (information->vbox_details);
772 /* Request the contact's info */
773 gtk_widget_show (information->vbox_details);
774 gtk_widget_show (information->hbox_details_requested);
775 gtk_widget_hide (information->table_details);
776 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
778 contact = empathy_contact_get_tp_contact (information->contact);
779 g_assert (information->details_cancellable == NULL);
780 information->details_cancellable = g_cancellable_new ();
781 tp_contact_request_contact_info_async (contact,
782 information->details_cancellable, contact_widget_details_request_cb,
787 contact_widget_details_update (EmpathyContactWidget *information)
789 TpContact *tp_contact = NULL;
791 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
792 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
795 gtk_widget_hide (information->vbox_details);
797 if (information->contact != NULL)
798 tp_contact = empathy_contact_get_tp_contact (information->contact);
800 if (tp_contact != NULL)
802 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
803 TpConnection *connection;
805 /* First, make sure the CONTACT_INFO feature is ready on the connection */
806 connection = tp_contact_get_connection (tp_contact);
807 tp_proxy_prepare_async (connection, features,
808 contact_widget_details_feature_prepared_cb, information);
813 contact_widget_client_update (EmpathyContactWidget *information)
815 /* FIXME: Needs new telepathy spec */
819 contact_widget_client_setup (EmpathyContactWidget *information)
821 /* FIXME: Needs new telepathy spec */
822 gtk_widget_hide (information->vbox_client);
826 contact_widget_groups_update (EmpathyContactWidget *information)
828 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
829 information->contact != NULL)
831 FolksPersona *persona =
832 empathy_contact_get_persona (information->contact);
834 if (FOLKS_IS_GROUP_DETAILS (persona))
836 empathy_groups_widget_set_group_details (
837 EMPATHY_GROUPS_WIDGET (information->groups_widget),
838 FOLKS_GROUP_DETAILS (persona));
839 gtk_widget_show (information->groups_widget);
845 /* In case of failure */
846 gtk_widget_hide (information->groups_widget);
849 /* Converts the Location's GHashTable's key to a user readable string */
851 location_key_to_label (const gchar *key)
853 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
854 return _("Country ISO Code:");
855 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
856 return _("Country:");
857 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
859 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
861 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
863 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
864 return _("Postal Code:");
865 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
867 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
868 return _("Building:");
869 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
871 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
873 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
875 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
876 return _("Description:");
877 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
879 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
880 return _("Accuracy Level:");
881 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
883 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
884 return _("Vertical Error (meters):");
885 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
886 return _("Horizontal Error (meters):");
887 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
889 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
890 return _("Bearing:");
891 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
892 return _("Climb Speed:");
893 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
894 return _("Last Updated on:");
895 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
896 return _("Longitude:");
897 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
898 return _("Latitude:");
899 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
900 return _("Altitude:");
903 DEBUG ("Unexpected Location key: %s", key);
909 contact_widget_location_update (EmpathyContactWidget *information)
911 GHashTable *location;
913 #ifdef HAVE_LIBCHAMPLAIN
914 gdouble lat = 0.0, lon = 0.0;
915 gboolean has_position = TRUE;
919 static const gchar* ordered_geolocation_keys[] = {
920 EMPATHY_LOCATION_TEXT,
921 EMPATHY_LOCATION_URI,
922 EMPATHY_LOCATION_DESCRIPTION,
923 EMPATHY_LOCATION_BUILDING,
924 EMPATHY_LOCATION_FLOOR,
925 EMPATHY_LOCATION_ROOM,
926 EMPATHY_LOCATION_STREET,
927 EMPATHY_LOCATION_AREA,
928 EMPATHY_LOCATION_LOCALITY,
929 EMPATHY_LOCATION_REGION,
930 EMPATHY_LOCATION_COUNTRY,
935 gboolean display_map = FALSE;
937 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
939 gtk_widget_hide (information->vbox_location);
943 location = empathy_contact_get_location (information->contact);
944 if (location == NULL || g_hash_table_size (location) == 0)
946 gtk_widget_hide (information->vbox_location);
950 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
953 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
954 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
964 stamp = g_value_get_int64 (value);
966 user_date = empathy_time_to_string_relative (stamp);
968 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
969 /* translators: format is "Location, $date" */
970 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
972 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
978 /* Prepare the location information table */
979 if (information->table_location != NULL)
981 gtk_widget_destroy (information->table_location);
984 information->table_location = gtk_table_new (1, 2, FALSE);
985 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
986 information->table_location, FALSE, FALSE, 5);
989 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
991 const gchar* user_label;
995 gvalue = g_hash_table_lookup (location, (gpointer) skey);
999 user_label = location_key_to_label (skey);
1001 label = gtk_label_new (user_label);
1002 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1003 gtk_table_attach (GTK_TABLE (information->table_location),
1004 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1005 gtk_widget_show (label);
1007 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1010 dvalue = g_value_get_double (gvalue);
1011 svalue = g_strdup_printf ("%f", dvalue);
1013 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1015 svalue = g_value_dup_string (gvalue);
1017 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1021 time_ = g_value_get_int64 (value);
1022 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1027 label = gtk_label_new (svalue);
1028 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1029 label, 1, 2, row, row + 1);
1030 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1031 gtk_widget_show (label);
1033 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1034 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1041 #ifdef HAVE_LIBCHAMPLAIN
1043 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1045 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1053 /* We can display some fields */
1054 gtk_widget_show (information->table_location);
1056 else if (!display_map)
1058 /* Can't display either fields or map */
1059 gtk_widget_hide (information->vbox_location);
1063 #ifdef HAVE_LIBCHAMPLAIN
1066 ClutterActor *marker;
1067 ChamplainMarkerLayer *layer;
1069 information->map_view_embed = gtk_champlain_embed_new ();
1070 information->map_view = gtk_champlain_embed_get_view (
1071 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1073 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1074 information->map_view_embed);
1075 g_object_set (G_OBJECT (information->map_view),
1076 "kinetic-mode", TRUE,
1080 layer = champlain_marker_layer_new ();
1081 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
1083 marker = champlain_label_new_with_text (
1084 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
1085 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
1086 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
1088 champlain_view_center_on (information->map_view, lat, lon);
1089 gtk_widget_show_all (information->viewport_map);
1093 gtk_widget_show (information->vbox_location);
1097 save_avatar_menu_activate_cb (GtkWidget *widget,
1098 EmpathyContactWidget *information)
1101 EmpathyAvatar *avatar;
1102 gchar *ext = NULL, *filename;
1104 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1106 GTK_FILE_CHOOSER_ACTION_SAVE,
1107 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1108 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1111 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1114 /* look for the avatar extension */
1115 avatar = empathy_contact_get_avatar (information->contact);
1116 if (avatar->format != NULL)
1120 splitted = g_strsplit (avatar->format, "/", 2);
1121 if (splitted[0] != NULL && splitted[1] != NULL)
1122 ext = g_strdup (splitted[1]);
1124 g_strfreev (splitted);
1128 /* Avatar was loaded from the cache so was converted to PNG */
1129 ext = g_strdup ("png");
1136 id = tp_escape_as_identifier (empathy_contact_get_id (
1137 information->contact));
1139 filename = g_strdup_printf ("%s.%s", id, ext);
1140 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1147 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1149 GError *error = NULL;
1151 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1153 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1156 GtkWidget *error_dialog;
1158 error_dialog = gtk_message_dialog_new (NULL, 0,
1159 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1160 _("Unable to save avatar"));
1162 gtk_message_dialog_format_secondary_text (
1163 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1165 g_signal_connect (error_dialog, "response",
1166 G_CALLBACK (gtk_widget_destroy), NULL);
1168 gtk_window_present (GTK_WINDOW (error_dialog));
1170 g_clear_error (&error);
1176 gtk_widget_destroy (dialog);
1180 popup_avatar_menu (EmpathyContactWidget *information,
1182 GdkEventButton *event)
1184 GtkWidget *menu, *item;
1185 gint button, event_time;
1187 if (information->contact == NULL ||
1188 empathy_contact_get_avatar (information->contact) == NULL)
1191 menu = empathy_context_menu_new (parent);
1193 /* Add "Save as..." entry */
1194 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1195 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1196 gtk_widget_show (item);
1198 g_signal_connect (item, "activate",
1199 G_CALLBACK (save_avatar_menu_activate_cb), information);
1203 button = event->button;
1204 event_time = event->time;
1209 event_time = gtk_get_current_event_time ();
1212 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1213 button, event_time);
1217 widget_avatar_popup_menu_cb (GtkWidget *widget,
1218 EmpathyContactWidget *information)
1220 popup_avatar_menu (information, widget, NULL);
1226 widget_avatar_button_press_event_cb (GtkWidget *widget,
1227 GdkEventButton *event,
1228 EmpathyContactWidget *information)
1230 /* Ignore double-clicks and triple-clicks */
1231 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1233 popup_avatar_menu (information, widget, event);
1241 set_avatar_cb (GObject *source,
1245 GError *error = NULL;
1247 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1248 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1249 g_error_free (error);
1254 set_avatar_on_account (TpAccount *account,
1257 const gchar *mime_type)
1259 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1260 tp_proxy_get_object_path (account));
1262 tp_account_set_avatar_async (account, (const guchar *) data, size,
1263 mime_type, set_avatar_cb, NULL);
1267 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1268 EmpathyContactWidget *information)
1272 const gchar *mime_type;
1275 empathy_avatar_chooser_get_image_data (
1276 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1277 &data, &size, &mime_type);
1279 account = empathy_contact_get_account (information->contact);
1280 set_avatar_on_account (account, data, size, mime_type);
1284 set_nickname_cb (GObject *source,
1288 GError *error = NULL;
1290 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1292 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1293 g_error_free (error);
1297 /* Update all the contact info fields having the
1298 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1299 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1302 update_nickname_in_contact_info (EmpathyContactWidget *self,
1303 TpConnection *connection,
1304 const gchar *nickname)
1308 specs = tp_connection_get_contact_info_supported_fields (connection);
1310 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1312 TpContactInfoField *field = l->data;
1313 TpContactInfoFieldSpec *spec;
1315 spec = get_spec_from_list (specs, field->field_name);
1316 /* We shouldn't have added the field to details_to_set if it's not
1317 * supported by the CM */
1318 g_assert (spec != NULL);
1320 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1322 const gchar *strv[] = { nickname, NULL };
1324 DEBUG ("Updating field '%s' to '%s' as it has the "
1325 "Overwritten_By_Nickname flag and Account.Nickname has "
1326 "been updated", field->field_name, nickname);
1328 if (field->field_value != NULL)
1329 g_strfreev (field->field_value);
1330 field->field_value = g_strdupv ((GStrv) strv);
1334 g_list_free (specs);
1338 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1339 GdkEventFocus *event,
1340 EmpathyContactWidget *information)
1342 if (information->contact)
1346 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1348 if (empathy_contact_is_user (information->contact))
1350 TpAccount * account;
1351 const gchar *current_nickname;
1353 account = empathy_contact_get_account (information->contact);
1354 current_nickname = tp_account_get_nickname (account);
1356 if (tp_strdiff (current_nickname, alias))
1358 DEBUG ("Set Account.Nickname to %s", alias);
1360 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1363 update_nickname_in_contact_info (information,
1364 empathy_contact_get_connection (information->contact), alias);
1369 empathy_contact_set_alias (information->contact, alias);
1377 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1378 EmpathyAvatarChooser *avatar_chooser)
1382 account = empathy_account_chooser_get_account (account_chooser);
1383 if (account == NULL)
1386 empathy_avatar_chooser_set_account (avatar_chooser, account);
1390 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1392 EmpathyAvatar *avatar = NULL;
1394 if (information->contact)
1395 avatar = empathy_contact_get_avatar (information->contact);
1397 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1399 g_signal_handlers_block_by_func (information->widget_avatar,
1400 contact_widget_avatar_changed_cb,
1402 empathy_avatar_chooser_set (
1403 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1404 g_signal_handlers_unblock_by_func (information->widget_avatar,
1405 contact_widget_avatar_changed_cb, information);
1408 empathy_avatar_image_set (
1409 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1413 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1415 if (GTK_IS_ENTRY (information->widget_alias))
1416 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1417 empathy_contact_get_alias (information->contact));
1419 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1420 empathy_contact_get_alias (information->contact));
1424 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1426 const gchar *status;
1427 gchar *markup_text = NULL;
1429 status = empathy_contact_get_status (information->contact);
1431 markup_text = empathy_add_link_markup (status);
1432 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1433 g_free (markup_text);
1435 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1436 empathy_icon_name_for_contact (information->contact),
1437 GTK_ICON_SIZE_BUTTON);
1438 gtk_widget_show (information->image_state);
1442 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1443 EmpathyContact *contact,
1444 gboolean is_favourite,
1445 EmpathyContactWidget *information)
1447 if (contact != information->contact)
1450 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1451 information->favourite_checkbox), is_favourite);
1455 contact_widget_remove_contact (EmpathyContactWidget *information)
1457 if (information->contact)
1459 TpContact *tp_contact;
1461 contact_widget_save (information);
1463 g_signal_handlers_disconnect_by_func (information->contact,
1464 contact_widget_name_notify_cb, information);
1465 g_signal_handlers_disconnect_by_func (information->contact,
1466 contact_widget_presence_notify_cb, information);
1467 g_signal_handlers_disconnect_by_func (information->contact,
1468 contact_widget_avatar_notify_cb, information);
1470 tp_contact = empathy_contact_get_tp_contact (information->contact);
1471 if (tp_contact != NULL)
1473 g_signal_handlers_disconnect_by_func (tp_contact,
1474 contact_widget_details_notify_cb, information);
1477 g_object_unref (information->contact);
1478 information->contact = NULL;
1481 if (information->details_cancellable != NULL)
1483 g_cancellable_cancel (information->details_cancellable);
1484 tp_clear_object (&information->details_cancellable);
1488 static void contact_widget_change_contact (EmpathyContactWidget *information);
1491 contact_widget_contact_update (EmpathyContactWidget *information)
1493 TpAccount *account = NULL;
1494 const gchar *id = NULL;
1496 /* Connect and get info from new contact */
1497 if (information->contact)
1499 g_signal_connect_swapped (information->contact, "notify::name",
1500 G_CALLBACK (contact_widget_name_notify_cb), information);
1501 g_signal_connect_swapped (information->contact, "notify::presence",
1502 G_CALLBACK (contact_widget_presence_notify_cb), information);
1503 g_signal_connect_swapped (information->contact,
1504 "notify::presence-message",
1505 G_CALLBACK (contact_widget_presence_notify_cb), information);
1506 g_signal_connect_swapped (information->contact, "notify::avatar",
1507 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1509 account = empathy_contact_get_account (information->contact);
1510 id = empathy_contact_get_id (information->contact);
1513 /* Update account widget */
1514 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1518 g_signal_handlers_block_by_func (information->widget_account,
1519 contact_widget_change_contact,
1521 empathy_account_chooser_set_account (
1522 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1523 g_signal_handlers_unblock_by_func (information->widget_account,
1524 contact_widget_change_contact, information);
1533 name = tp_account_get_display_name (account);
1534 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1536 name = tp_account_get_icon_name (account);
1537 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1538 name, GTK_ICON_SIZE_MENU);
1542 /* Update id widget */
1543 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1544 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1546 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1548 /* Update other widgets */
1549 if (information->contact)
1551 contact_widget_name_notify_cb (information);
1552 contact_widget_presence_notify_cb (information);
1553 contact_widget_avatar_notify_cb (information);
1555 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1557 FolksPersona *persona = empathy_contact_get_persona (
1558 information->contact);
1560 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1562 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1563 FOLKS_FAVOURITE_DETAILS (persona));
1564 contact_widget_favourites_changed_cb (information->manager,
1565 information->contact, is_favourite, information);
1569 gtk_widget_show (information->label_alias);
1570 gtk_widget_show (information->widget_alias);
1571 gtk_widget_show (information->hbox_presence);
1572 gtk_widget_show (information->widget_avatar);
1576 gtk_widget_hide (information->label_alias);
1577 gtk_widget_hide (information->widget_alias);
1578 gtk_widget_hide (information->hbox_presence);
1579 gtk_widget_hide (information->widget_avatar);
1584 contact_widget_set_contact (EmpathyContactWidget *information,
1585 EmpathyContact *contact)
1587 if (contact == information->contact)
1590 contact_widget_remove_contact (information);
1592 information->contact = g_object_ref (contact);
1594 /* set the selected account to be the account this contact came from */
1595 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1596 empathy_account_chooser_set_account (
1597 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1598 empathy_contact_get_account (contact));
1601 /* Update information for widgets */
1602 contact_widget_contact_update (information);
1603 contact_widget_groups_update (information);
1604 contact_widget_details_update (information);
1605 contact_widget_client_update (information);
1606 contact_widget_location_update (information);
1610 contact_widget_got_contact_cb (TpConnection *connection,
1611 EmpathyContact *contact,
1612 const GError *error,
1614 GObject *weak_object)
1616 EmpathyContactWidget *information = user_data;
1620 DEBUG ("Error: %s", error->message);
1624 contact_widget_set_contact (information, contact);
1628 contact_widget_change_contact (EmpathyContactWidget *information)
1630 TpConnection *connection;
1632 connection = empathy_account_chooser_get_connection (
1633 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1637 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1641 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1642 if (!EMP_STR_EMPTY (id))
1644 empathy_tp_contact_factory_get_from_id (connection, id,
1645 contact_widget_got_contact_cb, information, NULL,
1646 G_OBJECT (information->vbox_contact_widget));
1651 empathy_tp_contact_factory_get_from_handle (connection,
1652 tp_connection_get_self_handle (connection),
1653 contact_widget_got_contact_cb, information, NULL,
1654 G_OBJECT (information->vbox_contact_widget));
1659 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1661 contact_widget_change_contact (self);
1666 contact_widget_id_changed_cb (GtkEntry *entry,
1667 EmpathyContactWidget *self)
1669 if (self->widget_id_timeout != 0)
1671 g_source_remove (self->widget_id_timeout);
1674 self->widget_id_timeout =
1675 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1676 (GSourceFunc) contact_widget_id_activate_timeout, self);
1680 contact_widget_id_focus_out_cb (GtkWidget *widget,
1681 GdkEventFocus *event,
1682 EmpathyContactWidget *information)
1684 contact_widget_change_contact (information);
1689 favourite_toggled_cb (GtkToggleButton *button,
1690 EmpathyContactWidget *information)
1692 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1694 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1696 gboolean active = gtk_toggle_button_get_active (button);
1697 folks_favourite_details_set_is_favourite (
1698 FOLKS_FAVOURITE_DETAILS (persona), active);
1703 contact_widget_contact_setup (EmpathyContactWidget *information)
1705 information->label_status = gtk_label_new ("");
1706 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1707 PANGO_WRAP_WORD_CHAR);
1708 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1711 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1712 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1714 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1715 information->label_status, TRUE, TRUE, 0);
1716 gtk_widget_show (information->label_status);
1718 /* Setup account label/chooser */
1719 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1721 information->widget_account = empathy_account_chooser_new ();
1723 g_signal_connect_swapped (information->widget_account, "changed",
1724 G_CALLBACK (contact_widget_change_contact),
1729 /* Pack the protocol icon with the account name in an hbox */
1730 information->widget_account = gtk_hbox_new (FALSE, 6);
1732 information->label_account = gtk_label_new (NULL);
1733 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1734 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1736 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1737 gtk_widget_show (information->label_account);
1739 information->image_account = gtk_image_new ();
1740 gtk_widget_show (information->image_account);
1742 gtk_box_pack_start (GTK_BOX (information->widget_account),
1743 information->image_account, FALSE, FALSE, 0);
1744 gtk_box_pack_start (GTK_BOX (information->widget_account),
1745 information->label_account, FALSE, TRUE, 0);
1747 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1748 information->widget_account,
1750 gtk_widget_show (information->widget_account);
1752 /* Set up avatar chooser/display */
1753 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1755 information->widget_avatar = empathy_avatar_chooser_new ();
1756 g_signal_connect (information->widget_avatar, "changed",
1757 G_CALLBACK (contact_widget_avatar_changed_cb),
1759 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1761 g_signal_connect (information->widget_account, "changed",
1762 G_CALLBACK (update_avatar_chooser_account_cb),
1763 information->widget_avatar);
1764 update_avatar_chooser_account_cb (
1765 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1766 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1771 information->widget_avatar = empathy_avatar_image_new ();
1773 g_signal_connect (information->widget_avatar, "popup-menu",
1774 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1775 g_signal_connect (information->widget_avatar, "button-press-event",
1776 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1779 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1780 information->widget_avatar,
1783 gtk_widget_show (information->widget_avatar);
1785 /* Setup id label/entry */
1786 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1788 information->widget_id = gtk_entry_new ();
1789 g_signal_connect (information->widget_id, "focus-out-event",
1790 G_CALLBACK (contact_widget_id_focus_out_cb),
1792 g_signal_connect (information->widget_id, "changed",
1793 G_CALLBACK (contact_widget_id_changed_cb),
1798 information->widget_id = gtk_label_new (NULL);
1799 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1800 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1802 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1804 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1805 information->widget_id,
1807 gtk_widget_show (information->widget_id);
1809 /* Setup alias label/entry */
1810 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1812 information->widget_alias = gtk_entry_new ();
1814 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1815 g_signal_connect (information->widget_alias, "focus-out-event",
1816 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1819 /* Make return activate the window default (the Close button) */
1820 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1825 information->widget_alias = gtk_label_new (NULL);
1826 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1827 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1829 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1831 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1832 information->widget_alias,
1834 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1835 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1837 gtk_widget_show (information->widget_alias);
1840 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1842 information->favourite_checkbox = gtk_check_button_new_with_label (
1845 g_signal_connect (information->favourite_checkbox, "toggled",
1846 G_CALLBACK (favourite_toggled_cb), information);
1848 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1849 information->favourite_checkbox, 0, 2, 3, 4);
1851 information->fav_sig_id = g_signal_connect (information->manager,
1852 "favourites-changed",
1853 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1855 gtk_widget_show (information->favourite_checkbox);
1860 contact_widget_destroy_cb (GtkWidget *widget,
1861 EmpathyContactWidget *information)
1863 contact_widget_remove_contact (information);
1865 if (information->widget_id_timeout != 0)
1867 g_source_remove (information->widget_id_timeout);
1870 if (information->fav_sig_id != 0)
1871 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1873 g_object_unref (information->manager);
1875 g_slice_free (EmpathyContactWidget, information);
1879 * empathy_contact_widget_new:
1880 * @contact: an #EmpathyContact
1881 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1883 * Creates a new #EmpathyContactWidget.
1885 * Return value: a new #EmpathyContactWidget
1888 empathy_contact_widget_new (EmpathyContact *contact,
1889 EmpathyContactWidgetFlags flags)
1891 EmpathyContactWidget *information;
1895 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1897 information = g_slice_new0 (EmpathyContactWidget);
1898 information->flags = flags;
1900 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1902 gui = empathy_builder_get_file (filename,
1903 "vbox_contact_widget", &information->vbox_contact_widget,
1904 "hbox_contact", &information->hbox_contact,
1905 "hbox_presence", &information->hbox_presence,
1906 "label_alias", &information->label_alias,
1907 "image_state", &information->image_state,
1908 "table_contact", &information->table_contact,
1909 "vbox_avatar", &information->vbox_avatar,
1910 "vbox_location", &information->vbox_location,
1911 "subvbox_location", &information->subvbox_location,
1912 "label_location", &information->label_location,
1913 #ifdef HAVE_LIBCHAMPLAIN
1914 "viewport_map", &information->viewport_map,
1916 "groups_widget", &information->groups_widget,
1917 "vbox_details", &information->vbox_details,
1918 "table_details", &information->table_details,
1919 "hbox_details_requested", &information->hbox_details_requested,
1920 "vbox_client", &information->vbox_client,
1921 "table_client", &information->table_client,
1922 "hbox_client_requested", &information->hbox_client_requested,
1926 empathy_builder_connect (gui, information,
1927 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1929 information->table_location = NULL;
1931 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1932 "EmpathyContactWidget",
1935 information->manager = empathy_contact_manager_dup_singleton ();
1937 /* Create widgets */
1938 contact_widget_contact_setup (information);
1939 contact_widget_details_setup (information);
1940 contact_widget_client_setup (information);
1942 if (contact != NULL)
1943 contact_widget_set_contact (information, contact);
1944 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1945 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1946 contact_widget_change_contact (information);
1948 return empathy_builder_unref_and_keep_widget (gui,
1949 information->vbox_contact_widget);
1953 * empathy_contact_widget_get_contact:
1954 * @widget: an #EmpathyContactWidget
1956 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1958 * Returns: the #EmpathyContact associated with @widget
1961 empathy_contact_widget_get_contact (GtkWidget *widget)
1963 EmpathyContactWidget *information;
1965 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1967 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1971 return information->contact;
1975 empathy_contact_widget_get_alias (GtkWidget *widget)
1977 EmpathyContactWidget *information;
1979 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1981 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1985 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1989 * empathy_contact_widget_set_contact:
1990 * @widget: an #EmpathyContactWidget
1991 * @contact: a different #EmpathyContact
1993 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1996 empathy_contact_widget_set_contact (GtkWidget *widget,
1997 EmpathyContact *contact)
1999 EmpathyContactWidget *information;
2001 g_return_if_fail (GTK_IS_WIDGET (widget));
2002 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
2004 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2008 contact_widget_set_contact (information, contact);
2012 * empathy_contact_widget_set_account_filter:
2013 * @widget: an #EmpathyContactWidget
2014 * @filter: a #EmpathyAccountChooserFilterFunc
2015 * @user_data: user data to pass to @filter, or %NULL
2017 * Set a filter on the #EmpathyAccountChooser included in the
2018 * #EmpathyContactWidget.
2021 empathy_contact_widget_set_account_filter (
2023 EmpathyAccountChooserFilterFunc filter,
2026 EmpathyContactWidget *information;
2027 EmpathyAccountChooser *chooser;
2029 g_return_if_fail (GTK_IS_WIDGET (widget));
2031 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2035 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2037 empathy_account_chooser_set_filter (chooser, filter, user_data);