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-calendar-button.h"
46 #include "empathy-contact-widget.h"
47 #include "empathy-contactinfo-utils.h"
48 #include "empathy-account-chooser.h"
49 #include "empathy-avatar-chooser.h"
50 #include "empathy-avatar-image.h"
51 #include "empathy-groups-widget.h"
52 #include "empathy-ui-utils.h"
53 #include "empathy-string-parser.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
56 #include <libempathy/empathy-debug.h>
59 * SECTION:empathy-contact-widget
60 * @title:EmpathyContactWidget
61 * @short_description: A widget used to display and edit details about a contact
62 * @include: libempathy-empathy-contact-widget.h
64 * #EmpathyContactWidget is a widget which displays appropriate widgets
65 * with details about a contact, also allowing changing these details,
70 * EmpathyContactWidget:
71 * @parent: parent object
73 * Widget which displays appropriate widgets with details about a contact,
74 * also allowing changing these details, if desired.
77 /* Delay before updating the widget when the id entry changed (seconds) */
78 #define ID_CHANGED_TIMEOUT 1
80 #define DATA_FIELD "contact-info-field"
84 EmpathyContact *contact;
85 EmpathyContactWidgetFlags flags;
86 guint widget_id_timeout;
89 GtkWidget *vbox_contact_widget;
92 GtkWidget *widget_avatar;
93 GtkWidget *widget_account;
94 GtkWidget *image_account;
95 GtkWidget *label_account;
97 GtkWidget *widget_alias;
98 GtkWidget *label_alias;
99 GtkWidget *hbox_presence;
100 GtkWidget *image_state;
101 GtkWidget *label_status;
102 GtkWidget *grid_contact;
103 GtkWidget *vbox_avatar;
104 GtkWidget *favourite_checkbox;
105 GtkWidget *label_details;
108 GtkWidget *vbox_location;
109 GtkWidget *subvbox_location;
110 GtkWidget *grid_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 *grid_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 *grid_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 (EmpathyCalendarButton *button,
257 EmpathyContactWidget *self)
259 const gchar *strv[] = { NULL, NULL };
260 TpContactInfoField *field;
262 self->details_changed = TRUE;
264 field = g_object_get_data ((GObject *) button, DATA_FIELD);
265 g_assert (field != NULL);
271 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT,
276 if (field->field_value != NULL)
277 g_strfreev (field->field_value);
278 field->field_value = g_strdupv ((GStrv) strv);
281 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
284 field_name_in_field_list (GList *list,
289 for (l = list; l != NULL; l = g_list_next (l))
291 TpContactInfoField *field = l->data;
293 if (!tp_strdiff (field->field_name, name))
300 static TpContactInfoFieldSpec *
301 get_spec_from_list (GList *list,
306 for (l = list; l != NULL; l = g_list_next (l))
308 TpContactInfoFieldSpec *spec = l->data;
310 if (!tp_strdiff (spec->name, name))
318 contact_widget_details_update_edit (EmpathyContactWidget *information)
321 TpConnection *connection;
325 const char **field_names = empathy_contact_info_get_field_names (NULL);
328 g_assert (information->details_to_set == NULL);
330 information->details_changed = FALSE;
332 contact = empathy_contact_get_tp_contact (information->contact);
333 connection = tp_contact_get_connection (contact);
335 info = tp_contact_get_contact_info (contact);
337 specs = tp_connection_get_contact_info_supported_fields (connection);
339 /* Look at the fields set in our vCard */
340 for (l = info; l != NULL; l = l->next)
342 TpContactInfoField *field = l->data;
344 /* make a copy for the details_to_set list */
345 field = tp_contact_info_field_copy (field);
346 DEBUG ("Field %s is in our vCard", field->field_name);
348 information->details_to_set = g_list_prepend (information->details_to_set,
352 /* Add fields which are supported but not in the vCard */
353 for (i = 0; field_names[i] != NULL; i++)
355 TpContactInfoFieldSpec *spec;
356 TpContactInfoField *field;
358 /* Check if the field was in the vCard */
359 if (field_name_in_field_list (information->details_to_set,
363 /* Check if the CM supports the field */
364 spec = get_spec_from_list (specs, field_names[i]);
368 /* add an empty field so user can set a value */
369 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
371 information->details_to_set = g_list_prepend (information->details_to_set,
375 /* Add widgets for supported fields */
376 information->details_to_set = g_list_sort (information->details_to_set,
377 (GCompareFunc) empathy_contact_info_field_spec_cmp);
379 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
381 TpContactInfoField *field = l->data;
383 TpContactInfoFieldSpec *spec;
387 has_field = empathy_contact_info_lookup_field (field->field_name,
391 /* Empathy doesn't display this field so we can't change it.
392 * But we put it in the details_to_set list so it won't be erased
393 * when calling SetContactInfo (bgo #630427) */
394 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
398 spec = get_spec_from_list (specs, field->field_name);
399 /* We shouldn't have added the field to details_to_set if it's not
400 * supported by the CM */
401 g_assert (spec != NULL);
403 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
405 DEBUG ("Ignoring field '%s' due it to having the "
406 "Overwritten_By_Nickname flag", field->field_name);
411 title = empathy_contact_info_field_label (field->field_name,
413 w = gtk_label_new (title);
416 gtk_grid_attach (GTK_GRID (information->grid_details),
419 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
423 if (!tp_strdiff (field->field_name, "bday"))
425 w = empathy_calendar_button_new ();
427 if (field->field_value[0])
431 g_date_set_parse (&date, field->field_value[0]);
432 if (g_date_valid (&date))
434 empathy_calendar_button_set_date (EMPATHY_CALENDAR_BUTTON (w),
439 gtk_grid_attach (GTK_GRID (information->grid_details),
441 gtk_widget_show_all (w);
443 g_object_set_data ((GObject *) w, DATA_FIELD, field);
445 g_signal_connect (w, "date-changed",
446 G_CALLBACK (contact_widget_bday_changed_cb), information);
450 w = gtk_entry_new ();
451 gtk_entry_set_text (GTK_ENTRY (w),
452 field->field_value[0] ? field->field_value[0] : "");
453 gtk_grid_attach (GTK_GRID (information->grid_details),
457 g_object_set_data ((GObject *) w, DATA_FIELD, field);
459 g_signal_connect (w, "changed",
460 G_CALLBACK (contact_widget_details_changed_cb), information);
473 add_row (GtkGrid *grid,
478 gtk_grid_attach (grid, title, 0, row, 1, 1);
479 gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
480 gtk_widget_show (title);
482 gtk_grid_attach (grid, value, 1, row, 1, 1);
483 gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
484 gtk_widget_show (value);
488 contact_widget_details_update_show (EmpathyContactWidget *information)
493 GtkWidget *channels_label;
496 contact = empathy_contact_get_tp_contact (information->contact);
497 info = tp_contact_get_contact_info (contact);
498 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
499 for (l = info; l != NULL; l = l->next)
501 TpContactInfoField *field = l->data;
503 gchar *markup = NULL, *title;
504 GtkWidget *title_widget, *value_widget;
505 EmpathyContactInfoFormatFunc format;
507 if (field->field_value == NULL || field->field_value[0] == NULL)
510 value = field->field_value[0];
512 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
514 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
520 markup = format (field->field_value);
524 DEBUG ("Invalid value for field '%s' (first element was '%s')",
525 field->field_name, field->field_value[0]);
531 title = empathy_contact_info_field_label (field->field_name,
533 title_widget = gtk_label_new (title);
537 value_widget = gtk_label_new (value);
540 gtk_label_set_markup (GTK_LABEL (value_widget), markup);
544 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
545 gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
547 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
553 account = empathy_contact_get_account (information->contact);
555 channels_label = empathy_contact_info_create_channel_list_label (account,
558 if (channels_label != NULL)
560 GtkWidget *title_widget;
562 title_widget = gtk_label_new (_("Channels:"));
564 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
576 contact_widget_details_notify_cb (EmpathyContactWidget *information)
580 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
581 (GtkCallback) gtk_widget_destroy, NULL);
583 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
584 n_rows = contact_widget_details_update_edit (information);
586 n_rows = contact_widget_details_update_show (information);
590 gtk_widget_show (information->vbox_details);
591 gtk_widget_show (information->grid_details);
595 gtk_widget_hide (information->vbox_details);
598 gtk_widget_hide (information->hbox_details_requested);
599 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
603 contact_widget_details_request_cb (GObject *object,
607 TpContact *contact = TP_CONTACT (object);
608 EmpathyContactWidget *information = user_data;
609 GError *error = NULL;
611 if (!tp_contact_request_contact_info_finish (contact, res, &error))
613 /* If the request got cancelled it could mean the contact widget is
614 * destroyed, so we should not dereference information */
615 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
617 g_clear_error (&error);
621 gtk_widget_hide (information->vbox_details);
622 g_clear_error (&error);
626 contact_widget_details_notify_cb (information);
629 /* If we are going to edit ContactInfo, we don't want live updates */
630 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
632 g_signal_connect_swapped (contact, "notify::contact-info",
633 G_CALLBACK (contact_widget_details_notify_cb), information);
636 tp_clear_object (&information->details_cancellable);
640 fetch_contact_information (EmpathyContactWidget *information,
641 TpConnection *connection)
644 TpContactInfoFlags flags;
646 if (!tp_proxy_has_interface_by_id (connection,
647 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
649 gtk_widget_hide (information->vbox_details);
653 /* If we want to edit info, but connection does not support that, stop */
654 flags = tp_connection_get_contact_info_flags (connection);
655 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
656 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
658 gtk_widget_hide (information->vbox_details);
662 /* Request the contact's info */
663 gtk_widget_show (information->vbox_details);
664 gtk_widget_show (information->hbox_details_requested);
665 gtk_widget_hide (information->grid_details);
666 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
668 contact = empathy_contact_get_tp_contact (information->contact);
669 g_assert (information->details_cancellable == NULL);
670 information->details_cancellable = g_cancellable_new ();
671 tp_contact_request_contact_info_async (contact,
672 information->details_cancellable, contact_widget_details_request_cb,
677 contact_widget_details_update (EmpathyContactWidget *information)
679 TpContact *tp_contact = NULL;
681 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
682 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
685 gtk_widget_hide (information->vbox_details);
687 if (information->contact != NULL)
688 tp_contact = empathy_contact_get_tp_contact (information->contact);
690 if (tp_contact != NULL)
692 TpConnection *connection;
694 connection = tp_contact_get_connection (tp_contact);
696 fetch_contact_information (information, connection);
701 contact_widget_client_update (EmpathyContactWidget *information)
703 /* FIXME: Needs new telepathy spec */
707 contact_widget_client_setup (EmpathyContactWidget *information)
709 /* FIXME: Needs new telepathy spec */
710 gtk_widget_hide (information->vbox_client);
714 contact_widget_groups_update (EmpathyContactWidget *information)
716 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
717 information->contact != NULL)
719 FolksPersona *persona =
720 empathy_contact_get_persona (information->contact);
722 if (FOLKS_IS_GROUP_DETAILS (persona))
724 empathy_groups_widget_set_group_details (
725 EMPATHY_GROUPS_WIDGET (information->groups_widget),
726 FOLKS_GROUP_DETAILS (persona));
727 gtk_widget_show (information->groups_widget);
733 /* In case of failure */
734 gtk_widget_hide (information->groups_widget);
737 /* Converts the Location's GHashTable's key to a user readable string */
739 location_key_to_label (const gchar *key)
741 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
742 return _("Country ISO Code:");
743 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
744 return _("Country:");
745 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
747 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
749 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
751 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
752 return _("Postal Code:");
753 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
755 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
756 return _("Building:");
757 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
759 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
761 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
763 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
764 return _("Description:");
765 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
767 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
768 return _("Accuracy Level:");
769 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
771 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
772 return _("Vertical Error (meters):");
773 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
774 return _("Horizontal Error (meters):");
775 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
777 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
778 return _("Bearing:");
779 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
780 return _("Climb Speed:");
781 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
782 return _("Last Updated on:");
783 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
784 return _("Longitude:");
785 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
786 return _("Latitude:");
787 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
788 return _("Altitude:");
791 DEBUG ("Unexpected Location key: %s", key);
797 contact_widget_location_update (EmpathyContactWidget *information)
799 GHashTable *location;
801 #ifdef HAVE_LIBCHAMPLAIN
802 gdouble lat = 0.0, lon = 0.0;
803 gboolean has_position = TRUE;
807 static const gchar* ordered_geolocation_keys[] = {
808 EMPATHY_LOCATION_TEXT,
809 EMPATHY_LOCATION_URI,
810 EMPATHY_LOCATION_DESCRIPTION,
811 EMPATHY_LOCATION_BUILDING,
812 EMPATHY_LOCATION_FLOOR,
813 EMPATHY_LOCATION_ROOM,
814 EMPATHY_LOCATION_STREET,
815 EMPATHY_LOCATION_AREA,
816 EMPATHY_LOCATION_LOCALITY,
817 EMPATHY_LOCATION_REGION,
818 EMPATHY_LOCATION_COUNTRY,
823 gboolean display_map = FALSE;
825 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
827 gtk_widget_hide (information->vbox_location);
831 location = empathy_contact_get_location (information->contact);
832 if (location == NULL || g_hash_table_size (location) == 0)
834 gtk_widget_hide (information->vbox_location);
838 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
841 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
842 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
852 stamp = g_value_get_int64 (value);
854 user_date = empathy_time_to_string_relative (stamp);
856 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
857 /* translators: format is "Location, $date" */
858 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
860 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
866 /* Prepare the location information grid */
867 if (information->grid_location != NULL)
869 gtk_widget_destroy (information->grid_location);
872 information->grid_location = gtk_grid_new ();
873 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
874 information->grid_location, FALSE, FALSE, 5);
877 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
879 const gchar* user_label;
883 gvalue = g_hash_table_lookup (location, (gpointer) skey);
887 user_label = location_key_to_label (skey);
889 label = gtk_label_new (user_label);
890 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
891 gtk_grid_attach (GTK_GRID (information->grid_location),
892 label, 0, row, 1, 1);
893 gtk_widget_show (label);
895 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
898 dvalue = g_value_get_double (gvalue);
899 svalue = g_strdup_printf ("%f", dvalue);
901 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
903 svalue = g_value_dup_string (gvalue);
905 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
909 time_ = g_value_get_int64 (value);
910 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
915 label = gtk_label_new (svalue);
916 gtk_grid_attach (GTK_GRID (information->grid_location),
917 label, 1, row, 1, 1);
918 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
919 gtk_widget_show (label);
921 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
922 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
929 #ifdef HAVE_LIBCHAMPLAIN
931 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
933 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
941 /* We can display some fields */
942 gtk_widget_show (information->grid_location);
944 else if (!display_map)
946 /* Can't display either fields or map */
947 gtk_widget_hide (information->vbox_location);
951 #ifdef HAVE_LIBCHAMPLAIN
954 ClutterActor *marker;
955 ChamplainMarkerLayer *layer;
957 information->map_view_embed = gtk_champlain_embed_new ();
958 information->map_view = gtk_champlain_embed_get_view (
959 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
961 gtk_container_add (GTK_CONTAINER (information->viewport_map),
962 information->map_view_embed);
963 g_object_set (G_OBJECT (information->map_view),
964 "kinetic-mode", TRUE,
968 layer = champlain_marker_layer_new ();
969 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
971 marker = champlain_label_new_with_text (
972 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
973 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
974 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
976 champlain_view_center_on (information->map_view, lat, lon);
977 gtk_widget_show_all (information->viewport_map);
981 gtk_widget_show (information->vbox_location);
985 save_avatar_menu_activate_cb (GtkWidget *widget,
986 EmpathyContactWidget *information)
989 EmpathyAvatar *avatar;
990 gchar *ext = NULL, *filename;
992 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
994 GTK_FILE_CHOOSER_ACTION_SAVE,
995 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
996 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
999 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1002 /* look for the avatar extension */
1003 avatar = empathy_contact_get_avatar (information->contact);
1004 if (avatar->format != NULL)
1008 splitted = g_strsplit (avatar->format, "/", 2);
1009 if (splitted[0] != NULL && splitted[1] != NULL)
1010 ext = g_strdup (splitted[1]);
1012 g_strfreev (splitted);
1016 /* Avatar was loaded from the cache so was converted to PNG */
1017 ext = g_strdup ("png");
1024 id = tp_escape_as_identifier (empathy_contact_get_id (
1025 information->contact));
1027 filename = g_strdup_printf ("%s.%s", id, ext);
1028 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1035 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1037 GError *error = NULL;
1039 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1041 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1044 GtkWidget *error_dialog;
1046 error_dialog = gtk_message_dialog_new (NULL, 0,
1047 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1048 _("Unable to save avatar"));
1050 gtk_message_dialog_format_secondary_text (
1051 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1053 g_signal_connect (error_dialog, "response",
1054 G_CALLBACK (gtk_widget_destroy), NULL);
1056 gtk_window_present (GTK_WINDOW (error_dialog));
1058 g_clear_error (&error);
1064 gtk_widget_destroy (dialog);
1068 popup_avatar_menu (EmpathyContactWidget *information,
1070 GdkEventButton *event)
1072 GtkWidget *menu, *item;
1073 gint button, event_time;
1075 if (information->contact == NULL ||
1076 empathy_contact_get_avatar (information->contact) == NULL)
1079 menu = empathy_context_menu_new (parent);
1081 /* Add "Save as..." entry */
1082 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1083 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1084 gtk_widget_show (item);
1086 g_signal_connect (item, "activate",
1087 G_CALLBACK (save_avatar_menu_activate_cb), information);
1091 button = event->button;
1092 event_time = event->time;
1097 event_time = gtk_get_current_event_time ();
1100 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1101 button, event_time);
1105 widget_avatar_popup_menu_cb (GtkWidget *widget,
1106 EmpathyContactWidget *information)
1108 popup_avatar_menu (information, widget, NULL);
1114 widget_avatar_button_press_event_cb (GtkWidget *widget,
1115 GdkEventButton *event,
1116 EmpathyContactWidget *information)
1118 /* Ignore double-clicks and triple-clicks */
1119 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1121 popup_avatar_menu (information, widget, event);
1129 set_avatar_cb (GObject *source,
1133 GError *error = NULL;
1135 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1136 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1137 g_error_free (error);
1142 set_avatar_on_account (TpAccount *account,
1145 const gchar *mime_type)
1147 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1148 tp_proxy_get_object_path (account));
1150 tp_account_set_avatar_async (account, (const guchar *) data, size,
1151 mime_type, set_avatar_cb, NULL);
1155 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1156 EmpathyContactWidget *information)
1160 const gchar *mime_type;
1163 empathy_avatar_chooser_get_image_data (
1164 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1165 &data, &size, &mime_type);
1167 account = empathy_contact_get_account (information->contact);
1168 set_avatar_on_account (account, data, size, mime_type);
1172 set_nickname_cb (GObject *source,
1176 GError *error = NULL;
1178 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1180 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1181 g_error_free (error);
1185 /* Update all the contact info fields having the
1186 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1187 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1190 update_nickname_in_contact_info (EmpathyContactWidget *self,
1191 TpConnection *connection,
1192 const gchar *nickname)
1196 specs = tp_connection_get_contact_info_supported_fields (connection);
1198 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1200 TpContactInfoField *field = l->data;
1201 TpContactInfoFieldSpec *spec;
1203 spec = get_spec_from_list (specs, field->field_name);
1204 /* We shouldn't have added the field to details_to_set if it's not
1205 * supported by the CM */
1206 g_assert (spec != NULL);
1208 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1210 const gchar *strv[] = { nickname, NULL };
1212 DEBUG ("Updating field '%s' to '%s' as it has the "
1213 "Overwritten_By_Nickname flag and Account.Nickname has "
1214 "been updated", field->field_name, nickname);
1216 if (field->field_value != NULL)
1217 g_strfreev (field->field_value);
1218 field->field_value = g_strdupv ((GStrv) strv);
1222 g_list_free (specs);
1226 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1227 GdkEventFocus *event,
1228 EmpathyContactWidget *information)
1230 if (information->contact)
1234 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1236 if (empathy_contact_is_user (information->contact))
1238 TpAccount * account;
1239 const gchar *current_nickname;
1241 account = empathy_contact_get_account (information->contact);
1242 current_nickname = tp_account_get_nickname (account);
1244 if (tp_strdiff (current_nickname, alias))
1246 DEBUG ("Set Account.Nickname to %s", alias);
1248 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1251 update_nickname_in_contact_info (information,
1252 empathy_contact_get_connection (information->contact), alias);
1257 empathy_contact_set_alias (information->contact, alias);
1265 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1266 EmpathyAvatarChooser *avatar_chooser)
1270 account = empathy_account_chooser_get_account (account_chooser);
1271 if (account == NULL)
1274 empathy_avatar_chooser_set_account (avatar_chooser, account);
1278 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1280 EmpathyAvatar *avatar = NULL;
1282 if (information->contact)
1283 avatar = empathy_contact_get_avatar (information->contact);
1285 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1287 g_signal_handlers_block_by_func (information->widget_avatar,
1288 contact_widget_avatar_changed_cb,
1290 empathy_avatar_chooser_set (
1291 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1292 g_signal_handlers_unblock_by_func (information->widget_avatar,
1293 contact_widget_avatar_changed_cb, information);
1296 empathy_avatar_image_set (
1297 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1301 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1303 if (GTK_IS_ENTRY (information->widget_alias))
1304 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1305 empathy_contact_get_alias (information->contact));
1307 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1308 empathy_contact_get_alias (information->contact));
1312 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1314 const gchar *status;
1315 gchar *markup_text = NULL;
1317 status = empathy_contact_get_status (information->contact);
1319 markup_text = empathy_add_link_markup (status);
1320 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1321 g_free (markup_text);
1323 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1324 empathy_icon_name_for_contact (information->contact),
1325 GTK_ICON_SIZE_BUTTON);
1326 gtk_widget_show (information->image_state);
1330 contact_widget_remove_contact (EmpathyContactWidget *information)
1332 if (information->contact)
1334 TpContact *tp_contact;
1336 contact_widget_save (information);
1338 g_signal_handlers_disconnect_by_func (information->contact,
1339 contact_widget_name_notify_cb, information);
1340 g_signal_handlers_disconnect_by_func (information->contact,
1341 contact_widget_presence_notify_cb, information);
1342 g_signal_handlers_disconnect_by_func (information->contact,
1343 contact_widget_avatar_notify_cb, information);
1345 tp_contact = empathy_contact_get_tp_contact (information->contact);
1346 if (tp_contact != NULL)
1348 g_signal_handlers_disconnect_by_func (tp_contact,
1349 contact_widget_details_notify_cb, information);
1352 g_object_unref (information->contact);
1353 information->contact = NULL;
1356 if (information->details_cancellable != NULL)
1358 g_cancellable_cancel (information->details_cancellable);
1359 tp_clear_object (&information->details_cancellable);
1363 static void contact_widget_change_contact (EmpathyContactWidget *information);
1366 contact_widget_contact_update (EmpathyContactWidget *information)
1368 TpAccount *account = NULL;
1369 const gchar *id = NULL;
1371 /* Connect and get info from new contact */
1372 if (information->contact)
1374 g_signal_connect_swapped (information->contact, "notify::name",
1375 G_CALLBACK (contact_widget_name_notify_cb), information);
1376 g_signal_connect_swapped (information->contact, "notify::presence",
1377 G_CALLBACK (contact_widget_presence_notify_cb), information);
1378 g_signal_connect_swapped (information->contact,
1379 "notify::presence-message",
1380 G_CALLBACK (contact_widget_presence_notify_cb), information);
1381 g_signal_connect_swapped (information->contact, "notify::avatar",
1382 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1384 account = empathy_contact_get_account (information->contact);
1385 id = empathy_contact_get_id (information->contact);
1388 /* Update account widget */
1389 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1393 g_signal_handlers_block_by_func (information->widget_account,
1394 contact_widget_change_contact,
1396 empathy_account_chooser_set_account (
1397 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1398 g_signal_handlers_unblock_by_func (information->widget_account,
1399 contact_widget_change_contact, information);
1408 name = tp_account_get_display_name (account);
1409 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1411 name = tp_account_get_icon_name (account);
1412 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1413 name, GTK_ICON_SIZE_MENU);
1417 /* Update id widget */
1418 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1419 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1421 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1423 /* Update other widgets */
1424 if (information->contact)
1426 contact_widget_name_notify_cb (information);
1427 contact_widget_presence_notify_cb (information);
1428 contact_widget_avatar_notify_cb (information);
1430 gtk_widget_show (information->label_alias);
1431 gtk_widget_show (information->widget_alias);
1432 gtk_widget_show (information->widget_avatar);
1434 gtk_widget_set_visible (information->hbox_presence,
1435 !(information->flags & EMPATHY_CONTACT_WIDGET_NO_STATUS));
1437 if (empathy_contact_is_user (information->contact))
1438 gtk_label_set_text (GTK_LABEL (information->label_details),
1439 _("Personal Details"));
1441 gtk_label_set_text (GTK_LABEL (information->label_details),
1442 _("Contact Details"));
1446 gtk_widget_hide (information->label_alias);
1447 gtk_widget_hide (information->widget_alias);
1448 gtk_widget_hide (information->hbox_presence);
1449 gtk_widget_hide (information->widget_avatar);
1454 contact_widget_set_contact (EmpathyContactWidget *information,
1455 EmpathyContact *contact)
1457 if (contact == information->contact)
1460 contact_widget_remove_contact (information);
1462 information->contact = g_object_ref (contact);
1464 /* set the selected account to be the account this contact came from */
1465 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1466 empathy_account_chooser_set_account (
1467 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1468 empathy_contact_get_account (contact));
1471 /* Update information for widgets */
1472 contact_widget_contact_update (information);
1473 contact_widget_groups_update (information);
1474 contact_widget_details_update (information);
1475 contact_widget_client_update (information);
1476 contact_widget_location_update (information);
1480 contact_widget_got_contact_cb (TpConnection *connection,
1481 EmpathyContact *contact,
1482 const GError *error,
1484 GObject *weak_object)
1486 EmpathyContactWidget *information = user_data;
1490 DEBUG ("Error: %s", error->message);
1494 contact_widget_set_contact (information, contact);
1498 contact_widget_change_contact (EmpathyContactWidget *information)
1500 TpConnection *connection;
1502 connection = empathy_account_chooser_get_connection (
1503 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1507 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1511 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1512 if (!EMP_STR_EMPTY (id))
1514 empathy_tp_contact_factory_get_from_id (connection, id,
1515 contact_widget_got_contact_cb, information, NULL,
1516 G_OBJECT (information->vbox_contact_widget));
1521 empathy_tp_contact_factory_get_from_handle (connection,
1522 tp_connection_get_self_handle (connection),
1523 contact_widget_got_contact_cb, information, NULL,
1524 G_OBJECT (information->vbox_contact_widget));
1529 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1531 contact_widget_change_contact (self);
1536 contact_widget_id_changed_cb (GtkEntry *entry,
1537 EmpathyContactWidget *self)
1539 if (self->widget_id_timeout != 0)
1541 g_source_remove (self->widget_id_timeout);
1544 self->widget_id_timeout =
1545 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1546 (GSourceFunc) contact_widget_id_activate_timeout, self);
1550 contact_widget_id_focus_out_cb (GtkWidget *widget,
1551 GdkEventFocus *event,
1552 EmpathyContactWidget *information)
1554 contact_widget_change_contact (information);
1559 contact_widget_contact_setup (EmpathyContactWidget *information)
1561 information->label_status = gtk_label_new ("");
1562 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1563 PANGO_WRAP_WORD_CHAR);
1564 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1566 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1568 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1569 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1571 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1572 information->label_status, TRUE, TRUE, 0);
1573 gtk_widget_show (information->label_status);
1575 /* Setup account label/chooser */
1576 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1578 information->widget_account = empathy_account_chooser_new ();
1580 g_signal_connect_swapped (information->widget_account, "changed",
1581 G_CALLBACK (contact_widget_change_contact),
1586 /* Pack the protocol icon with the account name in an hbox */
1587 information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1589 information->label_account = gtk_label_new (NULL);
1590 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1591 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1593 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1594 gtk_widget_show (information->label_account);
1596 information->image_account = gtk_image_new ();
1597 gtk_widget_show (information->image_account);
1599 gtk_box_pack_start (GTK_BOX (information->widget_account),
1600 information->image_account, FALSE, FALSE, 0);
1601 gtk_box_pack_start (GTK_BOX (information->widget_account),
1602 information->label_account, FALSE, TRUE, 0);
1605 gtk_grid_attach (GTK_GRID (information->grid_contact),
1606 information->widget_account,
1609 gtk_widget_show (information->widget_account);
1611 /* Set up avatar chooser/display */
1612 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1614 information->widget_avatar = empathy_avatar_chooser_new ();
1615 g_signal_connect (information->widget_avatar, "changed",
1616 G_CALLBACK (contact_widget_avatar_changed_cb),
1618 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1620 g_signal_connect (information->widget_account, "changed",
1621 G_CALLBACK (update_avatar_chooser_account_cb),
1622 information->widget_avatar);
1623 update_avatar_chooser_account_cb (
1624 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1625 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1630 information->widget_avatar = empathy_avatar_image_new ();
1632 g_signal_connect (information->widget_avatar, "popup-menu",
1633 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1634 g_signal_connect (information->widget_avatar, "button-press-event",
1635 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1638 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1639 information->widget_avatar,
1642 gtk_widget_show (information->widget_avatar);
1644 /* Setup id label/entry */
1645 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1647 information->widget_id = gtk_entry_new ();
1648 g_signal_connect (information->widget_id, "focus-out-event",
1649 G_CALLBACK (contact_widget_id_focus_out_cb),
1651 g_signal_connect (information->widget_id, "changed",
1652 G_CALLBACK (contact_widget_id_changed_cb),
1657 information->widget_id = gtk_label_new (NULL);
1658 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1659 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1661 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1664 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1667 gtk_widget_show (information->widget_id);
1669 /* Setup alias label/entry */
1670 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1672 information->widget_alias = gtk_entry_new ();
1674 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1675 g_signal_connect (information->widget_alias, "focus-out-event",
1676 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1679 /* Make return activate the window default (the Close button) */
1680 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1685 information->widget_alias = gtk_label_new (NULL);
1686 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1687 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1689 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1692 gtk_grid_attach (GTK_GRID (information->grid_contact),
1693 information->widget_alias, 1, 2, 1, 1);
1695 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1696 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1698 gtk_widget_show (information->widget_alias);
1702 contact_widget_destroy_cb (GtkWidget *widget,
1703 EmpathyContactWidget *information)
1705 contact_widget_remove_contact (information);
1707 if (information->widget_id_timeout != 0)
1709 g_source_remove (information->widget_id_timeout);
1712 g_slice_free (EmpathyContactWidget, information);
1716 * empathy_contact_widget_new:
1717 * @contact: an #EmpathyContact
1718 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1720 * Creates a new #EmpathyContactWidget.
1722 * Return value: a new #EmpathyContactWidget
1725 empathy_contact_widget_new (EmpathyContact *contact,
1726 EmpathyContactWidgetFlags flags)
1728 EmpathyContactWidget *information;
1732 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1734 information = g_slice_new0 (EmpathyContactWidget);
1735 information->flags = flags;
1737 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1739 gui = empathy_builder_get_file (filename,
1740 "vbox_contact_widget", &information->vbox_contact_widget,
1741 "hbox_presence", &information->hbox_presence,
1742 "label_alias", &information->label_alias,
1743 "image_state", &information->image_state,
1744 "grid_contact", &information->grid_contact,
1745 "vbox_avatar", &information->vbox_avatar,
1746 "vbox_location", &information->vbox_location,
1747 "subvbox_location", &information->subvbox_location,
1748 "label_location", &information->label_location,
1749 #ifdef HAVE_LIBCHAMPLAIN
1750 "viewport_map", &information->viewport_map,
1752 "groups_widget", &information->groups_widget,
1753 "vbox_details", &information->vbox_details,
1754 "grid_details", &information->grid_details,
1755 "hbox_details_requested", &information->hbox_details_requested,
1756 "vbox_client", &information->vbox_client,
1757 "grid_client", &information->grid_client,
1758 "hbox_client_requested", &information->hbox_client_requested,
1759 "label_details", &information->label_details,
1763 empathy_builder_connect (gui, information,
1764 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1766 information->grid_location = NULL;
1768 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1769 "EmpathyContactWidget",
1772 /* Create widgets */
1773 contact_widget_contact_setup (information);
1774 contact_widget_details_setup (information);
1775 contact_widget_client_setup (information);
1777 if (contact != NULL)
1778 contact_widget_set_contact (information, contact);
1779 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1780 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1781 contact_widget_change_contact (information);
1783 return empathy_builder_unref_and_keep_widget (gui,
1784 information->vbox_contact_widget);
1788 * empathy_contact_widget_get_contact:
1789 * @widget: an #EmpathyContactWidget
1791 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1793 * Returns: the #EmpathyContact associated with @widget
1796 empathy_contact_widget_get_contact (GtkWidget *widget)
1798 EmpathyContactWidget *information;
1800 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1802 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1806 return information->contact;
1810 empathy_contact_widget_get_alias (GtkWidget *widget)
1812 EmpathyContactWidget *information;
1814 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1816 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1820 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1824 * empathy_contact_widget_set_contact:
1825 * @widget: an #EmpathyContactWidget
1826 * @contact: a different #EmpathyContact
1828 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1831 empathy_contact_widget_set_contact (GtkWidget *widget,
1832 EmpathyContact *contact)
1834 EmpathyContactWidget *information;
1836 g_return_if_fail (GTK_IS_WIDGET (widget));
1837 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1839 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1843 contact_widget_set_contact (information, contact);
1847 * empathy_contact_widget_set_account_filter:
1848 * @widget: an #EmpathyContactWidget
1849 * @filter: a #EmpathyAccountChooserFilterFunc
1850 * @user_data: user data to pass to @filter, or %NULL
1852 * Set a filter on the #EmpathyAccountChooser included in the
1853 * #EmpathyContactWidget.
1856 empathy_contact_widget_set_account_filter (
1858 EmpathyAccountChooserFilterFunc filter,
1861 EmpathyContactWidget *information;
1862 EmpathyAccountChooser *chooser;
1864 g_return_if_fail (GTK_IS_WIDGET (widget));
1866 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1870 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1872 empathy_account_chooser_set_filter (chooser, filter, user_data);