]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-widget.c
Added functions to determine if a contact has video capabilities
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2009 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include <gtk/gtk.h>
28 #include <glib/gi18n-lib.h>
29
30 #if HAVE_LIBCHAMPLAIN
31 #include <champlain/champlain.h>
32 #include <champlain-gtk/champlain-gtk.h>
33 #endif
34
35 #include <telepathy-glib/util.h>
36
37 #include <libempathy/empathy-tp-contact-factory.h>
38 #include <libempathy/empathy-contact-manager.h>
39 #include <libempathy/empathy-contact-list.h>
40 #include <libempathy/empathy-location.h>
41 #include <libempathy/empathy-time.h>
42 #include <libempathy/empathy-utils.h>
43 #include <libempathy/empathy-account.h>
44
45 #include "empathy-contact-widget.h"
46 #include "empathy-account-chooser.h"
47 #include "empathy-avatar-chooser.h"
48 #include "empathy-avatar-image.h"
49 #include "empathy-ui-utils.h"
50
51 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
52 #include <libempathy/empathy-debug.h>
53
54 /**
55  * SECTION:empathy-contact-widget
56  * @title:EmpathyContactWidget
57  * @short_description: A widget used to display and edit details about a contact
58  * @include: libempathy-empathy-contact-widget.h
59  *
60  * #EmpathyContactWidget is a widget which displays appropriate widgets
61  * with details about a contact, also allowing changing these details,
62  * if desired.
63  */
64
65 /**
66  * EmpathyContactWidget:
67  * @parent: parent object
68  *
69  * Widget which displays appropriate widgets with details about a contact,
70  * also allowing changing these details, if desired.
71  */
72
73 /* Delay before updating the widget when the id entry changed (seconds) */
74 #define ID_CHANGED_TIMEOUT 1
75
76 typedef struct
77 {
78   EmpathyTpContactFactory *factory;
79   EmpathyContactManager *manager;
80   EmpathyContact *contact;
81   EmpathyContactWidgetFlags flags;
82   guint widget_id_timeout;
83
84   GtkWidget *vbox_contact_widget;
85
86   /* Contact */
87   GtkWidget *vbox_contact;
88   GtkWidget *widget_avatar;
89   GtkWidget *widget_account;
90   GtkWidget *widget_id;
91   GtkWidget *widget_alias;
92   GtkWidget *label_alias;
93   GtkWidget *entry_alias;
94   GtkWidget *hbox_presence;
95   GtkWidget *image_state;
96   GtkWidget *label_status;
97   GtkWidget *table_contact;
98   GtkWidget *vbox_avatar;
99
100   /* Location */
101   GtkWidget *vbox_location;
102   GtkWidget *subvbox_location;
103   GtkWidget *table_location;
104   GtkWidget *label_location;
105 #if HAVE_LIBCHAMPLAIN
106   GtkWidget *viewport_map;
107   GtkWidget *map_view_embed;
108   ChamplainView *map_view;
109 #endif
110
111   /* Groups */
112   GtkWidget *vbox_groups;
113   GtkWidget *entry_group;
114   GtkWidget *button_group;
115   GtkWidget *treeview_groups;
116
117   /* Details */
118   GtkWidget *vbox_details;
119   GtkWidget *table_details;
120   GtkWidget *hbox_details_requested;
121
122   /* Client */
123   GtkWidget *vbox_client;
124   GtkWidget *table_client;
125   GtkWidget *hbox_client_requested;
126 } EmpathyContactWidget;
127
128 typedef struct
129 {
130   EmpathyContactWidget *information;
131   const gchar *name;
132   gboolean found;
133   GtkTreeIter found_iter;
134 } FindName;
135
136 static void contact_widget_destroy_cb (GtkWidget *widget,
137     EmpathyContactWidget *information);
138 static void contact_widget_remove_contact (EmpathyContactWidget *information);
139 static void contact_widget_set_contact (EmpathyContactWidget *information,
140     EmpathyContact *contact);
141 static void contact_widget_contact_setup (EmpathyContactWidget *information);
142 static void contact_widget_contact_update (EmpathyContactWidget *information);
143 static void contact_widget_change_contact (EmpathyContactWidget *information);
144 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
145     EmpathyContactWidget *information);
146 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
147     GdkEventFocus *event, EmpathyContactWidget *information);
148 static gboolean contact_widget_entry_alias_focus_event_cb (
149     GtkEditable *editable, GdkEventFocus *event,
150     EmpathyContactWidget *information);
151 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
152 static void contact_widget_presence_notify_cb (
153     EmpathyContactWidget *information);
154 static void contact_widget_avatar_notify_cb (
155     EmpathyContactWidget *information);
156 static void contact_widget_groups_setup (
157     EmpathyContactWidget *information);
158 static void contact_widget_groups_update (EmpathyContactWidget *information);
159 static void contact_widget_model_setup (EmpathyContactWidget *information);
160 static void contact_widget_model_populate_columns (
161     EmpathyContactWidget *information);
162 static void contact_widget_groups_populate_data (
163     EmpathyContactWidget *information);
164 static void contact_widget_groups_notify_cb (
165     EmpathyContactWidget *information);
166 static gboolean contact_widget_model_find_name (
167     EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
168 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
169     GtkTreePath *path, GtkTreeIter *iter, FindName *data);
170 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
171     gchar *path_string, EmpathyContactWidget *information);
172 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
173     EmpathyContactWidget *information);
174 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
175     EmpathyContactWidget *information);
176 static void contact_widget_button_group_clicked_cb (GtkButton *button,
177     EmpathyContactWidget *information);
178 static void contact_widget_details_setup (EmpathyContactWidget *information);
179 static void contact_widget_details_update (EmpathyContactWidget *information);
180 static void contact_widget_client_setup (EmpathyContactWidget *information);
181 static void contact_widget_client_update (EmpathyContactWidget *information);
182 static void contact_widget_location_update (EmpathyContactWidget *information);
183
184 enum
185 {
186   COL_NAME,
187   COL_ENABLED,
188   COL_EDITABLE,
189   COL_COUNT
190 };
191
192 /**
193  * empathy_contact_widget_new:
194  * @contact: an #EmpathyContact
195  * @flags: #EmpathyContactWidgetFlags for the new contact widget
196  *
197  * Creates a new #EmpathyContactWidget.
198  *
199  * Return value: a new #EmpathyContactWidget
200  */
201 GtkWidget *
202 empathy_contact_widget_new (EmpathyContact *contact,
203                             EmpathyContactWidgetFlags flags)
204 {
205   EmpathyContactWidget *information;
206   GtkBuilder *gui;
207   gchar *filename;
208
209   g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
210
211   information = g_slice_new0 (EmpathyContactWidget);
212   information->flags = flags;
213
214   filename = empathy_file_lookup ("empathy-contact-widget.ui",
215       "libempathy-gtk");
216   gui = empathy_builder_get_file (filename,
217        "vbox_contact_widget", &information->vbox_contact_widget,
218        "vbox_contact", &information->vbox_contact,
219        "hbox_presence", &information->hbox_presence,
220        "label_alias", &information->label_alias,
221        "image_state", &information->image_state,
222        "label_status", &information->label_status,
223        "table_contact", &information->table_contact,
224        "vbox_avatar", &information->vbox_avatar,
225        "vbox_location", &information->vbox_location,
226        "subvbox_location", &information->subvbox_location,
227        "label_location", &information->label_location,
228 #if HAVE_LIBCHAMPLAIN
229        "viewport_map", &information->viewport_map,
230 #endif
231        "vbox_groups", &information->vbox_groups,
232        "entry_group", &information->entry_group,
233        "button_group", &information->button_group,
234        "treeview_groups", &information->treeview_groups,
235        "vbox_details", &information->vbox_details,
236        "table_details", &information->table_details,
237        "hbox_details_requested", &information->hbox_details_requested,
238        "vbox_client", &information->vbox_client,
239        "table_client", &information->table_client,
240        "hbox_client_requested", &information->hbox_client_requested,
241        NULL);
242   g_free (filename);
243
244   empathy_builder_connect (gui, information,
245       "vbox_contact_widget", "destroy", contact_widget_destroy_cb,
246       "entry_group", "changed", contact_widget_entry_group_changed_cb,
247       "entry_group", "activate", contact_widget_entry_group_activate_cb,
248       "button_group", "clicked", contact_widget_button_group_clicked_cb,
249       NULL);
250   information->table_location = NULL;
251
252   g_object_set_data (G_OBJECT (information->vbox_contact_widget),
253       "EmpathyContactWidget",
254       information);
255
256   /* Create widgets */
257   contact_widget_contact_setup (information);
258   contact_widget_groups_setup (information);
259   contact_widget_details_setup (information);
260   contact_widget_client_setup (information);
261
262   if (contact != NULL)
263     contact_widget_set_contact (information, contact);
264
265   else if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT ||
266       information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
267     contact_widget_change_contact (information);
268
269   return empathy_builder_unref_and_keep_widget (gui,
270     information->vbox_contact_widget);
271 }
272
273 /**
274  * empathy_contact_widget_get_contact:
275  * @widget: an #EmpathyContactWidget
276  *
277  * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
278  *
279  * Returns: the #EmpathyContact associated with @widget
280  */
281 EmpathyContact *
282 empathy_contact_widget_get_contact (GtkWidget *widget)
283 {
284   EmpathyContactWidget *information;
285
286   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
287
288   information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
289   if (!information)
290       return NULL;
291
292   return information->contact;
293 }
294
295 /**
296  * empathy_contact_widget_set_contact:
297  * @widget: an #EmpathyContactWidget
298  * @contact: a different #EmpathyContact
299  *
300  * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
301  */
302 void
303 empathy_contact_widget_set_contact (GtkWidget *widget,
304                                     EmpathyContact *contact)
305 {
306   EmpathyContactWidget *information;
307
308   g_return_if_fail (GTK_IS_WIDGET (widget));
309   g_return_if_fail (EMPATHY_IS_CONTACT (contact));
310
311   information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
312   if (!information)
313     return;
314
315   contact_widget_set_contact (information, contact);
316 }
317
318 /**
319  * empathy_contact_widget_set_account_filter:
320  * @widget: an #EmpathyContactWidget
321  * @filter: a #EmpathyAccountChooserFilterFunc
322  * @user_data: user data to pass to @filter, or %NULL
323  *
324  * Set a filter on the #EmpathyAccountChooser included in the
325  * #EmpathyContactWidget.
326  */
327 void
328 empathy_contact_widget_set_account_filter (
329     GtkWidget *widget,
330     EmpathyAccountChooserFilterFunc filter,
331     gpointer user_data)
332 {
333   EmpathyContactWidget *information;
334   EmpathyAccountChooser *chooser;
335
336   g_return_if_fail (GTK_IS_WIDGET (widget));
337
338   information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
339   if (!information)
340     return;
341
342   chooser = EMPATHY_ACCOUNT_CHOOSER (information->widget_account);
343   if (chooser)
344       empathy_account_chooser_set_filter (chooser, filter, user_data);
345 }
346
347 static void
348 contact_widget_destroy_cb (GtkWidget *widget,
349                            EmpathyContactWidget *information)
350 {
351   contact_widget_remove_contact (information);
352
353   if (information->widget_id_timeout != 0)
354     {
355       g_source_remove (information->widget_id_timeout);
356     }
357   if (information->manager)
358     {
359       g_object_unref (information->manager);
360     }
361
362   g_slice_free (EmpathyContactWidget, information);
363 }
364
365 static void
366 contact_widget_remove_contact (EmpathyContactWidget *information)
367 {
368   if (information->contact)
369     {
370       g_signal_handlers_disconnect_by_func (information->contact,
371           contact_widget_name_notify_cb, information);
372       g_signal_handlers_disconnect_by_func (information->contact,
373           contact_widget_presence_notify_cb, information);
374       g_signal_handlers_disconnect_by_func (information->contact,
375           contact_widget_avatar_notify_cb, information);
376       g_signal_handlers_disconnect_by_func (information->contact,
377           contact_widget_groups_notify_cb, information);
378
379       g_object_unref (information->contact);
380       g_object_unref (information->factory);
381       information->contact = NULL;
382       information->factory = NULL;
383     }
384 }
385
386 static void
387 contact_widget_set_contact (EmpathyContactWidget *information,
388                             EmpathyContact *contact)
389 {
390   if (contact == information->contact)
391     return;
392
393   contact_widget_remove_contact (information);
394   if (contact)
395     {
396       TpConnection *connection;
397
398       connection = empathy_contact_get_connection (contact);
399       information->contact = g_object_ref (contact);
400       information->factory = empathy_tp_contact_factory_dup_singleton (connection);
401     }
402
403   /* Update information for widgets */
404   contact_widget_contact_update (information);
405   contact_widget_groups_update (information);
406   contact_widget_details_update (information);
407   contact_widget_client_update (information);
408   contact_widget_location_update (information);
409 }
410
411 static gboolean
412 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
413 {
414   contact_widget_change_contact (self);
415   return FALSE;
416 }
417
418 static void
419 contact_widget_id_changed_cb (GtkEntry *entry,
420                               EmpathyContactWidget *self)
421 {
422   if (self->widget_id_timeout != 0)
423     {
424       g_source_remove (self->widget_id_timeout);
425     }
426
427   self->widget_id_timeout =
428     g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
429         (GSourceFunc) contact_widget_id_activate_timeout, self);
430 }
431
432 static void
433 save_avatar_menu_activate_cb (GtkWidget *widget,
434                               EmpathyContactWidget *information)
435 {
436   GtkWidget *dialog;
437   EmpathyAvatar *avatar;
438   gchar *ext = NULL, *filename;
439
440   dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
441       NULL,
442       GTK_FILE_CHOOSER_ACTION_SAVE,
443       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
444       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
445       NULL);
446
447   gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
448       TRUE);
449
450   /* look for the avatar extension */
451   avatar = empathy_contact_get_avatar (information->contact);
452   if (avatar->format != NULL)
453     {
454       gchar **splitted;
455
456       splitted = g_strsplit (avatar->format, "/", 2);
457       if (splitted[0] != NULL && splitted[1] != NULL)
458           ext = g_strdup (splitted[1]);
459
460       g_strfreev (splitted);
461     }
462   else
463     {
464       /* Avatar was loaded from the cache so was converted to PNG */
465       ext = g_strdup ("png");
466     }
467
468   if (ext != NULL)
469     {
470       gchar *id;
471
472       id = tp_escape_as_identifier (empathy_contact_get_id (
473             information->contact));
474
475       filename = g_strdup_printf ("%s.%s", id, ext);
476       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
477
478       g_free (id);
479       g_free (ext);
480       g_free (filename);
481     }
482
483   if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
484     {
485       GError *error = NULL;
486
487       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
488
489       if (!empathy_avatar_save_to_file (avatar, filename, &error))
490         {
491           /* Save error */
492           GtkWidget *dialog;
493
494           dialog = gtk_message_dialog_new (NULL, 0,
495               GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
496               _("Unable to save avatar"));
497
498           gtk_message_dialog_format_secondary_text (
499               GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
500
501           g_signal_connect (dialog, "response",
502               G_CALLBACK (gtk_widget_destroy), NULL);
503
504           gtk_window_present (GTK_WINDOW (dialog));
505
506           g_clear_error (&error);
507         }
508
509       g_free (filename);
510     }
511
512   gtk_widget_destroy (dialog);
513 }
514
515 static void
516 popup_avatar_menu (EmpathyContactWidget *information,
517                    GtkWidget *parent,
518                    GdkEventButton *event)
519 {
520   GtkWidget *menu, *item;
521   gint button, event_time;
522
523   if (information->contact == NULL ||
524       empathy_contact_get_avatar (information->contact) == NULL)
525       return;
526
527   menu = gtk_menu_new ();
528
529   /* Add "Save as..." entry */
530   item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
531   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
532   gtk_widget_show (item);
533
534   g_signal_connect (item, "activate",
535       G_CALLBACK (save_avatar_menu_activate_cb), information);
536
537   if (event)
538     {
539       button = event->button;
540       event_time = event->time;
541     }
542   else
543     {
544       button = 0;
545       event_time = gtk_get_current_event_time ();
546     }
547
548   gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
549   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
550       button, event_time);
551 }
552
553 static gboolean
554 widget_avatar_popup_menu_cb (GtkWidget *widget,
555                              EmpathyContactWidget *information)
556 {
557   popup_avatar_menu (information, widget, NULL);
558
559   return TRUE;
560 }
561
562 static gboolean
563 widget_avatar_button_press_event_cb (GtkWidget *widget,
564                                      GdkEventButton *event,
565                                      EmpathyContactWidget *information)
566 {
567   /* Ignore double-clicks and triple-clicks */
568   if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
569     {
570       popup_avatar_menu (information, widget, event);
571       return TRUE;
572     }
573
574   return FALSE;
575 }
576
577 static void
578 update_avatar_chooser_account_cb (EmpathyAccountChooser *account_chooser,
579                                   EmpathyAvatarChooser *avatar_chooser)
580 {
581   TpConnection *connection;
582
583   connection = empathy_account_chooser_get_connection (account_chooser);
584   g_object_set (avatar_chooser, "connection", connection, NULL);
585 }
586
587 static void
588 contact_widget_contact_setup (EmpathyContactWidget *information)
589 {
590   /* Setup account label/chooser */
591   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
592     {
593       information->widget_account = empathy_account_chooser_new ();
594
595       g_signal_connect_swapped (information->widget_account, "changed",
596             G_CALLBACK (contact_widget_change_contact),
597             information);
598     }
599   else
600     {
601       information->widget_account = gtk_label_new (NULL);
602       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
603         gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
604       }
605       gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
606     }
607   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
608            information->widget_account,
609            1, 2, 0, 1);
610   gtk_widget_show (information->widget_account);
611
612   /* Set up avatar chooser/display */
613   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
614     {
615       information->widget_avatar = empathy_avatar_chooser_new ();
616       g_signal_connect (information->widget_avatar, "changed",
617             G_CALLBACK (contact_widget_avatar_changed_cb),
618             information);
619       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
620         {
621           g_signal_connect (information->widget_account, "changed",
622               G_CALLBACK (update_avatar_chooser_account_cb),
623               information->widget_avatar);
624           update_avatar_chooser_account_cb (
625               EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
626               EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
627         }
628     }
629   else
630     {
631       information->widget_avatar = empathy_avatar_image_new ();
632
633       g_signal_connect (information->widget_avatar, "popup-menu",
634           G_CALLBACK (widget_avatar_popup_menu_cb), information);
635       g_signal_connect (information->widget_avatar, "button-press-event",
636           G_CALLBACK (widget_avatar_button_press_event_cb), information);
637     }
638
639   gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
640           information->widget_avatar,
641           FALSE, FALSE,
642           6);
643   gtk_widget_show (information->widget_avatar);
644
645   /* Setup id label/entry */
646   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
647     {
648       information->widget_id = gtk_entry_new ();
649       g_signal_connect (information->widget_id, "focus-out-event",
650             G_CALLBACK (contact_widget_id_focus_out_cb),
651             information);
652       g_signal_connect (information->widget_id, "changed",
653             G_CALLBACK (contact_widget_id_changed_cb),
654             information);
655     }
656   else
657     {
658       information->widget_id = gtk_label_new (NULL);
659       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
660         gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
661       }
662       gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
663     }
664   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
665            information->widget_id,
666            1, 2, 1, 2);
667   gtk_widget_show (information->widget_id);
668
669   /* Setup alias label/entry */
670   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
671     {
672       information->widget_alias = gtk_entry_new ();
673       g_signal_connect (information->widget_alias, "focus-out-event",
674             G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
675             information);
676       /* Make return activate the window default (the Close button) */
677       gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
678           TRUE);
679     }
680   else
681     {
682       information->widget_alias = gtk_label_new (NULL);
683       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
684         gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
685       }
686       gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
687     }
688   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
689            information->widget_alias,
690            1, 2, 2, 3);
691   if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
692     gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
693   }
694   gtk_widget_show (information->widget_alias);
695 }
696
697 static void
698 contact_widget_contact_update (EmpathyContactWidget *information)
699 {
700   EmpathyAccount *account = NULL;
701   const gchar *id = NULL;
702
703   /* Connect and get info from new contact */
704   if (information->contact)
705     {
706       g_signal_connect_swapped (information->contact, "notify::name",
707           G_CALLBACK (contact_widget_name_notify_cb), information);
708       g_signal_connect_swapped (information->contact, "notify::presence",
709           G_CALLBACK (contact_widget_presence_notify_cb), information);
710       g_signal_connect_swapped (information->contact,
711           "notify::presence-message",
712           G_CALLBACK (contact_widget_presence_notify_cb), information);
713       g_signal_connect_swapped (information->contact, "notify::avatar",
714           G_CALLBACK (contact_widget_avatar_notify_cb), information);
715
716       account = empathy_contact_get_account (information->contact);
717       id = empathy_contact_get_id (information->contact);
718     }
719
720   /* Update account widget */
721   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
722     {
723       if (account)
724         {
725           g_signal_handlers_block_by_func (information->widget_account,
726                    contact_widget_change_contact,
727                    information);
728           empathy_account_chooser_set_account (
729               EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
730           g_signal_handlers_unblock_by_func (information->widget_account,
731               contact_widget_change_contact, information);
732         }
733     }
734   else
735     {
736       if (account)
737         {
738           const gchar *name;
739
740           name = empathy_account_get_display_name (account);
741           gtk_label_set_label (GTK_LABEL (information->widget_account), name);
742         }
743     }
744
745   /* Update id widget */
746   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
747       gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
748   else
749       gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
750
751   /* Update other widgets */
752   if (information->contact)
753     {
754       contact_widget_name_notify_cb (information);
755       contact_widget_presence_notify_cb (information);
756       contact_widget_avatar_notify_cb (information);
757
758       gtk_widget_show (information->label_alias);
759       gtk_widget_show (information->widget_alias);
760       gtk_widget_show (information->hbox_presence);
761       gtk_widget_show (information->widget_avatar);
762     }
763   else
764     {
765       gtk_widget_hide (information->label_alias);
766       gtk_widget_hide (information->widget_alias);
767       gtk_widget_hide (information->hbox_presence);
768       gtk_widget_hide (information->widget_avatar);
769     }
770 }
771
772 static void
773 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
774                                EmpathyContact *contact,
775                                const GError *error,
776                                gpointer user_data,
777                                GObject *weak_object)
778 {
779   EmpathyContactWidget *information = user_data;
780
781   if (error != NULL)
782     {
783       DEBUG ("Error: %s", error->message);
784       return;
785     }
786
787   contact_widget_set_contact (information, contact);
788 }
789
790 static void
791 contact_widget_change_contact (EmpathyContactWidget *information)
792 {
793   EmpathyTpContactFactory *factory;
794   TpConnection *connection;
795
796   connection = empathy_account_chooser_get_connection (
797       EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
798   if (!connection)
799       return;
800
801   factory = empathy_tp_contact_factory_dup_singleton (connection);
802   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
803     {
804       const gchar *id;
805
806       id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
807       if (!EMP_STR_EMPTY (id))
808         {
809           empathy_tp_contact_factory_get_from_id (factory, id,
810               contact_widget_got_contact_cb, information, NULL,
811               G_OBJECT (information->vbox_contact_widget));
812         }
813     }
814   else
815     {
816       empathy_tp_contact_factory_get_from_handle (factory,
817           tp_connection_get_self_handle (connection),
818           contact_widget_got_contact_cb, information, NULL,
819           G_OBJECT (information->vbox_contact_widget));
820     }
821
822   g_object_unref (factory);
823 }
824
825 static void
826 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
827                                   EmpathyContactWidget *information)
828 {
829   const gchar *data;
830   gsize size;
831   const gchar *mime_type;
832
833   empathy_avatar_chooser_get_image_data (
834       EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
835       &data, &size, &mime_type);
836   empathy_tp_contact_factory_set_avatar (information->factory,
837       data, size, mime_type);
838 }
839
840 static gboolean
841 contact_widget_id_focus_out_cb (GtkWidget *widget,
842                                 GdkEventFocus *event,
843                                 EmpathyContactWidget *information)
844 {
845   contact_widget_change_contact (information);
846   return FALSE;
847 }
848
849 static gboolean
850 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
851                                            GdkEventFocus *event,
852                                            EmpathyContactWidget *information)
853 {
854   if (information->contact)
855     {
856       const gchar *alias;
857
858       alias = gtk_entry_get_text (GTK_ENTRY (editable));
859       empathy_tp_contact_factory_set_alias (information->factory,
860           information->contact, alias);
861     }
862
863   return FALSE;
864 }
865
866 static void
867 contact_widget_name_notify_cb (EmpathyContactWidget *information)
868 {
869   if (GTK_IS_ENTRY (information->widget_alias))
870       gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
871           empathy_contact_get_name (information->contact));
872   else
873       gtk_label_set_label (GTK_LABEL (information->widget_alias),
874           empathy_contact_get_name (information->contact));
875 }
876
877 static void
878 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
879 {
880   gtk_label_set_text (GTK_LABEL (information->label_status),
881       empathy_contact_get_status (information->contact));
882   gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
883       empathy_icon_name_for_contact (information->contact),
884       GTK_ICON_SIZE_BUTTON);
885 }
886
887 static void
888 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
889 {
890   EmpathyAvatar *avatar = NULL;
891
892   if (information->contact)
893       avatar = empathy_contact_get_avatar (information->contact);
894
895   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
896     {
897       g_signal_handlers_block_by_func (information->widget_avatar,
898           contact_widget_avatar_changed_cb,
899           information);
900       empathy_avatar_chooser_set (
901           EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
902       g_signal_handlers_unblock_by_func (information->widget_avatar,
903           contact_widget_avatar_changed_cb, information);
904     }
905   else
906       empathy_avatar_image_set (
907           EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
908 }
909
910 static void
911 contact_widget_groups_setup (EmpathyContactWidget *information)
912 {
913   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
914     {
915       information->manager = empathy_contact_manager_dup_singleton ();
916       contact_widget_model_setup (information);
917     }
918 }
919
920 static void
921 contact_widget_groups_update (EmpathyContactWidget *information)
922 {
923   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
924       information->contact)
925     {
926       g_signal_connect_swapped (information->contact, "notify::groups",
927           G_CALLBACK (contact_widget_groups_notify_cb), information);
928       contact_widget_groups_populate_data (information);
929
930       gtk_widget_show (information->vbox_groups);
931     }
932   else
933       gtk_widget_hide (information->vbox_groups);
934 }
935
936 static void
937 contact_widget_model_setup (EmpathyContactWidget *information)
938 {
939   GtkTreeView *view;
940   GtkListStore *store;
941   GtkTreeSelection *selection;
942
943   view = GTK_TREE_VIEW (information->treeview_groups);
944
945   store = gtk_list_store_new (COL_COUNT,
946       G_TYPE_STRING,   /* name */
947       G_TYPE_BOOLEAN,  /* enabled */
948       G_TYPE_BOOLEAN); /* editable */
949
950   gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
951
952   selection = gtk_tree_view_get_selection (view);
953   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
954
955   contact_widget_model_populate_columns (information);
956
957   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
958       COL_NAME, GTK_SORT_ASCENDING);
959
960   g_object_unref (store);
961 }
962
963 static void
964 contact_widget_model_populate_columns (EmpathyContactWidget *information)
965 {
966   GtkTreeView *view;
967   GtkTreeModel *model;
968   GtkTreeViewColumn *column;
969   GtkCellRenderer  *renderer;
970   guint col_offset;
971
972   view = GTK_TREE_VIEW (information->treeview_groups);
973   model = gtk_tree_view_get_model (view);
974
975   renderer = gtk_cell_renderer_toggle_new ();
976   g_signal_connect (renderer, "toggled",
977       G_CALLBACK (contact_widget_cell_toggled), information);
978
979   column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
980       "active", COL_ENABLED, NULL);
981
982   gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
983   gtk_tree_view_column_set_fixed_width (column, 50);
984   gtk_tree_view_append_column (view, column);
985
986   renderer = gtk_cell_renderer_text_new ();
987   col_offset = gtk_tree_view_insert_column_with_attributes (view,
988       -1, _("Group"),
989       renderer,
990       "text", COL_NAME,
991       /* "editable", COL_EDITABLE, */
992       NULL);
993
994   g_object_set_data (G_OBJECT (renderer),
995       "column", GINT_TO_POINTER (COL_NAME));
996
997   column = gtk_tree_view_get_column (view, col_offset - 1);
998   gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
999   gtk_tree_view_column_set_resizable (column,FALSE);
1000   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
1001 }
1002
1003 static void
1004 contact_widget_groups_populate_data (EmpathyContactWidget *information)
1005 {
1006   GtkTreeView *view;
1007   GtkListStore *store;
1008   GtkTreeIter iter;
1009   GList *my_groups, *l;
1010   GList *all_groups;
1011
1012   view = GTK_TREE_VIEW (information->treeview_groups);
1013   store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1014   gtk_list_store_clear (store);
1015
1016   all_groups = empathy_contact_list_get_all_groups (
1017       EMPATHY_CONTACT_LIST (information->manager));
1018   my_groups = empathy_contact_list_get_groups (
1019       EMPATHY_CONTACT_LIST (information->manager),
1020       information->contact);
1021
1022   for (l = all_groups; l; l = l->next)
1023     {
1024       const gchar *group_str;
1025       gboolean enabled;
1026
1027       group_str = l->data;
1028
1029       enabled = g_list_find_custom (my_groups,
1030           group_str, (GCompareFunc) strcmp) != NULL;
1031
1032       gtk_list_store_append (store, &iter);
1033       gtk_list_store_set (store, &iter,
1034           COL_NAME, group_str,
1035           COL_EDITABLE, TRUE,
1036           COL_ENABLED, enabled,
1037           -1);
1038     }
1039
1040   g_list_foreach (all_groups, (GFunc) g_free, NULL);
1041   g_list_foreach (my_groups, (GFunc) g_free, NULL);
1042   g_list_free (all_groups);
1043   g_list_free (my_groups);
1044 }
1045
1046 static void
1047 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
1048 {
1049   /* FIXME: not implemented */
1050 }
1051
1052 static gboolean
1053 contact_widget_model_find_name (EmpathyContactWidget *information,
1054                                 const gchar *name,
1055                                 GtkTreeIter *iter)
1056 {
1057   GtkTreeView *view;
1058   GtkTreeModel *model;
1059   FindName data;
1060
1061   if (EMP_STR_EMPTY (name))
1062       return FALSE;
1063
1064   data.information = information;
1065   data.name = name;
1066   data.found = FALSE;
1067
1068   view = GTK_TREE_VIEW (information->treeview_groups);
1069   model = gtk_tree_view_get_model (view);
1070
1071   gtk_tree_model_foreach (model,
1072       (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1073       &data);
1074
1075   if (data.found == TRUE)
1076     {
1077       *iter = data.found_iter;
1078       return TRUE;
1079     }
1080
1081   return FALSE;
1082 }
1083
1084 static gboolean
1085 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1086                                         GtkTreePath *path,
1087                                         GtkTreeIter *iter,
1088                                         FindName *data)
1089 {
1090   gchar *name;
1091
1092   gtk_tree_model_get (model, iter,
1093       COL_NAME, &name,
1094       -1);
1095
1096   if (!name)
1097       return FALSE;
1098
1099   if (data->name && strcmp (data->name, name) == 0)
1100     {
1101       data->found = TRUE;
1102       data->found_iter = *iter;
1103
1104       g_free (name);
1105
1106       return TRUE;
1107     }
1108
1109   g_free (name);
1110
1111   return FALSE;
1112 }
1113
1114 static void
1115 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1116                              gchar *path_string,
1117                              EmpathyContactWidget *information)
1118 {
1119   GtkTreeView *view;
1120   GtkTreeModel *model;
1121   GtkListStore *store;
1122   GtkTreePath *path;
1123   GtkTreeIter iter;
1124   gboolean enabled;
1125   gchar *group;
1126
1127   view = GTK_TREE_VIEW (information->treeview_groups);
1128   model = gtk_tree_view_get_model (view);
1129   store = GTK_LIST_STORE (model);
1130
1131   path = gtk_tree_path_new_from_string (path_string);
1132
1133   gtk_tree_model_get_iter (model, &iter, path);
1134   gtk_tree_model_get (model, &iter,
1135       COL_ENABLED, &enabled,
1136       COL_NAME, &group,
1137       -1);
1138
1139   gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1140   gtk_tree_path_free (path);
1141
1142   if (group)
1143     {
1144       if (enabled)
1145         {
1146           empathy_contact_list_remove_from_group (
1147               EMPATHY_CONTACT_LIST (information->manager), information->contact,
1148               group);
1149         }
1150       else
1151         {
1152           empathy_contact_list_add_to_group (
1153               EMPATHY_CONTACT_LIST (information->manager), information->contact,
1154               group);
1155         }
1156       g_free (group);
1157     }
1158 }
1159
1160 static void
1161 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1162                                        EmpathyContactWidget *information)
1163 {
1164   GtkTreeIter iter;
1165   const gchar *group;
1166
1167   group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1168
1169   if (contact_widget_model_find_name (information, group, &iter))
1170       gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1171   else
1172       gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1173           !EMP_STR_EMPTY (group));
1174 }
1175
1176 static void
1177 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1178                                         EmpathyContactWidget  *information)
1179 {
1180   gtk_widget_activate (GTK_WIDGET (information->button_group));
1181 }
1182
1183 static void
1184 contact_widget_button_group_clicked_cb (GtkButton *button,
1185                                         EmpathyContactWidget *information)
1186 {
1187   GtkTreeView *view;
1188   GtkListStore *store;
1189   GtkTreeIter iter;
1190   const gchar *group;
1191
1192   view = GTK_TREE_VIEW (information->treeview_groups);
1193   store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1194
1195   group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1196
1197   gtk_list_store_append (store, &iter);
1198   gtk_list_store_set (store, &iter,
1199       COL_NAME, group,
1200       COL_ENABLED, TRUE,
1201       -1);
1202
1203   empathy_contact_list_add_to_group (
1204       EMPATHY_CONTACT_LIST (information->manager), information->contact,
1205       group);
1206 }
1207
1208 static void
1209 contact_widget_details_setup (EmpathyContactWidget *information)
1210 {
1211   /* FIXME: Needs new telepathy spec */
1212   gtk_widget_hide (information->vbox_details);
1213 }
1214
1215 static void
1216 contact_widget_details_update (EmpathyContactWidget *information)
1217 {
1218   /* FIXME: Needs new telepathy spec */
1219 }
1220
1221 static void
1222 contact_widget_client_setup (EmpathyContactWidget *information)
1223 {
1224   /* FIXME: Needs new telepathy spec */
1225   gtk_widget_hide (information->vbox_client);
1226 }
1227
1228 static void
1229 contact_widget_client_update (EmpathyContactWidget *information)
1230 {
1231   /* FIXME: Needs new telepathy spec */
1232 }
1233
1234 /* Converts the Location's GHashTable's key to a user readable string */
1235 static const gchar *
1236 location_key_to_label (const gchar *key)
1237 {
1238   if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
1239     return _("Country ISO Code:");
1240   else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
1241     return _("Country:");
1242   else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
1243     return _("State:");
1244   else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
1245     return _("City:");
1246   else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
1247     return _("Area:");
1248   else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
1249     return _("Postal Code:");
1250   else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
1251     return _("Street:");
1252   else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
1253     return _("Building:");
1254   else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
1255     return _("Floor:");
1256   else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
1257     return _("Room:");
1258   else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
1259     return _("Text:");
1260   else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
1261     return _("Description:");
1262   else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
1263     return _("URI:");
1264   else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
1265     return _("Accuracy Level:");
1266   else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
1267     return _("Error:");
1268   else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
1269     return _("Vertical Error (meters):");
1270   else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
1271     return _("Horizontal Error (meters):");
1272   else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
1273     return _("Speed:");
1274   else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
1275     return _("Bearing:");
1276   else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
1277     return _("Climb Speed:");
1278   else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
1279     return _("Last Updated on:");
1280   else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
1281     return _("Longitude:");
1282   else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
1283     return _("Latitude:");
1284   else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
1285     return _("Altitude:");
1286   else
1287   {
1288     DEBUG ("Unexpected Location key: %s", key);
1289     return key;
1290   }
1291 }
1292
1293 static void
1294 contact_widget_location_update (EmpathyContactWidget *information)
1295 {
1296   GHashTable *location;
1297   GValue *value;
1298   gdouble lat = 0.0, lon = 0.0;
1299   gboolean has_position = TRUE;
1300   GtkWidget *label;
1301   guint row = 0;
1302   GHashTableIter iter;
1303   gpointer key, pvalue;
1304
1305   if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
1306     {
1307       gtk_widget_hide (information->vbox_location);
1308       return;
1309     }
1310
1311   location = empathy_contact_get_location (information->contact);
1312   if (location == NULL || g_hash_table_size (location) == 0)
1313     {
1314       gtk_widget_hide (information->vbox_location);
1315       return;
1316     }
1317
1318   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
1319   if (value == NULL)
1320       has_position = FALSE;
1321   else
1322       lat = g_value_get_double (value);
1323
1324   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
1325   if (value == NULL)
1326       has_position = FALSE;
1327   else
1328       lon = g_value_get_double (value);
1329
1330   value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
1331   if (value == NULL)
1332     gtk_label_set_markup (GTK_LABEL (information->label_location), _("<b>Location</b>"));
1333   else
1334     {
1335       gchar *user_date;
1336       gchar *text;
1337       gint64 stamp;
1338       time_t time;
1339
1340       stamp = g_value_get_int64 (value);
1341       time = stamp;
1342
1343       user_date = empathy_time_to_string_relative (time);
1344
1345       text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
1346       gtk_label_set_markup (GTK_LABEL (information->label_location), text);
1347       g_free (text);
1348     }
1349
1350
1351   /* Prepare the location information table */
1352   if (information->table_location != NULL)
1353     {
1354       gtk_widget_destroy (information->table_location);
1355     }
1356
1357   information->table_location = gtk_table_new (1, 2, FALSE);
1358   gtk_box_pack_start (GTK_BOX (information->subvbox_location),
1359       information->table_location, FALSE, FALSE, 5);
1360
1361   g_hash_table_iter_init (&iter, location);
1362   while (g_hash_table_iter_next (&iter, &key, &pvalue))
1363     {
1364       const gchar *skey;
1365       const gchar* user_label;
1366       GValue *gvalue;
1367       char *svalue = NULL;
1368
1369       skey = (const gchar *) key;
1370
1371       user_label = location_key_to_label (skey);
1372       gvalue = (GValue *) pvalue;
1373
1374       label = gtk_label_new (user_label);
1375       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1376       gtk_table_attach (GTK_TABLE (information->table_location),
1377           label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1378       gtk_widget_show (label);
1379
1380       if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1381         {
1382           gdouble dvalue;
1383           dvalue = g_value_get_double (gvalue);
1384           svalue = g_strdup_printf ("%f", dvalue);
1385         }
1386       else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1387         {
1388           svalue = g_value_dup_string (gvalue);
1389         }
1390       else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1391         {
1392           time_t time;
1393
1394           time = g_value_get_int64 (value);
1395           svalue = empathy_time_to_string_utc (time, _("%B %e, %Y at %R UTC"));
1396         }
1397
1398       if (svalue != NULL)
1399         {
1400           label = gtk_label_new (svalue);
1401           gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1402               label, 1, 2, row, row + 1);
1403           gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1404           gtk_widget_show (label);
1405         }
1406
1407       g_free (svalue);
1408       row++;
1409     }
1410
1411   gtk_widget_show (information->table_location);
1412
1413 #if HAVE_LIBCHAMPLAIN
1414   /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1415    * windows
1416    */
1417   if (has_position &&
1418       !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1419     {
1420       ClutterActor *marker;
1421       ChamplainLayer *layer;
1422
1423       information->map_view_embed = gtk_champlain_embed_new ();
1424       information->map_view = gtk_champlain_embed_get_view (
1425           GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1426
1427       gtk_container_add (GTK_CONTAINER (information->viewport_map),
1428           information->map_view_embed);
1429       g_object_set (G_OBJECT (information->map_view), "show-license", FALSE,
1430           "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
1431           NULL);
1432
1433       layer = champlain_layer_new ();
1434       champlain_view_add_layer (information->map_view, layer);
1435
1436       marker = champlain_marker_new_with_text (
1437           empathy_contact_get_name (information->contact), NULL, NULL, NULL);
1438       champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
1439       clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
1440
1441       champlain_view_center_on (information->map_view, lat, lon);
1442       gtk_widget_show_all (information->viewport_map);
1443     }
1444 #endif
1445
1446     gtk_widget_show (information->vbox_location);
1447 }