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-location.h>
41 #include <libempathy/empathy-time.h>
42 #include <libempathy/empathy-utils.h>
44 #include "empathy-calendar-button.h"
45 #include "empathy-contact-widget.h"
46 #include "empathy-contactinfo-utils.h"
47 #include "empathy-account-chooser.h"
48 #include "empathy-avatar-chooser.h"
49 #include "empathy-avatar-image.h"
50 #include "empathy-groups-widget.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-string-parser.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
55 #include <libempathy/empathy-debug.h>
58 * SECTION:empathy-contact-widget
59 * @title:EmpathyContactWidget
60 * @short_description: A widget used to display and edit details about a contact
61 * @include: libempathy-empathy-contact-widget.h
63 * #EmpathyContactWidget is a widget which displays appropriate widgets
64 * with details about a contact, also allowing changing these details,
69 * EmpathyContactWidget:
70 * @parent: parent object
72 * Widget which displays appropriate widgets with details about a contact,
73 * also allowing changing these details, if desired.
76 /* Delay before updating the widget when the id entry changed (seconds) */
77 #define ID_CHANGED_TIMEOUT 1
79 #define DATA_FIELD "contact-info-field"
83 EmpathyContact *contact;
84 EmpathyContactWidgetFlags flags;
85 guint widget_id_timeout;
88 GtkWidget *vbox_contact_widget;
91 GtkWidget *widget_avatar;
92 GtkWidget *widget_account;
93 GtkWidget *image_account;
94 GtkWidget *label_account;
96 GtkWidget *widget_alias;
97 GtkWidget *label_alias;
98 GtkWidget *hbox_presence;
99 GtkWidget *image_state;
100 GtkWidget *label_status;
101 GtkWidget *grid_contact;
102 GtkWidget *vbox_avatar;
103 GtkWidget *favourite_checkbox;
104 GtkWidget *label_details;
105 GtkWidget *label_left_account;
108 GtkWidget *vbox_location;
109 GtkWidget *subvbox_location;
110 GtkWidget *grid_location;
111 GtkWidget *label_location;
112 #ifdef HAVE_LIBCHAMPLAIN
113 GtkWidget *viewport_map;
114 GtkWidget *map_view_embed;
115 ChamplainView *map_view;
119 GtkWidget *groups_widget;
122 GtkWidget *vbox_details;
123 GtkWidget *grid_details;
124 GtkWidget *hbox_details_requested;
125 GtkWidget *spinner_details;
126 GList *details_to_set;
127 GCancellable *details_cancellable;
128 gboolean details_changed;
131 GtkWidget *vbox_client;
132 GtkWidget *grid_client;
133 GtkWidget *hbox_client_requested;
134 } EmpathyContactWidget;
138 EmpathyContactWidget *information;
141 GtkTreeIter found_iter;
153 field_value_is_empty (TpContactInfoField *field)
157 if (field->field_value == NULL)
160 /* Field is empty if all its values are empty */
161 for (i = 0; field->field_value[i] != NULL; i++)
163 if (!tp_str_empty (field->field_value[i]))
171 set_contact_info_cb (GObject *source,
172 GAsyncResult *result,
175 GError *error = NULL;
177 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
180 DEBUG ("SetContactInfo() failed: %s", error->message);
181 g_error_free (error);
185 DEBUG ("SetContactInfo() succeeded");
189 contact_widget_save (EmpathyContactWidget *information)
191 TpConnection *connection;
194 connection = empathy_contact_get_connection (information->contact);
196 /* Remove empty fields */
197 for (l = information->details_to_set; l != NULL; l = next)
199 TpContactInfoField *field = l->data;
202 if (field_value_is_empty (field))
204 DEBUG ("Drop empty field: %s", field->field_name);
205 tp_contact_info_field_free (field);
206 information->details_to_set =
207 g_list_delete_link (information->details_to_set, l);
211 if (information->details_to_set != NULL)
213 if (information->details_changed)
215 tp_connection_set_contact_info_async (connection,
216 information->details_to_set, set_contact_info_cb, NULL);
219 tp_contact_info_list_free (information->details_to_set);
220 information->details_to_set = NULL;
225 contact_widget_details_setup (EmpathyContactWidget *information)
227 gtk_widget_hide (information->vbox_details);
229 information->spinner_details = gtk_spinner_new ();
230 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
231 information->spinner_details, TRUE, TRUE, 0);
232 gtk_widget_show (information->spinner_details);
236 contact_widget_details_changed_cb (GtkEntry *entry,
237 EmpathyContactWidget *self)
239 const gchar *strv[] = { NULL, NULL };
240 TpContactInfoField *field;
242 self->details_changed = TRUE;
244 field = g_object_get_data ((GObject *) entry, DATA_FIELD);
245 g_assert (field != NULL);
247 strv[0] = gtk_entry_get_text (entry);
249 if (field->field_value != NULL)
250 g_strfreev (field->field_value);
251 field->field_value = g_strdupv ((GStrv) strv);
255 contact_widget_bday_changed_cb (EmpathyCalendarButton *button,
257 EmpathyContactWidget *self)
259 const gchar *strv[] = { NULL, NULL };
260 TpContactInfoField *field;
262 self->details_changed = TRUE;
264 field = g_object_get_data ((GObject *) button, DATA_FIELD);
265 g_assert (field != NULL);
271 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT,
276 if (field->field_value != NULL)
277 g_strfreev (field->field_value);
278 field->field_value = g_strdupv ((GStrv) strv);
281 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
284 field_name_in_field_list (GList *list,
289 for (l = list; l != NULL; l = g_list_next (l))
291 TpContactInfoField *field = l->data;
293 if (!tp_strdiff (field->field_name, name))
300 static TpContactInfoFieldSpec *
301 get_spec_from_list (GList *list,
306 for (l = list; l != NULL; l = g_list_next (l))
308 TpContactInfoFieldSpec *spec = l->data;
310 if (!tp_strdiff (spec->name, name))
318 contact_widget_details_update_edit (EmpathyContactWidget *information)
321 TpConnection *connection;
325 const char **field_names = empathy_contact_info_get_field_names (NULL);
328 g_assert (information->details_to_set == NULL);
330 information->details_changed = FALSE;
332 contact = empathy_contact_get_tp_contact (information->contact);
333 connection = tp_contact_get_connection (contact);
335 info = tp_contact_get_contact_info (contact);
337 specs = tp_connection_get_contact_info_supported_fields (connection);
339 /* Look at the fields set in our vCard */
340 for (l = info; l != NULL; l = l->next)
342 TpContactInfoField *field = l->data;
344 /* make a copy for the details_to_set list */
345 field = tp_contact_info_field_copy (field);
346 DEBUG ("Field %s is in our vCard", field->field_name);
348 information->details_to_set = g_list_prepend (information->details_to_set,
352 /* Add fields which are supported but not in the vCard */
353 for (i = 0; field_names[i] != NULL; i++)
355 TpContactInfoFieldSpec *spec;
356 TpContactInfoField *field;
358 /* Check if the field was in the vCard */
359 if (field_name_in_field_list (information->details_to_set,
363 /* Check if the CM supports the field */
364 spec = get_spec_from_list (specs, field_names[i]);
368 /* add an empty field so user can set a value */
369 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
371 information->details_to_set = g_list_prepend (information->details_to_set,
375 /* Add widgets for supported fields */
376 information->details_to_set = g_list_sort (information->details_to_set,
377 (GCompareFunc) empathy_contact_info_field_spec_cmp);
379 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
381 TpContactInfoField *field = l->data;
383 TpContactInfoFieldSpec *spec;
387 has_field = empathy_contact_info_lookup_field (field->field_name,
391 /* Empathy doesn't display this field so we can't change it.
392 * But we put it in the details_to_set list so it won't be erased
393 * when calling SetContactInfo (bgo #630427) */
394 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
398 spec = get_spec_from_list (specs, field->field_name);
399 /* We shouldn't have added the field to details_to_set if it's not
400 * supported by the CM */
401 g_assert (spec != NULL);
403 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
405 DEBUG ("Ignoring field '%s' due it to having the "
406 "Overwritten_By_Nickname flag", field->field_name);
411 title = empathy_contact_info_field_label (field->field_name,
413 (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT));
414 w = gtk_label_new (title);
417 /* TODO: if TP_CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT is not set we
418 * should allow user to tag the vCard fields (bgo#672034) */
420 gtk_grid_attach (GTK_GRID (information->grid_details),
423 gtk_misc_set_alignment (GTK_MISC (w), 1, 0.5);
427 if (!tp_strdiff (field->field_name, "bday"))
429 w = empathy_calendar_button_new ();
431 if (field->field_value[0])
435 g_date_set_parse (&date, field->field_value[0]);
436 if (g_date_valid (&date))
438 empathy_calendar_button_set_date (EMPATHY_CALENDAR_BUTTON (w),
443 gtk_grid_attach (GTK_GRID (information->grid_details),
445 gtk_widget_show_all (w);
447 g_object_set_data ((GObject *) w, DATA_FIELD, field);
449 g_signal_connect (w, "date-changed",
450 G_CALLBACK (contact_widget_bday_changed_cb), information);
454 w = gtk_entry_new ();
455 gtk_entry_set_text (GTK_ENTRY (w),
456 field->field_value[0] ? field->field_value[0] : "");
457 gtk_grid_attach (GTK_GRID (information->grid_details),
461 g_object_set_data ((GObject *) w, DATA_FIELD, field);
463 g_signal_connect (w, "changed",
464 G_CALLBACK (contact_widget_details_changed_cb), information);
477 add_row (GtkGrid *grid,
482 gtk_grid_attach (grid, title, 0, row, 1, 1);
483 gtk_misc_set_alignment (GTK_MISC (title), 0, 0.5);
484 gtk_widget_show (title);
486 gtk_grid_attach (grid, value, 1, row, 1, 1);
487 gtk_misc_set_alignment (GTK_MISC (value), 0, 0.5);
488 gtk_widget_show (value);
492 contact_widget_details_update_show (EmpathyContactWidget *information)
497 GtkWidget *channels_label;
500 contact = empathy_contact_get_tp_contact (information->contact);
501 info = tp_contact_get_contact_info (contact);
502 info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
503 for (l = info; l != NULL; l = l->next)
505 TpContactInfoField *field = l->data;
507 gchar *markup = NULL, *title;
508 GtkWidget *title_widget, *value_widget;
509 EmpathyContactInfoFormatFunc format;
511 if (field->field_value == NULL || field->field_value[0] == NULL)
514 value = field->field_value[0];
516 if (!empathy_contact_info_lookup_field (field->field_name, NULL, &format))
518 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
524 markup = format (field->field_value);
528 DEBUG ("Invalid value for field '%s' (first element was '%s')",
529 field->field_name, field->field_value[0]);
535 title = empathy_contact_info_field_label (field->field_name,
536 field->parameters, TRUE);
537 title_widget = gtk_label_new (title);
541 value_widget = gtk_label_new (value);
544 gtk_label_set_markup (GTK_LABEL (value_widget), markup);
548 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
549 gtk_label_set_selectable (GTK_LABEL (value_widget), TRUE);
551 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
557 account = empathy_contact_get_account (information->contact);
559 channels_label = empathy_contact_info_create_channel_list_label (account,
562 if (channels_label != NULL)
564 GtkWidget *title_widget;
566 title_widget = gtk_label_new (_("Channels:"));
568 add_row (GTK_GRID (information->grid_details), n_rows, title_widget,
580 contact_widget_details_notify_cb (EmpathyContactWidget *information)
584 gtk_container_foreach (GTK_CONTAINER (information->grid_details),
585 (GtkCallback) gtk_widget_destroy, NULL);
587 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
588 n_rows = contact_widget_details_update_edit (information);
590 n_rows = contact_widget_details_update_show (information);
594 gtk_widget_show (information->vbox_details);
595 gtk_widget_show (information->grid_details);
599 gtk_widget_hide (information->vbox_details);
602 gtk_widget_hide (information->hbox_details_requested);
603 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
607 contact_widget_details_request_cb (GObject *object,
611 TpContact *contact = TP_CONTACT (object);
612 EmpathyContactWidget *information = user_data;
613 GError *error = NULL;
615 if (!tp_contact_request_contact_info_finish (contact, res, &error))
617 /* If the request got cancelled it could mean the contact widget is
618 * destroyed, so we should not dereference information */
619 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
621 g_clear_error (&error);
625 gtk_widget_hide (information->vbox_details);
626 g_clear_error (&error);
630 contact_widget_details_notify_cb (information);
633 /* If we are going to edit ContactInfo, we don't want live updates */
634 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
636 g_signal_connect_swapped (contact, "notify::contact-info",
637 G_CALLBACK (contact_widget_details_notify_cb), information);
640 tp_clear_object (&information->details_cancellable);
644 fetch_contact_information (EmpathyContactWidget *information,
645 TpConnection *connection)
648 TpContactInfoFlags flags;
650 if (!tp_proxy_has_interface_by_id (connection,
651 TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_INFO))
653 gtk_widget_hide (information->vbox_details);
657 /* If we want to edit info, but connection does not support that, stop */
658 flags = tp_connection_get_contact_info_flags (connection);
659 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
660 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
662 gtk_widget_hide (information->vbox_details);
666 /* Request the contact's info */
667 gtk_widget_show (information->vbox_details);
668 gtk_widget_show (information->hbox_details_requested);
669 gtk_widget_hide (information->grid_details);
670 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
672 contact = empathy_contact_get_tp_contact (information->contact);
673 g_assert (information->details_cancellable == NULL);
674 information->details_cancellable = g_cancellable_new ();
675 tp_contact_request_contact_info_async (contact,
676 information->details_cancellable, contact_widget_details_request_cb,
681 contact_widget_details_update (EmpathyContactWidget *information)
683 TpContact *tp_contact = NULL;
685 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
686 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
689 gtk_widget_hide (information->vbox_details);
691 if (information->contact != NULL)
692 tp_contact = empathy_contact_get_tp_contact (information->contact);
694 if (tp_contact != NULL)
696 TpConnection *connection;
698 connection = tp_contact_get_connection (tp_contact);
700 fetch_contact_information (information, connection);
705 contact_widget_client_update (EmpathyContactWidget *information)
707 /* FIXME: Needs new telepathy spec */
711 contact_widget_client_setup (EmpathyContactWidget *information)
713 /* FIXME: Needs new telepathy spec */
714 gtk_widget_hide (information->vbox_client);
718 contact_widget_groups_update (EmpathyContactWidget *information)
720 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
721 information->contact != NULL)
723 FolksPersona *persona =
724 empathy_contact_get_persona (information->contact);
726 if (FOLKS_IS_GROUP_DETAILS (persona))
728 empathy_groups_widget_set_group_details (
729 EMPATHY_GROUPS_WIDGET (information->groups_widget),
730 FOLKS_GROUP_DETAILS (persona));
731 gtk_widget_show (information->groups_widget);
737 /* In case of failure */
738 gtk_widget_hide (information->groups_widget);
741 /* Converts the Location's GHashTable's key to a user readable string */
743 location_key_to_label (const gchar *key)
745 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
746 return _("Country ISO Code:");
747 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
748 return _("Country:");
749 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
751 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
753 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
755 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
756 return _("Postal Code:");
757 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
759 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
760 return _("Building:");
761 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
763 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
765 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
767 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
768 return _("Description:");
769 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
771 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
772 return _("Accuracy Level:");
773 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
775 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
776 return _("Vertical Error (meters):");
777 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
778 return _("Horizontal Error (meters):");
779 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
781 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
782 return _("Bearing:");
783 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
784 return _("Climb Speed:");
785 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
786 return _("Last Updated on:");
787 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
788 return _("Longitude:");
789 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
790 return _("Latitude:");
791 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
792 return _("Altitude:");
795 DEBUG ("Unexpected Location key: %s", key);
801 contact_widget_location_update (EmpathyContactWidget *information)
803 GHashTable *location;
805 #ifdef HAVE_LIBCHAMPLAIN
806 gdouble lat = 0.0, lon = 0.0;
807 gboolean has_position = TRUE;
811 static const gchar* ordered_geolocation_keys[] = {
812 EMPATHY_LOCATION_TEXT,
813 EMPATHY_LOCATION_URI,
814 EMPATHY_LOCATION_DESCRIPTION,
815 EMPATHY_LOCATION_BUILDING,
816 EMPATHY_LOCATION_FLOOR,
817 EMPATHY_LOCATION_ROOM,
818 EMPATHY_LOCATION_STREET,
819 EMPATHY_LOCATION_AREA,
820 EMPATHY_LOCATION_LOCALITY,
821 EMPATHY_LOCATION_REGION,
822 EMPATHY_LOCATION_COUNTRY,
827 gboolean display_map = FALSE;
829 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
831 gtk_widget_hide (information->vbox_location);
835 location = empathy_contact_get_location (information->contact);
836 if (location == NULL || g_hash_table_size (location) == 0)
838 gtk_widget_hide (information->vbox_location);
842 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
845 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
846 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
856 stamp = g_value_get_int64 (value);
858 user_date = empathy_time_to_string_relative (stamp);
860 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
861 /* translators: format is "Location, $date" */
862 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
864 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
870 /* Prepare the location information grid */
871 if (information->grid_location != NULL)
873 gtk_widget_destroy (information->grid_location);
876 information->grid_location = gtk_grid_new ();
877 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
878 information->grid_location, FALSE, FALSE, 5);
881 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
883 const gchar* user_label;
887 gvalue = g_hash_table_lookup (location, (gpointer) skey);
891 user_label = location_key_to_label (skey);
893 label = gtk_label_new (user_label);
894 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
895 gtk_grid_attach (GTK_GRID (information->grid_location),
896 label, 0, row, 1, 1);
897 gtk_widget_show (label);
899 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
902 dvalue = g_value_get_double (gvalue);
903 svalue = g_strdup_printf ("%f", dvalue);
905 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
907 svalue = g_value_dup_string (gvalue);
909 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
913 time_ = g_value_get_int64 (value);
914 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
919 label = gtk_label_new (svalue);
920 gtk_grid_attach (GTK_GRID (information->grid_location),
921 label, 1, row, 1, 1);
922 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
923 gtk_widget_show (label);
925 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
926 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
933 #ifdef HAVE_LIBCHAMPLAIN
935 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
937 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
945 /* We can display some fields */
946 gtk_widget_show (information->grid_location);
948 else if (!display_map)
950 /* Can't display either fields or map */
951 gtk_widget_hide (information->vbox_location);
955 #ifdef HAVE_LIBCHAMPLAIN
958 ClutterActor *marker;
959 ChamplainMarkerLayer *layer;
961 information->map_view_embed = gtk_champlain_embed_new ();
962 information->map_view = gtk_champlain_embed_get_view (
963 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
965 gtk_container_add (GTK_CONTAINER (information->viewport_map),
966 information->map_view_embed);
967 g_object_set (G_OBJECT (information->map_view),
968 "kinetic-mode", TRUE,
972 layer = champlain_marker_layer_new ();
973 champlain_view_add_layer (information->map_view, CHAMPLAIN_LAYER (layer));
975 marker = champlain_label_new_with_text (
976 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
977 champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
978 champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
980 champlain_view_center_on (information->map_view, lat, lon);
981 gtk_widget_show_all (information->viewport_map);
985 gtk_widget_show (information->vbox_location);
989 save_avatar_menu_activate_cb (GtkWidget *widget,
990 EmpathyContactWidget *information)
993 EmpathyAvatar *avatar;
994 gchar *ext = NULL, *filename;
996 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
998 GTK_FILE_CHOOSER_ACTION_SAVE,
999 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1000 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1003 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1006 /* look for the avatar extension */
1007 avatar = empathy_contact_get_avatar (information->contact);
1008 if (avatar->format != NULL)
1012 splitted = g_strsplit (avatar->format, "/", 2);
1013 if (splitted[0] != NULL && splitted[1] != NULL)
1014 ext = g_strdup (splitted[1]);
1016 g_strfreev (splitted);
1020 /* Avatar was loaded from the cache so was converted to PNG */
1021 ext = g_strdup ("png");
1028 id = tp_escape_as_identifier (empathy_contact_get_id (
1029 information->contact));
1031 filename = g_strdup_printf ("%s.%s", id, ext);
1032 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1039 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1041 GError *error = NULL;
1043 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1045 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1048 GtkWidget *error_dialog;
1050 error_dialog = gtk_message_dialog_new (NULL, 0,
1051 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1052 _("Unable to save avatar"));
1054 gtk_message_dialog_format_secondary_text (
1055 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1057 g_signal_connect (error_dialog, "response",
1058 G_CALLBACK (gtk_widget_destroy), NULL);
1060 gtk_window_present (GTK_WINDOW (error_dialog));
1062 g_clear_error (&error);
1068 gtk_widget_destroy (dialog);
1072 popup_avatar_menu (EmpathyContactWidget *information,
1074 GdkEventButton *event)
1076 GtkWidget *menu, *item;
1077 gint button, event_time;
1079 if (information->contact == NULL ||
1080 empathy_contact_get_avatar (information->contact) == NULL)
1083 menu = empathy_context_menu_new (parent);
1085 /* Add "Save as..." entry */
1086 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1087 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1088 gtk_widget_show (item);
1090 g_signal_connect (item, "activate",
1091 G_CALLBACK (save_avatar_menu_activate_cb), information);
1095 button = event->button;
1096 event_time = event->time;
1101 event_time = gtk_get_current_event_time ();
1104 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1105 button, event_time);
1109 widget_avatar_popup_menu_cb (GtkWidget *widget,
1110 EmpathyContactWidget *information)
1112 popup_avatar_menu (information, widget, NULL);
1118 widget_avatar_button_press_event_cb (GtkWidget *widget,
1119 GdkEventButton *event,
1120 EmpathyContactWidget *information)
1122 /* Ignore double-clicks and triple-clicks */
1123 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1125 popup_avatar_menu (information, widget, event);
1133 set_avatar_cb (GObject *source,
1137 GError *error = NULL;
1139 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1140 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1141 g_error_free (error);
1146 set_avatar_on_account (TpAccount *account,
1149 const gchar *mime_type)
1151 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1152 tp_proxy_get_object_path (account));
1154 tp_account_set_avatar_async (account, (const guchar *) data, size,
1155 mime_type, set_avatar_cb, NULL);
1159 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1160 EmpathyContactWidget *information)
1164 const gchar *mime_type;
1167 empathy_avatar_chooser_get_image_data (
1168 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1169 &data, &size, &mime_type);
1171 account = empathy_contact_get_account (information->contact);
1172 set_avatar_on_account (account, data, size, mime_type);
1176 set_nickname_cb (GObject *source,
1180 GError *error = NULL;
1182 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1184 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1185 g_error_free (error);
1189 /* Update all the contact info fields having the
1190 * Overwritten_By_Nickname flag to the new alias. This avoid accidentally
1191 * reseting the alias when calling SetContactInfo(). See bgo #644298 for
1194 update_nickname_in_contact_info (EmpathyContactWidget *self,
1195 TpConnection *connection,
1196 const gchar *nickname)
1200 specs = tp_connection_get_contact_info_supported_fields (connection);
1202 for (l = self->details_to_set; l != NULL; l= g_list_next (l))
1204 TpContactInfoField *field = l->data;
1205 TpContactInfoFieldSpec *spec;
1207 spec = get_spec_from_list (specs, field->field_name);
1208 /* We shouldn't have added the field to details_to_set if it's not
1209 * supported by the CM */
1210 g_assert (spec != NULL);
1212 if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME)
1214 const gchar *strv[] = { nickname, NULL };
1216 DEBUG ("Updating field '%s' to '%s' as it has the "
1217 "Overwritten_By_Nickname flag and Account.Nickname has "
1218 "been updated", field->field_name, nickname);
1220 if (field->field_value != NULL)
1221 g_strfreev (field->field_value);
1222 field->field_value = g_strdupv ((GStrv) strv);
1226 g_list_free (specs);
1230 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1231 GdkEventFocus *event,
1232 EmpathyContactWidget *information)
1234 if (information->contact)
1238 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1240 if (empathy_contact_is_user (information->contact))
1242 TpAccount * account;
1243 const gchar *current_nickname;
1245 account = empathy_contact_get_account (information->contact);
1246 current_nickname = tp_account_get_nickname (account);
1248 if (tp_strdiff (current_nickname, alias))
1250 DEBUG ("Set Account.Nickname to %s", alias);
1252 tp_account_set_nickname_async (account, alias, set_nickname_cb,
1255 update_nickname_in_contact_info (information,
1256 empathy_contact_get_connection (information->contact), alias);
1261 empathy_contact_set_alias (information->contact, alias);
1269 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1270 EmpathyAvatarChooser *avatar_chooser)
1274 account = empathy_account_chooser_get_account (account_chooser);
1275 if (account == NULL)
1278 empathy_avatar_chooser_set_account (avatar_chooser, account);
1282 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1284 EmpathyAvatar *avatar = NULL;
1286 if (information->contact)
1287 avatar = empathy_contact_get_avatar (information->contact);
1289 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1291 g_signal_handlers_block_by_func (information->widget_avatar,
1292 contact_widget_avatar_changed_cb,
1294 empathy_avatar_chooser_set (
1295 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1296 g_signal_handlers_unblock_by_func (information->widget_avatar,
1297 contact_widget_avatar_changed_cb, information);
1300 empathy_avatar_image_set (
1301 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1305 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1307 if (GTK_IS_ENTRY (information->widget_alias))
1308 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1309 empathy_contact_get_alias (information->contact));
1311 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1312 empathy_contact_get_alias (information->contact));
1316 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1318 const gchar *status;
1319 gchar *markup_text = NULL;
1321 status = empathy_contact_get_status (information->contact);
1323 markup_text = empathy_add_link_markup (status);
1324 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1325 g_free (markup_text);
1327 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1328 empathy_icon_name_for_contact (information->contact),
1329 GTK_ICON_SIZE_BUTTON);
1330 gtk_widget_show (information->image_state);
1334 contact_widget_remove_contact (EmpathyContactWidget *information)
1336 if (information->contact)
1338 TpContact *tp_contact;
1340 contact_widget_save (information);
1342 g_signal_handlers_disconnect_by_func (information->contact,
1343 contact_widget_name_notify_cb, information);
1344 g_signal_handlers_disconnect_by_func (information->contact,
1345 contact_widget_presence_notify_cb, information);
1346 g_signal_handlers_disconnect_by_func (information->contact,
1347 contact_widget_avatar_notify_cb, information);
1349 tp_contact = empathy_contact_get_tp_contact (information->contact);
1350 if (tp_contact != NULL)
1352 g_signal_handlers_disconnect_by_func (tp_contact,
1353 contact_widget_details_notify_cb, information);
1356 g_object_unref (information->contact);
1357 information->contact = NULL;
1360 if (information->details_cancellable != NULL)
1362 g_cancellable_cancel (information->details_cancellable);
1363 tp_clear_object (&information->details_cancellable);
1367 static void contact_widget_change_contact (EmpathyContactWidget *information);
1370 contact_widget_contact_update (EmpathyContactWidget *information)
1372 TpAccount *account = NULL;
1373 const gchar *id = NULL;
1375 /* Connect and get info from new contact */
1376 if (information->contact)
1378 g_signal_connect_swapped (information->contact, "notify::name",
1379 G_CALLBACK (contact_widget_name_notify_cb), information);
1380 g_signal_connect_swapped (information->contact, "notify::presence",
1381 G_CALLBACK (contact_widget_presence_notify_cb), information);
1382 g_signal_connect_swapped (information->contact,
1383 "notify::presence-message",
1384 G_CALLBACK (contact_widget_presence_notify_cb), information);
1385 g_signal_connect_swapped (information->contact, "notify::avatar",
1386 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1388 account = empathy_contact_get_account (information->contact);
1389 id = empathy_contact_get_id (information->contact);
1392 /* Update account widget */
1393 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1397 g_signal_handlers_block_by_func (information->widget_account,
1398 contact_widget_change_contact,
1400 empathy_account_chooser_set_account (
1401 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1402 g_signal_handlers_unblock_by_func (information->widget_account,
1403 contact_widget_change_contact, information);
1408 if (EMPATHY_IS_AVATAR_CHOOSER (information->widget_avatar))
1410 empathy_avatar_chooser_set_account (
1411 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), account);
1414 if ((information->flags & EMPATHY_CONTACT_WIDGET_NO_ACCOUNT) == 0)
1420 name = tp_account_get_display_name (account);
1421 gtk_label_set_label (GTK_LABEL (information->label_account),
1424 name = tp_account_get_icon_name (account);
1425 gtk_image_set_from_icon_name (
1426 GTK_IMAGE (information->image_account),
1427 name, GTK_ICON_SIZE_MENU);
1432 /* Update id widget */
1433 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1434 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1436 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1438 /* Update other widgets */
1439 if (information->contact)
1441 contact_widget_name_notify_cb (information);
1442 contact_widget_presence_notify_cb (information);
1443 contact_widget_avatar_notify_cb (information);
1445 gtk_widget_show (information->label_alias);
1446 gtk_widget_show (information->widget_alias);
1447 gtk_widget_show (information->widget_avatar);
1449 gtk_widget_set_visible (information->hbox_presence,
1450 !(information->flags & EMPATHY_CONTACT_WIDGET_NO_STATUS));
1452 if (empathy_contact_is_user (information->contact))
1453 gtk_label_set_text (GTK_LABEL (information->label_details),
1454 _("Personal Details"));
1456 gtk_label_set_text (GTK_LABEL (information->label_details),
1457 _("Contact Details"));
1461 gtk_widget_hide (information->label_alias);
1462 gtk_widget_hide (information->widget_alias);
1463 gtk_widget_hide (information->hbox_presence);
1464 gtk_widget_hide (information->widget_avatar);
1469 contact_widget_set_contact (EmpathyContactWidget *information,
1470 EmpathyContact *contact)
1472 if (contact == information->contact)
1475 contact_widget_remove_contact (information);
1477 information->contact = g_object_ref (contact);
1479 /* set the selected account to be the account this contact came from */
1480 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1481 empathy_account_chooser_set_account (
1482 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1483 empathy_contact_get_account (contact));
1486 /* Update information for widgets */
1487 contact_widget_contact_update (information);
1488 contact_widget_groups_update (information);
1489 contact_widget_details_update (information);
1490 contact_widget_client_update (information);
1491 contact_widget_location_update (information);
1495 contact_widget_got_contact_cb (TpConnection *connection,
1496 EmpathyContact *contact,
1497 const GError *error,
1499 GObject *weak_object)
1501 EmpathyContactWidget *information = user_data;
1505 DEBUG ("Error: %s", error->message);
1509 contact_widget_set_contact (information, contact);
1513 contact_widget_change_contact (EmpathyContactWidget *information)
1515 TpConnection *connection;
1517 connection = empathy_account_chooser_get_connection (
1518 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1522 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1526 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1527 if (!EMP_STR_EMPTY (id))
1529 empathy_tp_contact_factory_get_from_id (connection, id,
1530 contact_widget_got_contact_cb, information, NULL,
1531 G_OBJECT (information->vbox_contact_widget));
1536 EmpathyContact *contact;
1538 contact = empathy_contact_dup_from_tp_contact (
1539 tp_connection_get_self_contact (connection));
1541 contact_widget_set_contact (information, contact);
1542 g_object_unref (contact);
1547 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1549 contact_widget_change_contact (self);
1554 contact_widget_id_changed_cb (GtkEntry *entry,
1555 EmpathyContactWidget *self)
1557 if (self->widget_id_timeout != 0)
1559 g_source_remove (self->widget_id_timeout);
1562 self->widget_id_timeout =
1563 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1564 (GSourceFunc) contact_widget_id_activate_timeout, self);
1568 contact_widget_id_focus_out_cb (GtkWidget *widget,
1569 GdkEventFocus *event,
1570 EmpathyContactWidget *information)
1572 contact_widget_change_contact (information);
1577 contact_widget_contact_setup (EmpathyContactWidget *information)
1579 information->label_status = gtk_label_new ("");
1580 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1581 PANGO_WRAP_WORD_CHAR);
1582 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1584 gtk_misc_set_alignment (GTK_MISC (information->label_status), 0, 0.5);
1586 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1587 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1589 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1590 information->label_status, TRUE, TRUE, 0);
1591 gtk_widget_show (information->label_status);
1593 /* Setup account label/chooser */
1594 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1596 information->widget_account = empathy_account_chooser_new ();
1598 g_signal_connect_swapped (information->widget_account, "changed",
1599 G_CALLBACK (contact_widget_change_contact),
1602 else if (information->flags & EMPATHY_CONTACT_WIDGET_NO_ACCOUNT)
1604 /* Don't display the account */
1605 gtk_widget_hide (information->label_left_account);
1609 /* Pack the protocol icon with the account name in an hbox */
1610 information->widget_account = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1612 information->label_account = gtk_label_new (NULL);
1613 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1614 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1616 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1617 gtk_widget_show (information->label_account);
1619 information->image_account = gtk_image_new ();
1620 gtk_widget_show (information->image_account);
1622 gtk_box_pack_start (GTK_BOX (information->widget_account),
1623 information->image_account, FALSE, FALSE, 0);
1624 gtk_box_pack_start (GTK_BOX (information->widget_account),
1625 information->label_account, FALSE, TRUE, 0);
1628 if (information->widget_account != NULL)
1630 gtk_grid_attach (GTK_GRID (information->grid_contact),
1631 information->widget_account,
1634 gtk_widget_show (information->widget_account);
1637 /* Set up avatar chooser/display */
1638 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1640 information->widget_avatar = empathy_avatar_chooser_new ();
1641 g_signal_connect (information->widget_avatar, "changed",
1642 G_CALLBACK (contact_widget_avatar_changed_cb),
1644 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1646 g_signal_connect (information->widget_account, "changed",
1647 G_CALLBACK (update_avatar_chooser_account_cb),
1648 information->widget_avatar);
1649 update_avatar_chooser_account_cb (
1650 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1651 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1656 information->widget_avatar = empathy_avatar_image_new ();
1658 g_signal_connect (information->widget_avatar, "popup-menu",
1659 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1660 g_signal_connect (information->widget_avatar, "button-press-event",
1661 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1664 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1665 information->widget_avatar,
1668 gtk_widget_show (information->widget_avatar);
1670 /* Setup id label/entry */
1671 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1673 information->widget_id = gtk_entry_new ();
1674 g_signal_connect (information->widget_id, "focus-out-event",
1675 G_CALLBACK (contact_widget_id_focus_out_cb),
1677 g_signal_connect (information->widget_id, "changed",
1678 G_CALLBACK (contact_widget_id_changed_cb),
1683 information->widget_id = gtk_label_new (NULL);
1684 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1685 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1687 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1690 gtk_grid_attach (GTK_GRID (information->grid_contact), information->widget_id,
1693 gtk_widget_show (information->widget_id);
1695 /* Setup alias label/entry */
1696 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1698 information->widget_alias = gtk_entry_new ();
1700 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1701 g_signal_connect (information->widget_alias, "focus-out-event",
1702 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1705 /* Make return activate the window default (the Close button) */
1706 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1711 information->widget_alias = gtk_label_new (NULL);
1712 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1713 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1715 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1718 gtk_grid_attach (GTK_GRID (information->grid_contact),
1719 information->widget_alias, 1, 2, 1, 1);
1721 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1722 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1724 gtk_widget_show (information->widget_alias);
1728 contact_widget_destroy_cb (GtkWidget *widget,
1729 EmpathyContactWidget *information)
1731 contact_widget_remove_contact (information);
1733 if (information->widget_id_timeout != 0)
1735 g_source_remove (information->widget_id_timeout);
1738 g_slice_free (EmpathyContactWidget, information);
1742 * empathy_contact_widget_new:
1743 * @contact: an #EmpathyContact
1744 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1746 * Creates a new #EmpathyContactWidget.
1748 * Return value: a new #EmpathyContactWidget
1751 empathy_contact_widget_new (EmpathyContact *contact,
1752 EmpathyContactWidgetFlags flags)
1754 EmpathyContactWidget *information;
1758 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1760 information = g_slice_new0 (EmpathyContactWidget);
1761 information->flags = flags;
1763 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1765 gui = empathy_builder_get_file (filename,
1766 "vbox_contact_widget", &information->vbox_contact_widget,
1767 "hbox_presence", &information->hbox_presence,
1768 "label_alias", &information->label_alias,
1769 "image_state", &information->image_state,
1770 "grid_contact", &information->grid_contact,
1771 "vbox_avatar", &information->vbox_avatar,
1772 "vbox_location", &information->vbox_location,
1773 "subvbox_location", &information->subvbox_location,
1774 "label_location", &information->label_location,
1775 #ifdef HAVE_LIBCHAMPLAIN
1776 "viewport_map", &information->viewport_map,
1778 "groups_widget", &information->groups_widget,
1779 "vbox_details", &information->vbox_details,
1780 "grid_details", &information->grid_details,
1781 "hbox_details_requested", &information->hbox_details_requested,
1782 "vbox_client", &information->vbox_client,
1783 "grid_client", &information->grid_client,
1784 "hbox_client_requested", &information->hbox_client_requested,
1785 "label_details", &information->label_details,
1786 "label_left_account", &information->label_left_account,
1790 empathy_builder_connect (gui, information,
1791 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1793 information->grid_location = NULL;
1795 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1796 "EmpathyContactWidget",
1799 /* Create widgets */
1800 contact_widget_contact_setup (information);
1801 contact_widget_details_setup (information);
1802 contact_widget_client_setup (information);
1804 if (contact != NULL)
1805 contact_widget_set_contact (information, contact);
1806 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1807 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1808 contact_widget_change_contact (information);
1810 return empathy_builder_unref_and_keep_widget (gui,
1811 information->vbox_contact_widget);
1815 * empathy_contact_widget_get_contact:
1816 * @widget: an #EmpathyContactWidget
1818 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1820 * Returns: the #EmpathyContact associated with @widget
1823 empathy_contact_widget_get_contact (GtkWidget *widget)
1825 EmpathyContactWidget *information;
1827 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1829 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1833 return information->contact;
1837 empathy_contact_widget_get_alias (GtkWidget *widget)
1839 EmpathyContactWidget *information;
1841 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1843 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1847 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1851 * empathy_contact_widget_set_contact:
1852 * @widget: an #EmpathyContactWidget
1853 * @contact: a different #EmpathyContact
1855 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1858 empathy_contact_widget_set_contact (GtkWidget *widget,
1859 EmpathyContact *contact)
1861 EmpathyContactWidget *information;
1863 g_return_if_fail (GTK_IS_WIDGET (widget));
1864 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1866 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1870 contact_widget_set_contact (information, contact);
1874 * empathy_contact_widget_set_account_filter:
1875 * @widget: an #EmpathyContactWidget
1876 * @filter: a #EmpathyAccountChooserFilterFunc
1877 * @user_data: user data to pass to @filter, or %NULL
1879 * Set a filter on the #EmpathyAccountChooser included in the
1880 * #EmpathyContactWidget.
1883 empathy_contact_widget_set_account_filter (
1885 EmpathyAccountChooserFilterFunc filter,
1888 EmpathyContactWidget *information;
1889 EmpathyAccountChooser *chooser;
1891 g_return_if_fail (GTK_IS_WIDGET (widget));
1893 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1897 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1899 empathy_account_chooser_set_filter (chooser, filter, user_data);