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);
242 contact_widget_bday_changed_cb (GtkCalendar *calendar,
243 TpContactInfoField *field)
245 guint year, month, day;
248 const gchar *strv[] = { NULL, NULL };
250 gtk_calendar_get_date (calendar, &year, &month, &day);
251 date = g_date_new_dmy (day, month+1, year);
253 gtk_calendar_clear_marks (calendar);
254 gtk_calendar_mark_day (calendar, g_date_get_day (date));
256 g_date_strftime (tmp, sizeof (tmp), EMPATHY_DATE_FORMAT_DISPLAY_SHORT, date);
258 if (field->field_value != NULL)
259 g_strfreev (field->field_value);
260 field->field_value = g_strdupv ((GStrv) strv);
265 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
269 const gchar *field_name;
274 static InfoFieldData info_field_datas[] =
276 { "fn", N_("Full name:"), FALSE },
277 { "tel", N_("Phone number:"), FALSE },
278 { "email", N_("E-mail address:"), TRUE },
279 { "url", N_("Website:"), TRUE },
280 { "bday", N_("Birthday:"), FALSE },
284 static InfoFieldData *
285 find_info_field_data (const gchar *field_name)
289 for (i = 0; info_field_datas[i].field_name != NULL; i++)
291 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
292 return info_field_datas + i;
298 contact_info_field_name_cmp (const gchar *name1,
303 if (!tp_strdiff (name1, name2))
306 /* We use the order of info_field_datas */
307 for (i = 0; info_field_datas[i].field_name != NULL; i++)
309 if (!tp_strdiff (info_field_datas[i].field_name, name1))
311 if (!tp_strdiff (info_field_datas[i].field_name, name2))
315 return g_strcmp0 (name1, name2);
319 contact_info_field_cmp (TpContactInfoField *field1,
320 TpContactInfoField *field2)
322 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
326 field_name_in_field_list (GList *list,
331 for (l = list; l != NULL; l = g_list_next (l))
333 TpContactInfoField *field = l->data;
335 if (!tp_strdiff (field->field_name, name))
342 static TpContactInfoFieldSpec *
343 get_spec_from_list (GList *list,
348 for (l = list; l != NULL; l = g_list_next (l))
350 TpContactInfoFieldSpec *spec = l->data;
352 if (!tp_strdiff (spec->name, name))
360 contact_widget_details_update_edit (EmpathyContactWidget *information)
363 TpConnection *connection;
369 g_assert (information->details_to_set == NULL);
371 contact = empathy_contact_get_tp_contact (information->contact);
372 connection = tp_contact_get_connection (contact);
374 info = tp_contact_get_contact_info (contact);
376 specs = tp_connection_get_contact_info_supported_fields (connection);
378 /* Look at the fields set in our vCard */
379 for (l = info; l != NULL; l = l->next)
381 TpContactInfoField *field = l->data;
383 /* make a copy for the details_to_set list */
384 field = tp_contact_info_field_copy (field);
385 DEBUG ("Field %s is in our vCard", field->field_name);
387 information->details_to_set = g_list_prepend (information->details_to_set,
391 /* Add fields which are supported but not in the vCard */
392 for (i = 0; info_field_datas[i].field_name != NULL; i++)
394 TpContactInfoFieldSpec *spec;
395 TpContactInfoField *field;
397 /* Check if the field was in the vCard */
398 if (field_name_in_field_list (information->details_to_set,
399 info_field_datas[i].field_name))
402 /* Check if the CM supports the field */
403 spec = get_spec_from_list (specs, info_field_datas[i].field_name);
407 /* add an empty field so user can set a value */
408 field = tp_contact_info_field_new (spec->name, spec->parameters, NULL);
410 information->details_to_set = g_list_prepend (information->details_to_set,
414 /* Add widgets for supported fields */
415 information->details_to_set = g_list_sort (information->details_to_set,
416 (GCompareFunc) contact_info_field_cmp);
418 for (l = information->details_to_set; l != NULL; l= g_list_next (l))
420 TpContactInfoField *field = l->data;
421 InfoFieldData *field_data;
424 field_data = find_info_field_data (field->field_name);
425 if (field_data == NULL)
427 /* Empathy doesn't display this field so we can't change it.
428 * But we put it in the details_to_set list so it won't be erased
429 * when calling SetContactInfo (bgo #630427) */
430 DEBUG ("Unhandled ContactInfo field spec: %s", field->field_name);
435 w = gtk_label_new (_(field_data->title));
436 gtk_table_attach (GTK_TABLE (information->table_details),
437 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
438 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
442 if (!tp_strdiff (field->field_name, "bday"))
444 w = gtk_calendar_new ();
445 if (field->field_value[0])
449 g_date_set_parse (&date, field->field_value[0]);
450 if (g_date_valid (&date))
452 gtk_calendar_select_day (GTK_CALENDAR (w),
453 g_date_get_day (&date));
454 gtk_calendar_select_month (GTK_CALENDAR (w),
455 g_date_get_month (&date) - 1, g_date_get_year (&date));
456 gtk_calendar_mark_day (GTK_CALENDAR (w),
457 g_date_get_day (&date));
460 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
461 w, 1, 2, n_rows, n_rows + 1);
464 g_signal_connect (w, "day-selected-double-click",
465 G_CALLBACK (contact_widget_bday_changed_cb), field);
466 g_signal_connect (w, "month-changed",
467 G_CALLBACK (contact_widget_bday_changed_cb), field);
471 w = gtk_entry_new ();
472 gtk_entry_set_text (GTK_ENTRY (w),
473 field->field_value[0] ? field->field_value[0] : "");
474 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
475 w, 1, 2, n_rows, n_rows + 1);
478 g_signal_connect (w, "changed",
479 G_CALLBACK (contact_widget_details_changed_cb), field);
492 contact_widget_details_update_show (EmpathyContactWidget *information)
498 contact = empathy_contact_get_tp_contact (information->contact);
499 info = tp_contact_get_contact_info (contact);
500 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
501 for (l = info; l != NULL; l = l->next)
503 TpContactInfoField *field = l->data;
504 InfoFieldData *field_data;
508 if (field->field_value == NULL || field->field_value[0] == NULL)
511 value = field->field_value[0];
513 field_data = find_info_field_data (field->field_name);
514 if (field_data == NULL)
516 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
521 w = gtk_label_new (_(field_data->title));
522 gtk_table_attach (GTK_TABLE (information->table_details),
523 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
524 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
528 w = gtk_label_new (value);
529 if (field_data->linkify)
533 markup = empathy_add_link_markup (value);
534 gtk_label_set_markup (GTK_LABEL (w), markup);
538 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
539 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
541 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
542 w, 1, 2, n_rows, n_rows + 1);
543 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
554 contact_widget_details_notify_cb (EmpathyContactWidget *information)
558 gtk_container_foreach (GTK_CONTAINER (information->table_details),
559 (GtkCallback) gtk_widget_destroy, NULL);
561 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
562 n_rows = contact_widget_details_update_edit (information);
564 n_rows = contact_widget_details_update_show (information);
568 gtk_widget_show (information->vbox_details);
569 gtk_widget_show (information->table_details);
573 gtk_widget_hide (information->vbox_details);
576 gtk_widget_hide (information->hbox_details_requested);
577 gtk_spinner_stop (GTK_SPINNER (information->spinner_details));
581 contact_widget_details_request_cb (GObject *object,
585 TpContact *contact = TP_CONTACT (object);
586 EmpathyContactWidget *information = user_data;
587 GError *error = NULL;
589 if (!tp_contact_request_contact_info_finish (contact, res, &error))
591 /* If the request got cancelled it could mean the contact widget is
592 * destroyed, so we should not dereference information */
593 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
595 g_clear_error (&error);
599 gtk_widget_hide (information->vbox_details);
600 g_clear_error (&error);
604 contact_widget_details_notify_cb (information);
607 /* If we are going to edit ContactInfo, we don't want live updates */
608 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
610 g_signal_connect_swapped (contact, "notify::contact-info",
611 G_CALLBACK (contact_widget_details_notify_cb), information);
614 tp_clear_object (&information->details_cancellable);
618 contact_widget_details_feature_prepared_cb (GObject *object,
622 TpConnection *connection = TP_CONNECTION (object);
623 EmpathyContactWidget *information = user_data;
625 TpContactInfoFlags flags;
627 if (!tp_proxy_prepare_finish (connection, res, NULL))
629 gtk_widget_hide (information->vbox_details);
633 /* If we want to edit info, but connection does not support that, stop */
634 flags = tp_connection_get_contact_info_flags (connection);
635 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
636 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
638 gtk_widget_hide (information->vbox_details);
642 /* Request the contact's info */
643 gtk_widget_show (information->vbox_details);
644 gtk_widget_show (information->hbox_details_requested);
645 gtk_widget_hide (information->table_details);
646 gtk_spinner_start (GTK_SPINNER (information->spinner_details));
648 contact = empathy_contact_get_tp_contact (information->contact);
649 g_assert (information->details_cancellable == NULL);
650 information->details_cancellable = g_cancellable_new ();
651 tp_contact_request_contact_info_async (contact,
652 information->details_cancellable, contact_widget_details_request_cb,
657 contact_widget_details_update (EmpathyContactWidget *information)
659 TpContact *tp_contact = NULL;
661 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
662 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
665 gtk_widget_hide (information->vbox_details);
667 if (information->contact != NULL)
668 tp_contact = empathy_contact_get_tp_contact (information->contact);
670 if (tp_contact != NULL)
672 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
673 TpConnection *connection;
675 /* First, make sure the CONTACT_INFO feature is ready on the connection */
676 connection = tp_contact_get_connection (tp_contact);
677 tp_proxy_prepare_async (connection, features,
678 contact_widget_details_feature_prepared_cb, information);
683 contact_widget_client_update (EmpathyContactWidget *information)
685 /* FIXME: Needs new telepathy spec */
689 contact_widget_client_setup (EmpathyContactWidget *information)
691 /* FIXME: Needs new telepathy spec */
692 gtk_widget_hide (information->vbox_client);
696 contact_widget_groups_update (EmpathyContactWidget *information)
698 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
699 information->contact != NULL)
701 FolksPersona *persona =
702 empathy_contact_get_persona (information->contact);
704 if (FOLKS_IS_GROUPABLE (persona))
706 empathy_groups_widget_set_groupable (
707 EMPATHY_GROUPS_WIDGET (information->groups_widget),
708 FOLKS_GROUPABLE (persona));
709 gtk_widget_show (information->groups_widget);
715 /* In case of failure */
716 gtk_widget_hide (information->groups_widget);
719 /* Converts the Location's GHashTable's key to a user readable string */
721 location_key_to_label (const gchar *key)
723 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
724 return _("Country ISO Code:");
725 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
726 return _("Country:");
727 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
729 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
731 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
733 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
734 return _("Postal Code:");
735 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
737 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
738 return _("Building:");
739 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
741 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
743 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
745 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
746 return _("Description:");
747 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
749 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
750 return _("Accuracy Level:");
751 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
753 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
754 return _("Vertical Error (meters):");
755 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
756 return _("Horizontal Error (meters):");
757 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
759 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
760 return _("Bearing:");
761 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
762 return _("Climb Speed:");
763 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
764 return _("Last Updated on:");
765 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
766 return _("Longitude:");
767 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
768 return _("Latitude:");
769 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
770 return _("Altitude:");
773 DEBUG ("Unexpected Location key: %s", key);
779 contact_widget_location_update (EmpathyContactWidget *information)
781 GHashTable *location;
783 gdouble lat = 0.0, lon = 0.0;
784 gboolean has_position = TRUE;
787 static const gchar* ordered_geolocation_keys[] = {
788 EMPATHY_LOCATION_TEXT,
789 EMPATHY_LOCATION_URI,
790 EMPATHY_LOCATION_DESCRIPTION,
791 EMPATHY_LOCATION_BUILDING,
792 EMPATHY_LOCATION_FLOOR,
793 EMPATHY_LOCATION_ROOM,
794 EMPATHY_LOCATION_STREET,
795 EMPATHY_LOCATION_AREA,
796 EMPATHY_LOCATION_LOCALITY,
797 EMPATHY_LOCATION_REGION,
798 EMPATHY_LOCATION_COUNTRY,
803 gboolean display_map = FALSE;
805 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
807 gtk_widget_hide (information->vbox_location);
811 location = empathy_contact_get_location (information->contact);
812 if (location == NULL || g_hash_table_size (location) == 0)
814 gtk_widget_hide (information->vbox_location);
818 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
820 has_position = FALSE;
822 lat = g_value_get_double (value);
824 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
826 has_position = FALSE;
828 lon = g_value_get_double (value);
830 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
833 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
834 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
845 stamp = g_value_get_int64 (value);
848 user_date = empathy_time_to_string_relative (time_);
850 tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
851 /* translators: format is "Location, $date" */
852 text = g_strdup_printf (_("%s, %s"), tmp, user_date);
854 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
860 /* Prepare the location information table */
861 if (information->table_location != NULL)
863 gtk_widget_destroy (information->table_location);
866 information->table_location = gtk_table_new (1, 2, FALSE);
867 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
868 information->table_location, FALSE, FALSE, 5);
871 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
873 const gchar* user_label;
877 gvalue = g_hash_table_lookup (location, (gpointer) skey);
881 user_label = location_key_to_label (skey);
883 label = gtk_label_new (user_label);
884 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
885 gtk_table_attach (GTK_TABLE (information->table_location),
886 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
887 gtk_widget_show (label);
889 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
892 dvalue = g_value_get_double (gvalue);
893 svalue = g_strdup_printf ("%f", dvalue);
895 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
897 svalue = g_value_dup_string (gvalue);
899 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
903 time_ = g_value_get_int64 (value);
904 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
909 label = gtk_label_new (svalue);
910 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
911 label, 1, 2, row, row + 1);
912 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
913 gtk_widget_show (label);
915 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
916 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
923 #ifdef HAVE_LIBCHAMPLAIN
925 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
927 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
935 /* We can display some fields */
936 gtk_widget_show (information->table_location);
938 else if (!display_map)
940 /* Can't display either fields or map */
941 gtk_widget_hide (information->vbox_location);
945 #ifdef HAVE_LIBCHAMPLAIN
948 ClutterActor *marker;
949 ChamplainLayer *layer;
951 information->map_view_embed = gtk_champlain_embed_new ();
952 information->map_view = gtk_champlain_embed_get_view (
953 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
955 gtk_container_add (GTK_CONTAINER (information->viewport_map),
956 information->map_view_embed);
957 g_object_set (G_OBJECT (information->map_view),
958 "show-license", TRUE,
959 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
963 layer = champlain_layer_new ();
964 champlain_view_add_layer (information->map_view, layer);
966 marker = champlain_marker_new_with_text (
967 empathy_contact_get_alias (information->contact), NULL, NULL, NULL);
968 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
969 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
971 champlain_view_center_on (information->map_view, lat, lon);
972 gtk_widget_show_all (information->viewport_map);
976 gtk_widget_show (information->vbox_location);
980 save_avatar_menu_activate_cb (GtkWidget *widget,
981 EmpathyContactWidget *information)
984 EmpathyAvatar *avatar;
985 gchar *ext = NULL, *filename;
987 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
989 GTK_FILE_CHOOSER_ACTION_SAVE,
990 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
991 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
994 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
997 /* look for the avatar extension */
998 avatar = empathy_contact_get_avatar (information->contact);
999 if (avatar->format != NULL)
1003 splitted = g_strsplit (avatar->format, "/", 2);
1004 if (splitted[0] != NULL && splitted[1] != NULL)
1005 ext = g_strdup (splitted[1]);
1007 g_strfreev (splitted);
1011 /* Avatar was loaded from the cache so was converted to PNG */
1012 ext = g_strdup ("png");
1019 id = tp_escape_as_identifier (empathy_contact_get_id (
1020 information->contact));
1022 filename = g_strdup_printf ("%s.%s", id, ext);
1023 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1030 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1032 GError *error = NULL;
1034 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1036 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1039 GtkWidget *error_dialog;
1041 error_dialog = gtk_message_dialog_new (NULL, 0,
1042 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1043 _("Unable to save avatar"));
1045 gtk_message_dialog_format_secondary_text (
1046 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1048 g_signal_connect (error_dialog, "response",
1049 G_CALLBACK (gtk_widget_destroy), NULL);
1051 gtk_window_present (GTK_WINDOW (error_dialog));
1053 g_clear_error (&error);
1059 gtk_widget_destroy (dialog);
1063 popup_avatar_menu (EmpathyContactWidget *information,
1065 GdkEventButton *event)
1067 GtkWidget *menu, *item;
1068 gint button, event_time;
1070 if (information->contact == NULL ||
1071 empathy_contact_get_avatar (information->contact) == NULL)
1074 menu = gtk_menu_new ();
1076 /* Add "Save as..." entry */
1077 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1078 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1079 gtk_widget_show (item);
1081 g_signal_connect (item, "activate",
1082 G_CALLBACK (save_avatar_menu_activate_cb), information);
1086 button = event->button;
1087 event_time = event->time;
1092 event_time = gtk_get_current_event_time ();
1095 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1096 button, event_time);
1097 g_object_ref_sink (menu);
1098 g_object_unref (menu);
1102 widget_avatar_popup_menu_cb (GtkWidget *widget,
1103 EmpathyContactWidget *information)
1105 popup_avatar_menu (information, widget, NULL);
1111 widget_avatar_button_press_event_cb (GtkWidget *widget,
1112 GdkEventButton *event,
1113 EmpathyContactWidget *information)
1115 /* Ignore double-clicks and triple-clicks */
1116 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1118 popup_avatar_menu (information, widget, event);
1126 set_avatar_cb (GObject *source,
1130 GError *error = NULL;
1132 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1133 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1134 g_error_free (error);
1139 set_avatar_on_account (TpAccount *account,
1142 const gchar *mime_type)
1144 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1145 tp_proxy_get_object_path (account));
1147 tp_account_set_avatar_async (account, (const guchar *) data, size,
1148 mime_type, set_avatar_cb, NULL);
1152 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1153 EmpathyContactWidget *information)
1157 const gchar *mime_type;
1160 empathy_avatar_chooser_get_image_data (
1161 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1162 &data, &size, &mime_type);
1164 account = empathy_contact_get_account (information->contact);
1165 set_avatar_on_account (account, data, size, mime_type);
1169 set_nickname_cb (GObject *source,
1173 GError *error = NULL;
1175 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1177 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1178 g_error_free (error);
1183 set_alias_on_account (TpAccount *account,
1186 DEBUG ("Set Account.Nickname to %s", alias);
1188 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1192 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1193 GdkEventFocus *event,
1194 EmpathyContactWidget *information)
1196 if (information->contact)
1200 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1202 if (empathy_contact_is_user (information->contact))
1204 TpAccount * account;
1206 account = empathy_contact_get_account (information->contact);
1207 set_alias_on_account (account, alias);
1211 empathy_contact_set_alias (information->contact, alias);
1219 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1220 EmpathyAvatarChooser *avatar_chooser)
1224 account = empathy_account_chooser_get_account (account_chooser);
1225 if (account == NULL)
1228 empathy_avatar_chooser_set_account (avatar_chooser, account);
1232 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1234 EmpathyAvatar *avatar = NULL;
1236 if (information->contact)
1237 avatar = empathy_contact_get_avatar (information->contact);
1239 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1241 g_signal_handlers_block_by_func (information->widget_avatar,
1242 contact_widget_avatar_changed_cb,
1244 empathy_avatar_chooser_set (
1245 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1246 g_signal_handlers_unblock_by_func (information->widget_avatar,
1247 contact_widget_avatar_changed_cb, information);
1250 empathy_avatar_image_set (
1251 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1255 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1257 if (GTK_IS_ENTRY (information->widget_alias))
1258 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1259 empathy_contact_get_alias (information->contact));
1261 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1262 empathy_contact_get_alias (information->contact));
1266 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1268 const gchar *status;
1269 gchar *markup_text = NULL;
1271 status = empathy_contact_get_status (information->contact);
1273 markup_text = empathy_add_link_markup (status);
1274 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1275 g_free (markup_text);
1277 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1278 empathy_icon_name_for_contact (information->contact),
1279 GTK_ICON_SIZE_BUTTON);
1280 gtk_widget_show (information->image_state);
1284 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1285 EmpathyContact *contact,
1286 gboolean is_favourite,
1287 EmpathyContactWidget *information)
1289 if (contact != information->contact)
1292 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1293 information->favourite_checkbox), is_favourite);
1297 contact_widget_remove_contact (EmpathyContactWidget *information)
1299 if (information->contact)
1301 TpContact *tp_contact;
1303 contact_widget_save (information);
1305 g_signal_handlers_disconnect_by_func (information->contact,
1306 contact_widget_name_notify_cb, information);
1307 g_signal_handlers_disconnect_by_func (information->contact,
1308 contact_widget_presence_notify_cb, information);
1309 g_signal_handlers_disconnect_by_func (information->contact,
1310 contact_widget_avatar_notify_cb, information);
1312 tp_contact = empathy_contact_get_tp_contact (information->contact);
1313 if (tp_contact != NULL)
1315 g_signal_handlers_disconnect_by_func (tp_contact,
1316 contact_widget_details_notify_cb, information);
1319 g_object_unref (information->contact);
1320 information->contact = NULL;
1323 if (information->details_cancellable != NULL)
1325 g_cancellable_cancel (information->details_cancellable);
1326 tp_clear_object (&information->details_cancellable);
1330 static void contact_widget_change_contact (EmpathyContactWidget *information);
1333 contact_widget_contact_update (EmpathyContactWidget *information)
1335 TpAccount *account = NULL;
1336 const gchar *id = NULL;
1338 /* Connect and get info from new contact */
1339 if (information->contact)
1341 g_signal_connect_swapped (information->contact, "notify::name",
1342 G_CALLBACK (contact_widget_name_notify_cb), information);
1343 g_signal_connect_swapped (information->contact, "notify::presence",
1344 G_CALLBACK (contact_widget_presence_notify_cb), information);
1345 g_signal_connect_swapped (information->contact,
1346 "notify::presence-message",
1347 G_CALLBACK (contact_widget_presence_notify_cb), information);
1348 g_signal_connect_swapped (information->contact, "notify::avatar",
1349 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1351 account = empathy_contact_get_account (information->contact);
1352 id = empathy_contact_get_id (information->contact);
1355 /* Update account widget */
1356 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1360 g_signal_handlers_block_by_func (information->widget_account,
1361 contact_widget_change_contact,
1363 empathy_account_chooser_set_account (
1364 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1365 g_signal_handlers_unblock_by_func (information->widget_account,
1366 contact_widget_change_contact, information);
1375 name = tp_account_get_display_name (account);
1376 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1378 name = tp_account_get_icon_name (account);
1379 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1380 name, GTK_ICON_SIZE_MENU);
1384 /* Update id widget */
1385 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1386 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1388 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1390 /* Update other widgets */
1391 if (information->contact)
1393 contact_widget_name_notify_cb (information);
1394 contact_widget_presence_notify_cb (information);
1395 contact_widget_avatar_notify_cb (information);
1397 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1399 FolksPersona *persona = empathy_contact_get_persona (
1400 information->contact);
1402 if (persona != NULL && FOLKS_IS_FAVOURITABLE (persona))
1404 gboolean is_favourite = folks_favouritable_get_is_favourite (
1405 FOLKS_FAVOURITABLE (persona));
1406 contact_widget_favourites_changed_cb (information->manager,
1407 information->contact, is_favourite, information);
1411 gtk_widget_show (information->label_alias);
1412 gtk_widget_show (information->widget_alias);
1413 gtk_widget_show (information->hbox_presence);
1414 gtk_widget_show (information->widget_avatar);
1418 gtk_widget_hide (information->label_alias);
1419 gtk_widget_hide (information->widget_alias);
1420 gtk_widget_hide (information->hbox_presence);
1421 gtk_widget_hide (information->widget_avatar);
1426 contact_widget_set_contact (EmpathyContactWidget *information,
1427 EmpathyContact *contact)
1429 if (contact == information->contact)
1432 contact_widget_remove_contact (information);
1434 information->contact = g_object_ref (contact);
1436 /* set the selected account to be the account this contact came from */
1437 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1438 empathy_account_chooser_set_account (
1439 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1440 empathy_contact_get_account (contact));
1443 /* Update information for widgets */
1444 contact_widget_contact_update (information);
1445 contact_widget_groups_update (information);
1446 contact_widget_details_update (information);
1447 contact_widget_client_update (information);
1448 contact_widget_location_update (information);
1452 contact_widget_got_contact_cb (TpConnection *connection,
1453 EmpathyContact *contact,
1454 const GError *error,
1456 GObject *weak_object)
1458 EmpathyContactWidget *information = user_data;
1462 DEBUG ("Error: %s", error->message);
1466 contact_widget_set_contact (information, contact);
1470 contact_widget_change_contact (EmpathyContactWidget *information)
1472 TpConnection *connection;
1474 connection = empathy_account_chooser_get_connection (
1475 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1479 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1483 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1484 if (!EMP_STR_EMPTY (id))
1486 empathy_tp_contact_factory_get_from_id (connection, id,
1487 contact_widget_got_contact_cb, information, NULL,
1488 G_OBJECT (information->vbox_contact_widget));
1493 empathy_tp_contact_factory_get_from_handle (connection,
1494 tp_connection_get_self_handle (connection),
1495 contact_widget_got_contact_cb, information, NULL,
1496 G_OBJECT (information->vbox_contact_widget));
1501 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1503 contact_widget_change_contact (self);
1508 contact_widget_id_changed_cb (GtkEntry *entry,
1509 EmpathyContactWidget *self)
1511 if (self->widget_id_timeout != 0)
1513 g_source_remove (self->widget_id_timeout);
1516 self->widget_id_timeout =
1517 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1518 (GSourceFunc) contact_widget_id_activate_timeout, self);
1522 contact_widget_id_focus_out_cb (GtkWidget *widget,
1523 GdkEventFocus *event,
1524 EmpathyContactWidget *information)
1526 contact_widget_change_contact (information);
1531 favourite_toggled_cb (GtkToggleButton *button,
1532 EmpathyContactWidget *information)
1534 FolksPersona *persona = empathy_contact_get_persona (information->contact);
1536 if (persona != NULL && FOLKS_IS_FAVOURITABLE (persona))
1538 gboolean active = gtk_toggle_button_get_active (button);
1539 folks_favouritable_set_is_favourite (FOLKS_FAVOURITABLE (persona), active);
1544 contact_widget_contact_setup (EmpathyContactWidget *information)
1546 information->label_status = gtk_label_new ("");
1547 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1548 PANGO_WRAP_WORD_CHAR);
1549 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1552 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1553 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1555 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1556 information->label_status, TRUE, TRUE, 0);
1557 gtk_widget_show (information->label_status);
1559 /* Setup account label/chooser */
1560 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1562 information->widget_account = empathy_account_chooser_new ();
1564 g_signal_connect_swapped (information->widget_account, "changed",
1565 G_CALLBACK (contact_widget_change_contact),
1570 /* Pack the protocol icon with the account name in an hbox */
1571 information->widget_account = gtk_hbox_new (FALSE, 6);
1573 information->label_account = gtk_label_new (NULL);
1574 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1575 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1577 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1578 gtk_widget_show (information->label_account);
1580 information->image_account = gtk_image_new ();
1581 gtk_widget_show (information->image_account);
1583 gtk_box_pack_start (GTK_BOX (information->widget_account),
1584 information->image_account, FALSE, FALSE, 0);
1585 gtk_box_pack_start (GTK_BOX (information->widget_account),
1586 information->label_account, FALSE, TRUE, 0);
1588 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1589 information->widget_account,
1591 gtk_widget_show (information->widget_account);
1593 /* Set up avatar chooser/display */
1594 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1596 information->widget_avatar = empathy_avatar_chooser_new ();
1597 g_signal_connect (information->widget_avatar, "changed",
1598 G_CALLBACK (contact_widget_avatar_changed_cb),
1600 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1602 g_signal_connect (information->widget_account, "changed",
1603 G_CALLBACK (update_avatar_chooser_account_cb),
1604 information->widget_avatar);
1605 update_avatar_chooser_account_cb (
1606 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1607 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1612 information->widget_avatar = empathy_avatar_image_new ();
1614 g_signal_connect (information->widget_avatar, "popup-menu",
1615 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1616 g_signal_connect (information->widget_avatar, "button-press-event",
1617 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1620 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1621 information->widget_avatar,
1624 gtk_widget_show (information->widget_avatar);
1626 /* Setup id label/entry */
1627 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1629 information->widget_id = gtk_entry_new ();
1630 g_signal_connect (information->widget_id, "focus-out-event",
1631 G_CALLBACK (contact_widget_id_focus_out_cb),
1633 g_signal_connect (information->widget_id, "changed",
1634 G_CALLBACK (contact_widget_id_changed_cb),
1639 information->widget_id = gtk_label_new (NULL);
1640 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1641 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1643 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1645 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1646 information->widget_id,
1648 gtk_widget_show (information->widget_id);
1650 /* Setup alias label/entry */
1651 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1653 information->widget_alias = gtk_entry_new ();
1655 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1656 g_signal_connect (information->widget_alias, "focus-out-event",
1657 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1660 /* Make return activate the window default (the Close button) */
1661 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1666 information->widget_alias = gtk_label_new (NULL);
1667 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1668 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1670 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1672 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1673 information->widget_alias,
1675 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1676 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1678 gtk_widget_show (information->widget_alias);
1681 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1683 information->favourite_checkbox = gtk_check_button_new_with_label (
1686 g_signal_connect (information->favourite_checkbox, "toggled",
1687 G_CALLBACK (favourite_toggled_cb), information);
1689 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1690 information->favourite_checkbox, 0, 2, 3, 4);
1692 information->fav_sig_id = g_signal_connect (information->manager,
1693 "favourites-changed",
1694 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1696 gtk_widget_show (information->favourite_checkbox);
1701 contact_widget_destroy_cb (GtkWidget *widget,
1702 EmpathyContactWidget *information)
1704 contact_widget_remove_contact (information);
1706 if (information->widget_id_timeout != 0)
1708 g_source_remove (information->widget_id_timeout);
1711 if (information->fav_sig_id != 0)
1712 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1714 g_object_unref (information->manager);
1716 g_slice_free (EmpathyContactWidget, information);
1720 * empathy_contact_widget_new:
1721 * @contact: an #EmpathyContact
1722 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1724 * Creates a new #EmpathyContactWidget.
1726 * Return value: a new #EmpathyContactWidget
1729 empathy_contact_widget_new (EmpathyContact *contact,
1730 EmpathyContactWidgetFlags flags)
1732 EmpathyContactWidget *information;
1736 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1738 information = g_slice_new0 (EmpathyContactWidget);
1739 information->flags = flags;
1741 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1743 gui = empathy_builder_get_file (filename,
1744 "vbox_contact_widget", &information->vbox_contact_widget,
1745 "hbox_contact", &information->hbox_contact,
1746 "hbox_presence", &information->hbox_presence,
1747 "label_alias", &information->label_alias,
1748 "image_state", &information->image_state,
1749 "table_contact", &information->table_contact,
1750 "vbox_avatar", &information->vbox_avatar,
1751 "vbox_location", &information->vbox_location,
1752 "subvbox_location", &information->subvbox_location,
1753 "label_location", &information->label_location,
1754 #ifdef HAVE_LIBCHAMPLAIN
1755 "viewport_map", &information->viewport_map,
1757 "groups_widget", &information->groups_widget,
1758 "vbox_details", &information->vbox_details,
1759 "table_details", &information->table_details,
1760 "hbox_details_requested", &information->hbox_details_requested,
1761 "vbox_client", &information->vbox_client,
1762 "table_client", &information->table_client,
1763 "hbox_client_requested", &information->hbox_client_requested,
1767 empathy_builder_connect (gui, information,
1768 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1770 information->table_location = NULL;
1772 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1773 "EmpathyContactWidget",
1776 information->manager = empathy_contact_manager_dup_singleton ();
1778 /* Create widgets */
1779 contact_widget_contact_setup (information);
1780 contact_widget_details_setup (information);
1781 contact_widget_client_setup (information);
1783 if (contact != NULL)
1784 contact_widget_set_contact (information, contact);
1785 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1786 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1787 contact_widget_change_contact (information);
1789 return empathy_builder_unref_and_keep_widget (gui,
1790 information->vbox_contact_widget);
1794 * empathy_contact_widget_get_contact:
1795 * @widget: an #EmpathyContactWidget
1797 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1799 * Returns: the #EmpathyContact associated with @widget
1802 empathy_contact_widget_get_contact (GtkWidget *widget)
1804 EmpathyContactWidget *information;
1806 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1808 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1812 return information->contact;
1816 empathy_contact_widget_get_alias (GtkWidget *widget)
1818 EmpathyContactWidget *information;
1820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1822 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1826 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1830 * empathy_contact_widget_set_contact:
1831 * @widget: an #EmpathyContactWidget
1832 * @contact: a different #EmpathyContact
1834 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1837 empathy_contact_widget_set_contact (GtkWidget *widget,
1838 EmpathyContact *contact)
1840 EmpathyContactWidget *information;
1842 g_return_if_fail (GTK_IS_WIDGET (widget));
1843 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1845 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1849 contact_widget_set_contact (information, contact);
1853 * empathy_contact_widget_set_account_filter:
1854 * @widget: an #EmpathyContactWidget
1855 * @filter: a #EmpathyAccountChooserFilterFunc
1856 * @user_data: user data to pass to @filter, or %NULL
1858 * Set a filter on the #EmpathyAccountChooser included in the
1859 * #EmpathyContactWidget.
1862 empathy_contact_widget_set_account_filter (
1864 EmpathyAccountChooserFilterFunc filter,
1867 EmpathyContactWidget *information;
1868 EmpathyAccountChooser *chooser;
1870 g_return_if_fail (GTK_IS_WIDGET (widget));
1872 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1876 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
1878 empathy_account_chooser_set_filter (chooser, filter, user_data);