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>
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-ui-utils.h"
51 #include "empathy-string-parser.h"
52 #include "empathy-kludge-label.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 #if HAVE_LIBCHAMPLAIN
111 GtkWidget *viewport_map;
112 GtkWidget *map_view_embed;
113 ChamplainView *map_view;
117 GtkWidget *vbox_groups;
118 GtkWidget *entry_group;
119 GtkWidget *button_group;
120 GtkWidget *treeview_groups;
123 GtkWidget *vbox_details;
124 GtkWidget *table_details;
125 GtkWidget *hbox_details_requested;
126 GList *details_to_set;
127 GCancellable *details_cancellable;
130 GtkWidget *vbox_client;
131 GtkWidget *table_client;
132 GtkWidget *hbox_client_requested;
133 } EmpathyContactWidget;
137 EmpathyContactWidget *information;
140 GtkTreeIter found_iter;
152 contact_widget_save (EmpathyContactWidget *information)
154 TpConnection *connection;
157 connection = empathy_contact_get_connection (information->contact);
159 /* Remove empty fields */
160 for (l = information->details_to_set; l != NULL; l = next)
162 TpContactInfoField *field = l->data;
165 if (field->field_value == NULL || EMP_STR_EMPTY (field->field_value[0]))
167 DEBUG ("Drop empty field: %s", field->field_name);
168 tp_contact_info_field_free (field);
169 information->details_to_set =
170 g_list_delete_link (information->details_to_set, l);
174 if (information->details_to_set != NULL)
176 tp_connection_set_contact_info_async (connection,
177 information->details_to_set, NULL, NULL);
178 tp_contact_info_list_free (information->details_to_set);
179 information->details_to_set = NULL;
184 contact_widget_details_setup (EmpathyContactWidget *information)
186 gtk_widget_hide (information->vbox_details);
190 contact_widget_details_changed_cb (GtkEntry *entry,
191 TpContactInfoField *field)
193 const gchar *strv[] = { NULL, NULL };
195 strv[0] = gtk_entry_get_text (entry);
197 if (field->field_value != NULL)
198 g_strfreev (field->field_value);
199 field->field_value = g_strdupv ((GStrv) strv);
202 static void contact_widget_details_notify_cb (EmpathyContactWidget *information);
206 const gchar *field_name;
211 static InfoFieldData info_field_datas[] =
213 { "fn", N_("Full name:"), FALSE },
214 { "tel", N_("Phone number:"), FALSE },
215 { "email", N_("E-mail address:"), TRUE },
216 { "url", N_("Website:"), TRUE },
217 { "bday", N_("Birthday:"), FALSE },
221 static InfoFieldData *
222 find_info_field_data (const gchar *field_name)
226 for (i = 0; info_field_datas[i].field_name != NULL; i++)
228 if (!tp_strdiff (info_field_datas[i].field_name, field_name))
229 return info_field_datas + i;
235 contact_info_field_name_cmp (const gchar *name1,
240 if (!tp_strdiff (name1, name2))
243 /* We use the order of info_field_datas */
244 for (i = 0; info_field_datas[i].field_name != NULL; i++)
246 if (!tp_strdiff (info_field_datas[i].field_name, name1))
248 if (!tp_strdiff (info_field_datas[i].field_name, name2))
252 return g_strcmp0 (name1, name2);
256 contact_info_field_cmp (TpContactInfoField *field1,
257 TpContactInfoField *field2)
259 return contact_info_field_name_cmp (field1->field_name, field2->field_name);
263 contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1,
264 TpContactInfoFieldSpec *spec2)
266 return contact_info_field_name_cmp (spec1->name, spec2->name);
270 contact_widget_details_update_edit (EmpathyContactWidget *information)
273 TpConnection *connection;
277 g_assert (information->details_to_set == NULL);
279 contact = empathy_contact_get_tp_contact (information->contact);
280 connection = tp_contact_get_connection (contact);
282 specs = tp_connection_get_contact_info_supported_fields (connection);
283 specs = g_list_sort (specs, (GCompareFunc) contact_info_field_spec_cmp);
284 for (l = specs; l != NULL; l = l->next)
286 TpContactInfoFieldSpec *spec = l->data;
287 TpContactInfoField *field;
288 InfoFieldData *field_data;
293 field_data = find_info_field_data (spec->name);
294 if (field_data == NULL)
296 DEBUG ("Unhandled ContactInfo field spec: %s", spec->name);
300 /* Search initial value */
301 info = tp_contact_get_contact_info (contact);
302 for (ll = info; ll != NULL; ll = ll->next)
305 if (!tp_strdiff (field->field_name, spec->name))
307 value = field->field_value;
312 field = tp_contact_info_field_new (spec->name, spec->parameters, value);
313 information->details_to_set = g_list_prepend (information->details_to_set,
317 w = gtk_label_new (_(field_data->title));
318 gtk_table_attach (GTK_TABLE (information->table_details),
319 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
320 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
324 w = gtk_entry_new ();
325 gtk_entry_set_text (GTK_ENTRY (w),
326 field->field_value[0] ? field->field_value[0] : "");
327 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
328 w, 1, 2, n_rows, n_rows + 1);
331 g_signal_connect (w, "changed",
332 G_CALLBACK (contact_widget_details_changed_cb), field);
342 contact_widget_details_update_show (EmpathyContactWidget *information)
348 contact = empathy_contact_get_tp_contact (information->contact);
349 info = tp_contact_get_contact_info (contact);
350 info = g_list_sort (info, (GCompareFunc) contact_info_field_cmp);
351 for (l = info; l != NULL; l = l->next)
353 TpContactInfoField *field = l->data;
354 InfoFieldData *field_data;
358 if (field->field_value == NULL || field->field_value[0] == NULL)
361 value = field->field_value[0];
363 field_data = find_info_field_data (field->field_name);
364 if (field_data == NULL)
366 DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
371 w = gtk_label_new (_(field_data->title));
372 gtk_table_attach (GTK_TABLE (information->table_details),
373 w, 0, 1, n_rows, n_rows + 1, GTK_FILL, 0, 0, 0);
374 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
378 w = gtk_label_new (value);
379 if (field_data->linkify)
383 markup = empathy_add_link_markup (value);
384 gtk_label_set_markup (GTK_LABEL (w), markup);
388 if ((information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) == 0)
389 gtk_label_set_selectable (GTK_LABEL (w), TRUE);
391 gtk_table_attach_defaults (GTK_TABLE (information->table_details),
392 w, 1, 2, n_rows, n_rows + 1);
393 gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
404 contact_widget_details_notify_cb (EmpathyContactWidget *information)
408 gtk_container_foreach (GTK_CONTAINER (information->table_details),
409 (GtkCallback) gtk_widget_destroy, NULL);
411 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
412 n_rows = contact_widget_details_update_edit (information);
414 n_rows = contact_widget_details_update_show (information);
418 gtk_widget_show (information->vbox_details);
419 gtk_widget_show (information->table_details);
423 gtk_widget_hide (information->vbox_details);
426 gtk_widget_hide (information->hbox_details_requested);
430 contact_widget_details_request_cb (GObject *object,
434 TpContact *contact = TP_CONTACT (object);
435 EmpathyContactWidget *information = user_data;
436 GError *error = NULL;
438 if (!tp_contact_request_contact_info_finish (contact, res, &error))
440 /* If the request got cancelled it could mean the contact widget is
441 * destroyed, so we should not dereference information */
442 if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
444 g_clear_error (&error);
448 gtk_widget_hide (information->vbox_details);
449 g_clear_error (&error);
453 contact_widget_details_notify_cb (information);
456 /* If we are going to edit ContactInfo, we don't want live updates */
457 if ((information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
459 g_signal_connect_swapped (contact, "notify::contact-info",
460 G_CALLBACK (contact_widget_details_notify_cb), information);
463 g_object_unref (information->details_cancellable);
464 information->details_cancellable = NULL;
468 contact_widget_details_feature_prepared_cb (GObject *object,
472 TpConnection *connection = TP_CONNECTION (object);
473 EmpathyContactWidget *information = user_data;
475 TpContactInfoFlags flags;
477 if (!tp_proxy_prepare_finish (connection, res, NULL))
479 gtk_widget_hide (information->vbox_details);
483 /* If we want to edit info, but connection does not support that, stop */
484 flags = tp_connection_get_contact_info_flags (connection);
485 if ((flags & TP_CONTACT_INFO_FLAG_CAN_SET) == 0 &&
486 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) != 0)
488 gtk_widget_hide (information->vbox_details);
492 /* Request the contact's info */
493 gtk_widget_show (information->vbox_details);
494 gtk_widget_show (information->hbox_details_requested);
495 gtk_widget_hide (information->table_details);
497 contact = empathy_contact_get_tp_contact (information->contact);
498 g_assert (information->details_cancellable == NULL);
499 information->details_cancellable = g_cancellable_new ();
500 tp_contact_request_contact_info_async (contact,
501 information->details_cancellable, contact_widget_details_request_cb,
506 contact_widget_details_update (EmpathyContactWidget *information)
508 TpContact *tp_contact = NULL;
510 if ((information->flags & EMPATHY_CONTACT_WIDGET_SHOW_DETAILS) == 0 &&
511 (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_DETAILS) == 0)
514 gtk_widget_hide (information->vbox_details);
516 if (information->contact != NULL)
517 tp_contact = empathy_contact_get_tp_contact (information->contact);
519 if (tp_contact != NULL)
521 GQuark features[] = { TP_CONNECTION_FEATURE_CONTACT_INFO, 0 };
522 TpConnection *connection;
524 /* First, make sure the CONTACT_INFO feature is ready on the connection */
525 connection = tp_contact_get_connection (tp_contact);
526 tp_proxy_prepare_async (connection, features,
527 contact_widget_details_feature_prepared_cb, information);
532 contact_widget_client_update (EmpathyContactWidget *information)
534 /* FIXME: Needs new telepathy spec */
538 contact_widget_client_setup (EmpathyContactWidget *information)
540 /* FIXME: Needs new telepathy spec */
541 gtk_widget_hide (information->vbox_client);
545 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
547 EmpathyContactWidget *information)
557 view = GTK_TREE_VIEW (information->treeview_groups);
558 model = gtk_tree_view_get_model (view);
559 store = GTK_LIST_STORE (model);
561 path = gtk_tree_path_new_from_string (path_string);
563 gtk_tree_model_get_iter (model, &iter, path);
564 gtk_tree_model_get (model, &iter,
565 COL_ENABLED, &enabled,
569 gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
570 gtk_tree_path_free (path);
576 empathy_contact_list_remove_from_group (
577 EMPATHY_CONTACT_LIST (information->manager), information->contact,
582 empathy_contact_list_add_to_group (
583 EMPATHY_CONTACT_LIST (information->manager), information->contact,
591 contact_widget_model_populate_columns (EmpathyContactWidget *information)
595 GtkTreeViewColumn *column;
596 GtkCellRenderer *renderer;
599 view = GTK_TREE_VIEW (information->treeview_groups);
600 model = gtk_tree_view_get_model (view);
602 renderer = gtk_cell_renderer_toggle_new ();
603 g_signal_connect (renderer, "toggled",
604 G_CALLBACK (contact_widget_cell_toggled), information);
606 column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
607 "active", COL_ENABLED, NULL);
609 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
610 gtk_tree_view_column_set_fixed_width (column, 50);
611 gtk_tree_view_append_column (view, column);
613 renderer = gtk_cell_renderer_text_new ();
614 col_offset = gtk_tree_view_insert_column_with_attributes (view,
618 /* "editable", COL_EDITABLE, */
621 g_object_set_data (G_OBJECT (renderer),
622 "column", GINT_TO_POINTER (COL_NAME));
624 column = gtk_tree_view_get_column (view, col_offset - 1);
625 gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
626 gtk_tree_view_column_set_resizable (column,FALSE);
627 gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
631 contact_widget_model_setup (EmpathyContactWidget *information)
635 GtkTreeSelection *selection;
637 view = GTK_TREE_VIEW (information->treeview_groups);
639 store = gtk_list_store_new (COL_COUNT,
640 G_TYPE_STRING, /* name */
641 G_TYPE_BOOLEAN, /* enabled */
642 G_TYPE_BOOLEAN); /* editable */
644 gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
646 selection = gtk_tree_view_get_selection (view);
647 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
649 contact_widget_model_populate_columns (information);
651 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
652 COL_NAME, GTK_SORT_ASCENDING);
654 g_object_unref (store);
658 contact_widget_groups_populate_data (EmpathyContactWidget *information)
663 GList *my_groups, *l;
666 view = GTK_TREE_VIEW (information->treeview_groups);
667 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
668 gtk_list_store_clear (store);
670 all_groups = empathy_contact_list_get_all_groups (
671 EMPATHY_CONTACT_LIST (information->manager));
672 my_groups = empathy_contact_list_get_groups (
673 EMPATHY_CONTACT_LIST (information->manager),
674 information->contact);
676 for (l = all_groups; l; l = l->next)
678 const gchar *group_str;
683 enabled = g_list_find_custom (my_groups,
684 group_str, (GCompareFunc) strcmp) != NULL;
686 gtk_list_store_append (store, &iter);
687 gtk_list_store_set (store, &iter,
690 COL_ENABLED, enabled,
694 g_list_foreach (all_groups, (GFunc) g_free, NULL);
695 g_list_foreach (my_groups, (GFunc) g_free, NULL);
696 g_list_free (all_groups);
697 g_list_free (my_groups);
701 contact_widget_model_find_name_foreach (GtkTreeModel *model,
708 gtk_tree_model_get (model, iter,
715 if (data->name && strcmp (data->name, name) == 0)
718 data->found_iter = *iter;
731 contact_widget_model_find_name (EmpathyContactWidget *information,
739 if (EMP_STR_EMPTY (name))
742 data.information = information;
746 view = GTK_TREE_VIEW (information->treeview_groups);
747 model = gtk_tree_view_get_model (view);
749 gtk_tree_model_foreach (model,
750 (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
753 if (data.found == TRUE)
755 *iter = data.found_iter;
763 contact_widget_entry_group_changed_cb (GtkEditable *editable,
764 EmpathyContactWidget *information)
769 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
771 if (contact_widget_model_find_name (information, group, &iter))
772 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
774 gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
775 !EMP_STR_EMPTY (group));
779 contact_widget_entry_group_activate_cb (GtkEntry *entry,
780 EmpathyContactWidget *information)
782 gtk_widget_activate (GTK_WIDGET (information->button_group));
786 contact_widget_button_group_clicked_cb (GtkButton *button,
787 EmpathyContactWidget *information)
794 view = GTK_TREE_VIEW (information->treeview_groups);
795 store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
797 group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
799 gtk_list_store_append (store, &iter);
800 gtk_list_store_set (store, &iter,
805 empathy_contact_list_add_to_group (
806 EMPATHY_CONTACT_LIST (information->manager), information->contact,
811 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
813 /* FIXME: not implemented */
817 contact_widget_groups_setup (EmpathyContactWidget *information)
819 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
821 contact_widget_model_setup (information);
826 contact_widget_groups_update (EmpathyContactWidget *information)
828 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
829 information->contact)
831 g_signal_connect_swapped (information->contact, "notify::groups",
832 G_CALLBACK (contact_widget_groups_notify_cb), information);
833 contact_widget_groups_populate_data (information);
835 gtk_widget_show (information->vbox_groups);
838 gtk_widget_hide (information->vbox_groups);
841 /* Converts the Location's GHashTable's key to a user readable string */
843 location_key_to_label (const gchar *key)
845 if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
846 return _("Country ISO Code:");
847 else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
848 return _("Country:");
849 else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
851 else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
853 else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
855 else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
856 return _("Postal Code:");
857 else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
859 else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
860 return _("Building:");
861 else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
863 else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
865 else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
867 else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
868 return _("Description:");
869 else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
871 else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
872 return _("Accuracy Level:");
873 else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
875 else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
876 return _("Vertical Error (meters):");
877 else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
878 return _("Horizontal Error (meters):");
879 else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
881 else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
882 return _("Bearing:");
883 else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
884 return _("Climb Speed:");
885 else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
886 return _("Last Updated on:");
887 else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
888 return _("Longitude:");
889 else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
890 return _("Latitude:");
891 else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
892 return _("Altitude:");
895 DEBUG ("Unexpected Location key: %s", key);
901 contact_widget_location_update (EmpathyContactWidget *information)
903 GHashTable *location;
905 gdouble lat = 0.0, lon = 0.0;
906 gboolean has_position = TRUE;
909 static const gchar* ordered_geolocation_keys[] = {
910 EMPATHY_LOCATION_TEXT,
911 EMPATHY_LOCATION_URI,
912 EMPATHY_LOCATION_DESCRIPTION,
913 EMPATHY_LOCATION_BUILDING,
914 EMPATHY_LOCATION_FLOOR,
915 EMPATHY_LOCATION_ROOM,
916 EMPATHY_LOCATION_STREET,
917 EMPATHY_LOCATION_AREA,
918 EMPATHY_LOCATION_LOCALITY,
919 EMPATHY_LOCATION_REGION,
920 EMPATHY_LOCATION_COUNTRY,
925 gboolean display_map = FALSE;
927 if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
929 gtk_widget_hide (information->vbox_location);
933 location = empathy_contact_get_location (information->contact);
934 if (location == NULL || g_hash_table_size (location) == 0)
936 gtk_widget_hide (information->vbox_location);
940 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
942 has_position = FALSE;
944 lat = g_value_get_double (value);
946 value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
948 has_position = FALSE;
950 lon = g_value_get_double (value);
952 value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
955 gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location"));
956 gtk_label_set_markup (GTK_LABEL (information->label_location), loc);
966 stamp = g_value_get_int64 (value);
969 user_date = empathy_time_to_string_relative (time_);
971 text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
972 gtk_label_set_markup (GTK_LABEL (information->label_location), text);
977 /* Prepare the location information table */
978 if (information->table_location != NULL)
980 gtk_widget_destroy (information->table_location);
983 information->table_location = gtk_table_new (1, 2, FALSE);
984 gtk_box_pack_start (GTK_BOX (information->subvbox_location),
985 information->table_location, FALSE, FALSE, 5);
988 for (i = 0; (skey = ordered_geolocation_keys[i]); i++)
990 const gchar* user_label;
994 gvalue = g_hash_table_lookup (location, (gpointer) skey);
998 user_label = location_key_to_label (skey);
1000 label = gtk_label_new (user_label);
1001 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1002 gtk_table_attach (GTK_TABLE (information->table_location),
1003 label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1004 gtk_widget_show (label);
1006 if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1009 dvalue = g_value_get_double (gvalue);
1010 svalue = g_strdup_printf ("%f", dvalue);
1012 else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1014 svalue = g_value_dup_string (gvalue);
1016 else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1020 time_ = g_value_get_int64 (value);
1021 svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
1026 label = gtk_label_new (svalue);
1027 gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1028 label, 1, 2, row, row + 1);
1029 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1030 gtk_widget_show (label);
1032 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1033 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
1040 #if HAVE_LIBCHAMPLAIN
1042 !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1044 /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1052 /* We can display some fields */
1053 gtk_widget_show (information->table_location);
1055 else if (!display_map)
1057 /* Can't display either fields or map */
1058 gtk_widget_hide (information->vbox_location);
1062 #if HAVE_LIBCHAMPLAIN
1065 ClutterActor *marker;
1066 ChamplainLayer *layer;
1068 information->map_view_embed = gtk_champlain_embed_new ();
1069 information->map_view = gtk_champlain_embed_get_view (
1070 GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1072 gtk_container_add (GTK_CONTAINER (information->viewport_map),
1073 information->map_view_embed);
1074 g_object_set (G_OBJECT (information->map_view),
1075 "show-license", TRUE,
1076 "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
1080 layer = champlain_layer_new ();
1081 champlain_view_add_layer (information->map_view, layer);
1083 marker = champlain_marker_new_with_text (
1084 empathy_contact_get_name (information->contact), NULL, NULL, NULL);
1085 champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
1086 clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
1088 champlain_view_center_on (information->map_view, lat, lon);
1089 gtk_widget_show_all (information->viewport_map);
1093 gtk_widget_show (information->vbox_location);
1097 save_avatar_menu_activate_cb (GtkWidget *widget,
1098 EmpathyContactWidget *information)
1101 EmpathyAvatar *avatar;
1102 gchar *ext = NULL, *filename;
1104 dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
1106 GTK_FILE_CHOOSER_ACTION_SAVE,
1107 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1108 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1111 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
1114 /* look for the avatar extension */
1115 avatar = empathy_contact_get_avatar (information->contact);
1116 if (avatar->format != NULL)
1120 splitted = g_strsplit (avatar->format, "/", 2);
1121 if (splitted[0] != NULL && splitted[1] != NULL)
1122 ext = g_strdup (splitted[1]);
1124 g_strfreev (splitted);
1128 /* Avatar was loaded from the cache so was converted to PNG */
1129 ext = g_strdup ("png");
1136 id = tp_escape_as_identifier (empathy_contact_get_id (
1137 information->contact));
1139 filename = g_strdup_printf ("%s.%s", id, ext);
1140 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
1147 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
1149 GError *error = NULL;
1151 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1153 if (!empathy_avatar_save_to_file (avatar, filename, &error))
1156 GtkWidget *error_dialog;
1158 error_dialog = gtk_message_dialog_new (NULL, 0,
1159 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1160 _("Unable to save avatar"));
1162 gtk_message_dialog_format_secondary_text (
1163 GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
1165 g_signal_connect (error_dialog, "response",
1166 G_CALLBACK (gtk_widget_destroy), NULL);
1168 gtk_window_present (GTK_WINDOW (error_dialog));
1170 g_clear_error (&error);
1176 gtk_widget_destroy (dialog);
1180 popup_avatar_menu (EmpathyContactWidget *information,
1182 GdkEventButton *event)
1184 GtkWidget *menu, *item;
1185 gint button, event_time;
1187 if (information->contact == NULL ||
1188 empathy_contact_get_avatar (information->contact) == NULL)
1191 menu = gtk_menu_new ();
1193 /* Add "Save as..." entry */
1194 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
1195 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1196 gtk_widget_show (item);
1198 g_signal_connect (item, "activate",
1199 G_CALLBACK (save_avatar_menu_activate_cb), information);
1203 button = event->button;
1204 event_time = event->time;
1209 event_time = gtk_get_current_event_time ();
1212 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1213 button, event_time);
1214 g_object_ref_sink (menu);
1215 g_object_unref (menu);
1219 widget_avatar_popup_menu_cb (GtkWidget *widget,
1220 EmpathyContactWidget *information)
1222 popup_avatar_menu (information, widget, NULL);
1228 widget_avatar_button_press_event_cb (GtkWidget *widget,
1229 GdkEventButton *event,
1230 EmpathyContactWidget *information)
1232 /* Ignore double-clicks and triple-clicks */
1233 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1235 popup_avatar_menu (information, widget, event);
1243 set_avatar_cb (GObject *source,
1247 GError *error = NULL;
1249 if (!tp_account_set_avatar_finish (TP_ACCOUNT (source), res, &error)) {
1250 DEBUG ("Failed to set Account.Avatar: %s", error->message);
1251 g_error_free (error);
1256 set_avatar_on_account (TpAccount *account,
1259 const gchar *mime_type)
1261 DEBUG ("%s Account.Avatar on %s", size > 0 ? "Set": "Clear",
1262 tp_proxy_get_object_path (account));
1264 tp_account_set_avatar_async (account, (const guchar *) data, size,
1265 mime_type, set_avatar_cb, NULL);
1269 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
1270 EmpathyContactWidget *information)
1274 const gchar *mime_type;
1277 empathy_avatar_chooser_get_image_data (
1278 EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
1279 &data, &size, &mime_type);
1281 account = empathy_contact_get_account (information->contact);
1282 set_avatar_on_account (account, data, size, mime_type);
1286 set_nickname_cb (GObject *source,
1290 GError *error = NULL;
1292 if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
1294 DEBUG ("Failed to set Account.Nickname: %s", error->message);
1295 g_error_free (error);
1300 set_alias_on_account (TpAccount *account,
1303 DEBUG ("Set Account.Nickname to %s", alias);
1305 tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL);
1309 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
1310 GdkEventFocus *event,
1311 EmpathyContactWidget *information)
1313 if (information->contact)
1317 alias = gtk_entry_get_text (GTK_ENTRY (editable));
1319 if (empathy_contact_is_user (information->contact))
1321 TpAccount * account;
1323 account = empathy_contact_get_account (information->contact);
1324 set_alias_on_account (account, alias);
1328 empathy_contact_set_alias (information->contact, alias);
1336 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
1337 EmpathyAvatarChooser *avatar_chooser)
1341 account = empathy_account_chooser_get_account (account_chooser);
1342 if (account == NULL)
1345 empathy_avatar_chooser_set_account (avatar_chooser, account);
1349 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
1351 EmpathyAvatar *avatar = NULL;
1353 if (information->contact)
1354 avatar = empathy_contact_get_avatar (information->contact);
1356 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1358 g_signal_handlers_block_by_func (information->widget_avatar,
1359 contact_widget_avatar_changed_cb,
1361 empathy_avatar_chooser_set (
1362 EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
1363 g_signal_handlers_unblock_by_func (information->widget_avatar,
1364 contact_widget_avatar_changed_cb, information);
1367 empathy_avatar_image_set (
1368 EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
1372 contact_widget_name_notify_cb (EmpathyContactWidget *information)
1374 if (GTK_IS_ENTRY (information->widget_alias))
1375 gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
1376 empathy_contact_get_name (information->contact));
1378 gtk_label_set_label (GTK_LABEL (information->widget_alias),
1379 empathy_contact_get_name (information->contact));
1383 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
1385 const gchar *status;
1386 gchar *markup_text = NULL;
1388 status = empathy_contact_get_status (information->contact);
1390 markup_text = empathy_add_link_markup (status);
1391 gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
1392 g_free (markup_text);
1394 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
1395 empathy_icon_name_for_contact (information->contact),
1396 GTK_ICON_SIZE_BUTTON);
1397 gtk_widget_show (information->image_state);
1400 #if HAVE_FAVOURITE_CONTACTS
1402 contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
1403 EmpathyContact *contact,
1404 gboolean is_favourite,
1405 EmpathyContactWidget *information)
1407 if (contact != information->contact)
1410 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
1411 information->favourite_checkbox), is_favourite);
1416 contact_widget_remove_contact (EmpathyContactWidget *information)
1418 if (information->contact)
1420 TpContact *tp_contact;
1422 contact_widget_save (information);
1424 g_signal_handlers_disconnect_by_func (information->contact,
1425 contact_widget_name_notify_cb, information);
1426 g_signal_handlers_disconnect_by_func (information->contact,
1427 contact_widget_presence_notify_cb, information);
1428 g_signal_handlers_disconnect_by_func (information->contact,
1429 contact_widget_avatar_notify_cb, information);
1430 g_signal_handlers_disconnect_by_func (information->contact,
1431 contact_widget_groups_notify_cb, information);
1433 tp_contact = empathy_contact_get_tp_contact (information->contact);
1434 if (tp_contact != NULL)
1436 g_signal_handlers_disconnect_by_func (tp_contact,
1437 contact_widget_details_notify_cb, information);
1440 g_object_unref (information->contact);
1441 information->contact = NULL;
1444 if (information->details_cancellable != NULL)
1446 g_cancellable_cancel (information->details_cancellable);
1447 g_object_unref (information->details_cancellable);
1448 information->details_cancellable = NULL;
1452 static void contact_widget_change_contact (EmpathyContactWidget *information);
1455 contact_widget_contact_update (EmpathyContactWidget *information)
1457 TpAccount *account = NULL;
1458 const gchar *id = NULL;
1460 /* Connect and get info from new contact */
1461 if (information->contact)
1463 g_signal_connect_swapped (information->contact, "notify::name",
1464 G_CALLBACK (contact_widget_name_notify_cb), information);
1465 g_signal_connect_swapped (information->contact, "notify::presence",
1466 G_CALLBACK (contact_widget_presence_notify_cb), information);
1467 g_signal_connect_swapped (information->contact,
1468 "notify::presence-message",
1469 G_CALLBACK (contact_widget_presence_notify_cb), information);
1470 g_signal_connect_swapped (information->contact, "notify::avatar",
1471 G_CALLBACK (contact_widget_avatar_notify_cb), information);
1473 account = empathy_contact_get_account (information->contact);
1474 id = empathy_contact_get_id (information->contact);
1477 /* Update account widget */
1478 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1482 g_signal_handlers_block_by_func (information->widget_account,
1483 contact_widget_change_contact,
1485 empathy_account_chooser_set_account (
1486 EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
1487 g_signal_handlers_unblock_by_func (information->widget_account,
1488 contact_widget_change_contact, information);
1497 name = tp_account_get_display_name (account);
1498 gtk_label_set_label (GTK_LABEL (information->label_account), name);
1500 name = tp_account_get_icon_name (account);
1501 gtk_image_set_from_icon_name (GTK_IMAGE (information->image_account),
1502 name, GTK_ICON_SIZE_MENU);
1506 /* Update id widget */
1507 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1508 gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
1510 gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
1512 /* Update other widgets */
1513 if (information->contact)
1515 contact_widget_name_notify_cb (information);
1516 contact_widget_presence_notify_cb (information);
1517 contact_widget_avatar_notify_cb (information);
1519 #if HAVE_FAVOURITE_CONTACTS
1520 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1522 gboolean is_favourite;
1524 is_favourite = empathy_contact_list_is_favourite (
1525 EMPATHY_CONTACT_LIST (information->manager),
1526 information->contact);
1528 contact_widget_favourites_changed_cb (information->manager,
1529 information->contact, is_favourite, information);
1533 gtk_widget_show (information->label_alias);
1534 gtk_widget_show (information->widget_alias);
1535 gtk_widget_show (information->hbox_presence);
1536 gtk_widget_show (information->widget_avatar);
1540 gtk_widget_hide (information->label_alias);
1541 gtk_widget_hide (information->widget_alias);
1542 gtk_widget_hide (information->hbox_presence);
1543 gtk_widget_hide (information->widget_avatar);
1548 contact_widget_set_contact (EmpathyContactWidget *information,
1549 EmpathyContact *contact)
1551 if (contact == information->contact)
1554 contact_widget_remove_contact (information);
1556 information->contact = g_object_ref (contact);
1558 /* set the selected account to be the account this contact came from */
1559 if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (information->widget_account)) {
1560 empathy_account_chooser_set_account (
1561 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1562 empathy_contact_get_account (contact));
1565 /* Update information for widgets */
1566 contact_widget_contact_update (information);
1567 contact_widget_groups_update (information);
1568 contact_widget_details_update (information);
1569 contact_widget_client_update (information);
1570 contact_widget_location_update (information);
1574 contact_widget_got_contact_cb (TpConnection *connection,
1575 EmpathyContact *contact,
1576 const GError *error,
1578 GObject *weak_object)
1580 EmpathyContactWidget *information = user_data;
1584 DEBUG ("Error: %s", error->message);
1588 contact_widget_set_contact (information, contact);
1592 contact_widget_change_contact (EmpathyContactWidget *information)
1594 TpConnection *connection;
1596 connection = empathy_account_chooser_get_connection (
1597 EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
1601 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1605 id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
1606 if (!EMP_STR_EMPTY (id))
1608 empathy_tp_contact_factory_get_from_id (connection, id,
1609 contact_widget_got_contact_cb, information, NULL,
1610 G_OBJECT (information->vbox_contact_widget));
1615 empathy_tp_contact_factory_get_from_handle (connection,
1616 tp_connection_get_self_handle (connection),
1617 contact_widget_got_contact_cb, information, NULL,
1618 G_OBJECT (information->vbox_contact_widget));
1623 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
1625 contact_widget_change_contact (self);
1630 contact_widget_id_changed_cb (GtkEntry *entry,
1631 EmpathyContactWidget *self)
1633 if (self->widget_id_timeout != 0)
1635 g_source_remove (self->widget_id_timeout);
1638 self->widget_id_timeout =
1639 g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
1640 (GSourceFunc) contact_widget_id_activate_timeout, self);
1644 contact_widget_id_focus_out_cb (GtkWidget *widget,
1645 GdkEventFocus *event,
1646 EmpathyContactWidget *information)
1648 contact_widget_change_contact (information);
1652 #if HAVE_FAVOURITE_CONTACTS
1654 favourite_toggled_cb (GtkToggleButton *button,
1655 EmpathyContactWidget *information)
1659 active = gtk_toggle_button_get_active (button);
1663 empathy_contact_list_add_to_favourites (
1664 EMPATHY_CONTACT_LIST (information->manager), information->contact);
1668 empathy_contact_list_remove_from_favourites (
1669 EMPATHY_CONTACT_LIST (information->manager), information->contact);
1675 contact_widget_contact_setup (EmpathyContactWidget *information)
1677 /* Setup label_status as a KludgeLabel */
1678 information->label_status = empathy_kludge_label_new ("");
1679 gtk_label_set_line_wrap_mode (GTK_LABEL (information->label_status),
1680 PANGO_WRAP_WORD_CHAR);
1681 gtk_label_set_line_wrap (GTK_LABEL (information->label_status),
1684 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1685 gtk_label_set_selectable (GTK_LABEL (information->label_status), TRUE);
1687 gtk_box_pack_start (GTK_BOX (information->hbox_presence),
1688 information->label_status, TRUE, TRUE, 0);
1689 gtk_widget_show (information->label_status);
1691 /* Setup account label/chooser */
1692 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1694 information->widget_account = empathy_account_chooser_new ();
1696 g_signal_connect_swapped (information->widget_account, "changed",
1697 G_CALLBACK (contact_widget_change_contact),
1702 /* Pack the protocol icon with the account name in an hbox */
1703 information->widget_account = gtk_hbox_new (FALSE, 6);
1705 information->label_account = gtk_label_new (NULL);
1706 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1707 gtk_label_set_selectable (GTK_LABEL (information->label_account), TRUE);
1709 gtk_misc_set_alignment (GTK_MISC (information->label_account), 0, 0.5);
1710 gtk_widget_show (information->label_account);
1712 information->image_account = gtk_image_new ();
1713 gtk_widget_show (information->image_account);
1715 gtk_box_pack_start (GTK_BOX (information->widget_account),
1716 information->image_account, FALSE, FALSE, 0);
1717 gtk_box_pack_start (GTK_BOX (information->widget_account),
1718 information->label_account, FALSE, TRUE, 0);
1720 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1721 information->widget_account,
1723 gtk_widget_show (information->widget_account);
1725 /* Set up avatar chooser/display */
1726 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
1728 information->widget_avatar = empathy_avatar_chooser_new ();
1729 g_signal_connect (information->widget_avatar, "changed",
1730 G_CALLBACK (contact_widget_avatar_changed_cb),
1732 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
1734 g_signal_connect (information->widget_account, "changed",
1735 G_CALLBACK (update_avatar_chooser_account_cb),
1736 information->widget_avatar);
1737 update_avatar_chooser_account_cb (
1738 EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
1739 EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
1744 information->widget_avatar = empathy_avatar_image_new ();
1746 g_signal_connect (information->widget_avatar, "popup-menu",
1747 G_CALLBACK (widget_avatar_popup_menu_cb), information);
1748 g_signal_connect (information->widget_avatar, "button-press-event",
1749 G_CALLBACK (widget_avatar_button_press_event_cb), information);
1752 gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
1753 information->widget_avatar,
1756 gtk_widget_show (information->widget_avatar);
1758 /* Setup id label/entry */
1759 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1761 information->widget_id = gtk_entry_new ();
1762 g_signal_connect (information->widget_id, "focus-out-event",
1763 G_CALLBACK (contact_widget_id_focus_out_cb),
1765 g_signal_connect (information->widget_id, "changed",
1766 G_CALLBACK (contact_widget_id_changed_cb),
1771 information->widget_id = gtk_label_new (NULL);
1772 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1773 gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
1775 gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
1777 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1778 information->widget_id,
1780 gtk_widget_show (information->widget_id);
1782 /* Setup alias label/entry */
1783 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
1785 information->widget_alias = gtk_entry_new ();
1787 if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
1788 g_signal_connect (information->widget_alias, "focus-out-event",
1789 G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
1792 /* Make return activate the window default (the Close button) */
1793 gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
1798 information->widget_alias = gtk_label_new (NULL);
1799 if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
1800 gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
1802 gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
1804 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1805 information->widget_alias,
1807 if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
1808 gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
1810 gtk_widget_show (information->widget_alias);
1812 #if HAVE_FAVOURITE_CONTACTS
1814 if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
1816 information->favourite_checkbox = gtk_check_button_new_with_label (
1819 g_signal_connect (information->favourite_checkbox, "toggled",
1820 G_CALLBACK (favourite_toggled_cb), information);
1822 gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
1823 information->favourite_checkbox, 0, 2, 3, 4);
1825 information->fav_sig_id = g_signal_connect (information->manager,
1826 "favourites-changed",
1827 G_CALLBACK (contact_widget_favourites_changed_cb), information);
1829 gtk_widget_show (information->favourite_checkbox);
1835 contact_widget_destroy_cb (GtkWidget *widget,
1836 EmpathyContactWidget *information)
1838 contact_widget_remove_contact (information);
1840 if (information->widget_id_timeout != 0)
1842 g_source_remove (information->widget_id_timeout);
1845 if (information->fav_sig_id != 0)
1846 g_signal_handler_disconnect (information->manager, information->fav_sig_id);
1848 g_object_unref (information->manager);
1850 g_slice_free (EmpathyContactWidget, information);
1854 * empathy_contact_widget_new:
1855 * @contact: an #EmpathyContact
1856 * @flags: #EmpathyContactWidgetFlags for the new contact widget
1858 * Creates a new #EmpathyContactWidget.
1860 * Return value: a new #EmpathyContactWidget
1863 empathy_contact_widget_new (EmpathyContact *contact,
1864 EmpathyContactWidgetFlags flags)
1866 EmpathyContactWidget *information;
1870 g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
1872 information = g_slice_new0 (EmpathyContactWidget);
1873 information->flags = flags;
1875 filename = empathy_file_lookup ("empathy-contact-widget.ui",
1877 gui = empathy_builder_get_file (filename,
1878 "vbox_contact_widget", &information->vbox_contact_widget,
1879 "hbox_contact", &information->hbox_contact,
1880 "hbox_presence", &information->hbox_presence,
1881 "label_alias", &information->label_alias,
1882 "image_state", &information->image_state,
1883 "table_contact", &information->table_contact,
1884 "vbox_avatar", &information->vbox_avatar,
1885 "vbox_location", &information->vbox_location,
1886 "subvbox_location", &information->subvbox_location,
1887 "label_location", &information->label_location,
1888 #if HAVE_LIBCHAMPLAIN
1889 "viewport_map", &information->viewport_map,
1891 "vbox_groups", &information->vbox_groups,
1892 "entry_group", &information->entry_group,
1893 "button_group", &information->button_group,
1894 "treeview_groups", &information->treeview_groups,
1895 "vbox_details", &information->vbox_details,
1896 "table_details", &information->table_details,
1897 "hbox_details_requested", &information->hbox_details_requested,
1898 "vbox_client", &information->vbox_client,
1899 "table_client", &information->table_client,
1900 "hbox_client_requested", &information->hbox_client_requested,
1904 empathy_builder_connect (gui, information,
1905 "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
1906 "entry_group", "changed", contact_widget_entry_group_changed_cb,
1907 "entry_group", "activate", contact_widget_entry_group_activate_cb,
1908 "button_group", "clicked", contact_widget_button_group_clicked_cb,
1910 information->table_location = NULL;
1912 g_object_set_data (G_OBJECT (information->vbox_contact_widget),
1913 "EmpathyContactWidget",
1916 information->manager = empathy_contact_manager_dup_singleton ();
1918 /* Create widgets */
1919 contact_widget_contact_setup (information);
1920 contact_widget_groups_setup (information);
1921 contact_widget_details_setup (information);
1922 contact_widget_client_setup (information);
1924 if (contact != NULL)
1925 contact_widget_set_contact (information, contact);
1926 else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
1927 information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
1928 contact_widget_change_contact (information);
1930 return empathy_builder_unref_and_keep_widget (gui,
1931 information->vbox_contact_widget);
1935 * empathy_contact_widget_get_contact:
1936 * @widget: an #EmpathyContactWidget
1938 * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
1940 * Returns: the #EmpathyContact associated with @widget
1943 empathy_contact_widget_get_contact (GtkWidget *widget)
1945 EmpathyContactWidget *information;
1947 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1949 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1953 return information->contact;
1957 empathy_contact_widget_get_alias (GtkWidget *widget)
1959 EmpathyContactWidget *information;
1961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1963 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1967 return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
1971 * empathy_contact_widget_set_contact:
1972 * @widget: an #EmpathyContactWidget
1973 * @contact: a different #EmpathyContact
1975 * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
1978 empathy_contact_widget_set_contact (GtkWidget *widget,
1979 EmpathyContact *contact)
1981 EmpathyContactWidget *information;
1983 g_return_if_fail (GTK_IS_WIDGET (widget));
1984 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1986 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
1990 contact_widget_set_contact (information, contact);
1994 * empathy_contact_widget_set_account_filter:
1995 * @widget: an #EmpathyContactWidget
1996 * @filter: a #EmpathyAccountChooserFilterFunc
1997 * @user_data: user data to pass to @filter, or %NULL
1999 * Set a filter on the #EmpathyAccountChooser included in the
2000 * #EmpathyContactWidget.
2003 empathy_contact_widget_set_account_filter (
2005 EmpathyAccountChooserFilterFunc filter,
2008 EmpathyContactWidget *information;
2009 EmpathyAccountChooser *chooser;
2011 g_return_if_fail (GTK_IS_WIDGET (widget));
2013 information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
2017 chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
2019 empathy_account_chooser_set_filter (chooser, filter, user_data);