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-list.h>
41 #include <libempathy/empathy-location.h>
42 #include <libempathy/empathy-time.h>
43 #include <libempathy/empathy-utils.h>
45 #include "empathy-contact-widget.h"
46 #include "empathy-contactinfo-utils.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 EmpathyContact *contact;
84 EmpathyContactWidgetFlags flags;
85 guint widget_id_timeout;
88 GtkWidget *vbox_contact_widget;
91 GtkWidget *widget_avatar;
92 GtkWidget *widget_account;
93 GtkWidget *image_account;
94 GtkWidget *label_account;
96 GtkWidget *widget_alias;
97 GtkWidget *label_alias;
98 GtkWidget *hbox_presence;
99 GtkWidget *image_state;
100 GtkWidget *label_status;
101 GtkWidget *grid_contact;
102 GtkWidget *vbox_avatar;
103 GtkWidget *favourite_checkbox;
104 GtkWidget *label_details;
107 GtkWidget *vbox_location;
108 GtkWidget *subvbox_location;
109 GtkWidget *grid_location;
110 GtkWidget *label_location;
111 #ifdef HAVE_LIBCHAMPLAIN
112 GtkWidget *viewport_map;
113 GtkWidget *map_view_embed;
114 ChamplainView *map_view;
118 GtkWidget *groups_widget;
121 GtkWidget *vbox_details;
122 GtkWidget *grid_details;
123 GtkWidget *hbox_details_requested;
124 GtkWidget *spinner_details;
125 GList *details_to_set;
126 GCancellable *details_cancellable;
127 gboolean details_changed;
130 GtkWidget *vbox_client;
131 GtkWidget *grid_client;
132 GtkWidget *hbox_client_requested;
133 } EmpathyContactWidget;
137 EmpathyContactWidget *information;
140 GtkTreeIter found_iter;
152 field_value_is_empty (TpContactInfoField *field)
156 if (field->field_value == NULL)
159 /* Field is empty if all its values are empty */
160 for (i = 0; field->field_value[i] != NULL; i++)
162 if (!tp_str_empty (field->field_value[i]))
170 set_contact_info_cb (GObject *source,
171 GAsyncResult *result,
174 GError *error = NULL;
176 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
179 DEBUG ("SetContactInfo() failed: %s", error->message);
180 g_error_free (error);
184 DEBUG ("SetContactInfo() succeeded");
188 contact_widget_save (EmpathyContactWidget *information)
190 TpConnection *connection;
193 connection = empathy_contact_get_connection (information->contact);
195 /* Remove empty fields */
196 for (l = information->details_to_set; l != NULL; l = next)
198 TpContactInfoField *field = l->data;
201 if (field_value_is_empty (field))
203 DEBUG ("Drop empty field: %s", field->field_name);
204 tp_contact_info_field_free (field);
205 information->details_to_set =
206 g_list_delete_link (information->details_to_set, l);
210 if (information->details_to_set != NULL)
212 if (information->details_changed)
214 tp_connection_set_contact_info_async (connection,
215 information->details_to_set, set_contact_info_cb, NULL);
218 tp_contact_info_list_free (information->details_to_set);
219 information->details_to_set = NULL;
224 contact_widget_details_setup (EmpathyContactWidget *information)
226 gtk_widget_hide (information->vbox_details);
228 information->spinner_details = gtk_spinner_new ();
229 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
230 information->spinner_details, TRUE, TRUE, 0);
231 gtk_widget_show (information->spinner_details);
235 contact_widget_details_changed_cb (GtkEntry *entry,
236 EmpathyContactWidget *self)
238 const gchar *strv[] = { NULL, NULL };
239 TpContactInfoField *field;
241 self->details_changed = TRUE;
243 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
244 g_assert (field != NULL);
246 strv[0] = gtk_entry_get_text (entry);
248 if (field->field_value != NULL)
249 g_strfreev (field->field_value);
250 field->field_value = g_strdupv ((GStrv) strv);
254 contact_widget_bday_changed_cb (GtkCalendar *calendar,
255 EmpathyContactWidget *self)
257 guint year, month, day;
260 const gchar *strv[] = { NULL, NULL };
261 TpContactInfoField *field;
263 self->details_changed = TRUE;
265 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
266 g_assert (field != NULL);
268 gtk_calendar_get_date (calendar, &year, &month, &day);
269 date = g_date_new_dmy (day, month+1, year);
271 gtk_calendar_clear_marks (calendar);
272 gtk_calendar_mark_day (calendar, g_date_get_day (date));
274 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
276 if (field->field_value != NULL)
277 g_strfreev (field->field_value);
278 field->field_value = g_strdupv ((GStrv) strv);
283 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
286 field_name_in_field_list (GList *list,
291 for (l = list; l != NULL; l = g_list_next (l))
293 TpContactInfoField *field = l->data;
295 if (!tp_strdiff (field->field_name, name))
302 static TpContactInfoFieldSpec *
303 get_spec_from_list (GList *list,
308 for (l = list; l != NULL; l = g_list_next (l))
310 TpContactInfoFieldSpec *spec = l->data;
312 if (!tp_strdiff (spec->name, name))
320 contact_widget_details_update_edit (EmpathyContactWidget *information)
323 TpConnection *connection;
327 const char **field_names = empathy_contact_info_get_field_names (NULL);
330 g_assert (information->details_to_set == NULL);
332 information->details_changed = FALSE;
334 contact = empathy_contact_get_tp_contact (information->contact);
335 connection = tp_contact_get_connection (contact);
337 info = tp_contact_get_contact_info (contact);
339 specs = tp_connection_get_contact_info_supported_fields (connection);
341 /* Look at the fields set in our vCard */
342 for (l = info; l != NULL; l = l->next)
344 TpContactInfoField *field = l->data;
346 /* make a copy for the details_to_set list */
347 field = tp_contact_info_field_copy (field);
348 DEBUG ("Field %s is in our vCard", field->field_name);
350 information->details_to_set = g_list_prepend (information->details_to_set,
354 /* Add fields which are supported but not in the vCard */
355 for (i = 0; field_names[i] != NULL; i++)
357 TpContactInfoFieldSpec *spec;
358 TpContactInfoField *field;
360 /* Check if the field was in the vCard */
361 if (field_name_in_field_list (information->details_to_set,
365 /* Check if the CM supports the field */
366 spec = get_spec_from_list (specs, field_names[i]);
370 /* add an empty field so user can set a value */
371 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
373 information->details_to_set = g_list_prepend (information->details_to_set,
377 /* Add widgets for supported fields */
378 information->details_to_set = g_list_sort (information->details_to_set,
379 (GCompareFunc) empathy_contact_info_field_spec_cmp);
381 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
383 TpContactInfoField *field = l->data;
385 TpContactInfoFieldSpec *spec;
389 has_field = empathy_contact_info_lookup_field (field->field_name,
393 /* Empathy doesn't display this field so we can't change it.
394 * But we put it in the details_to_set list so it won't be erased
395 * when calling SetContactInfo (bgo #630427) */
396 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
400 spec = get_spec_from_list (specs, field->field_name);
401 /* We shouldn't have added the field to details_to_set if it's not
402 * supported by the CM */
403 g_assert (spec != NULL);
405 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
407 DEBUG ("Ignoring field '%s' due it to having the "
408 "Overwritten_By_Nickname flag", field->field_name);
413 title = empathy_contact_info_field_label (field->field_name,
415 w = gtk_label_new (title);
418 gtk_grid_attach (GTK_GRID (information->grid_details),
421 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
425 if (!tp_strdiff (field->field_name, "bday"))
427 w = gtk_calendar_new ();
428 if (field->field_value[0])
432 g_date_set_parse (&date, field->field_value[0]);
433 if (g_date_valid (&date))
435 gtk_calendar_select_day (GTK_CALENDAR (w),
436 g_date_get_day (&date));
437 gtk_calendar_select_month (GTK_CALENDAR (w),
438 g_date_get_month (&date) - 1, g_date_get_year (&date));
439 gtk_calendar_mark_day (GTK_CALENDAR (w),
440 g_date_get_day (&date));
444 gtk_grid_attach (GTK_GRID (information->grid_details),
448 g_object_set_data ((GObject *) w, DATA_FIELD, field);
450 g_signal_connect (w, "day-selected",
451 G_CALLBACK (contact_widget_bday_changed_cb), information);
452 g_signal_connect (w, "month-changed",
453 G_CALLBACK (contact_widget_bday_changed_cb), information);
457 w = gtk_entry_new ();
458 gtk_entry_set_text (GTK_ENTRY (w),
459 field->field_value[0] ? field->field_value[0] : "");
460 gtk_grid_attach (GTK_GRID (information->grid_details),
464 g_object_set_data ((GObject *) w, DATA_FIELD, field);
466 g_signal_connect (w, "changed",
467 G_CALLBACK (contact_widget_details_changed_cb), information);
480 add_row (GtkGrid *grid,
485 gtk_grid_attach (grid, title, 0, row, 1, 1);
486 gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
487 gtk_widget_show (title);
489 gtk_grid_attach (grid, value, 1, row, 1, 1);
490 gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
491 gtk_widget_show (value);
495 contact_widget_details_update_show (EmpathyContactWidget *information)
500 GtkWidget *channels_label;
503 contact = empathy_contact_get_tp_contact (information->contact);
504 info = tp_contact_get_contact_info (contact);
505 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
506 for (l = info; l != NULL; l = l->next)
508 TpContactInfoField *field = l->data;
510 gchar *markup = NULL, *title;
511 GtkWidget *title_widget, *value_widget;
512 EmpathyContactInfoFormatFunc format;
514 if (field->field_value == NULL || field->field_value[0] == NULL)
517 value = field->field_value[0];
519 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
521 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
527 markup = format (field->field_value);
531 DEBUG ("Invalid value for field '%s' (first element was '%s')",
532 field->field_name, field->field_value[0]);
538 title = empathy_contact_info_field_label (field->field_name,
540 title_widget = gtk_label_new (title);
544 value_widget = gtk_label_new (value);
547 gtk_label_set_markup (GTK_LABEL (value_widget), markup);
551 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
552 gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
554 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
560 account = empathy_contact_get_account (information->contact);
562 channels_label = empathy_contact_info_create_channel_list_label (account,
565 if (channels_label != NULL)
567 GtkWidget *title_widget;
569 title_widget = gtk_label_new (_("Channels:"));
571 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
583 contact_widget_details_notify_cb (EmpathyContactWidget *information)
587 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
588 (GtkCallback) gtk_widget_destroy, NULL);
590 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
591 n_rows = contact_widget_details_update_edit (information);
593 n_rows = contact_widget_details_update_show (information);
597 gtk_widget_show (information->vbox_details);
598 gtk_widget_show (information->grid_details);
602 gtk_widget_hide (information->vbox_details);
605 gtk_widget_hide (information->hbox_details_requested);
606 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
610 contact_widget_details_request_cb (GObject *object,
614 TpContact *contact = TP_CONTACT (object);
615 EmpathyContactWidget *information = user_data;
616 GError *error = NULL;
618 if (!tp_contact_request_contact_info_finish (contact, res, &error))
620 /* If the request got cancelled it could mean the contact widget is
621 * destroyed, so we should not dereference information */
622 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
624 g_clear_error (&error);
628 gtk_widget_hide (information->vbox_details);
629 g_clear_error (&error);
633 contact_widget_details_notify_cb (information);
636 /* If we are going to edit ContactInfo, we don't want live updates */
637 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
639 g_signal_connect_swapped (contact, "notify::contact-info",
640 G_CALLBACK (contact_widget_details_notify_cb), information);
643 tp_clear_object (&information->details_cancellable);
647 fetch_contact_information (EmpathyContactWidget *information,
648 TpConnection *connection)
651 TpContactInfoFlags flags;
653 if (!tp_proxy_has_interface_by_id (connection,
654 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
656 gtk_widget_hide (information->vbox_details);
660 /* If we want to edit info, but connection does not support that, stop */
661 flags = tp_connection_get_contact_info_flags (connection);
662 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
663 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
665 gtk_widget_hide (information->vbox_details);
669 /* Request the contact's info */
670 gtk_widget_show (information->vbox_details);
671 gtk_widget_show (information->hbox_details_requested);
672 gtk_widget_hide (information->grid_details);
673 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
675 contact = empathy_contact_get_tp_contact (information->contact);
676 g_assert (information->details_cancellable == NULL);
677 information->details_cancellable = g_cancellable_new ();
678 tp_contact_request_contact_info_async (contact,
679 information->details_cancellable, contact_widget_details_request_cb,
684 contact_widget_details_update (EmpathyContactWidget *information)
686 TpContact *tp_contact = NULL;
688 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
689 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
692 gtk_widget_hide (information->vbox_details);
694 if (information->contact != NULL)
695 tp_contact = empathy_contact_get_tp_contact (information->contact);
697 if (tp_contact != NULL)
699 TpConnection *connection;
701 connection = tp_contact_get_connection (tp_contact);
703 fetch_contact_information (information, connection);
708 contact_widget_client_update (EmpathyContactWidget *information)
710 /* FIXME: Needs new telepathy spec */
714 contact_widget_client_setup (EmpathyContactWidget *information)
716 /* FIXME: Needs new telepathy spec */
717 gtk_widget_hide (information->vbox_client);
721 contact_widget_groups_update (EmpathyContactWidget *information)
723 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
724 information->contact != NULL)
726 FolksPersona *persona =
727 empathy_contact_get_persona (information->contact);
729 if (FOLKS_IS_GROUP_DETAILS (persona))
731 empathy_groups_widget_set_group_details (
732 EMPATHY_GROUPS_WIDGET (information->groups_widget),
733 FOLKS_GROUP_DETAILS (persona));
734 gtk_widget_show (information->groups_widget);
740 /* In case of failure */
741 gtk_widget_hide (information->groups_widget);
744 /* Converts the Location's GHashTable's key to a user readable string */
746 location_key_to_label (const gchar *key)
748 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
749 return _("Country ISO Code:");
750 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
751 return _("Country:");
752 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
754 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
756 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
758 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
759 return _("Postal Code:");
760 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
762 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
763 return _("Building:");
764 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
766 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
768 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
770 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
771 return _("Description:");
772 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
774 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
775 return _("Accuracy Level:");
776 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
778 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
779 return _("Vertical Error (meters):");
780 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
781 return _("Horizontal Error (meters):");
782 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
784 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
785 return _("Bearing:");
786 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
787 return _("Climb Speed:");
788 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
789 return _("Last Updated on:");
790 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
791 return _("Longitude:");
792 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
793 return _("Latitude:");
794 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
795 return _("Altitude:");
798 DEBUG ("Unexpected Location key: %s", key);
804 contact_widget_location_update (EmpathyContactWidget *information)
806 GHashTable *location;
808 #ifdef HAVE_LIBCHAMPLAIN
809 gdouble lat = 0.0, lon = 0.0;
810 gboolean has_position = TRUE;
814 static const gchar* ordered_geolocation_keys[] = {
815 EMPATHY_LOCATION_TEXT,
816 EMPATHY_LOCATION_URI,
817 EMPATHY_LOCATION_DESCRIPTION,
818 EMPATHY_LOCATION_BUILDING,
819 EMPATHY_LOCATION_FLOOR,
820 EMPATHY_LOCATION_ROOM,
821 EMPATHY_LOCATION_STREET,
822 EMPATHY_LOCATION_AREA,
823 EMPATHY_LOCATION_LOCALITY,
824 EMPATHY_LOCATION_REGION,
825 EMPATHY_LOCATION_COUNTRY,
830 gboolean display_map = FALSE;
832 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
834 gtk_widget_hide (information->vbox_location);
838 location = empathy_contact_get_location (information->contact);
839 if (location == NULL || g_hash_table_size (location) == 0)
841 gtk_widget_hide (information->vbox_location);
845 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
848 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
849 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
859 stamp = g_value_get_int64 (value);
861 user_date = empathy_time_to_string_relative (stamp);
863 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
864 /* translators: format is "Location, $date" */
865 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
867 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
873 /* Prepare the location information grid */
874 if (information->grid_location != NULL)
876 gtk_widget_destroy (information->grid_location);
879 information->grid_location = gtk_grid_new ();
880 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
881 information->grid_location, FALSE, FALSE, 5);
884 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
886 const gchar* user_label;
890 gvalue = g_hash_table_lookup (location, (gpointer) skey);
894 user_label = location_key_to_label (skey);
896 label = gtk_label_new (user_label);
897 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
898 gtk_grid_attach (GTK_GRID (information->grid_location),
899 label, 0, row, 1, 1);
900 gtk_widget_show (label);
902 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
905 dvalue = g_value_get_double (gvalue);
906 svalue = g_strdup_printf ("%f", dvalue);
908 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
910 svalue = g_value_dup_string (gvalue);
912 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
916 time_ = g_value_get_int64 (value);
917 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
922 label = gtk_label_new (svalue);
923 gtk_grid_attach (GTK_GRID (information->grid_location),
924 label, 1, row, 1, 1);
925 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
926 gtk_widget_show (label);
928 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
929 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
936 #ifdef HAVE_LIBCHAMPLAIN
938 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
940 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
948 /* We can display some fields */
949 gtk_widget_show (information->grid_location);
951 else if (!display_map)
953 /* Can't display either fields or map */
954 gtk_widget_hide (information->vbox_location);
958 #ifdef HAVE_LIBCHAMPLAIN
961 ClutterActor *marker;
962 ChamplainMarkerLayer *layer;
964 information->map_view_embed = gtk_champlain_embed_new ();
965 information->map_view = gtk_champlain_embed_get_view (
966 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
968 gtk_container_add (GTK_CONTAINER (information->viewport_map),
969 information->map_view_embed);
970 g_object_set (G_OBJECT (information->map_view),
971 "kinetic-mode", TRUE,
975 layer = champlain_marker_layer_new ();
976 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
978 marker = champlain_label_new_with_text (
979 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
980 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
981 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
983 champlain_view_center_on (information->map_view, lat, lon);
984 gtk_widget_show_all (information->viewport_map);
988 gtk_widget_show (information->vbox_location);
992 save_avatar_menu_activate_cb (GtkWidget *widget,
993 EmpathyContactWidget *information)
996 EmpathyAvatar *avatar;
997 gchar *ext = NULL, *filename;
999 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1001 GTK_FILE_CHOOSER_ACTION_SAVE,
1002 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1003 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1006 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1009 /* look for the avatar extension */
1010 avatar = empathy_contact_get_avatar (information->contact);
1011 if (avatar->format != NULL)
1015 splitted = g_strsplit (avatar->format, "/", 2);
1016 if (splitted[0] != NULL && splitted[1] != NULL)
1017 ext = g_strdup (splitted[1]);
1019 g_strfreev (splitted);
1023 /* Avatar was loaded from the cache so was converted to PNG */
1024 ext = g_strdup ("png");
1031 id = tp_escape_as_identifier (empathy_contact_get_id (
1032 information->contact));
1034 filename = g_strdup_printf ("%s.%s", id, ext);
1035 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1042 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1044 GError *error = NULL;
1046 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1048 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1051 GtkWidget *error_dialog;
1053 error_dialog = gtk_message_dialog_new (NULL, 0,
1054 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1055 _("Unable to save avatar"));
1057 gtk_message_dialog_format_secondary_text (
1058 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1060 g_signal_connect (error_dialog, "response",
1061 G_CALLBACK (gtk_widget_destroy), NULL);
1063 gtk_window_present (GTK_WINDOW (error_dialog));
1065 g_clear_error (&error);
1071 gtk_widget_destroy (dialog);
1075 popup_avatar_menu (EmpathyContactWidget *information,
1077 GdkEventButton *event)
1079 GtkWidget *menu, *item;
1080 gint button, event_time;
1082 if (information->contact == NULL ||
1083 empathy_contact_get_avatar (information->contact) == NULL)
1086 menu = empathy_context_menu_new (parent);
1088 /* Add "Save as..." entry */
1089 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1090 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1091 gtk_widget_show (item);
1093 g_signal_connect (item, "activate",
1094 G_CALLBACK (save_avatar_menu_activate_cb), information);
1098 button = event->button;
1099 event_time = event->time;
1104 event_time = gtk_get_current_event_time ();
1107 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1108 button, event_time);
1112 widget_avatar_popup_menu_cb (GtkWidget *widget,
1113 EmpathyContactWidget *information)
1115 popup_avatar_menu (information, widget, NULL);
1121 widget_avatar_button_press_event_cb (GtkWidget *widget,
1122 GdkEventButton *event,
1123 EmpathyContactWidget *information)
1125 /* Ignore double-clicks and triple-clicks */
1126 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1128 popup_avatar_menu (information, widget, event);
1136 set_avatar_cb (GObject *source,
1140 GError *error = NULL;
1142 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1143 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1144 g_error_free (error);
1149 set_avatar_on_account (TpAccount *account,
1152 const gchar *mime_type)
1154 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1155 tp_proxy_get_object_path (account));
1157 tp_account_set_avatar_async (account, (const guchar *) data, size,
1158 mime_type, set_avatar_cb, NULL);
1162 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1163 EmpathyContactWidget *information)
1167 const gchar *mime_type;
1170 empathy_avatar_chooser_get_image_data (
1171 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1172 &data, &size, &mime_type);
1174 account = empathy_contact_get_account (information->contact);
1175 set_avatar_on_account (account, data, size, mime_type);
1179 set_nickname_cb (GObject *source,
1183 GError *error = NULL;
1185 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1187 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1188 g_error_free (error);
1192 /* Update all the contact info fields having the
1193 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1194 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1197 update_nickname_in_contact_info (EmpathyContactWidget *self,
1198 TpConnection *connection,
1199 const gchar *nickname)
1203 specs = tp_connection_get_contact_info_supported_fields (connection);
1205 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1207 TpContactInfoField *field = l->data;
1208 TpContactInfoFieldSpec *spec;
1210 spec = get_spec_from_list (specs, field->field_name);
1211 /* We shouldn't have added the field to details_to_set if it's not
1212 * supported by the CM */
1213 g_assert (spec != NULL);
1215 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1217 const gchar *strv[] = { nickname, NULL };
1219 DEBUG ("Updating field '%s' to '%s' as it has the "
1220 "Overwritten_By_Nickname flag and Account.Nickname has "
1221 "been updated", field->field_name, nickname);
1223 if (field->field_value != NULL)
1224 g_strfreev (field->field_value);
1225 field->field_value = g_strdupv ((GStrv) strv);
1229 g_list_free (specs);
1233 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1234 GdkEventFocus *event,
1235 EmpathyContactWidget *information)
1237 if (information->contact)
1241 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1243 if (empathy_contact_is_user (information->contact))
1245 TpAccount * account;
1246 const gchar *current_nickname;
1248 account = empathy_contact_get_account (information->contact);
1249 current_nickname = tp_account_get_nickname (account);
1251 if (tp_strdiff (current_nickname, alias))
1253 DEBUG ("Set Account.Nickname to %s", alias);
1255 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1258 update_nickname_in_contact_info (information,
1259 empathy_contact_get_connection (information->contact), alias);
1264 empathy_contact_set_alias (information->contact, alias);
1272 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1273 EmpathyAvatarChooser *avatar_chooser)
1277 account = empathy_account_chooser_get_account (account_chooser);
1278 if (account == NULL)
1281 empathy_avatar_chooser_set_account (avatar_chooser, account);
1285 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1287 EmpathyAvatar *avatar = NULL;
1289 if (information->contact)
1290 avatar = empathy_contact_get_avatar (information->contact);
1292 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1294 g_signal_handlers_block_by_func (information->widget_avatar,
1295 contact_widget_avatar_changed_cb,
1297 empathy_avatar_chooser_set (
1298 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1299 g_signal_handlers_unblock_by_func (information->widget_avatar,
1300 contact_widget_avatar_changed_cb, information);
1303 empathy_avatar_image_set (
1304 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1308 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1310 if (GTK_IS_ENTRY (information->widget_alias))
1311 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1312 empathy_contact_get_alias (information->contact));
1314 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1315 empathy_contact_get_alias (information->contact));
1319 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1321 const gchar *status;
1322 gchar *markup_text = NULL;
1324 status = empathy_contact_get_status (information->contact);
1326 markup_text = empathy_add_link_markup (status);
1327 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1328 g_free (markup_text);
1330 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1331 empathy_icon_name_for_contact (information->contact),
1332 GTK_ICON_SIZE_BUTTON);
1333 gtk_widget_show (information->image_state);
1337 contact_widget_remove_contact (EmpathyContactWidget *information)
1339 if (information->contact)
1341 TpContact *tp_contact;
1343 contact_widget_save (information);
1345 g_signal_handlers_disconnect_by_func (information->contact,
1346 contact_widget_name_notify_cb, information);
1347 g_signal_handlers_disconnect_by_func (information->contact,
1348 contact_widget_presence_notify_cb, information);
1349 g_signal_handlers_disconnect_by_func (information->contact,
1350 contact_widget_avatar_notify_cb, information);
1352 tp_contact = empathy_contact_get_tp_contact (information->contact);
1353 if (tp_contact != NULL)
1355 g_signal_handlers_disconnect_by_func (tp_contact,
1356 contact_widget_details_notify_cb, information);
1359 g_object_unref (information->contact);
1360 information->contact = NULL;
1363 if (information->details_cancellable != NULL)
1365 g_cancellable_cancel (information->details_cancellable);
1366 tp_clear_object (&information->details_cancellable);
1370 static void contact_widget_change_contact (EmpathyContactWidget *information);
1373 contact_widget_contact_update (EmpathyContactWidget *information)
1375 TpAccount *account = NULL;
1376 const gchar *id = NULL;
1378 /* Connect and get info from new contact */
1379 if (information->contact)
1381 g_signal_connect_swapped (information->contact, "notify::name",
1382 G_CALLBACK (contact_widget_name_notify_cb), information);
1383 g_signal_connect_swapped (information->contact, "notify::presence",
1384 G_CALLBACK (contact_widget_presence_notify_cb), information);
1385 g_signal_connect_swapped (information->contact,
1386 "notify::presence-message",
1387 G_CALLBACK (contact_widget_presence_notify_cb), information);
1388 g_signal_connect_swapped (information->contact, "notify::avatar",
1389 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1391 account = empathy_contact_get_account (information->contact);
1392 id = empathy_contact_get_id (information->contact);
1395 /* Update account widget */
1396 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1400 g_signal_handlers_block_by_func (information->widget_account,
1401 contact_widget_change_contact,
1403 empathy_account_chooser_set_account (
1404 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1405 g_signal_handlers_unblock_by_func (information->widget_account,
1406 contact_widget_change_contact, information);
1415 name = tp_account_get_display_name (account);
1416 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1418 name = tp_account_get_icon_name (account);
1419 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1420 name, GTK_ICON_SIZE_MENU);
1424 /* Update id widget */
1425 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1426 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1428 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1430 /* Update other widgets */
1431 if (information->contact)
1433 contact_widget_name_notify_cb (information);
1434 contact_widget_presence_notify_cb (information);
1435 contact_widget_avatar_notify_cb (information);
1437 gtk_widget_show (information->label_alias);
1438 gtk_widget_show (information->widget_alias);
1439 gtk_widget_show (information->widget_avatar);
1441 gtk_widget_set_visible (information->hbox_presence,
1442 !(information->flags & EMPATHY_CONTACT_WIDGET_NO_STATUS));
1444 if (empathy_contact_is_user (information->contact))
1445 gtk_label_set_text (GTK_LABEL (information->label_details),
1446 _("Personal Details"));
1448 gtk_label_set_text (GTK_LABEL (information->label_details),
1449 _("Contact Details"));
1453 gtk_widget_hide (information->label_alias);
1454 gtk_widget_hide (information->widget_alias);
1455 gtk_widget_hide (information->hbox_presence);
1456 gtk_widget_hide (information->widget_avatar);
1461 contact_widget_set_contact (EmpathyContactWidget *information,
1462 EmpathyContact *contact)
1464 if (contact == information->contact)
1467 contact_widget_remove_contact (information);
1469 information->contact = g_object_ref (contact);
1471 /* set the selected account to be the account this contact came from */
1472 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1473 empathy_account_chooser_set_account (
1474 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1475 empathy_contact_get_account (contact));
1478 /* Update information for widgets */
1479 contact_widget_contact_update (information);
1480 contact_widget_groups_update (information);
1481 contact_widget_details_update (information);
1482 contact_widget_client_update (information);
1483 contact_widget_location_update (information);
1487 contact_widget_got_contact_cb (TpConnection *connection,
1488 EmpathyContact *contact,
1489 const GError *error,
1491 GObject *weak_object)
1493 EmpathyContactWidget *information = user_data;
1497 DEBUG ("Error: %s", error->message);
1501 contact_widget_set_contact (information, contact);
1505 contact_widget_change_contact (EmpathyContactWidget *information)
1507 TpConnection *connection;
1509 connection = empathy_account_chooser_get_connection (
1510 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1514 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1518 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1519 if (!EMP_STR_EMPTY (id))
1521 empathy_tp_contact_factory_get_from_id (connection, id,
1522 contact_widget_got_contact_cb, information, NULL,
1523 G_OBJECT (information->vbox_contact_widget));
1528 empathy_tp_contact_factory_get_from_handle (connection,
1529 tp_connection_get_self_handle (connection),
1530 contact_widget_got_contact_cb, information, NULL,
1531 G_OBJECT (information->vbox_contact_widget));
1536 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1538 contact_widget_change_contact (self);
1543 contact_widget_id_changed_cb (GtkEntry *entry,
1544 EmpathyContactWidget *self)
1546 if (self->widget_id_timeout != 0)
1548 g_source_remove (self->widget_id_timeout);
1551 self->widget_id_timeout =
1552 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1553 (GSourceFunc) contact_widget_id_activate_timeout, self);
1557 contact_widget_id_focus_out_cb (GtkWidget *widget,
1558 GdkEventFocus *event,
1559 EmpathyContactWidget *information)
1561 contact_widget_change_contact (information);
1566 contact_widget_contact_setup (EmpathyContactWidget *information)
1568 information->label_status = gtk_label_new ("");
1569 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1570 PANGO_WRAP_WORD_CHAR);
1571 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1573 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1575 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1576 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1578 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1579 information->label_status, TRUE, TRUE, 0);
1580 gtk_widget_show (information->label_status);
1582 /* Setup account label/chooser */
1583 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1585 information->widget_account = empathy_account_chooser_new ();
1587 g_signal_connect_swapped (information->widget_account, "changed",
1588 G_CALLBACK (contact_widget_change_contact),
1593 /* Pack the protocol icon with the account name in an hbox */
1594 information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1596 information->label_account = gtk_label_new (NULL);
1597 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1598 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1600 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1601 gtk_widget_show (information->label_account);
1603 information->image_account = gtk_image_new ();
1604 gtk_widget_show (information->image_account);
1606 gtk_box_pack_start (GTK_BOX (information->widget_account),
1607 information->image_account, FALSE, FALSE, 0);
1608 gtk_box_pack_start (GTK_BOX (information->widget_account),
1609 information->label_account, FALSE, TRUE, 0);
1612 gtk_grid_attach (GTK_GRID (information->grid_contact),
1613 information->widget_account,
1616 gtk_widget_show (information->widget_account);
1618 /* Set up avatar chooser/display */
1619 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1621 information->widget_avatar = empathy_avatar_chooser_new ();
1622 g_signal_connect (information->widget_avatar, "changed",
1623 G_CALLBACK (contact_widget_avatar_changed_cb),
1625 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1627 g_signal_connect (information->widget_account, "changed",
1628 G_CALLBACK (update_avatar_chooser_account_cb),
1629 information->widget_avatar);
1630 update_avatar_chooser_account_cb (
1631 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1632 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1637 information->widget_avatar = empathy_avatar_image_new ();
1639 g_signal_connect (information->widget_avatar, "popup-menu",
1640 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1641 g_signal_connect (information->widget_avatar, "button-press-event",
1642 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1645 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1646 information->widget_avatar,
1649 gtk_widget_show (information->widget_avatar);
1651 /* Setup id label/entry */
1652 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1654 information->widget_id = gtk_entry_new ();
1655 g_signal_connect (information->widget_id, "focus-out-event",
1656 G_CALLBACK (contact_widget_id_focus_out_cb),
1658 g_signal_connect (information->widget_id, "changed",
1659 G_CALLBACK (contact_widget_id_changed_cb),
1664 information->widget_id = gtk_label_new (NULL);
1665 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1666 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1668 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1671 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1674 gtk_widget_show (information->widget_id);
1676 /* Setup alias label/entry */
1677 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1679 information->widget_alias = gtk_entry_new ();
1681 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1682 g_signal_connect (information->widget_alias, "focus-out-event",
1683 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1686 /* Make return activate the window default (the Close button) */
1687 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1692 information->widget_alias = gtk_label_new (NULL);
1693 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1694 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1696 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1699 gtk_grid_attach (GTK_GRID (information->grid_contact),
1700 information->widget_alias, 1, 2, 1, 1);
1702 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1703 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1705 gtk_widget_show (information->widget_alias);
1709 contact_widget_destroy_cb (GtkWidget *widget,
1710 EmpathyContactWidget *information)
1712 contact_widget_remove_contact (information);
1714 if (information->widget_id_timeout != 0)
1716 g_source_remove (information->widget_id_timeout);
1719 g_slice_free (EmpathyContactWidget, information);
1723 * empathy_contact_widget_new:
1724 * @contact: an #EmpathyContact
1725 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1727 * Creates a new #EmpathyContactWidget.
1729 * Return value: a new #EmpathyContactWidget
1732 empathy_contact_widget_new (EmpathyContact *contact,
1733 EmpathyContactWidgetFlags flags)
1735 EmpathyContactWidget *information;
1739 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1741 information = g_slice_new0 (EmpathyContactWidget);
1742 information->flags = flags;
1744 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1746 gui = empathy_builder_get_file (filename,
1747 "vbox_contact_widget", &information->vbox_contact_widget,
1748 "hbox_presence", &information->hbox_presence,
1749 "label_alias", &information->label_alias,
1750 "image_state", &information->image_state,
1751 "grid_contact", &information->grid_contact,
1752 "vbox_avatar", &information->vbox_avatar,
1753 "vbox_location", &information->vbox_location,
1754 "subvbox_location", &information->subvbox_location,
1755 "label_location", &information->label_location,
1756 #ifdef HAVE_LIBCHAMPLAIN
1757 "viewport_map", &information->viewport_map,
1759 "groups_widget", &information->groups_widget,
1760 "vbox_details", &information->vbox_details,
1761 "grid_details", &information->grid_details,
1762 "hbox_details_requested", &information->hbox_details_requested,
1763 "vbox_client", &information->vbox_client,
1764 "grid_client", &information->grid_client,
1765 "hbox_client_requested", &information->hbox_client_requested,
1766 "label_details", &information->label_details,
1770 empathy_builder_connect (gui, information,
1771 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1773 information->grid_location = NULL;
1775 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1776 "EmpathyContactWidget",
1779 /* Create widgets */
1780 contact_widget_contact_setup (information);
1781 contact_widget_details_setup (information);
1782 contact_widget_client_setup (information);
1784 if (contact != NULL)
1785 contact_widget_set_contact (information, contact);
1786 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1787 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1788 contact_widget_change_contact (information);
1790 return empathy_builder_unref_and_keep_widget (gui,
1791 information->vbox_contact_widget);
1795 * empathy_contact_widget_get_contact:
1796 * @widget: an #EmpathyContactWidget
1798 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1800 * Returns: the #EmpathyContact associated with @widget
1803 empathy_contact_widget_get_contact (GtkWidget *widget)
1805 EmpathyContactWidget *information;
1807 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1809 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1813 return information->contact;
1817 empathy_contact_widget_get_alias (GtkWidget *widget)
1819 EmpathyContactWidget *information;
1821 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1823 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1827 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1831 * empathy_contact_widget_set_contact:
1832 * @widget: an #EmpathyContactWidget
1833 * @contact: a different #EmpathyContact
1835 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1838 empathy_contact_widget_set_contact (GtkWidget *widget,
1839 EmpathyContact *contact)
1841 EmpathyContactWidget *information;
1843 g_return_if_fail (GTK_IS_WIDGET (widget));
1844 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1846 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1850 contact_widget_set_contact (information, contact);
1854 * empathy_contact_widget_set_account_filter:
1855 * @widget: an #EmpathyContactWidget
1856 * @filter: a #EmpathyAccountChooserFilterFunc
1857 * @user_data: user data to pass to @filter, or %NULL
1859 * Set a filter on the #EmpathyAccountChooser included in the
1860 * #EmpathyContactWidget.
1863 empathy_contact_widget_set_account_filter (
1865 EmpathyAccountChooserFilterFunc filter,
1868 EmpathyContactWidget *information;
1869 EmpathyAccountChooser *chooser;
1871 g_return_if_fail (GTK_IS_WIDGET (widget));
1873 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1877 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1879 empathy_account_chooser_set_filter (chooser, filter, user_data);