]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-widget.c
Merge branch 'label-align'
[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 #include "empathy-kludge-label.h"
51
52 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
53 #include <libempathy/empathy-debug.h>
54
55 /**
56  * SECTION:empathy-contact-widget
57  * @title:EmpathyContactWidget
58  * @short_description: A widget used to display and edit details about a contact
59  * @include: libempathy-empathy-contact-widget.h
60  *
61  * #EmpathyContactWidget is a widget which displays appropriate widgets
62  * with details about a contact, also allowing changing these details,
63  * if desired.
64  */
65
66 /**
67  * EmpathyContactWidget:
68  * @parent: parent object
69  *
70  * Widget which displays appropriate widgets with details about a contact,
71  * also allowing changing these details, if desired.
72  */
73
74 /* Delay before updating the widget when the id entry changed (seconds) */
75 #define ID_CHANGED_TIMEOUT 1
76
77 typedef struct
78 {
79   EmpathyTpContactFactory *factory;
80   EmpathyContactManager *manager;
81   EmpathyContact *contact;
82   EmpathyContactWidgetFlags flags;
83   guint widget_id_timeout;
84
85   GtkWidget *vbox_contact_widget;
86
87   /* Contact */
88   GtkWidget *vbox_contact;
89   GtkWidget *widget_avatar;
90   GtkWidget *widget_account;
91   GtkWidget *widget_id;
92   GtkWidget *widget_alias;
93   GtkWidget *label_alias;
94   GtkWidget *entry_alias;
95   GtkWidget *hbox_presence;
96   GtkWidget *image_state;
97   GtkWidget *label_status;
98   GtkWidget *table_contact;
99   GtkWidget *vbox_avatar;
100
101   /* Location */
102   GtkWidget *vbox_location;
103   GtkWidget *subvbox_location;
104   GtkWidget *table_location;
105   GtkWidget *label_location;
106 #if HAVE_LIBCHAMPLAIN
107   GtkWidget *viewport_map;
108   GtkWidget *map_view_embed;
109   ChamplainView *map_view;
110 #endif
111
112   /* Groups */
113   GtkWidget *vbox_groups;
114   GtkWidget *entry_group;
115   GtkWidget *button_group;
116   GtkWidget *treeview_groups;
117
118   /* Details */
119   GtkWidget *vbox_details;
120   GtkWidget *table_details;
121   GtkWidget *hbox_details_requested;
122
123   /* Client */
124   GtkWidget *vbox_client;
125   GtkWidget *table_client;
126   GtkWidget *hbox_client_requested;
127 } EmpathyContactWidget;
128
129 typedef struct
130 {
131   EmpathyContactWidget *information;
132   const gchar *name;
133   gboolean found;
134   GtkTreeIter found_iter;
135 } FindName;
136
137 static void contact_widget_destroy_cb (GtkWidget *widget,
138     EmpathyContactWidget *information);
139 static void contact_widget_remove_contact (EmpathyContactWidget *information);
140 static void contact_widget_set_contact (EmpathyContactWidget *information,
141     EmpathyContact *contact);
142 static void contact_widget_contact_setup (EmpathyContactWidget *information);
143 static void contact_widget_contact_update (EmpathyContactWidget *information);
144 static void contact_widget_change_contact (EmpathyContactWidget *information);
145 static void contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
146     EmpathyContactWidget *information);
147 static gboolean contact_widget_id_focus_out_cb (GtkWidget *widget,
148     GdkEventFocus *event, EmpathyContactWidget *information);
149 static gboolean contact_widget_entry_alias_focus_event_cb (
150     GtkEditable *editable, GdkEventFocus *event,
151     EmpathyContactWidget *information);
152 static void contact_widget_name_notify_cb (EmpathyContactWidget *information);
153 static void contact_widget_presence_notify_cb (
154     EmpathyContactWidget *information);
155 static void contact_widget_avatar_notify_cb (
156     EmpathyContactWidget *information);
157 static void contact_widget_groups_setup (
158     EmpathyContactWidget *information);
159 static void contact_widget_groups_update (EmpathyContactWidget *information);
160 static void contact_widget_model_setup (EmpathyContactWidget *information);
161 static void contact_widget_model_populate_columns (
162     EmpathyContactWidget *information);
163 static void contact_widget_groups_populate_data (
164     EmpathyContactWidget *information);
165 static void contact_widget_groups_notify_cb (
166     EmpathyContactWidget *information);
167 static gboolean contact_widget_model_find_name (
168     EmpathyContactWidget *information,const gchar *name, GtkTreeIter *iter);
169 static gboolean contact_widget_model_find_name_foreach (GtkTreeModel *model,
170     GtkTreePath *path, GtkTreeIter *iter, FindName *data);
171 static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
172     gchar *path_string, EmpathyContactWidget *information);
173 static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
174     EmpathyContactWidget *information);
175 static void contact_widget_entry_group_activate_cb (GtkEntry *entry,
176     EmpathyContactWidget *information);
177 static void contact_widget_button_group_clicked_cb (GtkButton *button,
178     EmpathyContactWidget *information);
179 static void contact_widget_details_setup (EmpathyContactWidget *information);
180 static void contact_widget_details_update (EmpathyContactWidget *information);
181 static void contact_widget_client_setup (EmpathyContactWidget *information);
182 static void contact_widget_client_update (EmpathyContactWidget *information);
183 static void contact_widget_location_update (EmpathyContactWidget *information);
184
185 enum
186 {
187   COL_NAME,
188   COL_ENABLED,
189   COL_EDITABLE,
190   COL_COUNT
191 };
192
193 /**
194  * empathy_contact_widget_new:
195  * @contact: an #EmpathyContact
196  * @flags: #EmpathyContactWidgetFlags for the new contact widget
197  *
198  * Creates a new #EmpathyContactWidget.
199  *
200  * Return value: a new #EmpathyContactWidget
201  */
202 GtkWidget *
203 empathy_contact_widget_new (EmpathyContact *contact,
204                             EmpathyContactWidgetFlags flags)
205 {
206   EmpathyContactWidget *information;
207   GtkBuilder *gui;
208   gchar *filename;
209
210   g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
211
212   information = g_slice_new0 (EmpathyContactWidget);
213   information->flags = flags;
214
215   filename = empathy_file_lookup ("empathy-contact-widget.ui",
216       "libempathy-gtk");
217   gui = empathy_builder_get_file (filename,
218        "vbox_contact_widget", &information->vbox_contact_widget,
219        "vbox_contact", &information->vbox_contact,
220        "hbox_presence", &information->hbox_presence,
221        "label_alias", &information->label_alias,
222        "image_state", &information->image_state,
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 label_status as a KludgeLabel */
591   information->label_status = empathy_kludge_label_new ("");
592   gtk_box_pack_start (GTK_BOX (information->hbox_presence),
593         information->label_status, TRUE, TRUE, 0);
594   gtk_widget_show (information->label_status);
595
596   /* Setup account label/chooser */
597   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
598     {
599       information->widget_account = empathy_account_chooser_new ();
600
601       g_signal_connect_swapped (information->widget_account, "changed",
602             G_CALLBACK (contact_widget_change_contact),
603             information);
604     }
605   else
606     {
607       information->widget_account = gtk_label_new (NULL);
608       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
609         gtk_label_set_selectable (GTK_LABEL (information->widget_account), TRUE);
610       }
611       gtk_misc_set_alignment (GTK_MISC (information->widget_account), 0, 0.5);
612     }
613   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
614            information->widget_account,
615            1, 2, 0, 1);
616   gtk_widget_show (information->widget_account);
617
618   /* Set up avatar chooser/display */
619   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
620     {
621       information->widget_avatar = empathy_avatar_chooser_new ();
622       g_signal_connect (information->widget_avatar, "changed",
623             G_CALLBACK (contact_widget_avatar_changed_cb),
624             information);
625       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
626         {
627           g_signal_connect (information->widget_account, "changed",
628               G_CALLBACK (update_avatar_chooser_account_cb),
629               information->widget_avatar);
630           update_avatar_chooser_account_cb (
631               EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
632               EMPATHY_AVATAR_CHOOSER (information->widget_avatar));
633         }
634     }
635   else
636     {
637       information->widget_avatar = empathy_avatar_image_new ();
638
639       g_signal_connect (information->widget_avatar, "popup-menu",
640           G_CALLBACK (widget_avatar_popup_menu_cb), information);
641       g_signal_connect (information->widget_avatar, "button-press-event",
642           G_CALLBACK (widget_avatar_button_press_event_cb), information);
643     }
644
645   gtk_box_pack_start (GTK_BOX (information->vbox_avatar),
646           information->widget_avatar,
647           FALSE, FALSE,
648           6);
649   gtk_widget_show (information->widget_avatar);
650
651   /* Setup id label/entry */
652   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
653     {
654       information->widget_id = gtk_entry_new ();
655       g_signal_connect (information->widget_id, "focus-out-event",
656             G_CALLBACK (contact_widget_id_focus_out_cb),
657             information);
658       g_signal_connect (information->widget_id, "changed",
659             G_CALLBACK (contact_widget_id_changed_cb),
660             information);
661     }
662   else
663     {
664       information->widget_id = gtk_label_new (NULL);
665       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
666         gtk_label_set_selectable (GTK_LABEL (information->widget_id), TRUE);
667       }
668       gtk_misc_set_alignment (GTK_MISC (information->widget_id), 0, 0.5);
669     }
670   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
671            information->widget_id,
672            1, 2, 1, 2);
673   gtk_widget_show (information->widget_id);
674
675   /* Setup alias label/entry */
676   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
677     {
678       information->widget_alias = gtk_entry_new ();
679       g_signal_connect (information->widget_alias, "focus-out-event",
680             G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
681             information);
682       /* Make return activate the window default (the Close button) */
683       gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
684           TRUE);
685     }
686   else
687     {
688       information->widget_alias = gtk_label_new (NULL);
689       if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) {
690         gtk_label_set_selectable (GTK_LABEL (information->widget_alias), TRUE);
691       }
692       gtk_misc_set_alignment (GTK_MISC (information->widget_alias), 0, 0.5);
693     }
694   gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
695            information->widget_alias,
696            1, 2, 2, 3);
697   if (information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP) {
698     gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
699   }
700   gtk_widget_show (information->widget_alias);
701 }
702
703 static void
704 contact_widget_contact_update (EmpathyContactWidget *information)
705 {
706   EmpathyAccount *account = NULL;
707   const gchar *id = NULL;
708
709   /* Connect and get info from new contact */
710   if (information->contact)
711     {
712       g_signal_connect_swapped (information->contact, "notify::name",
713           G_CALLBACK (contact_widget_name_notify_cb), information);
714       g_signal_connect_swapped (information->contact, "notify::presence",
715           G_CALLBACK (contact_widget_presence_notify_cb), information);
716       g_signal_connect_swapped (information->contact,
717           "notify::presence-message",
718           G_CALLBACK (contact_widget_presence_notify_cb), information);
719       g_signal_connect_swapped (information->contact, "notify::avatar",
720           G_CALLBACK (contact_widget_avatar_notify_cb), information);
721
722       account = empathy_contact_get_account (information->contact);
723       id = empathy_contact_get_id (information->contact);
724     }
725
726   /* Update account widget */
727   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT)
728     {
729       if (account)
730         {
731           g_signal_handlers_block_by_func (information->widget_account,
732                    contact_widget_change_contact,
733                    information);
734           empathy_account_chooser_set_account (
735               EMPATHY_ACCOUNT_CHOOSER (information->widget_account), account);
736           g_signal_handlers_unblock_by_func (information->widget_account,
737               contact_widget_change_contact, information);
738         }
739     }
740   else
741     {
742       if (account)
743         {
744           const gchar *name;
745
746           name = empathy_account_get_display_name (account);
747           gtk_label_set_label (GTK_LABEL (information->widget_account), name);
748         }
749     }
750
751   /* Update id widget */
752   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
753       gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
754   else
755       gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
756
757   /* Update other widgets */
758   if (information->contact)
759     {
760       contact_widget_name_notify_cb (information);
761       contact_widget_presence_notify_cb (information);
762       contact_widget_avatar_notify_cb (information);
763
764       gtk_widget_show (information->label_alias);
765       gtk_widget_show (information->widget_alias);
766       gtk_widget_show (information->hbox_presence);
767       gtk_widget_show (information->widget_avatar);
768     }
769   else
770     {
771       gtk_widget_hide (information->label_alias);
772       gtk_widget_hide (information->widget_alias);
773       gtk_widget_hide (information->hbox_presence);
774       gtk_widget_hide (information->widget_avatar);
775     }
776 }
777
778 static void
779 contact_widget_got_contact_cb (EmpathyTpContactFactory *factory,
780                                EmpathyContact *contact,
781                                const GError *error,
782                                gpointer user_data,
783                                GObject *weak_object)
784 {
785   EmpathyContactWidget *information = user_data;
786
787   if (error != NULL)
788     {
789       DEBUG ("Error: %s", error->message);
790       return;
791     }
792
793   contact_widget_set_contact (information, contact);
794 }
795
796 static void
797 contact_widget_change_contact (EmpathyContactWidget *information)
798 {
799   EmpathyTpContactFactory *factory;
800   TpConnection *connection;
801
802   connection = empathy_account_chooser_get_connection (
803       EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
804   if (!connection)
805       return;
806
807   factory = empathy_tp_contact_factory_dup_singleton (connection);
808   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID)
809     {
810       const gchar *id;
811
812       id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
813       if (!EMP_STR_EMPTY (id))
814         {
815           empathy_tp_contact_factory_get_from_id (factory, id,
816               contact_widget_got_contact_cb, information, NULL,
817               G_OBJECT (information->vbox_contact_widget));
818         }
819     }
820   else
821     {
822       empathy_tp_contact_factory_get_from_handle (factory,
823           tp_connection_get_self_handle (connection),
824           contact_widget_got_contact_cb, information, NULL,
825           G_OBJECT (information->vbox_contact_widget));
826     }
827
828   g_object_unref (factory);
829 }
830
831 static void
832 contact_widget_avatar_changed_cb (EmpathyAvatarChooser *chooser,
833                                   EmpathyContactWidget *information)
834 {
835   const gchar *data;
836   gsize size;
837   const gchar *mime_type;
838
839   empathy_avatar_chooser_get_image_data (
840       EMPATHY_AVATAR_CHOOSER (information->widget_avatar),
841       &data, &size, &mime_type);
842   empathy_tp_contact_factory_set_avatar (information->factory,
843       data, size, mime_type);
844 }
845
846 static gboolean
847 contact_widget_id_focus_out_cb (GtkWidget *widget,
848                                 GdkEventFocus *event,
849                                 EmpathyContactWidget *information)
850 {
851   contact_widget_change_contact (information);
852   return FALSE;
853 }
854
855 static gboolean
856 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
857                                            GdkEventFocus *event,
858                                            EmpathyContactWidget *information)
859 {
860   if (information->contact)
861     {
862       const gchar *alias;
863
864       alias = gtk_entry_get_text (GTK_ENTRY (editable));
865       empathy_tp_contact_factory_set_alias (information->factory,
866           information->contact, alias);
867     }
868
869   return FALSE;
870 }
871
872 static void
873 contact_widget_name_notify_cb (EmpathyContactWidget *information)
874 {
875   if (GTK_IS_ENTRY (information->widget_alias))
876       gtk_entry_set_text (GTK_ENTRY (information->widget_alias),
877           empathy_contact_get_name (information->contact));
878   else
879       gtk_label_set_label (GTK_LABEL (information->widget_alias),
880           empathy_contact_get_name (information->contact));
881 }
882
883 static void
884 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
885 {
886   gtk_label_set_text (GTK_LABEL (information->label_status),
887       empathy_contact_get_status (information->contact));
888   gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
889       empathy_icon_name_for_contact (information->contact),
890       GTK_ICON_SIZE_BUTTON);
891 }
892
893 static void
894 contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
895 {
896   EmpathyAvatar *avatar = NULL;
897
898   if (information->contact)
899       avatar = empathy_contact_get_avatar (information->contact);
900
901   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR)
902     {
903       g_signal_handlers_block_by_func (information->widget_avatar,
904           contact_widget_avatar_changed_cb,
905           information);
906       empathy_avatar_chooser_set (
907           EMPATHY_AVATAR_CHOOSER (information->widget_avatar), avatar);
908       g_signal_handlers_unblock_by_func (information->widget_avatar,
909           contact_widget_avatar_changed_cb, information);
910     }
911   else
912       empathy_avatar_image_set (
913           EMPATHY_AVATAR_IMAGE (information->widget_avatar), avatar);
914 }
915
916 static void
917 contact_widget_groups_setup (EmpathyContactWidget *information)
918 {
919   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
920     {
921       information->manager = empathy_contact_manager_dup_singleton ();
922       contact_widget_model_setup (information);
923     }
924 }
925
926 static void
927 contact_widget_groups_update (EmpathyContactWidget *information)
928 {
929   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
930       information->contact)
931     {
932       g_signal_connect_swapped (information->contact, "notify::groups",
933           G_CALLBACK (contact_widget_groups_notify_cb), information);
934       contact_widget_groups_populate_data (information);
935
936       gtk_widget_show (information->vbox_groups);
937     }
938   else
939       gtk_widget_hide (information->vbox_groups);
940 }
941
942 static void
943 contact_widget_model_setup (EmpathyContactWidget *information)
944 {
945   GtkTreeView *view;
946   GtkListStore *store;
947   GtkTreeSelection *selection;
948
949   view = GTK_TREE_VIEW (information->treeview_groups);
950
951   store = gtk_list_store_new (COL_COUNT,
952       G_TYPE_STRING,   /* name */
953       G_TYPE_BOOLEAN,  /* enabled */
954       G_TYPE_BOOLEAN); /* editable */
955
956   gtk_tree_view_set_model (view, GTK_TREE_MODEL (store));
957
958   selection = gtk_tree_view_get_selection (view);
959   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
960
961   contact_widget_model_populate_columns (information);
962
963   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
964       COL_NAME, GTK_SORT_ASCENDING);
965
966   g_object_unref (store);
967 }
968
969 static void
970 contact_widget_model_populate_columns (EmpathyContactWidget *information)
971 {
972   GtkTreeView *view;
973   GtkTreeModel *model;
974   GtkTreeViewColumn *column;
975   GtkCellRenderer  *renderer;
976   guint col_offset;
977
978   view = GTK_TREE_VIEW (information->treeview_groups);
979   model = gtk_tree_view_get_model (view);
980
981   renderer = gtk_cell_renderer_toggle_new ();
982   g_signal_connect (renderer, "toggled",
983       G_CALLBACK (contact_widget_cell_toggled), information);
984
985   column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
986       "active", COL_ENABLED, NULL);
987
988   gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
989   gtk_tree_view_column_set_fixed_width (column, 50);
990   gtk_tree_view_append_column (view, column);
991
992   renderer = gtk_cell_renderer_text_new ();
993   col_offset = gtk_tree_view_insert_column_with_attributes (view,
994       -1, _("Group"),
995       renderer,
996       "text", COL_NAME,
997       /* "editable", COL_EDITABLE, */
998       NULL);
999
1000   g_object_set_data (G_OBJECT (renderer),
1001       "column", GINT_TO_POINTER (COL_NAME));
1002
1003   column = gtk_tree_view_get_column (view, col_offset - 1);
1004   gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
1005   gtk_tree_view_column_set_resizable (column,FALSE);
1006   gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE);
1007 }
1008
1009 static void
1010 contact_widget_groups_populate_data (EmpathyContactWidget *information)
1011 {
1012   GtkTreeView *view;
1013   GtkListStore *store;
1014   GtkTreeIter iter;
1015   GList *my_groups, *l;
1016   GList *all_groups;
1017
1018   view = GTK_TREE_VIEW (information->treeview_groups);
1019   store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1020   gtk_list_store_clear (store);
1021
1022   all_groups = empathy_contact_list_get_all_groups (
1023       EMPATHY_CONTACT_LIST (information->manager));
1024   my_groups = empathy_contact_list_get_groups (
1025       EMPATHY_CONTACT_LIST (information->manager),
1026       information->contact);
1027
1028   for (l = all_groups; l; l = l->next)
1029     {
1030       const gchar *group_str;
1031       gboolean enabled;
1032
1033       group_str = l->data;
1034
1035       enabled = g_list_find_custom (my_groups,
1036           group_str, (GCompareFunc) strcmp) != NULL;
1037
1038       gtk_list_store_append (store, &iter);
1039       gtk_list_store_set (store, &iter,
1040           COL_NAME, group_str,
1041           COL_EDITABLE, TRUE,
1042           COL_ENABLED, enabled,
1043           -1);
1044     }
1045
1046   g_list_foreach (all_groups, (GFunc) g_free, NULL);
1047   g_list_foreach (my_groups, (GFunc) g_free, NULL);
1048   g_list_free (all_groups);
1049   g_list_free (my_groups);
1050 }
1051
1052 static void
1053 contact_widget_groups_notify_cb (EmpathyContactWidget *information)
1054 {
1055   /* FIXME: not implemented */
1056 }
1057
1058 static gboolean
1059 contact_widget_model_find_name (EmpathyContactWidget *information,
1060                                 const gchar *name,
1061                                 GtkTreeIter *iter)
1062 {
1063   GtkTreeView *view;
1064   GtkTreeModel *model;
1065   FindName data;
1066
1067   if (EMP_STR_EMPTY (name))
1068       return FALSE;
1069
1070   data.information = information;
1071   data.name = name;
1072   data.found = FALSE;
1073
1074   view = GTK_TREE_VIEW (information->treeview_groups);
1075   model = gtk_tree_view_get_model (view);
1076
1077   gtk_tree_model_foreach (model,
1078       (GtkTreeModelForeachFunc) contact_widget_model_find_name_foreach,
1079       &data);
1080
1081   if (data.found == TRUE)
1082     {
1083       *iter = data.found_iter;
1084       return TRUE;
1085     }
1086
1087   return FALSE;
1088 }
1089
1090 static gboolean
1091 contact_widget_model_find_name_foreach (GtkTreeModel *model,
1092                                         GtkTreePath *path,
1093                                         GtkTreeIter *iter,
1094                                         FindName *data)
1095 {
1096   gchar *name;
1097
1098   gtk_tree_model_get (model, iter,
1099       COL_NAME, &name,
1100       -1);
1101
1102   if (!name)
1103       return FALSE;
1104
1105   if (data->name && strcmp (data->name, name) == 0)
1106     {
1107       data->found = TRUE;
1108       data->found_iter = *iter;
1109
1110       g_free (name);
1111
1112       return TRUE;
1113     }
1114
1115   g_free (name);
1116
1117   return FALSE;
1118 }
1119
1120 static void
1121 contact_widget_cell_toggled (GtkCellRendererToggle *cell,
1122                              gchar *path_string,
1123                              EmpathyContactWidget *information)
1124 {
1125   GtkTreeView *view;
1126   GtkTreeModel *model;
1127   GtkListStore *store;
1128   GtkTreePath *path;
1129   GtkTreeIter iter;
1130   gboolean enabled;
1131   gchar *group;
1132
1133   view = GTK_TREE_VIEW (information->treeview_groups);
1134   model = gtk_tree_view_get_model (view);
1135   store = GTK_LIST_STORE (model);
1136
1137   path = gtk_tree_path_new_from_string (path_string);
1138
1139   gtk_tree_model_get_iter (model, &iter, path);
1140   gtk_tree_model_get (model, &iter,
1141       COL_ENABLED, &enabled,
1142       COL_NAME, &group,
1143       -1);
1144
1145   gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
1146   gtk_tree_path_free (path);
1147
1148   if (group)
1149     {
1150       if (enabled)
1151         {
1152           empathy_contact_list_remove_from_group (
1153               EMPATHY_CONTACT_LIST (information->manager), information->contact,
1154               group);
1155         }
1156       else
1157         {
1158           empathy_contact_list_add_to_group (
1159               EMPATHY_CONTACT_LIST (information->manager), information->contact,
1160               group);
1161         }
1162       g_free (group);
1163     }
1164 }
1165
1166 static void
1167 contact_widget_entry_group_changed_cb (GtkEditable *editable,
1168                                        EmpathyContactWidget *information)
1169 {
1170   GtkTreeIter iter;
1171   const gchar *group;
1172
1173   group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1174
1175   if (contact_widget_model_find_name (information, group, &iter))
1176       gtk_widget_set_sensitive (GTK_WIDGET (information->button_group), FALSE);
1177   else
1178       gtk_widget_set_sensitive (GTK_WIDGET (information->button_group),
1179           !EMP_STR_EMPTY (group));
1180 }
1181
1182 static void
1183 contact_widget_entry_group_activate_cb (GtkEntry *entry,
1184                                         EmpathyContactWidget  *information)
1185 {
1186   gtk_widget_activate (GTK_WIDGET (information->button_group));
1187 }
1188
1189 static void
1190 contact_widget_button_group_clicked_cb (GtkButton *button,
1191                                         EmpathyContactWidget *information)
1192 {
1193   GtkTreeView *view;
1194   GtkListStore *store;
1195   GtkTreeIter iter;
1196   const gchar *group;
1197
1198   view = GTK_TREE_VIEW (information->treeview_groups);
1199   store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
1200
1201   group = gtk_entry_get_text (GTK_ENTRY (information->entry_group));
1202
1203   gtk_list_store_append (store, &iter);
1204   gtk_list_store_set (store, &iter,
1205       COL_NAME, group,
1206       COL_ENABLED, TRUE,
1207       -1);
1208
1209   empathy_contact_list_add_to_group (
1210       EMPATHY_CONTACT_LIST (information->manager), information->contact,
1211       group);
1212 }
1213
1214 static void
1215 contact_widget_details_setup (EmpathyContactWidget *information)
1216 {
1217   /* FIXME: Needs new telepathy spec */
1218   gtk_widget_hide (information->vbox_details);
1219 }
1220
1221 static void
1222 contact_widget_details_update (EmpathyContactWidget *information)
1223 {
1224   /* FIXME: Needs new telepathy spec */
1225 }
1226
1227 static void
1228 contact_widget_client_setup (EmpathyContactWidget *information)
1229 {
1230   /* FIXME: Needs new telepathy spec */
1231   gtk_widget_hide (information->vbox_client);
1232 }
1233
1234 static void
1235 contact_widget_client_update (EmpathyContactWidget *information)
1236 {
1237   /* FIXME: Needs new telepathy spec */
1238 }
1239
1240 /* Converts the Location's GHashTable's key to a user readable string */
1241 static const gchar *
1242 location_key_to_label (const gchar *key)
1243 {
1244   if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY_CODE) == FALSE)
1245     return _("Country ISO Code:");
1246   else if (tp_strdiff (key, EMPATHY_LOCATION_COUNTRY) == FALSE)
1247     return _("Country:");
1248   else if (tp_strdiff (key, EMPATHY_LOCATION_REGION) == FALSE)
1249     return _("State:");
1250   else if (tp_strdiff (key, EMPATHY_LOCATION_LOCALITY) == FALSE)
1251     return _("City:");
1252   else if (tp_strdiff (key, EMPATHY_LOCATION_AREA) == FALSE)
1253     return _("Area:");
1254   else if (tp_strdiff (key, EMPATHY_LOCATION_POSTAL_CODE) == FALSE)
1255     return _("Postal Code:");
1256   else if (tp_strdiff (key, EMPATHY_LOCATION_STREET) == FALSE)
1257     return _("Street:");
1258   else if (tp_strdiff (key, EMPATHY_LOCATION_BUILDING) == FALSE)
1259     return _("Building:");
1260   else if (tp_strdiff (key, EMPATHY_LOCATION_FLOOR) == FALSE)
1261     return _("Floor:");
1262   else if (tp_strdiff (key, EMPATHY_LOCATION_ROOM) == FALSE)
1263     return _("Room:");
1264   else if (tp_strdiff (key, EMPATHY_LOCATION_TEXT) == FALSE)
1265     return _("Text:");
1266   else if (tp_strdiff (key, EMPATHY_LOCATION_DESCRIPTION) == FALSE)
1267     return _("Description:");
1268   else if (tp_strdiff (key, EMPATHY_LOCATION_URI) == FALSE)
1269     return _("URI:");
1270   else if (tp_strdiff (key, EMPATHY_LOCATION_ACCURACY_LEVEL) == FALSE)
1271     return _("Accuracy Level:");
1272   else if (tp_strdiff (key, EMPATHY_LOCATION_ERROR) == FALSE)
1273     return _("Error:");
1274   else if (tp_strdiff (key, EMPATHY_LOCATION_VERTICAL_ERROR_M) == FALSE)
1275     return _("Vertical Error (meters):");
1276   else if (tp_strdiff (key, EMPATHY_LOCATION_HORIZONTAL_ERROR_M) == FALSE)
1277     return _("Horizontal Error (meters):");
1278   else if (tp_strdiff (key, EMPATHY_LOCATION_SPEED) == FALSE)
1279     return _("Speed:");
1280   else if (tp_strdiff (key, EMPATHY_LOCATION_BEARING) == FALSE)
1281     return _("Bearing:");
1282   else if (tp_strdiff (key, EMPATHY_LOCATION_CLIMB) == FALSE)
1283     return _("Climb Speed:");
1284   else if (tp_strdiff (key, EMPATHY_LOCATION_TIMESTAMP) == FALSE)
1285     return _("Last Updated on:");
1286   else if (tp_strdiff (key, EMPATHY_LOCATION_LON) == FALSE)
1287     return _("Longitude:");
1288   else if (tp_strdiff (key, EMPATHY_LOCATION_LAT) == FALSE)
1289     return _("Latitude:");
1290   else if (tp_strdiff (key, EMPATHY_LOCATION_ALT) == FALSE)
1291     return _("Altitude:");
1292   else
1293   {
1294     DEBUG ("Unexpected Location key: %s", key);
1295     return key;
1296   }
1297 }
1298
1299 static void
1300 contact_widget_location_update (EmpathyContactWidget *information)
1301 {
1302   GHashTable *location;
1303   GValue *value;
1304   gdouble lat = 0.0, lon = 0.0;
1305   gboolean has_position = TRUE;
1306   GtkWidget *label;
1307   guint row = 0;
1308   GHashTableIter iter;
1309   gpointer key, pvalue;
1310
1311   if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
1312     {
1313       gtk_widget_hide (information->vbox_location);
1314       return;
1315     }
1316
1317   location = empathy_contact_get_location (information->contact);
1318   if (location == NULL || g_hash_table_size (location) == 0)
1319     {
1320       gtk_widget_hide (information->vbox_location);
1321       return;
1322     }
1323
1324   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
1325   if (value == NULL)
1326       has_position = FALSE;
1327   else
1328       lat = g_value_get_double (value);
1329
1330   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
1331   if (value == NULL)
1332       has_position = FALSE;
1333   else
1334       lon = g_value_get_double (value);
1335
1336   value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
1337   if (value == NULL)
1338     gtk_label_set_markup (GTK_LABEL (information->label_location), _("<b>Location</b>"));
1339   else
1340     {
1341       gchar *user_date;
1342       gchar *text;
1343       gint64 stamp;
1344       time_t time;
1345
1346       stamp = g_value_get_int64 (value);
1347       time = stamp;
1348
1349       user_date = empathy_time_to_string_relative (time);
1350
1351       text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL);
1352       gtk_label_set_markup (GTK_LABEL (information->label_location), text);
1353       g_free (text);
1354     }
1355
1356
1357   /* Prepare the location information table */
1358   if (information->table_location != NULL)
1359     {
1360       gtk_widget_destroy (information->table_location);
1361     }
1362
1363   information->table_location = gtk_table_new (1, 2, FALSE);
1364   gtk_box_pack_start (GTK_BOX (information->subvbox_location),
1365       information->table_location, FALSE, FALSE, 5);
1366
1367   g_hash_table_iter_init (&iter, location);
1368   while (g_hash_table_iter_next (&iter, &key, &pvalue))
1369     {
1370       const gchar *skey;
1371       const gchar* user_label;
1372       GValue *gvalue;
1373       char *svalue = NULL;
1374
1375       skey = (const gchar *) key;
1376
1377       user_label = location_key_to_label (skey);
1378       gvalue = (GValue *) pvalue;
1379
1380       label = gtk_label_new (user_label);
1381       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1382       gtk_table_attach (GTK_TABLE (information->table_location),
1383           label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0);
1384       gtk_widget_show (label);
1385
1386       if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE)
1387         {
1388           gdouble dvalue;
1389           dvalue = g_value_get_double (gvalue);
1390           svalue = g_strdup_printf ("%f", dvalue);
1391         }
1392       else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING)
1393         {
1394           svalue = g_value_dup_string (gvalue);
1395         }
1396       else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
1397         {
1398           time_t time;
1399
1400           time = g_value_get_int64 (value);
1401           svalue = empathy_time_to_string_utc (time, _("%B %e, %Y at %R UTC"));
1402         }
1403
1404       if (svalue != NULL)
1405         {
1406           label = gtk_label_new (svalue);
1407           gtk_table_attach_defaults (GTK_TABLE (information->table_location),
1408               label, 1, 2, row, row + 1);
1409           gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1410           gtk_widget_show (label);
1411         }
1412
1413       g_free (svalue);
1414       row++;
1415     }
1416
1417   gtk_widget_show (information->table_location);
1418
1419 #if HAVE_LIBCHAMPLAIN
1420   /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
1421    * windows
1422    */
1423   if (has_position &&
1424       !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
1425     {
1426       ClutterActor *marker;
1427       ChamplainLayer *layer;
1428
1429       information->map_view_embed = gtk_champlain_embed_new ();
1430       information->map_view = gtk_champlain_embed_get_view (
1431           GTK_CHAMPLAIN_EMBED (information->map_view_embed));
1432
1433       gtk_container_add (GTK_CONTAINER (information->viewport_map),
1434           information->map_view_embed);
1435       g_object_set (G_OBJECT (information->map_view), "show-license", FALSE,
1436           "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
1437           NULL);
1438
1439       layer = champlain_layer_new ();
1440       champlain_view_add_layer (information->map_view, layer);
1441
1442       marker = champlain_marker_new_with_text (
1443           empathy_contact_get_name (information->contact), NULL, NULL, NULL);
1444       champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
1445       clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
1446
1447       champlain_view_center_on (information->map_view, lat, lon);
1448       gtk_widget_show_all (information->viewport_map);
1449     }
1450 #endif
1451
1452     gtk_widget_show (information->vbox_location);
1453 }