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);
288 const gchar *field_name;
293 static InfoFieldData info_field_datas[] =
295 { "fn", N_("Full name:"), FALSE },
296 { "tel", N_("Phone number:"), FALSE },
297 { "email", N_("E-mail address:"), TRUE },
298 { "url", N_("Website:"), TRUE },
299 { "bday", N_("Birthday:"), FALSE },
303 static InfoFieldData *
304 find_info_field_data (const gchar *field_name)
308 for (i = 0; info_field_datas[i].field_name != NULL; i++)
310 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
311 return info_field_datas + i;
317 contact_info_field_name_cmp (const gchar *name1,
322 if (!tp_strdiff (name1, name2))
325 /* We use the order of info_field_datas */
326 for (i = 0; info_field_datas[i].field_name != NULL; i++)
328 if (!tp_strdiff (info_field_datas[i].field_name, name1))
330 if (!tp_strdiff (info_field_datas[i].field_name, name2))
334 return g_strcmp0 (name1, name2);
338 contact_info_field_cmp (TpContactInfoField *field1,
339 TpContactInfoField *field2)
341 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
345 field_name_in_field_list (GList *list,
350 for (l = list; l != NULL; l = g_list_next (l))
352 TpContactInfoField *field = l->data;
354 if (!tp_strdiff (field->field_name, name))
361 static TpContactInfoFieldSpec *
362 get_spec_from_list (GList *list,
367 for (l = list; l != NULL; l = g_list_next (l))
369 TpContactInfoFieldSpec *spec = l->data;
371 if (!tp_strdiff (spec->name, name))
379 contact_widget_details_update_edit (EmpathyContactWidget *information)
382 TpConnection *connection;
388 g_assert (information->details_to_set == NULL);
390 information->details_changed = FALSE;
392 contact = empathy_contact_get_tp_contact (information->contact);
393 connection = tp_contact_get_connection (contact);
395 info = tp_contact_get_contact_info (contact);
397 specs = tp_connection_get_contact_info_supported_fields (connection);
399 /* Look at the fields set in our vCard */
400 for (l = info; l != NULL; l = l->next)
402 TpContactInfoField *field = l->data;
404 /* make a copy for the details_to_set list */
405 field = tp_contact_info_field_copy (field);
406 DEBUG ("Field %s is in our vCard", field->field_name);
408 information->details_to_set = g_list_prepend (information->details_to_set,
412 /* Add fields which are supported but not in the vCard */
413 for (i = 0; info_field_datas[i].field_name != NULL; i++)
415 TpContactInfoFieldSpec *spec;
416 TpContactInfoField *field;
418 /* Check if the field was in the vCard */
419 if (field_name_in_field_list (information->details_to_set,
420 info_field_datas[i].field_name))
423 /* Check if the CM supports the field */
424 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
428 /* add an empty field so user can set a value */
429 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
431 information->details_to_set = g_list_prepend (information->details_to_set,
435 /* Add widgets for supported fields */
436 information->details_to_set = g_list_sort (information->details_to_set,
437 (GCompareFunc) contact_info_field_cmp);
439 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
441 TpContactInfoField *field = l->data;
442 InfoFieldData *field_data;
444 TpContactInfoFieldSpec *spec;
446 field_data = find_info_field_data (field->field_name);
447 if (field_data == NULL)
449 /* Empathy doesn't display this field so we can't change it.
450 * But we put it in the details_to_set list so it won't be erased
451 * when calling SetContactInfo (bgo #630427) */
452 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
456 spec = get_spec_from_list (specs, field->field_name);
457 /* We shouldn't have added the field to details_to_set if it's not
458 * supported by the CM */
459 g_assert (spec != NULL);
461 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
463 DEBUG ("Ignoring field '%s' due it to having the "
464 "Overwritten_By_Nickname flag", field->field_name);
469 w = gtk_label_new (_(field_data->title));
470 gtk_table_attach (GTK_TABLE (information->table_details),
471 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
472 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
476 if (!tp_strdiff (field->field_name, "bday"))
478 w = gtk_calendar_new ();
479 if (field->field_value[0])
483 g_date_set_parse (&date, field->field_value[0]);
484 if (g_date_valid (&date))
486 gtk_calendar_select_day (GTK_CALENDAR (w),
487 g_date_get_day (&date));
488 gtk_calendar_select_month (GTK_CALENDAR (w),
489 g_date_get_month (&date) - 1, g_date_get_year (&date));
490 gtk_calendar_mark_day (GTK_CALENDAR (w),
491 g_date_get_day (&date));
494 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
495 w, 1, 2, n_rows, n_rows + 1);
498 g_object_set_data ((GObject *) w, DATA_FIELD, field);
500 g_signal_connect (w, "day-selected-double-click",
501 G_CALLBACK (contact_widget_bday_changed_cb), information);
502 g_signal_connect (w, "month-changed",
503 G_CALLBACK (contact_widget_bday_changed_cb), information);
507 w = gtk_entry_new ();
508 gtk_entry_set_text (GTK_ENTRY (w),
509 field->field_value[0] ? field->field_value[0] : "");
510 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
511 w, 1, 2, n_rows, n_rows + 1);
514 g_object_set_data ((GObject *) w, DATA_FIELD, field);
516 g_signal_connect (w, "changed",
517 G_CALLBACK (contact_widget_details_changed_cb), information);
530 contact_widget_details_update_show (EmpathyContactWidget *information)
536 contact = empathy_contact_get_tp_contact (information->contact);
537 info = tp_contact_get_contact_info (contact);
538 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
539 for (l = info; l != NULL; l = l->next)
541 TpContactInfoField *field = l->data;
542 InfoFieldData *field_data;
546 if (field->field_value == NULL || field->field_value[0] == NULL)
549 value = field->field_value[0];
551 field_data = find_info_field_data (field->field_name);
552 if (field_data == NULL)
554 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
559 w = gtk_label_new (_(field_data->title));
560 gtk_table_attach (GTK_TABLE (information->table_details),
561 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
562 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
566 w = gtk_label_new (value);
567 if (field_data->linkify)
571 markup = empathy_add_link_markup (value);
572 gtk_label_set_markup (GTK_LABEL (w), markup);
576 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
577 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
579 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
580 w, 1, 2, n_rows, n_rows + 1);
581 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
592 contact_widget_details_notify_cb (EmpathyContactWidget *information)
596 gtk_container_foreach (GTK_CONTAINER (information->table_details),
597 (GtkCallback) gtk_widget_destroy, NULL);
599 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
600 n_rows = contact_widget_details_update_edit (information);
602 n_rows = contact_widget_details_update_show (information);
606 gtk_widget_show (information->vbox_details);
607 gtk_widget_show (information->table_details);
611 gtk_widget_hide (information->vbox_details);
614 gtk_widget_hide (information->hbox_details_requested);
615 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
619 contact_widget_details_request_cb (GObject *object,
623 TpContact *contact = TP_CONTACT (object);
624 EmpathyContactWidget *information = user_data;
625 GError *error = NULL;
627 if (!tp_contact_request_contact_info_finish (contact, res, &error))
629 /* If the request got cancelled it could mean the contact widget is
630 * destroyed, so we should not dereference information */
631 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
633 g_clear_error (&error);
637 gtk_widget_hide (information->vbox_details);
638 g_clear_error (&error);
642 contact_widget_details_notify_cb (information);
645 /* If we are going to edit ContactInfo, we don't want live updates */
646 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
648 g_signal_connect_swapped (contact, "notify::contact-info",
649 G_CALLBACK (contact_widget_details_notify_cb), information);
652 tp_clear_object (&information->details_cancellable);
656 contact_widget_details_feature_prepared_cb (GObject *object,
660 TpConnection *connection = TP_CONNECTION (object);
661 EmpathyContactWidget *information = user_data;
663 TpContactInfoFlags flags;
665 if (!tp_proxy_prepare_finish (connection, res, NULL))
667 gtk_widget_hide (information->vbox_details);
671 /* If we want to edit info, but connection does not support that, stop */
672 flags = tp_connection_get_contact_info_flags (connection);
673 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
674 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
676 gtk_widget_hide (information->vbox_details);
680 /* Request the contact's info */
681 gtk_widget_show (information->vbox_details);
682 gtk_widget_show (information->hbox_details_requested);
683 gtk_widget_hide (information->table_details);
684 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
686 contact = empathy_contact_get_tp_contact (information->contact);
687 g_assert (information->details_cancellable == NULL);
688 information->details_cancellable = g_cancellable_new ();
689 tp_contact_request_contact_info_async (contact,
690 information->details_cancellable, contact_widget_details_request_cb,
695 contact_widget_details_update (EmpathyContactWidget *information)
697 TpContact *tp_contact = NULL;
699 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
700 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
703 gtk_widget_hide (information->vbox_details);
705 if (information->contact != NULL)
706 tp_contact = empathy_contact_get_tp_contact (information->contact);
708 if (tp_contact != NULL)
710 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
711 TpConnection *connection;
713 /* First, make sure the CONTACT_INFO feature is ready on the connection */
714 connection = tp_contact_get_connection (tp_contact);
715 tp_proxy_prepare_async (connection, features,
716 contact_widget_details_feature_prepared_cb, information);
721 contact_widget_client_update (EmpathyContactWidget *information)
723 /* FIXME: Needs new telepathy spec */
727 contact_widget_client_setup (EmpathyContactWidget *information)
729 /* FIXME: Needs new telepathy spec */
730 gtk_widget_hide (information->vbox_client);
734 contact_widget_groups_update (EmpathyContactWidget *information)
736 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
737 information->contact != NULL)
739 FolksPersona *persona =
740 empathy_contact_get_persona (information->contact);
742 if (FOLKS_IS_GROUP_DETAILS (persona))
744 empathy_groups_widget_set_group_details (
745 EMPATHY_GROUPS_WIDGET (information->groups_widget),
746 FOLKS_GROUP_DETAILS (persona));
747 gtk_widget_show (information->groups_widget);
753 /* In case of failure */
754 gtk_widget_hide (information->groups_widget);
757 /* Converts the Location's GHashTable's key to a user readable string */
759 location_key_to_label (const gchar *key)
761 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
762 return _("Country ISO Code:");
763 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
764 return _("Country:");
765 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
767 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
769 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
771 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
772 return _("Postal Code:");
773 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
775 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
776 return _("Building:");
777 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
779 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
781 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
783 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
784 return _("Description:");
785 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
787 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
788 return _("Accuracy Level:");
789 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
791 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
792 return _("Vertical Error (meters):");
793 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
794 return _("Horizontal Error (meters):");
795 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
797 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
798 return _("Bearing:");
799 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
800 return _("Climb Speed:");
801 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
802 return _("Last Updated on:");
803 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
804 return _("Longitude:");
805 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
806 return _("Latitude:");
807 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
808 return _("Altitude:");
811 DEBUG ("Unexpected Location key: %s", key);
817 contact_widget_location_update (EmpathyContactWidget *information)
819 GHashTable *location;
821 #ifdef HAVE_LIBCHAMPLAIN
822 gdouble lat = 0.0, lon = 0.0;
823 gboolean has_position = TRUE;
827 static const gchar* ordered_geolocation_keys[] = {
828 EMPATHY_LOCATION_TEXT,
829 EMPATHY_LOCATION_URI,
830 EMPATHY_LOCATION_DESCRIPTION,
831 EMPATHY_LOCATION_BUILDING,
832 EMPATHY_LOCATION_FLOOR,
833 EMPATHY_LOCATION_ROOM,
834 EMPATHY_LOCATION_STREET,
835 EMPATHY_LOCATION_AREA,
836 EMPATHY_LOCATION_LOCALITY,
837 EMPATHY_LOCATION_REGION,
838 EMPATHY_LOCATION_COUNTRY,
843 gboolean display_map = FALSE;
845 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
847 gtk_widget_hide (information->vbox_location);
851 location = empathy_contact_get_location (information->contact);
852 if (location == NULL || g_hash_table_size (location) == 0)
854 gtk_widget_hide (information->vbox_location);
858 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
861 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
862 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
872 stamp = g_value_get_int64 (value);
874 user_date = empathy_time_to_string_relative (stamp);
876 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
877 /* translators: format is "Location, $date" */
878 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
880 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
886 /* Prepare the location information table */
887 if (information->table_location != NULL)
889 gtk_widget_destroy (information->table_location);
892 information->table_location = gtk_table_new (1, 2, FALSE);
893 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
894 information->table_location, FALSE, FALSE, 5);
897 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
899 const gchar* user_label;
903 gvalue = g_hash_table_lookup (location, (gpointer) skey);
907 user_label = location_key_to_label (skey);
909 label = gtk_label_new (user_label);
910 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
911 gtk_table_attach (GTK_TABLE (information->table_location),
912 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
913 gtk_widget_show (label);
915 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
918 dvalue = g_value_get_double (gvalue);
919 svalue = g_strdup_printf ("%f", dvalue);
921 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
923 svalue = g_value_dup_string (gvalue);
925 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
929 time_ = g_value_get_int64 (value);
930 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
935 label = gtk_label_new (svalue);
936 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
937 label, 1, 2, row, row + 1);
938 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
939 gtk_widget_show (label);
941 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
942 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
949 #ifdef HAVE_LIBCHAMPLAIN
951 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
953 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
961 /* We can display some fields */
962 gtk_widget_show (information->table_location);
964 else if (!display_map)
966 /* Can't display either fields or map */
967 gtk_widget_hide (information->vbox_location);
971 #ifdef HAVE_LIBCHAMPLAIN
974 ClutterActor *marker;
975 ChamplainMarkerLayer *layer;
977 information->map_view_embed = gtk_champlain_embed_new ();
978 information->map_view = gtk_champlain_embed_get_view (
979 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
981 gtk_container_add (GTK_CONTAINER (information->viewport_map),
982 information->map_view_embed);
983 g_object_set (G_OBJECT (information->map_view),
984 "kinetic-mode", TRUE,
988 layer = champlain_marker_layer_new ();
989 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
991 marker = champlain_label_new_with_text (
992 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
993 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
994 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
996 champlain_view_center_on (information->map_view, lat, lon);
997 gtk_widget_show_all (information->viewport_map);
1001 gtk_widget_show (information->vbox_location);
1005 save_avatar_menu_activate_cb (GtkWidget *widget,
1006 EmpathyContactWidget *information)
1009 EmpathyAvatar *avatar;
1010 gchar *ext = NULL, *filename;
1012 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1014 GTK_FILE_CHOOSER_ACTION_SAVE,
1015 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1016 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1019 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1022 /* look for the avatar extension */
1023 avatar = empathy_contact_get_avatar (information->contact);
1024 if (avatar->format != NULL)
1028 splitted = g_strsplit (avatar->format, "/", 2);
1029 if (splitted[0] != NULL && splitted[1] != NULL)
1030 ext = g_strdup (splitted[1]);
1032 g_strfreev (splitted);
1036 /* Avatar was loaded from the cache so was converted to PNG */
1037 ext = g_strdup ("png");
1044 id = tp_escape_as_identifier (empathy_contact_get_id (
1045 information->contact));
1047 filename = g_strdup_printf ("%s.%s", id, ext);
1048 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1055 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1057 GError *error = NULL;
1059 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1061 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1064 GtkWidget *error_dialog;
1066 error_dialog = gtk_message_dialog_new (NULL, 0,
1067 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1068 _("Unable to save avatar"));
1070 gtk_message_dialog_format_secondary_text (
1071 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1073 g_signal_connect (error_dialog, "response",
1074 G_CALLBACK (gtk_widget_destroy), NULL);
1076 gtk_window_present (GTK_WINDOW (error_dialog));
1078 g_clear_error (&error);
1084 gtk_widget_destroy (dialog);
1088 popup_avatar_menu (EmpathyContactWidget *information,
1090 GdkEventButton *event)
1092 GtkWidget *menu, *item;
1093 gint button, event_time;
1095 if (information->contact == NULL ||
1096 empathy_contact_get_avatar (information->contact) == NULL)
1099 menu = empathy_context_menu_new (parent);
1101 /* Add "Save as..." entry */
1102 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1103 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1104 gtk_widget_show (item);
1106 g_signal_connect (item, "activate",
1107 G_CALLBACK (save_avatar_menu_activate_cb), information);
1111 button = event->button;
1112 event_time = event->time;
1117 event_time = gtk_get_current_event_time ();
1120 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1121 button, event_time);
1125 widget_avatar_popup_menu_cb (GtkWidget *widget,
1126 EmpathyContactWidget *information)
1128 popup_avatar_menu (information, widget, NULL);
1134 widget_avatar_button_press_event_cb (GtkWidget *widget,
1135 GdkEventButton *event,
1136 EmpathyContactWidget *information)
1138 /* Ignore double-clicks and triple-clicks */
1139 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1141 popup_avatar_menu (information, widget, event);
1149 set_avatar_cb (GObject *source,
1153 GError *error = NULL;
1155 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1156 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1157 g_error_free (error);
1162 set_avatar_on_account (TpAccount *account,
1165 const gchar *mime_type)
1167 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1168 tp_proxy_get_object_path (account));
1170 tp_account_set_avatar_async (account, (const guchar *) data, size,
1171 mime_type, set_avatar_cb, NULL);
1175 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1176 EmpathyContactWidget *information)
1180 const gchar *mime_type;
1183 empathy_avatar_chooser_get_image_data (
1184 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1185 &data, &size, &mime_type);
1187 account = empathy_contact_get_account (information->contact);
1188 set_avatar_on_account (account, data, size, mime_type);
1192 set_nickname_cb (GObject *source,
1196 GError *error = NULL;
1198 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1200 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1201 g_error_free (error);
1205 /* Update all the contact info fields having the
1206 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1207 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1210 update_nickname_in_contact_info (EmpathyContactWidget *self,
1211 TpConnection *connection,
1212 const gchar *nickname)
1216 specs = tp_connection_get_contact_info_supported_fields (connection);
1218 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1220 TpContactInfoField *field = l->data;
1221 TpContactInfoFieldSpec *spec;
1223 spec = get_spec_from_list (specs, field->field_name);
1224 /* We shouldn't have added the field to details_to_set if it's not
1225 * supported by the CM */
1226 g_assert (spec != NULL);
1228 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1230 const gchar *strv[] = { nickname, NULL };
1232 DEBUG ("Updating field '%s' to '%s' as it has the "
1233 "Overwritten_By_Nickname flag and Account.Nickname has "
1234 "been updated", field->field_name, nickname);
1236 if (field->field_value != NULL)
1237 g_strfreev (field->field_value);
1238 field->field_value = g_strdupv ((GStrv) strv);
1242 g_list_free (specs);
1246 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1247 GdkEventFocus *event,
1248 EmpathyContactWidget *information)
1250 if (information->contact)
1254 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1256 if (empathy_contact_is_user (information->contact))
1258 TpAccount * account;
1259 const gchar *current_nickname;
1261 account = empathy_contact_get_account (information->contact);
1262 current_nickname = tp_account_get_nickname (account);
1264 if (tp_strdiff (current_nickname, alias))
1266 DEBUG ("Set Account.Nickname to %s", alias);
1268 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1271 update_nickname_in_contact_info (information,
1272 empathy_contact_get_connection (information->contact), alias);
1277 empathy_contact_set_alias (information->contact, alias);
1285 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1286 EmpathyAvatarChooser *avatar_chooser)
1290 account = empathy_account_chooser_get_account (account_chooser);
1291 if (account == NULL)
1294 empathy_avatar_chooser_set_account (avatar_chooser, account);
1298 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1300 EmpathyAvatar *avatar = NULL;
1302 if (information->contact)
1303 avatar = empathy_contact_get_avatar (information->contact);
1305 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1307 g_signal_handlers_block_by_func (information->widget_avatar,
1308 contact_widget_avatar_changed_cb,
1310 empathy_avatar_chooser_set (
1311 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1312 g_signal_handlers_unblock_by_func (information->widget_avatar,
1313 contact_widget_avatar_changed_cb, information);
1316 empathy_avatar_image_set (
1317 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1321 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1323 if (GTK_IS_ENTRY (information->widget_alias))
1324 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1325 empathy_contact_get_alias (information->contact));
1327 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1328 empathy_contact_get_alias (information->contact));
1332 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1334 const gchar *status;
1335 gchar *markup_text = NULL;
1337 status = empathy_contact_get_status (information->contact);
1339 markup_text = empathy_add_link_markup (status);
1340 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1341 g_free (markup_text);
1343 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1344 empathy_icon_name_for_contact (information->contact),
1345 GTK_ICON_SIZE_BUTTON);
1346 gtk_widget_show (information->image_state);
1350 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1351 EmpathyContact *contact,
1352 gboolean is_favourite,
1353 EmpathyContactWidget *information)
1355 if (contact != information->contact)
1358 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1359 information->favourite_checkbox), is_favourite);
1363 contact_widget_remove_contact (EmpathyContactWidget *information)
1365 if (information->contact)
1367 TpContact *tp_contact;
1369 contact_widget_save (information);
1371 g_signal_handlers_disconnect_by_func (information->contact,
1372 contact_widget_name_notify_cb, information);
1373 g_signal_handlers_disconnect_by_func (information->contact,
1374 contact_widget_presence_notify_cb, information);
1375 g_signal_handlers_disconnect_by_func (information->contact,
1376 contact_widget_avatar_notify_cb, information);
1378 tp_contact = empathy_contact_get_tp_contact (information->contact);
1379 if (tp_contact != NULL)
1381 g_signal_handlers_disconnect_by_func (tp_contact,
1382 contact_widget_details_notify_cb, information);
1385 g_object_unref (information->contact);
1386 information->contact = NULL;
1389 if (information->details_cancellable != NULL)
1391 g_cancellable_cancel (information->details_cancellable);
1392 tp_clear_object (&information->details_cancellable);
1396 static void contact_widget_change_contact (EmpathyContactWidget *information);
1399 contact_widget_contact_update (EmpathyContactWidget *information)
1401 TpAccount *account = NULL;
1402 const gchar *id = NULL;
1404 /* Connect and get info from new contact */
1405 if (information->contact)
1407 g_signal_connect_swapped (information->contact, "notify::name",
1408 G_CALLBACK (contact_widget_name_notify_cb), information);
1409 g_signal_connect_swapped (information->contact, "notify::presence",
1410 G_CALLBACK (contact_widget_presence_notify_cb), information);
1411 g_signal_connect_swapped (information->contact,
1412 "notify::presence-message",
1413 G_CALLBACK (contact_widget_presence_notify_cb), information);
1414 g_signal_connect_swapped (information->contact, "notify::avatar",
1415 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1417 account = empathy_contact_get_account (information->contact);
1418 id = empathy_contact_get_id (information->contact);
1421 /* Update account widget */
1422 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1426 g_signal_handlers_block_by_func (information->widget_account,
1427 contact_widget_change_contact,
1429 empathy_account_chooser_set_account (
1430 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1431 g_signal_handlers_unblock_by_func (information->widget_account,
1432 contact_widget_change_contact, information);
1441 name = tp_account_get_display_name (account);
1442 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1444 name = tp_account_get_icon_name (account);
1445 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1446 name, GTK_ICON_SIZE_MENU);
1450 /* Update id widget */
1451 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1452 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1454 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1456 /* Update other widgets */
1457 if (information->contact)
1459 contact_widget_name_notify_cb (information);
1460 contact_widget_presence_notify_cb (information);
1461 contact_widget_avatar_notify_cb (information);
1463 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1465 FolksPersona *persona = empathy_contact_get_persona (
1466 information->contact);
1468 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1470 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1471 FOLKS_FAVOURITE_DETAILS (persona));
1472 contact_widget_favourites_changed_cb (information->manager,
1473 information->contact, is_favourite, information);
1477 gtk_widget_show (information->label_alias);
1478 gtk_widget_show (information->widget_alias);
1479 gtk_widget_show (information->hbox_presence);
1480 gtk_widget_show (information->widget_avatar);
1484 gtk_widget_hide (information->label_alias);
1485 gtk_widget_hide (information->widget_alias);
1486 gtk_widget_hide (information->hbox_presence);
1487 gtk_widget_hide (information->widget_avatar);
1492 contact_widget_set_contact (EmpathyContactWidget *information,
1493 EmpathyContact *contact)
1495 if (contact == information->contact)
1498 contact_widget_remove_contact (information);
1500 information->contact = g_object_ref (contact);
1502 /* set the selected account to be the account this contact came from */
1503 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1504 empathy_account_chooser_set_account (
1505 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1506 empathy_contact_get_account (contact));
1509 /* Update information for widgets */
1510 contact_widget_contact_update (information);
1511 contact_widget_groups_update (information);
1512 contact_widget_details_update (information);
1513 contact_widget_client_update (information);
1514 contact_widget_location_update (information);
1518 contact_widget_got_contact_cb (TpConnection *connection,
1519 EmpathyContact *contact,
1520 const GError *error,
1522 GObject *weak_object)
1524 EmpathyContactWidget *information = user_data;
1528 DEBUG ("Error: %s", error->message);
1532 contact_widget_set_contact (information, contact);
1536 contact_widget_change_contact (EmpathyContactWidget *information)
1538 TpConnection *connection;
1540 connection = empathy_account_chooser_get_connection (
1541 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1545 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1549 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1550 if (!EMP_STR_EMPTY (id))
1552 empathy_tp_contact_factory_get_from_id (connection, id,
1553 contact_widget_got_contact_cb, information, NULL,
1554 G_OBJECT (information->vbox_contact_widget));
1559 empathy_tp_contact_factory_get_from_handle (connection,
1560 tp_connection_get_self_handle (connection),
1561 contact_widget_got_contact_cb, information, NULL,
1562 G_OBJECT (information->vbox_contact_widget));
1567 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1569 contact_widget_change_contact (self);
1574 contact_widget_id_changed_cb (GtkEntry *entry,
1575 EmpathyContactWidget *self)
1577 if (self->widget_id_timeout != 0)
1579 g_source_remove (self->widget_id_timeout);
1582 self->widget_id_timeout =
1583 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1584 (GSourceFunc) contact_widget_id_activate_timeout, self);
1588 contact_widget_id_focus_out_cb (GtkWidget *widget,
1589 GdkEventFocus *event,
1590 EmpathyContactWidget *information)
1592 contact_widget_change_contact (information);
1597 favourite_toggled_cb (GtkToggleButton *button,
1598 EmpathyContactWidget *information)
1600 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1602 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1604 gboolean active = gtk_toggle_button_get_active (button);
1605 folks_favourite_details_set_is_favourite (
1606 FOLKS_FAVOURITE_DETAILS (persona), active);
1611 contact_widget_contact_setup (EmpathyContactWidget *information)
1613 information->label_status = gtk_label_new ("");
1614 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1615 PANGO_WRAP_WORD_CHAR);
1616 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1619 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1620 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1622 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1623 information->label_status, TRUE, TRUE, 0);
1624 gtk_widget_show (information->label_status);
1626 /* Setup account label/chooser */
1627 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1629 information->widget_account = empathy_account_chooser_new ();
1631 g_signal_connect_swapped (information->widget_account, "changed",
1632 G_CALLBACK (contact_widget_change_contact),
1637 /* Pack the protocol icon with the account name in an hbox */
1638 information->widget_account = gtk_hbox_new (FALSE, 6);
1640 information->label_account = gtk_label_new (NULL);
1641 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1642 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1644 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1645 gtk_widget_show (information->label_account);
1647 information->image_account = gtk_image_new ();
1648 gtk_widget_show (information->image_account);
1650 gtk_box_pack_start (GTK_BOX (information->widget_account),
1651 information->image_account, FALSE, FALSE, 0);
1652 gtk_box_pack_start (GTK_BOX (information->widget_account),
1653 information->label_account, FALSE, TRUE, 0);
1655 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1656 information->widget_account,
1658 gtk_widget_show (information->widget_account);
1660 /* Set up avatar chooser/display */
1661 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1663 information->widget_avatar = empathy_avatar_chooser_new ();
1664 g_signal_connect (information->widget_avatar, "changed",
1665 G_CALLBACK (contact_widget_avatar_changed_cb),
1667 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1669 g_signal_connect (information->widget_account, "changed",
1670 G_CALLBACK (update_avatar_chooser_account_cb),
1671 information->widget_avatar);
1672 update_avatar_chooser_account_cb (
1673 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1674 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1679 information->widget_avatar = empathy_avatar_image_new ();
1681 g_signal_connect (information->widget_avatar, "popup-menu",
1682 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1683 g_signal_connect (information->widget_avatar, "button-press-event",
1684 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1687 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1688 information->widget_avatar,
1691 gtk_widget_show (information->widget_avatar);
1693 /* Setup id label/entry */
1694 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1696 information->widget_id = gtk_entry_new ();
1697 g_signal_connect (information->widget_id, "focus-out-event",
1698 G_CALLBACK (contact_widget_id_focus_out_cb),
1700 g_signal_connect (information->widget_id, "changed",
1701 G_CALLBACK (contact_widget_id_changed_cb),
1706 information->widget_id = gtk_label_new (NULL);
1707 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1708 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1710 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1712 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1713 information->widget_id,
1715 gtk_widget_show (information->widget_id);
1717 /* Setup alias label/entry */
1718 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1720 information->widget_alias = gtk_entry_new ();
1722 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1723 g_signal_connect (information->widget_alias, "focus-out-event",
1724 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1727 /* Make return activate the window default (the Close button) */
1728 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1733 information->widget_alias = gtk_label_new (NULL);
1734 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1735 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1737 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1739 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1740 information->widget_alias,
1742 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1743 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1745 gtk_widget_show (information->widget_alias);
1748 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1750 information->favourite_checkbox = gtk_check_button_new_with_label (
1753 g_signal_connect (information->favourite_checkbox, "toggled",
1754 G_CALLBACK (favourite_toggled_cb), information);
1756 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1757 information->favourite_checkbox, 0, 2, 3, 4);
1759 information->fav_sig_id = g_signal_connect (information->manager,
1760 "favourites-changed",
1761 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1763 gtk_widget_show (information->favourite_checkbox);
1768 contact_widget_destroy_cb (GtkWidget *widget,
1769 EmpathyContactWidget *information)
1771 contact_widget_remove_contact (information);
1773 if (information->widget_id_timeout != 0)
1775 g_source_remove (information->widget_id_timeout);
1778 if (information->fav_sig_id != 0)
1779 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1781 g_object_unref (information->manager);
1783 g_slice_free (EmpathyContactWidget, information);
1787 * empathy_contact_widget_new:
1788 * @contact: an #EmpathyContact
1789 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1791 * Creates a new #EmpathyContactWidget.
1793 * Return value: a new #EmpathyContactWidget
1796 empathy_contact_widget_new (EmpathyContact *contact,
1797 EmpathyContactWidgetFlags flags)
1799 EmpathyContactWidget *information;
1803 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1805 information = g_slice_new0 (EmpathyContactWidget);
1806 information->flags = flags;
1808 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1810 gui = empathy_builder_get_file (filename,
1811 "vbox_contact_widget", &information->vbox_contact_widget,
1812 "hbox_contact", &information->hbox_contact,
1813 "hbox_presence", &information->hbox_presence,
1814 "label_alias", &information->label_alias,
1815 "image_state", &information->image_state,
1816 "table_contact", &information->table_contact,
1817 "vbox_avatar", &information->vbox_avatar,
1818 "vbox_location", &information->vbox_location,
1819 "subvbox_location", &information->subvbox_location,
1820 "label_location", &information->label_location,
1821 #ifdef HAVE_LIBCHAMPLAIN
1822 "viewport_map", &information->viewport_map,
1824 "groups_widget", &information->groups_widget,
1825 "vbox_details", &information->vbox_details,
1826 "table_details", &information->table_details,
1827 "hbox_details_requested", &information->hbox_details_requested,
1828 "vbox_client", &information->vbox_client,
1829 "table_client", &information->table_client,
1830 "hbox_client_requested", &information->hbox_client_requested,
1834 empathy_builder_connect (gui, information,
1835 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1837 information->table_location = NULL;
1839 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1840 "EmpathyContactWidget",
1843 information->manager = empathy_contact_manager_dup_singleton ();
1845 /* Create widgets */
1846 contact_widget_contact_setup (information);
1847 contact_widget_details_setup (information);
1848 contact_widget_client_setup (information);
1850 if (contact != NULL)
1851 contact_widget_set_contact (information, contact);
1852 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1853 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1854 contact_widget_change_contact (information);
1856 return empathy_builder_unref_and_keep_widget (gui,
1857 information->vbox_contact_widget);
1861 * empathy_contact_widget_get_contact:
1862 * @widget: an #EmpathyContactWidget
1864 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1866 * Returns: the #EmpathyContact associated with @widget
1869 empathy_contact_widget_get_contact (GtkWidget *widget)
1871 EmpathyContactWidget *information;
1873 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1875 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1879 return information->contact;
1883 empathy_contact_widget_get_alias (GtkWidget *widget)
1885 EmpathyContactWidget *information;
1887 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1889 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1893 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1897 * empathy_contact_widget_set_contact:
1898 * @widget: an #EmpathyContactWidget
1899 * @contact: a different #EmpathyContact
1901 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1904 empathy_contact_widget_set_contact (GtkWidget *widget,
1905 EmpathyContact *contact)
1907 EmpathyContactWidget *information;
1909 g_return_if_fail (GTK_IS_WIDGET (widget));
1910 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1912 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1916 contact_widget_set_contact (information, contact);
1920 * empathy_contact_widget_set_account_filter:
1921 * @widget: an #EmpathyContactWidget
1922 * @filter: a #EmpathyAccountChooserFilterFunc
1923 * @user_data: user data to pass to @filter, or %NULL
1925 * Set a filter on the #EmpathyAccountChooser included in the
1926 * #EmpathyContactWidget.
1929 empathy_contact_widget_set_account_filter (
1931 EmpathyAccountChooserFilterFunc filter,
1934 EmpathyContactWidget *information;
1935 EmpathyAccountChooser *chooser;
1937 g_return_if_fail (GTK_IS_WIDGET (widget));
1939 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1943 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1945 empathy_account_chooser_set_filter (chooser, filter, user_data);