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-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
81 EmpathyContactManager *manager;
82 EmpathyContact *contact;
83 EmpathyContactWidgetFlags flags;
84 guint widget_id_timeout;
87 GtkWidget *vbox_contact_widget;
90 GtkWidget *hbox_contact;
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 *table_contact;
102 GtkWidget *vbox_avatar;
103 GtkWidget *favourite_checkbox;
106 GtkWidget *vbox_location;
107 GtkWidget *subvbox_location;
108 GtkWidget *table_location;
109 GtkWidget *label_location;
110 #ifdef HAVE_LIBCHAMPLAIN
111 GtkWidget *viewport_map;
112 GtkWidget *map_view_embed;
113 ChamplainView *map_view;
117 GtkWidget *groups_widget;
120 GtkWidget *vbox_details;
121 GtkWidget *table_details;
122 GtkWidget *hbox_details_requested;
123 GtkWidget *spinner_details;
124 GList *details_to_set;
125 GCancellable *details_cancellable;
128 GtkWidget *vbox_client;
129 GtkWidget *table_client;
130 GtkWidget *hbox_client_requested;
131 } EmpathyContactWidget;
135 EmpathyContactWidget *information;
138 GtkTreeIter found_iter;
150 field_value_is_empty (TpContactInfoField *field)
154 if (field->field_value == NULL)
157 /* Field is empty if all its values are empty */
158 for (i = 0; field->field_value[i] != NULL; i++)
160 if (!tp_str_empty (field->field_value[i]))
168 set_contact_info_cb (GObject *source,
169 GAsyncResult *result,
172 GError *error = NULL;
174 if (!tp_connection_set_contact_info_finish (TP_CONNECTION (source), result,
177 DEBUG ("SetContactInfo() failed: %s", error->message);
178 g_error_free (error);
182 DEBUG ("SetContactInfo() succeeded");
186 contact_widget_save (EmpathyContactWidget *information)
188 TpConnection *connection;
191 connection = empathy_contact_get_connection (information->contact);
193 /* Remove empty fields */
194 for (l = information->details_to_set; l != NULL; l = next)
196 TpContactInfoField *field = l->data;
199 if (field_value_is_empty (field))
201 DEBUG ("Drop empty field: %s", field->field_name);
202 tp_contact_info_field_free (field);
203 information->details_to_set =
204 g_list_delete_link (information->details_to_set, l);
208 if (information->details_to_set != NULL)
210 tp_connection_set_contact_info_async (connection,
211 information->details_to_set, set_contact_info_cb, NULL);
212 tp_contact_info_list_free (information->details_to_set);
213 information->details_to_set = NULL;
218 contact_widget_details_setup (EmpathyContactWidget *information)
220 gtk_widget_hide (information->vbox_details);
222 information->spinner_details = gtk_spinner_new ();
223 gtk_box_pack_end (GTK_BOX (information->hbox_details_requested),
224 information->spinner_details, TRUE, TRUE, 0);
225 gtk_widget_show (information->spinner_details);
229 contact_widget_details_changed_cb (GtkEntry *entry,
230 TpContactInfoField *field)
232 const gchar *strv[] = { NULL, NULL };
234 strv[0] = gtk_entry_get_text (entry);
236 if (field->field_value != NULL)
237 g_strfreev (field->field_value);
238 field->field_value = g_strdupv ((GStrv) strv);
241 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
245 const gchar *field_name;
250 static InfoFieldData info_field_datas[] =
252 { "fn", N_("Full name:"), FALSE },
253 { "tel", N_("Phone number:"), FALSE },
254 { "email", N_("E-mail address:"), TRUE },
255 { "url", N_("Website:"), TRUE },
256 { "bday", N_("Birthday:"), FALSE },
260 static InfoFieldData *
261 find_info_field_data (const gchar *field_name)
265 for (i = 0; info_field_datas[i].field_name != NULL; i++)
267 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
268 return info_field_datas + i;
274 contact_info_field_name_cmp (const gchar *name1,
279 if (!tp_strdiff (name1, name2))
282 /* We use the order of info_field_datas */
283 for (i = 0; info_field_datas[i].field_name != NULL; i++)
285 if (!tp_strdiff (info_field_datas[i].field_name, name1))
287 if (!tp_strdiff (info_field_datas[i].field_name, name2))
291 return g_strcmp0 (name1, name2);
295 contact_info_field_cmp (TpContactInfoField *field1,
296 TpContactInfoField *field2)
298 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
302 field_name_in_field_list (GList *list,
307 for (l = list; l != NULL; l = g_list_next (l))
309 TpContactInfoField *field = l->data;
311 if (!tp_strdiff (field->field_name, name))
318 static TpContactInfoFieldSpec *
319 get_spec_from_list (GList *list,
324 for (l = list; l != NULL; l = g_list_next (l))
326 TpContactInfoFieldSpec *spec = l->data;
328 if (!tp_strdiff (spec->name, name))
336 contact_widget_details_update_edit (EmpathyContactWidget *information)
339 TpConnection *connection;
345 g_assert (information->details_to_set == NULL);
347 contact = empathy_contact_get_tp_contact (information->contact);
348 connection = tp_contact_get_connection (contact);
350 info = tp_contact_get_contact_info (contact);
352 specs = tp_connection_get_contact_info_supported_fields (connection);
354 /* Look at the fields set in our vCard */
355 for (l = info; l != NULL; l = l->next)
357 TpContactInfoField *field = l->data;
359 /* make a copy for the details_to_set list */
360 field = tp_contact_info_field_copy (field);
361 DEBUG ("Field %s is in our vCard", field->field_name);
363 information->details_to_set = g_list_prepend (information->details_to_set,
367 /* Add fields which are supported but not in the vCard */
368 for (i = 0; info_field_datas[i].field_name != NULL; i++)
370 TpContactInfoFieldSpec *spec;
371 TpContactInfoField *field;
373 /* Check if the field was in the vCard */
374 if (field_name_in_field_list (information->details_to_set,
375 info_field_datas[i].field_name))
378 /* Check if the CM supports the field */
379 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
383 /* add an empty field so user can set a value */
384 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
386 information->details_to_set = g_list_prepend (information->details_to_set,
390 /* Add widgets for supported fields */
391 information->details_to_set = g_list_sort (information->details_to_set,
392 (GCompareFunc) contact_info_field_cmp);
394 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
396 TpContactInfoField *field = l->data;
397 InfoFieldData *field_data;
400 field_data = find_info_field_data (field->field_name);
401 if (field_data == NULL)
403 /* Empathy doesn't display this field so we can't change it.
404 * But we put it in the details_to_set list so it won't be erased
405 * when calling SetContactInfo (bgo #630427) */
406 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
411 w = gtk_label_new (_(field_data->title));
412 gtk_table_attach (GTK_TABLE (information->table_details),
413 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
414 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
418 w = gtk_entry_new ();
419 gtk_entry_set_text (GTK_ENTRY (w),
420 field->field_value[0] ? field->field_value[0] : "");
421 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
422 w, 1, 2, n_rows, n_rows + 1);
425 g_signal_connect (w, "changed",
426 G_CALLBACK (contact_widget_details_changed_cb), field);
438 contact_widget_details_update_show (EmpathyContactWidget *information)
444 contact = empathy_contact_get_tp_contact (information->contact);
445 info = tp_contact_get_contact_info (contact);
446 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
447 for (l = info; l != NULL; l = l->next)
449 TpContactInfoField *field = l->data;
450 InfoFieldData *field_data;
454 if (field->field_value == NULL || field->field_value[0] == NULL)
457 value = field->field_value[0];
459 field_data = find_info_field_data (field->field_name);
460 if (field_data == NULL)
462 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
467 w = gtk_label_new (_(field_data->title));
468 gtk_table_attach (GTK_TABLE (information->table_details),
469 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
470 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
474 w = gtk_label_new (value);
475 if (field_data->linkify)
479 markup = empathy_add_link_markup (value);
480 gtk_label_set_markup (GTK_LABEL (w), markup);
484 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
485 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
487 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
488 w, 1, 2, n_rows, n_rows + 1);
489 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
500 contact_widget_details_notify_cb (EmpathyContactWidget *information)
504 gtk_container_foreach (GTK_CONTAINER (information->table_details),
505 (GtkCallback) gtk_widget_destroy, NULL);
507 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
508 n_rows = contact_widget_details_update_edit (information);
510 n_rows = contact_widget_details_update_show (information);
514 gtk_widget_show (information->vbox_details);
515 gtk_widget_show (information->table_details);
519 gtk_widget_hide (information->vbox_details);
522 gtk_widget_hide (information->hbox_details_requested);
523 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
527 contact_widget_details_request_cb (GObject *object,
531 TpContact *contact = TP_CONTACT (object);
532 EmpathyContactWidget *information = user_data;
533 GError *error = NULL;
535 if (!tp_contact_request_contact_info_finish (contact, res, &error))
537 /* If the request got cancelled it could mean the contact widget is
538 * destroyed, so we should not dereference information */
539 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
541 g_clear_error (&error);
545 gtk_widget_hide (information->vbox_details);
546 g_clear_error (&error);
550 contact_widget_details_notify_cb (information);
553 /* If we are going to edit ContactInfo, we don't want live updates */
554 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
556 g_signal_connect_swapped (contact, "notify::contact-info",
557 G_CALLBACK (contact_widget_details_notify_cb), information);
560 tp_clear_object (&information->details_cancellable);
564 contact_widget_details_feature_prepared_cb (GObject *object,
568 TpConnection *connection = TP_CONNECTION (object);
569 EmpathyContactWidget *information = user_data;
571 TpContactInfoFlags flags;
573 if (!tp_proxy_prepare_finish (connection, res, NULL))
575 gtk_widget_hide (information->vbox_details);
579 /* If we want to edit info, but connection does not support that, stop */
580 flags = tp_connection_get_contact_info_flags (connection);
581 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
582 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
584 gtk_widget_hide (information->vbox_details);
588 /* Request the contact's info */
589 gtk_widget_show (information->vbox_details);
590 gtk_widget_show (information->hbox_details_requested);
591 gtk_widget_hide (information->table_details);
592 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
594 contact = empathy_contact_get_tp_contact (information->contact);
595 g_assert (information->details_cancellable == NULL);
596 information->details_cancellable = g_cancellable_new ();
597 tp_contact_request_contact_info_async (contact,
598 information->details_cancellable, contact_widget_details_request_cb,
603 contact_widget_details_update (EmpathyContactWidget *information)
605 TpContact *tp_contact = NULL;
607 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
608 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
611 gtk_widget_hide (information->vbox_details);
613 if (information->contact != NULL)
614 tp_contact = empathy_contact_get_tp_contact (information->contact);
616 if (tp_contact != NULL)
618 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
619 TpConnection *connection;
621 /* First, make sure the CONTACT_INFO feature is ready on the connection */
622 connection = tp_contact_get_connection (tp_contact);
623 tp_proxy_prepare_async (connection, features,
624 contact_widget_details_feature_prepared_cb, information);
629 contact_widget_client_update (EmpathyContactWidget *information)
631 /* FIXME: Needs new telepathy spec */
635 contact_widget_client_setup (EmpathyContactWidget *information)
637 /* FIXME: Needs new telepathy spec */
638 gtk_widget_hide (information->vbox_client);
642 contact_widget_groups_update (EmpathyContactWidget *information)
644 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
645 information->contact != NULL)
647 FolksPersona *persona =
648 empathy_contact_get_persona (information->contact);
650 if (FOLKS_IS_GROUPABLE (persona))
652 empathy_groups_widget_set_groupable (
653 EMPATHY_GROUPS_WIDGET (information->groups_widget),
654 FOLKS_GROUPABLE (persona));
655 gtk_widget_show (information->groups_widget);
661 /* In case of failure */
662 gtk_widget_hide (information->groups_widget);
665 /* Converts the Location's GHashTable's key to a user readable string */
667 location_key_to_label (const gchar *key)
669 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
670 return _("Country ISO Code:");
671 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
672 return _("Country:");
673 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
675 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
677 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
679 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
680 return _("Postal Code:");
681 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
683 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
684 return _("Building:");
685 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
687 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
689 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
691 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
692 return _("Description:");
693 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
695 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
696 return _("Accuracy Level:");
697 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
699 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
700 return _("Vertical Error (meters):");
701 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
702 return _("Horizontal Error (meters):");
703 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
705 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
706 return _("Bearing:");
707 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
708 return _("Climb Speed:");
709 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
710 return _("Last Updated on:");
711 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
712 return _("Longitude:");
713 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
714 return _("Latitude:");
715 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
716 return _("Altitude:");
719 DEBUG ("Unexpected Location key: %s", key);
725 contact_widget_location_update (EmpathyContactWidget *information)
727 GHashTable *location;
729 gdouble lat = 0.0, lon = 0.0;
730 gboolean has_position = TRUE;
733 static const gchar* ordered_geolocation_keys[] = {
734 EMPATHY_LOCATION_TEXT,
735 EMPATHY_LOCATION_URI,
736 EMPATHY_LOCATION_DESCRIPTION,
737 EMPATHY_LOCATION_BUILDING,
738 EMPATHY_LOCATION_FLOOR,
739 EMPATHY_LOCATION_ROOM,
740 EMPATHY_LOCATION_STREET,
741 EMPATHY_LOCATION_AREA,
742 EMPATHY_LOCATION_LOCALITY,
743 EMPATHY_LOCATION_REGION,
744 EMPATHY_LOCATION_COUNTRY,
749 gboolean display_map = FALSE;
751 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
753 gtk_widget_hide (information->vbox_location);
757 location = empathy_contact_get_location (information->contact);
758 if (location == NULL || g_hash_table_size (location) == 0)
760 gtk_widget_hide (information->vbox_location);
764 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
766 has_position = FALSE;
768 lat = g_value_get_double (value);
770 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
772 has_position = FALSE;
774 lon = g_value_get_double (value);
776 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
779 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
780 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
791 stamp = g_value_get_int64 (value);
794 user_date = empathy_time_to_string_relative (time_);
796 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
797 /* translators: format is "Location, $date" */
798 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
800 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
806 /* Prepare the location information table */
807 if (information->table_location != NULL)
809 gtk_widget_destroy (information->table_location);
812 information->table_location = gtk_table_new (1, 2, FALSE);
813 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
814 information->table_location, FALSE, FALSE, 5);
817 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
819 const gchar* user_label;
823 gvalue = g_hash_table_lookup (location, (gpointer) skey);
827 user_label = location_key_to_label (skey);
829 label = gtk_label_new (user_label);
830 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
831 gtk_table_attach (GTK_TABLE (information->table_location),
832 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
833 gtk_widget_show (label);
835 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
838 dvalue = g_value_get_double (gvalue);
839 svalue = g_strdup_printf ("%f", dvalue);
841 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
843 svalue = g_value_dup_string (gvalue);
845 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
849 time_ = g_value_get_int64 (value);
850 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
855 label = gtk_label_new (svalue);
856 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
857 label, 1, 2, row, row + 1);
858 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
859 gtk_widget_show (label);
861 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
862 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
869 #ifdef HAVE_LIBCHAMPLAIN
871 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
873 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
881 /* We can display some fields */
882 gtk_widget_show (information->table_location);
884 else if (!display_map)
886 /* Can't display either fields or map */
887 gtk_widget_hide (information->vbox_location);
891 #ifdef HAVE_LIBCHAMPLAIN
894 ClutterActor *marker;
895 ChamplainLayer *layer;
897 information->map_view_embed = gtk_champlain_embed_new ();
898 information->map_view = gtk_champlain_embed_get_view (
899 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
901 gtk_container_add (GTK_CONTAINER (information->viewport_map),
902 information->map_view_embed);
903 g_object_set (G_OBJECT (information->map_view),
904 "show-license", TRUE,
905 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
909 layer = champlain_layer_new ();
910 champlain_view_add_layer (information->map_view, layer);
912 marker = champlain_marker_new_with_text (
913 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
914 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
915 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
917 champlain_view_center_on (information->map_view, lat, lon);
918 gtk_widget_show_all (information->viewport_map);
922 gtk_widget_show (information->vbox_location);
926 save_avatar_menu_activate_cb (GtkWidget *widget,
927 EmpathyContactWidget *information)
930 EmpathyAvatar *avatar;
931 gchar *ext = NULL, *filename;
933 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
935 GTK_FILE_CHOOSER_ACTION_SAVE,
936 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
937 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
940 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
943 /* look for the avatar extension */
944 avatar = empathy_contact_get_avatar (information->contact);
945 if (avatar->format != NULL)
949 splitted = g_strsplit (avatar->format, "/", 2);
950 if (splitted[0] != NULL && splitted[1] != NULL)
951 ext = g_strdup (splitted[1]);
953 g_strfreev (splitted);
957 /* Avatar was loaded from the cache so was converted to PNG */
958 ext = g_strdup ("png");
965 id = tp_escape_as_identifier (empathy_contact_get_id (
966 information->contact));
968 filename = g_strdup_printf ("%s.%s", id, ext);
969 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
976 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
978 GError *error = NULL;
980 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
982 if (!empathy_avatar_save_to_file (avatar, filename, &error))
985 GtkWidget *error_dialog;
987 error_dialog = gtk_message_dialog_new (NULL, 0,
988 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
989 _("Unable to save avatar"));
991 gtk_message_dialog_format_secondary_text (
992 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
994 g_signal_connect (error_dialog, "response",
995 G_CALLBACK (gtk_widget_destroy), NULL);
997 gtk_window_present (GTK_WINDOW (error_dialog));
999 g_clear_error (&error);
1005 gtk_widget_destroy (dialog);
1009 popup_avatar_menu (EmpathyContactWidget *information,
1011 GdkEventButton *event)
1013 GtkWidget *menu, *item;
1014 gint button, event_time;
1016 if (information->contact == NULL ||
1017 empathy_contact_get_avatar (information->contact) == NULL)
1020 menu = gtk_menu_new ();
1022 /* Add "Save as..." entry */
1023 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1024 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1025 gtk_widget_show (item);
1027 g_signal_connect (item, "activate",
1028 G_CALLBACK (save_avatar_menu_activate_cb), information);
1032 button = event->button;
1033 event_time = event->time;
1038 event_time = gtk_get_current_event_time ();
1041 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1042 button, event_time);
1043 g_object_ref_sink (menu);
1044 g_object_unref (menu);
1048 widget_avatar_popup_menu_cb (GtkWidget *widget,
1049 EmpathyContactWidget *information)
1051 popup_avatar_menu (information, widget, NULL);
1057 widget_avatar_button_press_event_cb (GtkWidget *widget,
1058 GdkEventButton *event,
1059 EmpathyContactWidget *information)
1061 /* Ignore double-clicks and triple-clicks */
1062 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1064 popup_avatar_menu (information, widget, event);
1072 set_avatar_cb (GObject *source,
1076 GError *error = NULL;
1078 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1079 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1080 g_error_free (error);
1085 set_avatar_on_account (TpAccount *account,
1088 const gchar *mime_type)
1090 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1091 tp_proxy_get_object_path (account));
1093 tp_account_set_avatar_async (account, (const guchar *) data, size,
1094 mime_type, set_avatar_cb, NULL);
1098 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1099 EmpathyContactWidget *information)
1103 const gchar *mime_type;
1106 empathy_avatar_chooser_get_image_data (
1107 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1108 &data, &size, &mime_type);
1110 account = empathy_contact_get_account (information->contact);
1111 set_avatar_on_account (account, data, size, mime_type);
1115 set_nickname_cb (GObject *source,
1119 GError *error = NULL;
1121 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1123 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1124 g_error_free (error);
1129 set_alias_on_account (TpAccount *account,
1132 DEBUG ("Set Account.Nickname to %s", alias);
1134 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1138 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1139 GdkEventFocus *event,
1140 EmpathyContactWidget *information)
1142 if (information->contact)
1146 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1148 if (empathy_contact_is_user (information->contact))
1150 TpAccount * account;
1152 account = empathy_contact_get_account (information->contact);
1153 set_alias_on_account (account, alias);
1157 empathy_contact_set_alias (information->contact, alias);
1165 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1166 EmpathyAvatarChooser *avatar_chooser)
1170 account = empathy_account_chooser_get_account (account_chooser);
1171 if (account == NULL)
1174 empathy_avatar_chooser_set_account (avatar_chooser, account);
1178 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1180 EmpathyAvatar *avatar = NULL;
1182 if (information->contact)
1183 avatar = empathy_contact_get_avatar (information->contact);
1185 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1187 g_signal_handlers_block_by_func (information->widget_avatar,
1188 contact_widget_avatar_changed_cb,
1190 empathy_avatar_chooser_set (
1191 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1192 g_signal_handlers_unblock_by_func (information->widget_avatar,
1193 contact_widget_avatar_changed_cb, information);
1196 empathy_avatar_image_set (
1197 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1201 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1203 if (GTK_IS_ENTRY (information->widget_alias))
1204 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1205 empathy_contact_get_alias (information->contact));
1207 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1208 empathy_contact_get_alias (information->contact));
1212 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1214 const gchar *status;
1215 gchar *markup_text = NULL;
1217 status = empathy_contact_get_status (information->contact);
1219 markup_text = empathy_add_link_markup (status);
1220 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1221 g_free (markup_text);
1223 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1224 empathy_icon_name_for_contact (information->contact),
1225 GTK_ICON_SIZE_BUTTON);
1226 gtk_widget_show (information->image_state);
1230 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1231 EmpathyContact *contact,
1232 gboolean is_favourite,
1233 EmpathyContactWidget *information)
1235 if (contact != information->contact)
1238 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1239 information->favourite_checkbox), is_favourite);
1243 contact_widget_remove_contact (EmpathyContactWidget *information)
1245 if (information->contact)
1247 TpContact *tp_contact;
1249 contact_widget_save (information);
1251 g_signal_handlers_disconnect_by_func (information->contact,
1252 contact_widget_name_notify_cb, information);
1253 g_signal_handlers_disconnect_by_func (information->contact,
1254 contact_widget_presence_notify_cb, information);
1255 g_signal_handlers_disconnect_by_func (information->contact,
1256 contact_widget_avatar_notify_cb, information);
1258 tp_contact = empathy_contact_get_tp_contact (information->contact);
1259 if (tp_contact != NULL)
1261 g_signal_handlers_disconnect_by_func (tp_contact,
1262 contact_widget_details_notify_cb, information);
1265 g_object_unref (information->contact);
1266 information->contact = NULL;
1269 if (information->details_cancellable != NULL)
1271 g_cancellable_cancel (information->details_cancellable);
1272 tp_clear_object (&information->details_cancellable);
1276 static void contact_widget_change_contact (EmpathyContactWidget *information);
1279 contact_widget_contact_update (EmpathyContactWidget *information)
1281 TpAccount *account = NULL;
1282 const gchar *id = NULL;
1284 /* Connect and get info from new contact */
1285 if (information->contact)
1287 g_signal_connect_swapped (information->contact, "notify::name",
1288 G_CALLBACK (contact_widget_name_notify_cb), information);
1289 g_signal_connect_swapped (information->contact, "notify::presence",
1290 G_CALLBACK (contact_widget_presence_notify_cb), information);
1291 g_signal_connect_swapped (information->contact,
1292 "notify::presence-message",
1293 G_CALLBACK (contact_widget_presence_notify_cb), information);
1294 g_signal_connect_swapped (information->contact, "notify::avatar",
1295 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1297 account = empathy_contact_get_account (information->contact);
1298 id = empathy_contact_get_id (information->contact);
1301 /* Update account widget */
1302 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1306 g_signal_handlers_block_by_func (information->widget_account,
1307 contact_widget_change_contact,
1309 empathy_account_chooser_set_account (
1310 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1311 g_signal_handlers_unblock_by_func (information->widget_account,
1312 contact_widget_change_contact, information);
1321 name = tp_account_get_display_name (account);
1322 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1324 name = tp_account_get_icon_name (account);
1325 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1326 name, GTK_ICON_SIZE_MENU);
1330 /* Update id widget */
1331 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1332 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1334 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1336 /* Update other widgets */
1337 if (information->contact)
1339 contact_widget_name_notify_cb (information);
1340 contact_widget_presence_notify_cb (information);
1341 contact_widget_avatar_notify_cb (information);
1343 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1345 FolksPersona *persona = empathy_contact_get_persona (
1346 information->contact);
1348 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1350 gboolean is_favourite = folks_favourite_get_is_favourite (
1351 FOLKS_FAVOURITE (persona));
1352 contact_widget_favourites_changed_cb (information->manager,
1353 information->contact, is_favourite, information);
1357 gtk_widget_show (information->label_alias);
1358 gtk_widget_show (information->widget_alias);
1359 gtk_widget_show (information->hbox_presence);
1360 gtk_widget_show (information->widget_avatar);
1364 gtk_widget_hide (information->label_alias);
1365 gtk_widget_hide (information->widget_alias);
1366 gtk_widget_hide (information->hbox_presence);
1367 gtk_widget_hide (information->widget_avatar);
1372 contact_widget_set_contact (EmpathyContactWidget *information,
1373 EmpathyContact *contact)
1375 if (contact == information->contact)
1378 contact_widget_remove_contact (information);
1380 information->contact = g_object_ref (contact);
1382 /* set the selected account to be the account this contact came from */
1383 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1384 empathy_account_chooser_set_account (
1385 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1386 empathy_contact_get_account (contact));
1389 /* Update information for widgets */
1390 contact_widget_contact_update (information);
1391 contact_widget_groups_update (information);
1392 contact_widget_details_update (information);
1393 contact_widget_client_update (information);
1394 contact_widget_location_update (information);
1398 contact_widget_got_contact_cb (TpConnection *connection,
1399 EmpathyContact *contact,
1400 const GError *error,
1402 GObject *weak_object)
1404 EmpathyContactWidget *information = user_data;
1408 DEBUG ("Error: %s", error->message);
1412 contact_widget_set_contact (information, contact);
1416 contact_widget_change_contact (EmpathyContactWidget *information)
1418 TpConnection *connection;
1420 connection = empathy_account_chooser_get_connection (
1421 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1425 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1429 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1430 if (!EMP_STR_EMPTY (id))
1432 empathy_tp_contact_factory_get_from_id (connection, id,
1433 contact_widget_got_contact_cb, information, NULL,
1434 G_OBJECT (information->vbox_contact_widget));
1439 empathy_tp_contact_factory_get_from_handle (connection,
1440 tp_connection_get_self_handle (connection),
1441 contact_widget_got_contact_cb, information, NULL,
1442 G_OBJECT (information->vbox_contact_widget));
1447 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1449 contact_widget_change_contact (self);
1454 contact_widget_id_changed_cb (GtkEntry *entry,
1455 EmpathyContactWidget *self)
1457 if (self->widget_id_timeout != 0)
1459 g_source_remove (self->widget_id_timeout);
1462 self->widget_id_timeout =
1463 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1464 (GSourceFunc) contact_widget_id_activate_timeout, self);
1468 contact_widget_id_focus_out_cb (GtkWidget *widget,
1469 GdkEventFocus *event,
1470 EmpathyContactWidget *information)
1472 contact_widget_change_contact (information);
1477 favourite_toggled_cb (GtkToggleButton *button,
1478 EmpathyContactWidget *information)
1480 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1482 if (persona != NULL && FOLKS_IS_FAVOURITE (persona))
1484 gboolean active = gtk_toggle_button_get_active (button);
1485 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (persona), active);
1490 contact_widget_contact_setup (EmpathyContactWidget *information)
1492 information->label_status = gtk_label_new ("");
1493 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1494 PANGO_WRAP_WORD_CHAR);
1495 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1498 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1499 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1501 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1502 information->label_status, TRUE, TRUE, 0);
1503 gtk_widget_show (information->label_status);
1505 /* Setup account label/chooser */
1506 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1508 information->widget_account = empathy_account_chooser_new ();
1510 g_signal_connect_swapped (information->widget_account, "changed",
1511 G_CALLBACK (contact_widget_change_contact),
1516 /* Pack the protocol icon with the account name in an hbox */
1517 information->widget_account = gtk_hbox_new (FALSE, 6);
1519 information->label_account = gtk_label_new (NULL);
1520 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1521 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1523 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1524 gtk_widget_show (information->label_account);
1526 information->image_account = gtk_image_new ();
1527 gtk_widget_show (information->image_account);
1529 gtk_box_pack_start (GTK_BOX (information->widget_account),
1530 information->image_account, FALSE, FALSE, 0);
1531 gtk_box_pack_start (GTK_BOX (information->widget_account),
1532 information->label_account, FALSE, TRUE, 0);
1534 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1535 information->widget_account,
1537 gtk_widget_show (information->widget_account);
1539 /* Set up avatar chooser/display */
1540 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1542 information->widget_avatar = empathy_avatar_chooser_new ();
1543 g_signal_connect (information->widget_avatar, "changed",
1544 G_CALLBACK (contact_widget_avatar_changed_cb),
1546 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1548 g_signal_connect (information->widget_account, "changed",
1549 G_CALLBACK (update_avatar_chooser_account_cb),
1550 information->widget_avatar);
1551 update_avatar_chooser_account_cb (
1552 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1553 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1558 information->widget_avatar = empathy_avatar_image_new ();
1560 g_signal_connect (information->widget_avatar, "popup-menu",
1561 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1562 g_signal_connect (information->widget_avatar, "button-press-event",
1563 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1566 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1567 information->widget_avatar,
1570 gtk_widget_show (information->widget_avatar);
1572 /* Setup id label/entry */
1573 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1575 information->widget_id = gtk_entry_new ();
1576 g_signal_connect (information->widget_id, "focus-out-event",
1577 G_CALLBACK (contact_widget_id_focus_out_cb),
1579 g_signal_connect (information->widget_id, "changed",
1580 G_CALLBACK (contact_widget_id_changed_cb),
1585 information->widget_id = gtk_label_new (NULL);
1586 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1587 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1589 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1591 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1592 information->widget_id,
1594 gtk_widget_show (information->widget_id);
1596 /* Setup alias label/entry */
1597 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1599 information->widget_alias = gtk_entry_new ();
1601 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1602 g_signal_connect (information->widget_alias, "focus-out-event",
1603 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1606 /* Make return activate the window default (the Close button) */
1607 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1612 information->widget_alias = gtk_label_new (NULL);
1613 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1614 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1616 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1618 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1619 information->widget_alias,
1621 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1622 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1624 gtk_widget_show (information->widget_alias);
1627 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1629 information->favourite_checkbox = gtk_check_button_new_with_label (
1632 g_signal_connect (information->favourite_checkbox, "toggled",
1633 G_CALLBACK (favourite_toggled_cb), information);
1635 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1636 information->favourite_checkbox, 0, 2, 3, 4);
1638 information->fav_sig_id = g_signal_connect (information->manager,
1639 "favourites-changed",
1640 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1642 gtk_widget_show (information->favourite_checkbox);
1647 contact_widget_destroy_cb (GtkWidget *widget,
1648 EmpathyContactWidget *information)
1650 contact_widget_remove_contact (information);
1652 if (information->widget_id_timeout != 0)
1654 g_source_remove (information->widget_id_timeout);
1657 if (information->fav_sig_id != 0)
1658 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1660 g_object_unref (information->manager);
1662 g_slice_free (EmpathyContactWidget, information);
1666 * empathy_contact_widget_new:
1667 * @contact: an #EmpathyContact
1668 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1670 * Creates a new #EmpathyContactWidget.
1672 * Return value: a new #EmpathyContactWidget
1675 empathy_contact_widget_new (EmpathyContact *contact,
1676 EmpathyContactWidgetFlags flags)
1678 EmpathyContactWidget *information;
1682 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1684 information = g_slice_new0 (EmpathyContactWidget);
1685 information->flags = flags;
1687 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1689 gui = empathy_builder_get_file (filename,
1690 "vbox_contact_widget", &information->vbox_contact_widget,
1691 "hbox_contact", &information->hbox_contact,
1692 "hbox_presence", &information->hbox_presence,
1693 "label_alias", &information->label_alias,
1694 "image_state", &information->image_state,
1695 "table_contact", &information->table_contact,
1696 "vbox_avatar", &information->vbox_avatar,
1697 "vbox_location", &information->vbox_location,
1698 "subvbox_location", &information->subvbox_location,
1699 "label_location", &information->label_location,
1700 #ifdef HAVE_LIBCHAMPLAIN
1701 "viewport_map", &information->viewport_map,
1703 "groups_widget", &information->groups_widget,
1704 "vbox_details", &information->vbox_details,
1705 "table_details", &information->table_details,
1706 "hbox_details_requested", &information->hbox_details_requested,
1707 "vbox_client", &information->vbox_client,
1708 "table_client", &information->table_client,
1709 "hbox_client_requested", &information->hbox_client_requested,
1713 empathy_builder_connect (gui, information,
1714 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1716 information->table_location = NULL;
1718 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1719 "EmpathyContactWidget",
1722 information->manager = empathy_contact_manager_dup_singleton ();
1724 /* Create widgets */
1725 contact_widget_contact_setup (information);
1726 contact_widget_details_setup (information);
1727 contact_widget_client_setup (information);
1729 if (contact != NULL)
1730 contact_widget_set_contact (information, contact);
1731 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1732 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1733 contact_widget_change_contact (information);
1735 return empathy_builder_unref_and_keep_widget (gui,
1736 information->vbox_contact_widget);
1740 * empathy_contact_widget_get_contact:
1741 * @widget: an #EmpathyContactWidget
1743 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1745 * Returns: the #EmpathyContact associated with @widget
1748 empathy_contact_widget_get_contact (GtkWidget *widget)
1750 EmpathyContactWidget *information;
1752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1754 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1758 return information->contact;
1762 empathy_contact_widget_get_alias (GtkWidget *widget)
1764 EmpathyContactWidget *information;
1766 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1768 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1772 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1776 * empathy_contact_widget_set_contact:
1777 * @widget: an #EmpathyContactWidget
1778 * @contact: a different #EmpathyContact
1780 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1783 empathy_contact_widget_set_contact (GtkWidget *widget,
1784 EmpathyContact *contact)
1786 EmpathyContactWidget *information;
1788 g_return_if_fail (GTK_IS_WIDGET (widget));
1789 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1791 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1795 contact_widget_set_contact (information, contact);
1799 * empathy_contact_widget_set_account_filter:
1800 * @widget: an #EmpathyContactWidget
1801 * @filter: a #EmpathyAccountChooserFilterFunc
1802 * @user_data: user data to pass to @filter, or %NULL
1804 * Set a filter on the #EmpathyAccountChooser included in the
1805 * #EmpathyContactWidget.
1808 empathy_contact_widget_set_account_filter (
1810 EmpathyAccountChooserFilterFunc filter,
1813 EmpathyContactWidget *information;
1814 EmpathyAccountChooser *chooser;
1816 g_return_if_fail (GTK_IS_WIDGET (widget));
1818 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1822 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1824 empathy_account_chooser_set_filter (chooser, filter, user_data);