1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
28 #include <glib/gi18n-lib.h>
30 #ifdef HAVE_LIBCHAMPLAIN
31 #include <champlain/champlain.h>
32 #include <champlain-gtk/champlain-gtk.h>
35 #include <telepathy-glib/account.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-glib/interfaces.h>
39 #include <libempathy/empathy-tp-contact-factory.h>
40 #include <libempathy/empathy-contact-manager.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-location.h>
43 #include <libempathy/empathy-time.h>
44 #include <libempathy/empathy-utils.h>
46 #include "empathy-contact-widget.h"
47 #include "empathy-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 EmpathyContactManager *manager;
85 EmpathyContact *contact;
86 EmpathyContactWidgetFlags flags;
87 guint widget_id_timeout;
90 GtkWidget *vbox_contact_widget;
93 GtkWidget *hbox_contact;
94 GtkWidget *widget_avatar;
95 GtkWidget *widget_account;
96 GtkWidget *image_account;
97 GtkWidget *label_account;
99 GtkWidget *widget_alias;
100 GtkWidget *label_alias;
101 GtkWidget *hbox_presence;
102 GtkWidget *image_state;
103 GtkWidget *label_status;
104 GtkWidget *grid_contact;
105 GtkWidget *vbox_avatar;
106 GtkWidget *favourite_checkbox;
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 (GtkCalendar *calendar,
257 EmpathyContactWidget *self)
259 guint year, month, day;
262 const gchar *strv[] = { NULL, NULL };
263 TpContactInfoField *field;
265 self->details_changed = TRUE;
267 field = g_object_get_data ((GObject *) calendar, DATA_FIELD);
268 g_assert (field != NULL);
270 gtk_calendar_get_date (calendar, &year, &month, &day);
271 date = g_date_new_dmy (day, month+1, year);
273 gtk_calendar_clear_marks (calendar);
274 gtk_calendar_mark_day (calendar, g_date_get_day (date));
276 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
278 if (field->field_value != NULL)
279 g_strfreev (field->field_value);
280 field->field_value = g_strdupv ((GStrv) strv);
285 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
288 field_name_in_field_list (GList *list,
293 for (l = list; l != NULL; l = g_list_next (l))
295 TpContactInfoField *field = l->data;
297 if (!tp_strdiff (field->field_name, name))
304 static TpContactInfoFieldSpec *
305 get_spec_from_list (GList *list,
310 for (l = list; l != NULL; l = g_list_next (l))
312 TpContactInfoFieldSpec *spec = l->data;
314 if (!tp_strdiff (spec->name, name))
322 contact_widget_details_update_edit (EmpathyContactWidget *information)
325 TpConnection *connection;
329 const char **field_names = empathy_contact_info_get_field_names (NULL);
332 g_assert (information->details_to_set == NULL);
334 information->details_changed = FALSE;
336 contact = empathy_contact_get_tp_contact (information->contact);
337 connection = tp_contact_get_connection (contact);
339 info = tp_contact_get_contact_info (contact);
341 specs = tp_connection_get_contact_info_supported_fields (connection);
343 /* Look at the fields set in our vCard */
344 for (l = info; l != NULL; l = l->next)
346 TpContactInfoField *field = l->data;
348 /* make a copy for the details_to_set list */
349 field = tp_contact_info_field_copy (field);
350 DEBUG ("Field %s is in our vCard", field->field_name);
352 information->details_to_set = g_list_prepend (information->details_to_set,
356 /* Add fields which are supported but not in the vCard */
357 for (i = 0; field_names[i] != NULL; i++)
359 TpContactInfoFieldSpec *spec;
360 TpContactInfoField *field;
362 /* Check if the field was in the vCard */
363 if (field_name_in_field_list (information->details_to_set,
367 /* Check if the CM supports the field */
368 spec = get_spec_from_list (specs, field_names[i]);
372 /* add an empty field so user can set a value */
373 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
375 information->details_to_set = g_list_prepend (information->details_to_set,
379 /* Add widgets for supported fields */
380 information->details_to_set = g_list_sort (information->details_to_set,
381 (GCompareFunc) empathy_contact_info_field_spec_cmp);
383 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
385 TpContactInfoField *field = l->data;
387 TpContactInfoFieldSpec *spec;
391 has_field = empathy_contact_info_lookup_field (field->field_name,
395 /* Empathy doesn't display this field so we can't change it.
396 * But we put it in the details_to_set list so it won't be erased
397 * when calling SetContactInfo (bgo #630427) */
398 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
402 spec = get_spec_from_list (specs, field->field_name);
403 /* We shouldn't have added the field to details_to_set if it's not
404 * supported by the CM */
405 g_assert (spec != NULL);
407 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
409 DEBUG ("Ignoring field '%s' due it to having the "
410 "Overwritten_By_Nickname flag", field->field_name);
415 title = empathy_contact_info_field_label (field->field_name,
417 w = gtk_label_new (title);
420 gtk_grid_attach (GTK_GRID (information->grid_details),
423 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
427 if (!tp_strdiff (field->field_name, "bday"))
429 w = gtk_calendar_new ();
430 if (field->field_value[0])
434 g_date_set_parse (&date, field->field_value[0]);
435 if (g_date_valid (&date))
437 gtk_calendar_select_day (GTK_CALENDAR (w),
438 g_date_get_day (&date));
439 gtk_calendar_select_month (GTK_CALENDAR (w),
440 g_date_get_month (&date) - 1, g_date_get_year (&date));
441 gtk_calendar_mark_day (GTK_CALENDAR (w),
442 g_date_get_day (&date));
446 gtk_grid_attach (GTK_GRID (information->grid_details),
450 g_object_set_data ((GObject *) w, DATA_FIELD, field);
452 g_signal_connect (w, "day-selected",
453 G_CALLBACK (contact_widget_bday_changed_cb), information);
454 g_signal_connect (w, "month-changed",
455 G_CALLBACK (contact_widget_bday_changed_cb), information);
459 w = gtk_entry_new ();
460 gtk_entry_set_text (GTK_ENTRY (w),
461 field->field_value[0] ? field->field_value[0] : "");
462 gtk_grid_attach (GTK_GRID (information->grid_details),
466 g_object_set_data ((GObject *) w, DATA_FIELD, field);
468 g_signal_connect (w, "changed",
469 G_CALLBACK (contact_widget_details_changed_cb), information);
482 add_row (GtkGrid *grid,
487 gtk_grid_attach (grid, title, 0, row, 1, 1);
488 gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
489 gtk_widget_show (title);
491 gtk_grid_attach (grid, value, 1, row, 1, 1);
492 gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
493 gtk_widget_show (value);
497 contact_widget_details_update_show (EmpathyContactWidget *information)
502 GtkWidget *channels_label;
505 contact = empathy_contact_get_tp_contact (information->contact);
506 info = tp_contact_get_contact_info (contact);
507 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
508 for (l = info; l != NULL; l = l->next)
510 TpContactInfoField *field = l->data;
512 gchar *markup = NULL, *title;
513 GtkWidget *title_widget, *value_widget;
514 EmpathyContactInfoFormatFunc format;
516 if (field->field_value == NULL || field->field_value[0] == NULL)
519 value = field->field_value[0];
521 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
523 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
529 markup = format (field->field_value);
533 DEBUG ("Invalid value for field '%s' (first element was '%s')",
534 field->field_name, field->field_value[0]);
540 title = empathy_contact_info_field_label (field->field_name,
542 title_widget = gtk_label_new (title);
546 value_widget = gtk_label_new (value);
549 gtk_label_set_markup (GTK_LABEL (value_widget), markup);
553 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
554 gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
556 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
562 account = empathy_contact_get_account (information->contact);
564 channels_label = empathy_contact_info_create_channel_list_label (account,
567 if (channels_label != NULL)
569 GtkWidget *title_widget;
571 title_widget = gtk_label_new (_("Channels:"));
573 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
585 contact_widget_details_notify_cb (EmpathyContactWidget *information)
589 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
590 (GtkCallback) gtk_widget_destroy, NULL);
592 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
593 n_rows = contact_widget_details_update_edit (information);
595 n_rows = contact_widget_details_update_show (information);
599 gtk_widget_show (information->vbox_details);
600 gtk_widget_show (information->grid_details);
604 gtk_widget_hide (information->vbox_details);
607 gtk_widget_hide (information->hbox_details_requested);
608 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
612 contact_widget_details_request_cb (GObject *object,
616 TpContact *contact = TP_CONTACT (object);
617 EmpathyContactWidget *information = user_data;
618 GError *error = NULL;
620 if (!tp_contact_request_contact_info_finish (contact, res, &error))
622 /* If the request got cancelled it could mean the contact widget is
623 * destroyed, so we should not dereference information */
624 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
626 g_clear_error (&error);
630 gtk_widget_hide (information->vbox_details);
631 g_clear_error (&error);
635 contact_widget_details_notify_cb (information);
638 /* If we are going to edit ContactInfo, we don't want live updates */
639 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
641 g_signal_connect_swapped (contact, "notify::contact-info",
642 G_CALLBACK (contact_widget_details_notify_cb), information);
645 tp_clear_object (&information->details_cancellable);
649 fetch_contact_information (EmpathyContactWidget *information,
650 TpConnection *connection)
653 TpContactInfoFlags flags;
655 if (!tp_proxy_has_interface_by_id (connection,
656 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
658 gtk_widget_hide (information->vbox_details);
662 /* If we want to edit info, but connection does not support that, stop */
663 flags = tp_connection_get_contact_info_flags (connection);
664 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
665 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
667 gtk_widget_hide (information->vbox_details);
671 /* Request the contact's info */
672 gtk_widget_show (information->vbox_details);
673 gtk_widget_show (information->hbox_details_requested);
674 gtk_widget_hide (information->grid_details);
675 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
677 contact = empathy_contact_get_tp_contact (information->contact);
678 g_assert (information->details_cancellable == NULL);
679 information->details_cancellable = g_cancellable_new ();
680 tp_contact_request_contact_info_async (contact,
681 information->details_cancellable, contact_widget_details_request_cb,
686 contact_widget_details_update (EmpathyContactWidget *information)
688 TpContact *tp_contact = NULL;
690 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
691 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
694 gtk_widget_hide (information->vbox_details);
696 if (information->contact != NULL)
697 tp_contact = empathy_contact_get_tp_contact (information->contact);
699 if (tp_contact != NULL)
701 TpConnection *connection;
703 connection = tp_contact_get_connection (tp_contact);
705 fetch_contact_information (information, connection);
710 contact_widget_client_update (EmpathyContactWidget *information)
712 /* FIXME: Needs new telepathy spec */
716 contact_widget_client_setup (EmpathyContactWidget *information)
718 /* FIXME: Needs new telepathy spec */
719 gtk_widget_hide (information->vbox_client);
723 contact_widget_groups_update (EmpathyContactWidget *information)
725 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
726 information->contact != NULL)
728 FolksPersona *persona =
729 empathy_contact_get_persona (information->contact);
731 if (FOLKS_IS_GROUP_DETAILS (persona))
733 empathy_groups_widget_set_group_details (
734 EMPATHY_GROUPS_WIDGET (information->groups_widget),
735 FOLKS_GROUP_DETAILS (persona));
736 gtk_widget_show (information->groups_widget);
742 /* In case of failure */
743 gtk_widget_hide (information->groups_widget);
746 /* Converts the Location's GHashTable's key to a user readable string */
748 location_key_to_label (const gchar *key)
750 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
751 return _("Country ISO Code:");
752 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
753 return _("Country:");
754 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
756 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
758 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
760 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
761 return _("Postal Code:");
762 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
764 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
765 return _("Building:");
766 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
768 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
770 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
772 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
773 return _("Description:");
774 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
776 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
777 return _("Accuracy Level:");
778 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
780 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
781 return _("Vertical Error (meters):");
782 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
783 return _("Horizontal Error (meters):");
784 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
786 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
787 return _("Bearing:");
788 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
789 return _("Climb Speed:");
790 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
791 return _("Last Updated on:");
792 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
793 return _("Longitude:");
794 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
795 return _("Latitude:");
796 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
797 return _("Altitude:");
800 DEBUG ("Unexpected Location key: %s", key);
806 contact_widget_location_update (EmpathyContactWidget *information)
808 GHashTable *location;
810 #ifdef HAVE_LIBCHAMPLAIN
811 gdouble lat = 0.0, lon = 0.0;
812 gboolean has_position = TRUE;
816 static const gchar* ordered_geolocation_keys[] = {
817 EMPATHY_LOCATION_TEXT,
818 EMPATHY_LOCATION_URI,
819 EMPATHY_LOCATION_DESCRIPTION,
820 EMPATHY_LOCATION_BUILDING,
821 EMPATHY_LOCATION_FLOOR,
822 EMPATHY_LOCATION_ROOM,
823 EMPATHY_LOCATION_STREET,
824 EMPATHY_LOCATION_AREA,
825 EMPATHY_LOCATION_LOCALITY,
826 EMPATHY_LOCATION_REGION,
827 EMPATHY_LOCATION_COUNTRY,
832 gboolean display_map = FALSE;
834 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
836 gtk_widget_hide (information->vbox_location);
840 location = empathy_contact_get_location (information->contact);
841 if (location == NULL || g_hash_table_size (location) == 0)
843 gtk_widget_hide (information->vbox_location);
847 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
850 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
851 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
861 stamp = g_value_get_int64 (value);
863 user_date = empathy_time_to_string_relative (stamp);
865 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
866 /* translators: format is "Location, $date" */
867 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
869 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
875 /* Prepare the location information grid */
876 if (information->grid_location != NULL)
878 gtk_widget_destroy (information->grid_location);
881 information->grid_location = gtk_grid_new ();
882 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
883 information->grid_location, FALSE, FALSE, 5);
886 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
888 const gchar* user_label;
892 gvalue = g_hash_table_lookup (location, (gpointer) skey);
896 user_label = location_key_to_label (skey);
898 label = gtk_label_new (user_label);
899 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
900 gtk_grid_attach (GTK_GRID (information->grid_location),
901 label, 0, row, 1, 1);
902 gtk_widget_show (label);
904 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
907 dvalue = g_value_get_double (gvalue);
908 svalue = g_strdup_printf ("%f", dvalue);
910 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
912 svalue = g_value_dup_string (gvalue);
914 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
918 time_ = g_value_get_int64 (value);
919 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
924 label = gtk_label_new (svalue);
925 gtk_grid_attach (GTK_GRID (information->grid_location),
926 label, 1, row, 1, 1);
927 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
928 gtk_widget_show (label);
930 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
931 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
938 #ifdef HAVE_LIBCHAMPLAIN
940 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
942 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
950 /* We can display some fields */
951 gtk_widget_show (information->grid_location);
953 else if (!display_map)
955 /* Can't display either fields or map */
956 gtk_widget_hide (information->vbox_location);
960 #ifdef HAVE_LIBCHAMPLAIN
963 ClutterActor *marker;
964 ChamplainMarkerLayer *layer;
966 information->map_view_embed = gtk_champlain_embed_new ();
967 information->map_view = gtk_champlain_embed_get_view (
968 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
970 gtk_container_add (GTK_CONTAINER (information->viewport_map),
971 information->map_view_embed);
972 g_object_set (G_OBJECT (information->map_view),
973 "kinetic-mode", TRUE,
977 layer = champlain_marker_layer_new ();
978 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
980 marker = champlain_label_new_with_text (
981 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
982 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
983 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
985 champlain_view_center_on (information->map_view, lat, lon);
986 gtk_widget_show_all (information->viewport_map);
990 gtk_widget_show (information->vbox_location);
994 save_avatar_menu_activate_cb (GtkWidget *widget,
995 EmpathyContactWidget *information)
998 EmpathyAvatar *avatar;
999 gchar *ext = NULL, *filename;
1001 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1003 GTK_FILE_CHOOSER_ACTION_SAVE,
1004 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1005 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1008 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1011 /* look for the avatar extension */
1012 avatar = empathy_contact_get_avatar (information->contact);
1013 if (avatar->format != NULL)
1017 splitted = g_strsplit (avatar->format, "/", 2);
1018 if (splitted[0] != NULL && splitted[1] != NULL)
1019 ext = g_strdup (splitted[1]);
1021 g_strfreev (splitted);
1025 /* Avatar was loaded from the cache so was converted to PNG */
1026 ext = g_strdup ("png");
1033 id = tp_escape_as_identifier (empathy_contact_get_id (
1034 information->contact));
1036 filename = g_strdup_printf ("%s.%s", id, ext);
1037 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1044 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1046 GError *error = NULL;
1048 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1050 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1053 GtkWidget *error_dialog;
1055 error_dialog = gtk_message_dialog_new (NULL, 0,
1056 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1057 _("Unable to save avatar"));
1059 gtk_message_dialog_format_secondary_text (
1060 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1062 g_signal_connect (error_dialog, "response",
1063 G_CALLBACK (gtk_widget_destroy), NULL);
1065 gtk_window_present (GTK_WINDOW (error_dialog));
1067 g_clear_error (&error);
1073 gtk_widget_destroy (dialog);
1077 popup_avatar_menu (EmpathyContactWidget *information,
1079 GdkEventButton *event)
1081 GtkWidget *menu, *item;
1082 gint button, event_time;
1084 if (information->contact == NULL ||
1085 empathy_contact_get_avatar (information->contact) == NULL)
1088 menu = empathy_context_menu_new (parent);
1090 /* Add "Save as..." entry */
1091 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1092 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1093 gtk_widget_show (item);
1095 g_signal_connect (item, "activate",
1096 G_CALLBACK (save_avatar_menu_activate_cb), information);
1100 button = event->button;
1101 event_time = event->time;
1106 event_time = gtk_get_current_event_time ();
1109 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1110 button, event_time);
1114 widget_avatar_popup_menu_cb (GtkWidget *widget,
1115 EmpathyContactWidget *information)
1117 popup_avatar_menu (information, widget, NULL);
1123 widget_avatar_button_press_event_cb (GtkWidget *widget,
1124 GdkEventButton *event,
1125 EmpathyContactWidget *information)
1127 /* Ignore double-clicks and triple-clicks */
1128 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1130 popup_avatar_menu (information, widget, event);
1138 set_avatar_cb (GObject *source,
1142 GError *error = NULL;
1144 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1145 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1146 g_error_free (error);
1151 set_avatar_on_account (TpAccount *account,
1154 const gchar *mime_type)
1156 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1157 tp_proxy_get_object_path (account));
1159 tp_account_set_avatar_async (account, (const guchar *) data, size,
1160 mime_type, set_avatar_cb, NULL);
1164 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1165 EmpathyContactWidget *information)
1169 const gchar *mime_type;
1172 empathy_avatar_chooser_get_image_data (
1173 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1174 &data, &size, &mime_type);
1176 account = empathy_contact_get_account (information->contact);
1177 set_avatar_on_account (account, data, size, mime_type);
1181 set_nickname_cb (GObject *source,
1185 GError *error = NULL;
1187 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1189 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1190 g_error_free (error);
1194 /* Update all the contact info fields having the
1195 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1196 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1199 update_nickname_in_contact_info (EmpathyContactWidget *self,
1200 TpConnection *connection,
1201 const gchar *nickname)
1205 specs = tp_connection_get_contact_info_supported_fields (connection);
1207 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1209 TpContactInfoField *field = l->data;
1210 TpContactInfoFieldSpec *spec;
1212 spec = get_spec_from_list (specs, field->field_name);
1213 /* We shouldn't have added the field to details_to_set if it's not
1214 * supported by the CM */
1215 g_assert (spec != NULL);
1217 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1219 const gchar *strv[] = { nickname, NULL };
1221 DEBUG ("Updating field '%s' to '%s' as it has the "
1222 "Overwritten_By_Nickname flag and Account.Nickname has "
1223 "been updated", field->field_name, nickname);
1225 if (field->field_value != NULL)
1226 g_strfreev (field->field_value);
1227 field->field_value = g_strdupv ((GStrv) strv);
1231 g_list_free (specs);
1235 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1236 GdkEventFocus *event,
1237 EmpathyContactWidget *information)
1239 if (information->contact)
1243 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1245 if (empathy_contact_is_user (information->contact))
1247 TpAccount * account;
1248 const gchar *current_nickname;
1250 account = empathy_contact_get_account (information->contact);
1251 current_nickname = tp_account_get_nickname (account);
1253 if (tp_strdiff (current_nickname, alias))
1255 DEBUG ("Set Account.Nickname to %s", alias);
1257 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1260 update_nickname_in_contact_info (information,
1261 empathy_contact_get_connection (information->contact), alias);
1266 empathy_contact_set_alias (information->contact, alias);
1274 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1275 EmpathyAvatarChooser *avatar_chooser)
1279 account = empathy_account_chooser_get_account (account_chooser);
1280 if (account == NULL)
1283 empathy_avatar_chooser_set_account (avatar_chooser, account);
1287 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1289 EmpathyAvatar *avatar = NULL;
1291 if (information->contact)
1292 avatar = empathy_contact_get_avatar (information->contact);
1294 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1296 g_signal_handlers_block_by_func (information->widget_avatar,
1297 contact_widget_avatar_changed_cb,
1299 empathy_avatar_chooser_set (
1300 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1301 g_signal_handlers_unblock_by_func (information->widget_avatar,
1302 contact_widget_avatar_changed_cb, information);
1305 empathy_avatar_image_set (
1306 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1310 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1312 if (GTK_IS_ENTRY (information->widget_alias))
1313 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1314 empathy_contact_get_alias (information->contact));
1316 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1317 empathy_contact_get_alias (information->contact));
1321 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1323 const gchar *status;
1324 gchar *markup_text = NULL;
1326 status = empathy_contact_get_status (information->contact);
1328 markup_text = empathy_add_link_markup (status);
1329 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1330 g_free (markup_text);
1332 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1333 empathy_icon_name_for_contact (information->contact),
1334 GTK_ICON_SIZE_BUTTON);
1335 gtk_widget_show (information->image_state);
1339 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1340 EmpathyContact *contact,
1341 gboolean is_favourite,
1342 EmpathyContactWidget *information)
1344 if (contact != information->contact)
1347 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1348 information->favourite_checkbox), is_favourite);
1352 contact_widget_remove_contact (EmpathyContactWidget *information)
1354 if (information->contact)
1356 TpContact *tp_contact;
1358 contact_widget_save (information);
1360 g_signal_handlers_disconnect_by_func (information->contact,
1361 contact_widget_name_notify_cb, information);
1362 g_signal_handlers_disconnect_by_func (information->contact,
1363 contact_widget_presence_notify_cb, information);
1364 g_signal_handlers_disconnect_by_func (information->contact,
1365 contact_widget_avatar_notify_cb, information);
1367 tp_contact = empathy_contact_get_tp_contact (information->contact);
1368 if (tp_contact != NULL)
1370 g_signal_handlers_disconnect_by_func (tp_contact,
1371 contact_widget_details_notify_cb, information);
1374 g_object_unref (information->contact);
1375 information->contact = NULL;
1378 if (information->details_cancellable != NULL)
1380 g_cancellable_cancel (information->details_cancellable);
1381 tp_clear_object (&information->details_cancellable);
1385 static void contact_widget_change_contact (EmpathyContactWidget *information);
1388 contact_widget_contact_update (EmpathyContactWidget *information)
1390 TpAccount *account = NULL;
1391 const gchar *id = NULL;
1393 /* Connect and get info from new contact */
1394 if (information->contact)
1396 g_signal_connect_swapped (information->contact, "notify::name",
1397 G_CALLBACK (contact_widget_name_notify_cb), information);
1398 g_signal_connect_swapped (information->contact, "notify::presence",
1399 G_CALLBACK (contact_widget_presence_notify_cb), information);
1400 g_signal_connect_swapped (information->contact,
1401 "notify::presence-message",
1402 G_CALLBACK (contact_widget_presence_notify_cb), information);
1403 g_signal_connect_swapped (information->contact, "notify::avatar",
1404 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1406 account = empathy_contact_get_account (information->contact);
1407 id = empathy_contact_get_id (information->contact);
1410 /* Update account widget */
1411 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1415 g_signal_handlers_block_by_func (information->widget_account,
1416 contact_widget_change_contact,
1418 empathy_account_chooser_set_account (
1419 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1420 g_signal_handlers_unblock_by_func (information->widget_account,
1421 contact_widget_change_contact, information);
1430 name = tp_account_get_display_name (account);
1431 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1433 name = tp_account_get_icon_name (account);
1434 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1435 name, GTK_ICON_SIZE_MENU);
1439 /* Update id widget */
1440 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1441 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1443 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1445 /* Update other widgets */
1446 if (information->contact)
1448 contact_widget_name_notify_cb (information);
1449 contact_widget_presence_notify_cb (information);
1450 contact_widget_avatar_notify_cb (information);
1452 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1454 FolksPersona *persona = empathy_contact_get_persona (
1455 information->contact);
1457 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1459 gboolean is_favourite = folks_favourite_details_get_is_favourite (
1460 FOLKS_FAVOURITE_DETAILS (persona));
1461 contact_widget_favourites_changed_cb (information->manager,
1462 information->contact, is_favourite, information);
1466 gtk_widget_show (information->label_alias);
1467 gtk_widget_show (information->widget_alias);
1468 gtk_widget_show (information->hbox_presence);
1469 gtk_widget_show (information->widget_avatar);
1473 gtk_widget_hide (information->label_alias);
1474 gtk_widget_hide (information->widget_alias);
1475 gtk_widget_hide (information->hbox_presence);
1476 gtk_widget_hide (information->widget_avatar);
1481 contact_widget_set_contact (EmpathyContactWidget *information,
1482 EmpathyContact *contact)
1484 if (contact == information->contact)
1487 contact_widget_remove_contact (information);
1489 information->contact = g_object_ref (contact);
1491 /* set the selected account to be the account this contact came from */
1492 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1493 empathy_account_chooser_set_account (
1494 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1495 empathy_contact_get_account (contact));
1498 /* Update information for widgets */
1499 contact_widget_contact_update (information);
1500 contact_widget_groups_update (information);
1501 contact_widget_details_update (information);
1502 contact_widget_client_update (information);
1503 contact_widget_location_update (information);
1507 contact_widget_got_contact_cb (TpConnection *connection,
1508 EmpathyContact *contact,
1509 const GError *error,
1511 GObject *weak_object)
1513 EmpathyContactWidget *information = user_data;
1517 DEBUG ("Error: %s", error->message);
1521 contact_widget_set_contact (information, contact);
1525 contact_widget_change_contact (EmpathyContactWidget *information)
1527 TpConnection *connection;
1529 connection = empathy_account_chooser_get_connection (
1530 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1534 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1538 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1539 if (!EMP_STR_EMPTY (id))
1541 empathy_tp_contact_factory_get_from_id (connection, id,
1542 contact_widget_got_contact_cb, information, NULL,
1543 G_OBJECT (information->vbox_contact_widget));
1548 empathy_tp_contact_factory_get_from_handle (connection,
1549 tp_connection_get_self_handle (connection),
1550 contact_widget_got_contact_cb, information, NULL,
1551 G_OBJECT (information->vbox_contact_widget));
1556 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1558 contact_widget_change_contact (self);
1563 contact_widget_id_changed_cb (GtkEntry *entry,
1564 EmpathyContactWidget *self)
1566 if (self->widget_id_timeout != 0)
1568 g_source_remove (self->widget_id_timeout);
1571 self->widget_id_timeout =
1572 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1573 (GSourceFunc) contact_widget_id_activate_timeout, self);
1577 contact_widget_id_focus_out_cb (GtkWidget *widget,
1578 GdkEventFocus *event,
1579 EmpathyContactWidget *information)
1581 contact_widget_change_contact (information);
1586 favourite_toggled_cb (GtkToggleButton *button,
1587 EmpathyContactWidget *information)
1589 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1591 if (persona != NULL && FOLKS_IS_FAVOURITE_DETAILS (persona))
1593 gboolean active = gtk_toggle_button_get_active (button);
1594 folks_favourite_details_set_is_favourite (
1595 FOLKS_FAVOURITE_DETAILS (persona), active);
1600 contact_widget_contact_setup (EmpathyContactWidget *information)
1602 information->label_status = gtk_label_new ("");
1603 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1604 PANGO_WRAP_WORD_CHAR);
1605 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1607 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1609 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1610 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1612 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1613 information->label_status, TRUE, TRUE, 0);
1614 gtk_widget_show (information->label_status);
1616 /* Setup account label/chooser */
1617 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1619 information->widget_account = empathy_account_chooser_new ();
1621 g_signal_connect_swapped (information->widget_account, "changed",
1622 G_CALLBACK (contact_widget_change_contact),
1627 /* Pack the protocol icon with the account name in an hbox */
1628 information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1630 information->label_account = gtk_label_new (NULL);
1631 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1632 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1634 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1635 gtk_widget_show (information->label_account);
1637 information->image_account = gtk_image_new ();
1638 gtk_widget_show (information->image_account);
1640 gtk_box_pack_start (GTK_BOX (information->widget_account),
1641 information->image_account, FALSE, FALSE, 0);
1642 gtk_box_pack_start (GTK_BOX (information->widget_account),
1643 information->label_account, FALSE, TRUE, 0);
1646 gtk_grid_attach (GTK_GRID (information->grid_contact),
1647 information->widget_account,
1650 gtk_widget_show (information->widget_account);
1652 /* Set up avatar chooser/display */
1653 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1655 information->widget_avatar = empathy_avatar_chooser_new ();
1656 g_signal_connect (information->widget_avatar, "changed",
1657 G_CALLBACK (contact_widget_avatar_changed_cb),
1659 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1661 g_signal_connect (information->widget_account, "changed",
1662 G_CALLBACK (update_avatar_chooser_account_cb),
1663 information->widget_avatar);
1664 update_avatar_chooser_account_cb (
1665 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1666 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1671 information->widget_avatar = empathy_avatar_image_new ();
1673 g_signal_connect (information->widget_avatar, "popup-menu",
1674 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1675 g_signal_connect (information->widget_avatar, "button-press-event",
1676 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1679 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1680 information->widget_avatar,
1683 gtk_widget_show (information->widget_avatar);
1685 /* Setup id label/entry */
1686 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1688 information->widget_id = gtk_entry_new ();
1689 g_signal_connect (information->widget_id, "focus-out-event",
1690 G_CALLBACK (contact_widget_id_focus_out_cb),
1692 g_signal_connect (information->widget_id, "changed",
1693 G_CALLBACK (contact_widget_id_changed_cb),
1698 information->widget_id = gtk_label_new (NULL);
1699 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1700 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1702 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1705 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1708 gtk_widget_show (information->widget_id);
1710 /* Setup alias label/entry */
1711 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1713 information->widget_alias = gtk_entry_new ();
1715 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1716 g_signal_connect (information->widget_alias, "focus-out-event",
1717 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1720 /* Make return activate the window default (the Close button) */
1721 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1726 information->widget_alias = gtk_label_new (NULL);
1727 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1728 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1730 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1733 gtk_grid_attach (GTK_GRID (information->grid_contact),
1734 information->widget_alias, 1, 2, 1, 1);
1736 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1737 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1739 gtk_widget_show (information->widget_alias);
1742 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1744 information->favourite_checkbox = gtk_check_button_new_with_label (
1747 g_signal_connect (information->favourite_checkbox, "toggled",
1748 G_CALLBACK (favourite_toggled_cb), information);
1750 gtk_grid_attach (GTK_GRID (information->grid_contact),
1751 information->favourite_checkbox, 0, 3, 1, 1);
1753 information->fav_sig_id = g_signal_connect (information->manager,
1754 "favourites-changed",
1755 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1757 gtk_widget_show (information->favourite_checkbox);
1762 contact_widget_destroy_cb (GtkWidget *widget,
1763 EmpathyContactWidget *information)
1765 contact_widget_remove_contact (information);
1767 if (information->widget_id_timeout != 0)
1769 g_source_remove (information->widget_id_timeout);
1772 if (information->fav_sig_id != 0)
1773 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1775 g_object_unref (information->manager);
1777 g_slice_free (EmpathyContactWidget, information);
1781 * empathy_contact_widget_new:
1782 * @contact: an #EmpathyContact
1783 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1785 * Creates a new #EmpathyContactWidget.
1787 * Return value: a new #EmpathyContactWidget
1790 empathy_contact_widget_new (EmpathyContact *contact,
1791 EmpathyContactWidgetFlags flags)
1793 EmpathyContactWidget *information;
1797 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1799 information = g_slice_new0 (EmpathyContactWidget);
1800 information->flags = flags;
1802 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1804 gui = empathy_builder_get_file (filename,
1805 "vbox_contact_widget", &information->vbox_contact_widget,
1806 "hbox_contact", &information->hbox_contact,
1807 "hbox_presence", &information->hbox_presence,
1808 "label_alias", &information->label_alias,
1809 "image_state", &information->image_state,
1810 "grid_contact", &information->grid_contact,
1811 "vbox_avatar", &information->vbox_avatar,
1812 "vbox_location", &information->vbox_location,
1813 "subvbox_location", &information->subvbox_location,
1814 "label_location", &information->label_location,
1815 #ifdef HAVE_LIBCHAMPLAIN
1816 "viewport_map", &information->viewport_map,
1818 "groups_widget", &information->groups_widget,
1819 "vbox_details", &information->vbox_details,
1820 "grid_details", &information->grid_details,
1821 "hbox_details_requested", &information->hbox_details_requested,
1822 "vbox_client", &information->vbox_client,
1823 "grid_client", &information->grid_client,
1824 "hbox_client_requested", &information->hbox_client_requested,
1828 empathy_builder_connect (gui, information,
1829 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1831 information->grid_location = NULL;
1833 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1834 "EmpathyContactWidget",
1837 information->manager = empathy_contact_manager_dup_singleton ();
1839 /* Create widgets */
1840 contact_widget_contact_setup (information);
1841 contact_widget_details_setup (information);
1842 contact_widget_client_setup (information);
1844 if (contact != NULL)
1845 contact_widget_set_contact (information, contact);
1846 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1847 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1848 contact_widget_change_contact (information);
1850 return empathy_builder_unref_and_keep_widget (gui,
1851 information->vbox_contact_widget);
1855 * empathy_contact_widget_get_contact:
1856 * @widget: an #EmpathyContactWidget
1858 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1860 * Returns: the #EmpathyContact associated with @widget
1863 empathy_contact_widget_get_contact (GtkWidget *widget)
1865 EmpathyContactWidget *information;
1867 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1869 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1873 return information->contact;
1877 empathy_contact_widget_get_alias (GtkWidget *widget)
1879 EmpathyContactWidget *information;
1881 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1883 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1887 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1891 * empathy_contact_widget_set_contact:
1892 * @widget: an #EmpathyContactWidget
1893 * @contact: a different #EmpathyContact
1895 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1898 empathy_contact_widget_set_contact (GtkWidget *widget,
1899 EmpathyContact *contact)
1901 EmpathyContactWidget *information;
1903 g_return_if_fail (GTK_IS_WIDGET (widget));
1904 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1906 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1910 contact_widget_set_contact (information, contact);
1914 * empathy_contact_widget_set_account_filter:
1915 * @widget: an #EmpathyContactWidget
1916 * @filter: a #EmpathyAccountChooserFilterFunc
1917 * @user_data: user data to pass to @filter, or %NULL
1919 * Set a filter on the #EmpathyAccountChooser included in the
1920 * #EmpathyContactWidget.
1923 empathy_contact_widget_set_account_filter (
1925 EmpathyAccountChooserFilterFunc filter,
1928 EmpathyContactWidget *information;
1929 EmpathyAccountChooser *chooser;
1931 g_return_if_fail (GTK_IS_WIDGET (widget));
1933 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1937 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1939 empathy_account_chooser_set_filter (chooser, filter, user_data);