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;
106 GtkWidget *label_left_account;
109 GtkWidget *vbox_location;
110 GtkWidget *subvbox_location;
111 GtkWidget *grid_location;
112 GtkWidget *label_location;
113 #ifdef HAVE_LIBCHAMPLAIN
114 GtkWidget *viewport_map;
115 GtkWidget *map_view_embed;
116 ChamplainView *map_view;
120 GtkWidget *groups_widget;
123 GtkWidget *vbox_details;
124 GtkWidget *grid_details;
125 GtkWidget *hbox_details_requested;
126 GtkWidget *spinner_details;
127 GList *details_to_set;
128 GCancellable *details_cancellable;
129 gboolean details_changed;
132 GtkWidget *vbox_client;
133 GtkWidget *grid_client;
134 GtkWidget *hbox_client_requested;
135 } EmpathyContactWidget;
139 EmpathyContactWidget *information;
142 GtkTreeIter found_iter;
154 field_value_is_empty (TpContactInfoField *field)
158 if (field->field_value == NULL)
161 /* Field is empty if all its values are empty */
162 for (i = 0; field->field_value[i] != NULL; i++)
164 if (!tp_str_empty (field->field_value[i]))
172 set_contact_info_cb (GObject *source,
173 GAsyncResult *result,
176 GError *error = NULL;
178 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
181 DEBUG ("SetContactInfo() failed: %s", error->message);
182 g_error_free (error);
186 DEBUG ("SetContactInfo() succeeded");
190 contact_widget_save (EmpathyContactWidget *information)
192 TpConnection *connection;
195 connection = empathy_contact_get_connection (information->contact);
197 /* Remove empty fields */
198 for (l = information->details_to_set; l != NULL; l = next)
200 TpContactInfoField *field = l->data;
203 if (field_value_is_empty (field))
205 DEBUG ("Drop empty field: %s", field->field_name);
206 tp_contact_info_field_free (field);
207 information->details_to_set =
208 g_list_delete_link (information->details_to_set, l);
212 if (information->details_to_set != NULL)
214 if (information->details_changed)
216 tp_connection_set_contact_info_async (connection,
217 information->details_to_set, set_contact_info_cb, NULL);
220 tp_contact_info_list_free (information->details_to_set);
221 information->details_to_set = NULL;
226 contact_widget_details_setup (EmpathyContactWidget *information)
228 gtk_widget_hide (information->vbox_details);
230 information->spinner_details = gtk_spinner_new ();
231 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
232 information->spinner_details, TRUE, TRUE, 0);
233 gtk_widget_show (information->spinner_details);
237 contact_widget_details_changed_cb (GtkEntry *entry,
238 EmpathyContactWidget *self)
240 const gchar *strv[] = { NULL, NULL };
241 TpContactInfoField *field;
243 self->details_changed = TRUE;
245 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
246 g_assert (field != NULL);
248 strv[0] = gtk_entry_get_text (entry);
250 if (field->field_value != NULL)
251 g_strfreev (field->field_value);
252 field->field_value = g_strdupv ((GStrv) strv);
256 contact_widget_bday_changed_cb (EmpathyCalendarButton *button,
258 EmpathyContactWidget *self)
260 const gchar *strv[] = { NULL, NULL };
261 TpContactInfoField *field;
263 self->details_changed = TRUE;
265 field = g_object_get_data ((GObject *) button, DATA_FIELD);
266 g_assert (field != NULL);
272 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT,
277 if (field->field_value != NULL)
278 g_strfreev (field->field_value);
279 field->field_value = g_strdupv ((GStrv) strv);
282 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
285 field_name_in_field_list (GList *list,
290 for (l = list; l != NULL; l = g_list_next (l))
292 TpContactInfoField *field = l->data;
294 if (!tp_strdiff (field->field_name, name))
301 static TpContactInfoFieldSpec *
302 get_spec_from_list (GList *list,
307 for (l = list; l != NULL; l = g_list_next (l))
309 TpContactInfoFieldSpec *spec = l->data;
311 if (!tp_strdiff (spec->name, name))
319 contact_widget_details_update_edit (EmpathyContactWidget *information)
322 TpConnection *connection;
326 const char **field_names = empathy_contact_info_get_field_names (NULL);
329 g_assert (information->details_to_set == NULL);
331 information->details_changed = FALSE;
333 contact = empathy_contact_get_tp_contact (information->contact);
334 connection = tp_contact_get_connection (contact);
336 info = tp_contact_get_contact_info (contact);
338 specs = tp_connection_get_contact_info_supported_fields (connection);
340 /* Look at the fields set in our vCard */
341 for (l = info; l != NULL; l = l->next)
343 TpContactInfoField *field = l->data;
345 /* make a copy for the details_to_set list */
346 field = tp_contact_info_field_copy (field);
347 DEBUG ("Field %s is in our vCard", field->field_name);
349 information->details_to_set = g_list_prepend (information->details_to_set,
353 /* Add fields which are supported but not in the vCard */
354 for (i = 0; field_names[i] != NULL; i++)
356 TpContactInfoFieldSpec *spec;
357 TpContactInfoField *field;
359 /* Check if the field was in the vCard */
360 if (field_name_in_field_list (information->details_to_set,
364 /* Check if the CM supports the field */
365 spec = get_spec_from_list (specs, field_names[i]);
369 /* add an empty field so user can set a value */
370 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
372 information->details_to_set = g_list_prepend (information->details_to_set,
376 /* Add widgets for supported fields */
377 information->details_to_set = g_list_sort (information->details_to_set,
378 (GCompareFunc) empathy_contact_info_field_spec_cmp);
380 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
382 TpContactInfoField *field = l->data;
384 TpContactInfoFieldSpec *spec;
388 has_field = empathy_contact_info_lookup_field (field->field_name,
392 /* Empathy doesn't display this field so we can't change it.
393 * But we put it in the details_to_set list so it won't be erased
394 * when calling SetContactInfo (bgo #630427) */
395 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
399 spec = get_spec_from_list (specs, field->field_name);
400 /* We shouldn't have added the field to details_to_set if it's not
401 * supported by the CM */
402 g_assert (spec != NULL);
404 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
406 DEBUG ("Ignoring field '%s' due it to having the "
407 "Overwritten_By_Nickname flag", field->field_name);
412 title = empathy_contact_info_field_label (field->field_name,
414 (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT));
415 w = gtk_label_new (title);
418 /* TODO: if TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT is not set we
419 * should allow user to tag the vCard fields (bgo#672034) */
421 gtk_grid_attach (GTK_GRID (information->grid_details),
424 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
428 if (!tp_strdiff (field->field_name, "bday"))
430 w = empathy_calendar_button_new ();
432 if (field->field_value[0])
436 g_date_set_parse (&date, field->field_value[0]);
437 if (g_date_valid (&date))
439 empathy_calendar_button_set_date (EMPATHY_CALENDAR_BUTTON (w),
444 gtk_grid_attach (GTK_GRID (information->grid_details),
446 gtk_widget_show_all (w);
448 g_object_set_data ((GObject *) w, DATA_FIELD, field);
450 g_signal_connect (w, "date-changed",
451 G_CALLBACK (contact_widget_bday_changed_cb), information);
455 w = gtk_entry_new ();
456 gtk_entry_set_text (GTK_ENTRY (w),
457 field->field_value[0] ? field->field_value[0] : "");
458 gtk_grid_attach (GTK_GRID (information->grid_details),
462 g_object_set_data ((GObject *) w, DATA_FIELD, field);
464 g_signal_connect (w, "changed",
465 G_CALLBACK (contact_widget_details_changed_cb), information);
478 add_row (GtkGrid *grid,
483 gtk_grid_attach (grid, title, 0, row, 1, 1);
484 gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
485 gtk_widget_show (title);
487 gtk_grid_attach (grid, value, 1, row, 1, 1);
488 gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
489 gtk_widget_show (value);
493 contact_widget_details_update_show (EmpathyContactWidget *information)
498 GtkWidget *channels_label;
501 contact = empathy_contact_get_tp_contact (information->contact);
502 info = tp_contact_get_contact_info (contact);
503 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
504 for (l = info; l != NULL; l = l->next)
506 TpContactInfoField *field = l->data;
508 gchar *markup = NULL, *title;
509 GtkWidget *title_widget, *value_widget;
510 EmpathyContactInfoFormatFunc format;
512 if (field->field_value == NULL || field->field_value[0] == NULL)
515 value = field->field_value[0];
517 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
519 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
525 markup = format (field->field_value);
529 DEBUG ("Invalid value for field '%s' (first element was '%s')",
530 field->field_name, field->field_value[0]);
536 title = empathy_contact_info_field_label (field->field_name,
537 field->parameters, TRUE);
538 title_widget = gtk_label_new (title);
542 value_widget = gtk_label_new (value);
545 gtk_label_set_markup (GTK_LABEL (value_widget), markup);
549 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
550 gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
552 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
558 account = empathy_contact_get_account (information->contact);
560 channels_label = empathy_contact_info_create_channel_list_label (account,
563 if (channels_label != NULL)
565 GtkWidget *title_widget;
567 title_widget = gtk_label_new (_("Channels:"));
569 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
581 contact_widget_details_notify_cb (EmpathyContactWidget *information)
585 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
586 (GtkCallback) gtk_widget_destroy, NULL);
588 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
589 n_rows = contact_widget_details_update_edit (information);
591 n_rows = contact_widget_details_update_show (information);
595 gtk_widget_show (information->vbox_details);
596 gtk_widget_show (information->grid_details);
600 gtk_widget_hide (information->vbox_details);
603 gtk_widget_hide (information->hbox_details_requested);
604 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
608 contact_widget_details_request_cb (GObject *object,
612 TpContact *contact = TP_CONTACT (object);
613 EmpathyContactWidget *information = user_data;
614 GError *error = NULL;
616 if (!tp_contact_request_contact_info_finish (contact, res, &error))
618 /* If the request got cancelled it could mean the contact widget is
619 * destroyed, so we should not dereference information */
620 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
622 g_clear_error (&error);
626 gtk_widget_hide (information->vbox_details);
627 g_clear_error (&error);
631 contact_widget_details_notify_cb (information);
634 /* If we are going to edit ContactInfo, we don't want live updates */
635 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
637 g_signal_connect_swapped (contact, "notify::contact-info",
638 G_CALLBACK (contact_widget_details_notify_cb), information);
641 tp_clear_object (&information->details_cancellable);
645 fetch_contact_information (EmpathyContactWidget *information,
646 TpConnection *connection)
649 TpContactInfoFlags flags;
651 if (!tp_proxy_has_interface_by_id (connection,
652 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
654 gtk_widget_hide (information->vbox_details);
658 /* If we want to edit info, but connection does not support that, stop */
659 flags = tp_connection_get_contact_info_flags (connection);
660 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
661 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
663 gtk_widget_hide (information->vbox_details);
667 /* Request the contact's info */
668 gtk_widget_show (information->vbox_details);
669 gtk_widget_show (information->hbox_details_requested);
670 gtk_widget_hide (information->grid_details);
671 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
673 contact = empathy_contact_get_tp_contact (information->contact);
674 g_assert (information->details_cancellable == NULL);
675 information->details_cancellable = g_cancellable_new ();
676 tp_contact_request_contact_info_async (contact,
677 information->details_cancellable, contact_widget_details_request_cb,
682 contact_widget_details_update (EmpathyContactWidget *information)
684 TpContact *tp_contact = NULL;
686 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
687 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
690 gtk_widget_hide (information->vbox_details);
692 if (information->contact != NULL)
693 tp_contact = empathy_contact_get_tp_contact (information->contact);
695 if (tp_contact != NULL)
697 TpConnection *connection;
699 connection = tp_contact_get_connection (tp_contact);
701 fetch_contact_information (information, connection);
706 contact_widget_client_update (EmpathyContactWidget *information)
708 /* FIXME: Needs new telepathy spec */
712 contact_widget_client_setup (EmpathyContactWidget *information)
714 /* FIXME: Needs new telepathy spec */
715 gtk_widget_hide (information->vbox_client);
719 contact_widget_groups_update (EmpathyContactWidget *information)
721 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
722 information->contact != NULL)
724 FolksPersona *persona =
725 empathy_contact_get_persona (information->contact);
727 if (FOLKS_IS_GROUP_DETAILS (persona))
729 empathy_groups_widget_set_group_details (
730 EMPATHY_GROUPS_WIDGET (information->groups_widget),
731 FOLKS_GROUP_DETAILS (persona));
732 gtk_widget_show (information->groups_widget);
738 /* In case of failure */
739 gtk_widget_hide (information->groups_widget);
742 /* Converts the Location's GHashTable's key to a user readable string */
744 location_key_to_label (const gchar *key)
746 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
747 return _("Country ISO Code:");
748 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
749 return _("Country:");
750 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
752 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
754 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
756 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
757 return _("Postal Code:");
758 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
760 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
761 return _("Building:");
762 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
764 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
766 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
768 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
769 return _("Description:");
770 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
772 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
773 return _("Accuracy Level:");
774 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
776 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
777 return _("Vertical Error (meters):");
778 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
779 return _("Horizontal Error (meters):");
780 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
782 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
783 return _("Bearing:");
784 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
785 return _("Climb Speed:");
786 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
787 return _("Last Updated on:");
788 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
789 return _("Longitude:");
790 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
791 return _("Latitude:");
792 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
793 return _("Altitude:");
796 DEBUG ("Unexpected Location key: %s", key);
802 contact_widget_location_update (EmpathyContactWidget *information)
804 GHashTable *location;
806 #ifdef HAVE_LIBCHAMPLAIN
807 gdouble lat = 0.0, lon = 0.0;
808 gboolean has_position = TRUE;
812 static const gchar* ordered_geolocation_keys[] = {
813 EMPATHY_LOCATION_TEXT,
814 EMPATHY_LOCATION_URI,
815 EMPATHY_LOCATION_DESCRIPTION,
816 EMPATHY_LOCATION_BUILDING,
817 EMPATHY_LOCATION_FLOOR,
818 EMPATHY_LOCATION_ROOM,
819 EMPATHY_LOCATION_STREET,
820 EMPATHY_LOCATION_AREA,
821 EMPATHY_LOCATION_LOCALITY,
822 EMPATHY_LOCATION_REGION,
823 EMPATHY_LOCATION_COUNTRY,
828 gboolean display_map = FALSE;
830 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
832 gtk_widget_hide (information->vbox_location);
836 location = empathy_contact_get_location (information->contact);
837 if (location == NULL || g_hash_table_size (location) == 0)
839 gtk_widget_hide (information->vbox_location);
843 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
846 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
847 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
857 stamp = g_value_get_int64 (value);
859 user_date = empathy_time_to_string_relative (stamp);
861 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
862 /* translators: format is "Location, $date" */
863 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
865 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
871 /* Prepare the location information grid */
872 if (information->grid_location != NULL)
874 gtk_widget_destroy (information->grid_location);
877 information->grid_location = gtk_grid_new ();
878 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
879 information->grid_location, FALSE, FALSE, 5);
882 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
884 const gchar* user_label;
888 gvalue = g_hash_table_lookup (location, (gpointer) skey);
892 user_label = location_key_to_label (skey);
894 label = gtk_label_new (user_label);
895 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
896 gtk_grid_attach (GTK_GRID (information->grid_location),
897 label, 0, row, 1, 1);
898 gtk_widget_show (label);
900 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
903 dvalue = g_value_get_double (gvalue);
904 svalue = g_strdup_printf ("%f", dvalue);
906 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
908 svalue = g_value_dup_string (gvalue);
910 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
914 time_ = g_value_get_int64 (value);
915 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
920 label = gtk_label_new (svalue);
921 gtk_grid_attach (GTK_GRID (information->grid_location),
922 label, 1, row, 1, 1);
923 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
924 gtk_widget_show (label);
926 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
927 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
934 #ifdef HAVE_LIBCHAMPLAIN
936 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
938 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
946 /* We can display some fields */
947 gtk_widget_show (information->grid_location);
949 else if (!display_map)
951 /* Can't display either fields or map */
952 gtk_widget_hide (information->vbox_location);
956 #ifdef HAVE_LIBCHAMPLAIN
959 ClutterActor *marker;
960 ChamplainMarkerLayer *layer;
962 information->map_view_embed = gtk_champlain_embed_new ();
963 information->map_view = gtk_champlain_embed_get_view (
964 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
966 gtk_container_add (GTK_CONTAINER (information->viewport_map),
967 information->map_view_embed);
968 g_object_set (G_OBJECT (information->map_view),
969 "kinetic-mode", TRUE,
973 layer = champlain_marker_layer_new ();
974 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
976 marker = champlain_label_new_with_text (
977 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
978 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
979 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
981 champlain_view_center_on (information->map_view, lat, lon);
982 gtk_widget_show_all (information->viewport_map);
986 gtk_widget_show (information->vbox_location);
990 save_avatar_menu_activate_cb (GtkWidget *widget,
991 EmpathyContactWidget *information)
994 EmpathyAvatar *avatar;
995 gchar *ext = NULL, *filename;
997 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
999 GTK_FILE_CHOOSER_ACTION_SAVE,
1000 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1001 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1004 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1007 /* look for the avatar extension */
1008 avatar = empathy_contact_get_avatar (information->contact);
1009 if (avatar->format != NULL)
1013 splitted = g_strsplit (avatar->format, "/", 2);
1014 if (splitted[0] != NULL && splitted[1] != NULL)
1015 ext = g_strdup (splitted[1]);
1017 g_strfreev (splitted);
1021 /* Avatar was loaded from the cache so was converted to PNG */
1022 ext = g_strdup ("png");
1029 id = tp_escape_as_identifier (empathy_contact_get_id (
1030 information->contact));
1032 filename = g_strdup_printf ("%s.%s", id, ext);
1033 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1040 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1042 GError *error = NULL;
1044 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1046 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1049 GtkWidget *error_dialog;
1051 error_dialog = gtk_message_dialog_new (NULL, 0,
1052 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1053 _("Unable to save avatar"));
1055 gtk_message_dialog_format_secondary_text (
1056 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1058 g_signal_connect (error_dialog, "response",
1059 G_CALLBACK (gtk_widget_destroy), NULL);
1061 gtk_window_present (GTK_WINDOW (error_dialog));
1063 g_clear_error (&error);
1069 gtk_widget_destroy (dialog);
1073 popup_avatar_menu (EmpathyContactWidget *information,
1075 GdkEventButton *event)
1077 GtkWidget *menu, *item;
1078 gint button, event_time;
1080 if (information->contact == NULL ||
1081 empathy_contact_get_avatar (information->contact) == NULL)
1084 menu = empathy_context_menu_new (parent);
1086 /* Add "Save as..." entry */
1087 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1088 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1089 gtk_widget_show (item);
1091 g_signal_connect (item, "activate",
1092 G_CALLBACK (save_avatar_menu_activate_cb), information);
1096 button = event->button;
1097 event_time = event->time;
1102 event_time = gtk_get_current_event_time ();
1105 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1106 button, event_time);
1110 widget_avatar_popup_menu_cb (GtkWidget *widget,
1111 EmpathyContactWidget *information)
1113 popup_avatar_menu (information, widget, NULL);
1119 widget_avatar_button_press_event_cb (GtkWidget *widget,
1120 GdkEventButton *event,
1121 EmpathyContactWidget *information)
1123 /* Ignore double-clicks and triple-clicks */
1124 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1126 popup_avatar_menu (information, widget, event);
1134 set_avatar_cb (GObject *source,
1138 GError *error = NULL;
1140 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1141 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1142 g_error_free (error);
1147 set_avatar_on_account (TpAccount *account,
1150 const gchar *mime_type)
1152 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1153 tp_proxy_get_object_path (account));
1155 tp_account_set_avatar_async (account, (const guchar *) data, size,
1156 mime_type, set_avatar_cb, NULL);
1160 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1161 EmpathyContactWidget *information)
1165 const gchar *mime_type;
1168 empathy_avatar_chooser_get_image_data (
1169 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1170 &data, &size, &mime_type);
1172 account = empathy_contact_get_account (information->contact);
1173 set_avatar_on_account (account, data, size, mime_type);
1177 set_nickname_cb (GObject *source,
1181 GError *error = NULL;
1183 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1185 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1186 g_error_free (error);
1190 /* Update all the contact info fields having the
1191 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1192 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1195 update_nickname_in_contact_info (EmpathyContactWidget *self,
1196 TpConnection *connection,
1197 const gchar *nickname)
1201 specs = tp_connection_get_contact_info_supported_fields (connection);
1203 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1205 TpContactInfoField *field = l->data;
1206 TpContactInfoFieldSpec *spec;
1208 spec = get_spec_from_list (specs, field->field_name);
1209 /* We shouldn't have added the field to details_to_set if it's not
1210 * supported by the CM */
1211 g_assert (spec != NULL);
1213 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1215 const gchar *strv[] = { nickname, NULL };
1217 DEBUG ("Updating field '%s' to '%s' as it has the "
1218 "Overwritten_By_Nickname flag and Account.Nickname has "
1219 "been updated", field->field_name, nickname);
1221 if (field->field_value != NULL)
1222 g_strfreev (field->field_value);
1223 field->field_value = g_strdupv ((GStrv) strv);
1227 g_list_free (specs);
1231 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1232 GdkEventFocus *event,
1233 EmpathyContactWidget *information)
1235 if (information->contact)
1239 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1241 if (empathy_contact_is_user (information->contact))
1243 TpAccount * account;
1244 const gchar *current_nickname;
1246 account = empathy_contact_get_account (information->contact);
1247 current_nickname = tp_account_get_nickname (account);
1249 if (tp_strdiff (current_nickname, alias))
1251 DEBUG ("Set Account.Nickname to %s", alias);
1253 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1256 update_nickname_in_contact_info (information,
1257 empathy_contact_get_connection (information->contact), alias);
1262 empathy_contact_set_alias (information->contact, alias);
1270 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1271 EmpathyAvatarChooser *avatar_chooser)
1275 account = empathy_account_chooser_get_account (account_chooser);
1276 if (account == NULL)
1279 empathy_avatar_chooser_set_account (avatar_chooser, account);
1283 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1285 EmpathyAvatar *avatar = NULL;
1287 if (information->contact)
1288 avatar = empathy_contact_get_avatar (information->contact);
1290 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1292 g_signal_handlers_block_by_func (information->widget_avatar,
1293 contact_widget_avatar_changed_cb,
1295 empathy_avatar_chooser_set (
1296 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1297 g_signal_handlers_unblock_by_func (information->widget_avatar,
1298 contact_widget_avatar_changed_cb, information);
1301 empathy_avatar_image_set (
1302 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1306 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1308 if (GTK_IS_ENTRY (information->widget_alias))
1309 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1310 empathy_contact_get_alias (information->contact));
1312 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1313 empathy_contact_get_alias (information->contact));
1317 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1319 const gchar *status;
1320 gchar *markup_text = NULL;
1322 status = empathy_contact_get_status (information->contact);
1324 markup_text = empathy_add_link_markup (status);
1325 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1326 g_free (markup_text);
1328 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1329 empathy_icon_name_for_contact (information->contact),
1330 GTK_ICON_SIZE_BUTTON);
1331 gtk_widget_show (information->image_state);
1335 contact_widget_remove_contact (EmpathyContactWidget *information)
1337 if (information->contact)
1339 TpContact *tp_contact;
1341 contact_widget_save (information);
1343 g_signal_handlers_disconnect_by_func (information->contact,
1344 contact_widget_name_notify_cb, information);
1345 g_signal_handlers_disconnect_by_func (information->contact,
1346 contact_widget_presence_notify_cb, information);
1347 g_signal_handlers_disconnect_by_func (information->contact,
1348 contact_widget_avatar_notify_cb, information);
1350 tp_contact = empathy_contact_get_tp_contact (information->contact);
1351 if (tp_contact != NULL)
1353 g_signal_handlers_disconnect_by_func (tp_contact,
1354 contact_widget_details_notify_cb, information);
1357 g_object_unref (information->contact);
1358 information->contact = NULL;
1361 if (information->details_cancellable != NULL)
1363 g_cancellable_cancel (information->details_cancellable);
1364 tp_clear_object (&information->details_cancellable);
1368 static void contact_widget_change_contact (EmpathyContactWidget *information);
1371 contact_widget_contact_update (EmpathyContactWidget *information)
1373 TpAccount *account = NULL;
1374 const gchar *id = NULL;
1376 /* Connect and get info from new contact */
1377 if (information->contact)
1379 g_signal_connect_swapped (information->contact, "notify::name",
1380 G_CALLBACK (contact_widget_name_notify_cb), information);
1381 g_signal_connect_swapped (information->contact, "notify::presence",
1382 G_CALLBACK (contact_widget_presence_notify_cb), information);
1383 g_signal_connect_swapped (information->contact,
1384 "notify::presence-message",
1385 G_CALLBACK (contact_widget_presence_notify_cb), information);
1386 g_signal_connect_swapped (information->contact, "notify::avatar",
1387 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1389 account = empathy_contact_get_account (information->contact);
1390 id = empathy_contact_get_id (information->contact);
1393 /* Update account widget */
1394 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1398 g_signal_handlers_block_by_func (information->widget_account,
1399 contact_widget_change_contact,
1401 empathy_account_chooser_set_account (
1402 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1403 g_signal_handlers_unblock_by_func (information->widget_account,
1404 contact_widget_change_contact, information);
1407 else if ((information->flags & EMPATHY_CONTACT_WIDGET_NO_ACCOUNT) == 0)
1413 name = tp_account_get_display_name (account);
1414 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1416 name = tp_account_get_icon_name (account);
1417 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1418 name, GTK_ICON_SIZE_MENU);
1422 /* Update id widget */
1423 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1424 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1426 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1428 /* Update other widgets */
1429 if (information->contact)
1431 contact_widget_name_notify_cb (information);
1432 contact_widget_presence_notify_cb (information);
1433 contact_widget_avatar_notify_cb (information);
1435 gtk_widget_show (information->label_alias);
1436 gtk_widget_show (information->widget_alias);
1437 gtk_widget_show (information->widget_avatar);
1439 gtk_widget_set_visible (information->hbox_presence,
1440 !(information->flags & EMPATHY_CONTACT_WIDGET_NO_STATUS));
1442 if (empathy_contact_is_user (information->contact))
1443 gtk_label_set_text (GTK_LABEL (information->label_details),
1444 _("Personal Details"));
1446 gtk_label_set_text (GTK_LABEL (information->label_details),
1447 _("Contact Details"));
1451 gtk_widget_hide (information->label_alias);
1452 gtk_widget_hide (information->widget_alias);
1453 gtk_widget_hide (information->hbox_presence);
1454 gtk_widget_hide (information->widget_avatar);
1459 contact_widget_set_contact (EmpathyContactWidget *information,
1460 EmpathyContact *contact)
1462 if (contact == information->contact)
1465 contact_widget_remove_contact (information);
1467 information->contact = g_object_ref (contact);
1469 /* set the selected account to be the account this contact came from */
1470 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1471 empathy_account_chooser_set_account (
1472 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1473 empathy_contact_get_account (contact));
1476 /* Update information for widgets */
1477 contact_widget_contact_update (information);
1478 contact_widget_groups_update (information);
1479 contact_widget_details_update (information);
1480 contact_widget_client_update (information);
1481 contact_widget_location_update (information);
1485 contact_widget_got_contact_cb (TpConnection *connection,
1486 EmpathyContact *contact,
1487 const GError *error,
1489 GObject *weak_object)
1491 EmpathyContactWidget *information = user_data;
1495 DEBUG ("Error: %s", error->message);
1499 contact_widget_set_contact (information, contact);
1503 contact_widget_change_contact (EmpathyContactWidget *information)
1505 TpConnection *connection;
1507 connection = empathy_account_chooser_get_connection (
1508 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1512 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1516 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1517 if (!EMP_STR_EMPTY (id))
1519 empathy_tp_contact_factory_get_from_id (connection, id,
1520 contact_widget_got_contact_cb, information, NULL,
1521 G_OBJECT (information->vbox_contact_widget));
1526 empathy_tp_contact_factory_get_from_handle (connection,
1527 tp_connection_get_self_handle (connection),
1528 contact_widget_got_contact_cb, information, NULL,
1529 G_OBJECT (information->vbox_contact_widget));
1534 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1536 contact_widget_change_contact (self);
1541 contact_widget_id_changed_cb (GtkEntry *entry,
1542 EmpathyContactWidget *self)
1544 if (self->widget_id_timeout != 0)
1546 g_source_remove (self->widget_id_timeout);
1549 self->widget_id_timeout =
1550 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1551 (GSourceFunc) contact_widget_id_activate_timeout, self);
1555 contact_widget_id_focus_out_cb (GtkWidget *widget,
1556 GdkEventFocus *event,
1557 EmpathyContactWidget *information)
1559 contact_widget_change_contact (information);
1564 contact_widget_contact_setup (EmpathyContactWidget *information)
1566 information->label_status = gtk_label_new ("");
1567 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1568 PANGO_WRAP_WORD_CHAR);
1569 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1571 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1573 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1574 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1576 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1577 information->label_status, TRUE, TRUE, 0);
1578 gtk_widget_show (information->label_status);
1580 /* Setup account label/chooser */
1581 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1583 information->widget_account = empathy_account_chooser_new ();
1585 g_signal_connect_swapped (information->widget_account, "changed",
1586 G_CALLBACK (contact_widget_change_contact),
1589 else if (information->flags & EMPATHY_CONTACT_WIDGET_NO_ACCOUNT)
1591 /* Don't display the account */
1592 gtk_widget_hide (information->label_left_account);
1596 /* Pack the protocol icon with the account name in an hbox */
1597 information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1599 information->label_account = gtk_label_new (NULL);
1600 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1601 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1603 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1604 gtk_widget_show (information->label_account);
1606 information->image_account = gtk_image_new ();
1607 gtk_widget_show (information->image_account);
1609 gtk_box_pack_start (GTK_BOX (information->widget_account),
1610 information->image_account, FALSE, FALSE, 0);
1611 gtk_box_pack_start (GTK_BOX (information->widget_account),
1612 information->label_account, FALSE, TRUE, 0);
1615 if (information->widget_account != NULL)
1617 gtk_grid_attach (GTK_GRID (information->grid_contact),
1618 information->widget_account,
1621 gtk_widget_show (information->widget_account);
1624 /* Set up avatar chooser/display */
1625 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1627 information->widget_avatar = empathy_avatar_chooser_new ();
1628 g_signal_connect (information->widget_avatar, "changed",
1629 G_CALLBACK (contact_widget_avatar_changed_cb),
1631 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1633 g_signal_connect (information->widget_account, "changed",
1634 G_CALLBACK (update_avatar_chooser_account_cb),
1635 information->widget_avatar);
1636 update_avatar_chooser_account_cb (
1637 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1638 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1643 information->widget_avatar = empathy_avatar_image_new ();
1645 g_signal_connect (information->widget_avatar, "popup-menu",
1646 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1647 g_signal_connect (information->widget_avatar, "button-press-event",
1648 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1651 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1652 information->widget_avatar,
1655 gtk_widget_show (information->widget_avatar);
1657 /* Setup id label/entry */
1658 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1660 information->widget_id = gtk_entry_new ();
1661 g_signal_connect (information->widget_id, "focus-out-event",
1662 G_CALLBACK (contact_widget_id_focus_out_cb),
1664 g_signal_connect (information->widget_id, "changed",
1665 G_CALLBACK (contact_widget_id_changed_cb),
1670 information->widget_id = gtk_label_new (NULL);
1671 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1672 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1674 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1677 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1680 gtk_widget_show (information->widget_id);
1682 /* Setup alias label/entry */
1683 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1685 information->widget_alias = gtk_entry_new ();
1687 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1688 g_signal_connect (information->widget_alias, "focus-out-event",
1689 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1692 /* Make return activate the window default (the Close button) */
1693 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1698 information->widget_alias = gtk_label_new (NULL);
1699 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1700 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1702 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1705 gtk_grid_attach (GTK_GRID (information->grid_contact),
1706 information->widget_alias, 1, 2, 1, 1);
1708 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1709 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1711 gtk_widget_show (information->widget_alias);
1715 contact_widget_destroy_cb (GtkWidget *widget,
1716 EmpathyContactWidget *information)
1718 contact_widget_remove_contact (information);
1720 if (information->widget_id_timeout != 0)
1722 g_source_remove (information->widget_id_timeout);
1725 g_slice_free (EmpathyContactWidget, information);
1729 * empathy_contact_widget_new:
1730 * @contact: an #EmpathyContact
1731 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1733 * Creates a new #EmpathyContactWidget.
1735 * Return value: a new #EmpathyContactWidget
1738 empathy_contact_widget_new (EmpathyContact *contact,
1739 EmpathyContactWidgetFlags flags)
1741 EmpathyContactWidget *information;
1745 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1747 information = g_slice_new0 (EmpathyContactWidget);
1748 information->flags = flags;
1750 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1752 gui = empathy_builder_get_file (filename,
1753 "vbox_contact_widget", &information->vbox_contact_widget,
1754 "hbox_presence", &information->hbox_presence,
1755 "label_alias", &information->label_alias,
1756 "image_state", &information->image_state,
1757 "grid_contact", &information->grid_contact,
1758 "vbox_avatar", &information->vbox_avatar,
1759 "vbox_location", &information->vbox_location,
1760 "subvbox_location", &information->subvbox_location,
1761 "label_location", &information->label_location,
1762 #ifdef HAVE_LIBCHAMPLAIN
1763 "viewport_map", &information->viewport_map,
1765 "groups_widget", &information->groups_widget,
1766 "vbox_details", &information->vbox_details,
1767 "grid_details", &information->grid_details,
1768 "hbox_details_requested", &information->hbox_details_requested,
1769 "vbox_client", &information->vbox_client,
1770 "grid_client", &information->grid_client,
1771 "hbox_client_requested", &information->hbox_client_requested,
1772 "label_details", &information->label_details,
1773 "label_left_account", &information->label_left_account,
1777 empathy_builder_connect (gui, information,
1778 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1780 information->grid_location = NULL;
1782 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1783 "EmpathyContactWidget",
1786 /* Create widgets */
1787 contact_widget_contact_setup (information);
1788 contact_widget_details_setup (information);
1789 contact_widget_client_setup (information);
1791 if (contact != NULL)
1792 contact_widget_set_contact (information, contact);
1793 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1794 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1795 contact_widget_change_contact (information);
1797 return empathy_builder_unref_and_keep_widget (gui,
1798 information->vbox_contact_widget);
1802 * empathy_contact_widget_get_contact:
1803 * @widget: an #EmpathyContactWidget
1805 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1807 * Returns: the #EmpathyContact associated with @widget
1810 empathy_contact_widget_get_contact (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 information->contact;
1824 empathy_contact_widget_get_alias (GtkWidget *widget)
1826 EmpathyContactWidget *information;
1828 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1830 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1834 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1838 * empathy_contact_widget_set_contact:
1839 * @widget: an #EmpathyContactWidget
1840 * @contact: a different #EmpathyContact
1842 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1845 empathy_contact_widget_set_contact (GtkWidget *widget,
1846 EmpathyContact *contact)
1848 EmpathyContactWidget *information;
1850 g_return_if_fail (GTK_IS_WIDGET (widget));
1851 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1853 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1857 contact_widget_set_contact (information, contact);
1861 * empathy_contact_widget_set_account_filter:
1862 * @widget: an #EmpathyContactWidget
1863 * @filter: a #EmpathyAccountChooserFilterFunc
1864 * @user_data: user data to pass to @filter, or %NULL
1866 * Set a filter on the #EmpathyAccountChooser included in the
1867 * #EmpathyContactWidget.
1870 empathy_contact_widget_set_account_filter (
1872 EmpathyAccountChooserFilterFunc filter,
1875 EmpathyContactWidget *information;
1876 EmpathyAccountChooser *chooser;
1878 g_return_if_fail (GTK_IS_WIDGET (widget));
1880 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1884 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1886 empathy_account_chooser_set_filter (chooser, filter, user_data);