]> git.0d.be Git - empathy.git/blobdiff - src/empathy-map-view.c
Merge remote-tracking branch 'glassrose/add-All-service-selection-in-debug-window'
[empathy.git] / src / empathy-map-view.c
index c504f9e220b60e3e8142e05bfed40f95d807853f..9ab82c091c518954bda82f95321d970a13382fd4 100644 (file)
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-connection-aggregator.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-location.h>
 
-#include <libempathy-gtk/empathy-contact-list-store.h>
-#include <libempathy-gtk/empathy-contact-list-view.h>
-#include <libempathy-gtk/empathy-presence-chooser.h>
+#include <libempathy-gtk/empathy-individual-menu.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 
 #include "empathy-map-view.h"
-#include "ephy-spinner.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
 #include <libempathy/empathy-debug.h>
 
-typedef struct {
-  EmpathyContactListStore *list_store;
+G_DEFINE_TYPE (EmpathyMapView, empathy_map_view, GTK_TYPE_WINDOW);
+
+#define GET_PRIV(self) ((EmpathyMapViewPriv *)((EmpathyMapView *) self)->priv)
+
+struct _EmpathyMapViewPriv {
+  EmpathyConnectionAggregator *aggregator;
 
-  GtkWidget *window;
   GtkWidget *zoom_in;
   GtkWidget *zoom_out;
   GtkWidget *throbber;
   ChamplainView *map_view;
-  ChamplainLayer *layer;
+  ChamplainMarkerLayer *layer;
   guint timeout_id;
   /* reffed (EmpathyContact *) => borrowed (ChamplainMarker *) */
   GHashTable *markers;
-} EmpathyMapView;
+  gulong members_changed_id;
+
+  /* TpContact -> EmpathyContact */
+  GHashTable *contacts;
+};
 
 static void
 map_view_state_changed (ChamplainView *view,
     GParamSpec *gobject,
-    EmpathyMapView *window)
+    EmpathyMapView *self)
 {
   ChamplainState state;
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
 
   g_object_get (G_OBJECT (view), "state", &state, NULL);
   if (state == CHAMPLAIN_STATE_LOADING)
-    ephy_spinner_start (EPHY_SPINNER (window->throbber));
+    {
+      gtk_spinner_start (GTK_SPINNER (priv->throbber));
+      gtk_widget_show (priv->throbber);
+    }
   else
-    ephy_spinner_stop (EPHY_SPINNER (window->throbber));
+    {
+      gtk_spinner_stop (GTK_SPINNER (priv->throbber));
+      gtk_widget_hide (priv->throbber);
+    }
+}
+
+static gboolean
+contact_has_location (EmpathyContact *contact)
+{
+  GHashTable *location;
+
+  location = empathy_contact_get_location (contact);
+
+  if (location == NULL || g_hash_table_size (location) == 0)
+    return FALSE;
+
+  return TRUE;
 }
 
+static ClutterActor * create_marker (EmpathyMapView *window,
+    EmpathyContact *contact);
+
 static void
 map_view_update_contact_position (EmpathyMapView *self,
     EmpathyContact *contact)
 {
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
   gdouble lon, lat;
   GValue *value;
   GHashTable *location;
-  ChamplainMarker *marker;
+  ClutterActor *marker;
+  gboolean has_location;
 
-  marker = g_hash_table_lookup (self->markers, contact);
-  g_assert (marker != NULL);
+  has_location = contact_has_location (contact);
 
-  location = empathy_contact_get_location (contact);
+  marker = g_hash_table_lookup (priv->markers, contact);
+  if (marker == NULL)
+    {
+      if (!has_location)
+        return;
 
-  if (location == NULL ||
-      g_hash_table_size (location) == 0)
-  {
-    champlain_base_marker_animate_out (CHAMPLAIN_BASE_MARKER (marker));
-    return;
-  }
+      marker = create_marker (self, contact);
+    }
+  else if (!has_location)
+    {
+      champlain_marker_animate_out (CHAMPLAIN_MARKER (marker));
+      return;
+    }
+
+  location = empathy_contact_get_location (contact);
 
   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT);
   if (value == NULL)
     {
-      clutter_actor_hide (CLUTTER_ACTOR (marker));
+      clutter_actor_hide (marker);
       return;
     }
   lat = g_value_get_double (value);
@@ -106,13 +141,13 @@ map_view_update_contact_position (EmpathyMapView *self,
   value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON);
   if (value == NULL)
     {
-      clutter_actor_hide (CLUTTER_ACTOR (marker));
+      clutter_actor_hide (marker);
       return;
     }
   lon = g_value_get_double (value);
 
-  champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
-  champlain_base_marker_animate_in (CHAMPLAIN_BASE_MARKER (marker));
+  champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon);
+  champlain_marker_animate_in (CHAMPLAIN_MARKER (marker));
 }
 
 static void
@@ -125,188 +160,163 @@ map_view_contact_location_notify (EmpathyContact *contact,
 
 static void
 map_view_zoom_in_cb (GtkWidget *widget,
-    EmpathyMapView *window)
+    EmpathyMapView *self)
 {
-  champlain_view_zoom_in (window->map_view);
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
+
+  champlain_view_zoom_in (priv->map_view);
 }
 
 static void
 map_view_zoom_out_cb (GtkWidget *widget,
-    EmpathyMapView *window)
+    EmpathyMapView *self)
 {
-  champlain_view_zoom_out (window->map_view);
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
+
+  champlain_view_zoom_out (priv->map_view);
 }
 
 static void
 map_view_zoom_fit_cb (GtkWidget *widget,
-    EmpathyMapView *window)
+    EmpathyMapView *self)
 {
-  GList *item, *children;
-  GPtrArray *markers;
-
-  children = clutter_container_get_children (CLUTTER_CONTAINER (window->layer));
-  markers =  g_ptr_array_sized_new (g_list_length (children) + 1);
-
-  for (item = children; item != NULL; item = g_list_next (item))
-    g_ptr_array_add (markers, (gpointer) item->data);
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
 
-  g_ptr_array_add (markers, (gpointer) NULL);
-  champlain_view_ensure_markers_visible (window->map_view,
-    (ChamplainBaseMarker **) markers->pdata,
-    TRUE);
-
-  g_ptr_array_free (markers, TRUE);
-  g_list_free (children);
+  champlain_view_ensure_layers_visible (priv->map_view, TRUE);
 }
 
 static gboolean
 marker_clicked_cb (ChamplainMarker *marker,
     ClutterButtonEvent *event,
-    EmpathyContact *contact)
+    EmpathyMapView *self)
 {
   GtkWidget *menu;
+  EmpathyContact *contact;
+  TpContact *tp_contact;
+  FolksIndividual *individual;
 
   if (event->button != 3)
     return FALSE;
 
-  menu = empathy_contact_menu_new (contact,
-      EMPATHY_CONTACT_FEATURE_CHAT |
-      EMPATHY_CONTACT_FEATURE_CALL |
-      EMPATHY_CONTACT_FEATURE_LOG |
-      EMPATHY_CONTACT_FEATURE_INFO);
+  contact = g_object_get_data (G_OBJECT (marker), "contact");
+  if (contact == NULL)
+    return FALSE;
+
+  tp_contact = empathy_contact_get_tp_contact (contact);
+  if (tp_contact == NULL)
+    return FALSE;
 
-  if (menu == NULL)
+  individual = empathy_create_individual_from_tp_contact (tp_contact);
+  if (individual == NULL)
     return FALSE;
 
+  menu = empathy_individual_menu_new (individual,
+      EMPATHY_INDIVIDUAL_FEATURE_CHAT |
+      EMPATHY_INDIVIDUAL_FEATURE_CALL |
+      EMPATHY_INDIVIDUAL_FEATURE_LOG |
+      EMPATHY_INDIVIDUAL_FEATURE_INFO, NULL);
+
+  if (menu == NULL)
+    goto out;
+
+  gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL);
+
   gtk_widget_show (menu);
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
       event->button, event->time);
-  g_object_ref_sink (menu);
-  g_object_unref (menu);
 
+out:
+  g_object_unref (individual);
   return FALSE;
 }
 
 static void
-map_view_contacts_update_label (ChamplainMarker *marker)
+map_view_contacts_update_label (ClutterActor *marker)
 {
   const gchar *name;
   gchar *date;
   gchar *label;
   GValue *gtime;
-  time_t loctime;
+  gint64 loctime;
   GHashTable *location;
   EmpathyContact *contact;
 
   contact = g_object_get_data (G_OBJECT (marker), "contact");
   location = empathy_contact_get_location (contact);
-  name = empathy_contact_get_name (contact);
+  name = empathy_contact_get_alias (contact);
   gtime = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
 
   if (gtime != NULL)
     {
-      time_t now;
+      GDateTime *now, *d;
+      GTimeSpan delta;
 
       loctime = g_value_get_int64 (gtime);
       date = empathy_time_to_string_relative (loctime);
       label = g_strconcat ("<b>", name, "</b>\n<small>", date, "</small>", NULL);
       g_free (date);
 
-      now = time (NULL);
+      now = g_date_time_new_now_utc ();
+      d = g_date_time_new_from_unix_utc (loctime);
+      delta = g_date_time_difference (now, d);
 
       /* if location is older than a week */
-      if (now - loctime > (60 * 60 * 24 * 7))
-        clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 0.75 * 255);
+      if (delta > G_TIME_SPAN_DAY * 7)
+        clutter_actor_set_opacity (marker, 0.75 * 255);
+
+      g_date_time_unref (now);
+      g_date_time_unref (d);
     }
   else
     {
       label = g_strconcat ("<b>", name, "</b>\n", NULL);
     }
 
-  champlain_marker_set_use_markup (CHAMPLAIN_MARKER (marker), TRUE);
-  champlain_marker_set_text (CHAMPLAIN_MARKER (marker), label);
+  champlain_label_set_use_markup (CHAMPLAIN_LABEL (marker), TRUE);
+  champlain_label_set_text (CHAMPLAIN_LABEL (marker), label);
 
   g_free (label);
 }
 
-static gboolean
-map_view_contacts_foreach (GtkTreeModel *model,
-    GtkTreePath *path,
-    GtkTreeIter *iter,
-    gpointer user_data)
+static ClutterActor *
+create_marker (EmpathyMapView *self,
+    EmpathyContact *contact)
 {
-  EmpathyMapView *window = (EmpathyMapView *) user_data;
-  EmpathyContact *contact;
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
   ClutterActor *marker;
-  ClutterActor *texture;
-  GHashTable *location;
   GdkPixbuf *avatar;
-
-  gtk_tree_model_get (model, iter, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT,
-     &contact, -1);
-
-  if (contact == NULL)
-    return FALSE;
-
-  location = empathy_contact_get_location (contact);
-
-  if (location == NULL || g_hash_table_size (location) == 0)
-    return FALSE;
-
-  marker = champlain_marker_new ();
+  ClutterActor *texture = NULL;
 
   avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
   if (avatar != NULL)
     {
-      texture = clutter_texture_new ();
-      gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (texture), avatar,
-          NULL);
-      champlain_marker_set_image (CHAMPLAIN_MARKER (marker), texture);
+      texture = gtk_clutter_texture_new ();
+
+      gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE (texture),
+          avatar, NULL);
+
       g_object_unref (avatar);
     }
-  else
-    champlain_marker_set_image (CHAMPLAIN_MARKER (marker), NULL);
+
+  marker = champlain_label_new_with_image (texture);
 
   g_object_set_data_full (G_OBJECT (marker), "contact",
       g_object_ref (contact), g_object_unref);
 
-  g_hash_table_insert (window->markers, g_object_ref (contact), marker);
+  g_hash_table_insert (priv->markers, g_object_ref (contact), marker);
 
-  map_view_contacts_update_label (CHAMPLAIN_MARKER (marker));
+  map_view_contacts_update_label (marker);
 
   clutter_actor_set_reactive (CLUTTER_ACTOR (marker), TRUE);
   g_signal_connect (marker, "button-release-event",
-      G_CALLBACK (marker_clicked_cb), contact);
-
-  clutter_container_add (CLUTTER_CONTAINER (window->layer), marker, NULL);
-
-  g_signal_connect (contact, "notify::location",
-      G_CALLBACK (map_view_contact_location_notify), window);
-
-  map_view_update_contact_position (window, contact);
-
-  g_object_unref (contact);
-  return FALSE;
-}
-
-static void
-map_view_destroy_cb (GtkWidget *widget,
-    EmpathyMapView *window)
-{
-  GHashTableIter iter;
-  gpointer contact;
+      G_CALLBACK (marker_clicked_cb), self);
 
-  g_source_remove (window->timeout_id);
+  champlain_marker_layer_add_marker (priv->layer, CHAMPLAIN_MARKER (marker));
 
-  g_hash_table_iter_init (&iter, window->markers);
-  while (g_hash_table_iter_next (&iter, &contact, NULL))
-    g_signal_handlers_disconnect_by_func (contact,
-        map_view_contact_location_notify, window);
+  DEBUG ("Create marker for %s", empathy_contact_get_id (contact));
 
-  g_hash_table_destroy (window->markers);
-  g_object_unref (window->list_store);
-  g_object_unref (window->layer);
-  g_slice_free (EmpathyMapView, window);
+  tp_clear_object (&texture);
+  return marker;
 }
 
 static gboolean
@@ -314,8 +324,8 @@ map_view_key_press_cb (GtkWidget *widget,
     GdkEventKey *event,
     gpointer user_data)
 {
-  if ((event->state & GDK_CONTROL_MASK && event->keyval == GDK_w)
-      || event->keyval == GDK_Escape)
+  if ((event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_w)
+      || event->keyval == GDK_KEY_Escape)
     {
       gtk_widget_destroy (widget);
       return TRUE;
@@ -325,106 +335,222 @@ map_view_key_press_cb (GtkWidget *widget,
 }
 
 static gboolean
-map_view_tick (EmpathyMapView *window)
+map_view_tick (EmpathyMapView *self)
 {
-  GList *marker;
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
+  GList *marker, *l;
 
-  marker = clutter_container_get_children (CLUTTER_CONTAINER (window->layer));
+  marker = champlain_marker_layer_get_markers (priv->layer);
 
-  for (; marker; marker = marker->next)
-    map_view_contacts_update_label (marker->data);
+  for (l = marker; l != NULL; l = g_list_next (l))
+    map_view_contacts_update_label (l->data);
 
+  g_list_free (marker);
   return TRUE;
 }
 
-GtkWidget *
-empathy_map_view_show (void)
+static void
+contact_list_changed_cb (EmpathyConnectionAggregator *aggregator,
+    GPtrArray *added,
+    GPtrArray *removed,
+    EmpathyMapView *self)
+{
+  EmpathyMapViewPriv *priv = GET_PRIV (self);
+  guint i;
+
+  for (i = 0; i < added->len; i++)
+    {
+      TpContact *tp_contact = g_ptr_array_index (added, i);
+      EmpathyContact *contact;
+
+      if (g_hash_table_lookup (priv->contacts, tp_contact) != NULL)
+        continue;
+
+      contact = empathy_contact_dup_from_tp_contact (tp_contact);
+
+      tp_g_signal_connect_object (contact, "notify::location",
+          G_CALLBACK (map_view_contact_location_notify), self, 0);
+
+      map_view_update_contact_position (self, contact);
+
+      /* Pass ownership to the hash table */
+      g_hash_table_insert (priv->contacts, g_object_ref (tp_contact),
+          contact);
+    }
+
+  for (i = 0; i < removed->len; i++)
+    {
+      TpContact *tp_contact = g_ptr_array_index (removed, i);
+      EmpathyContact *contact;
+      ClutterActor *marker;
+
+      contact = g_hash_table_lookup (priv->contacts, tp_contact);
+      if (contact == NULL)
+        continue;
+
+      marker = g_hash_table_lookup (priv->markers, contact);
+      if (marker != NULL)
+        {
+          clutter_actor_destroy (marker);
+          g_hash_table_remove (priv->markers, contact);
+        }
+
+      g_signal_handlers_disconnect_by_func (contact,
+          map_view_contact_location_notify, self);
+
+      g_hash_table_remove (priv->contacts, tp_contact);
+    }
+}
+
+static GObject *
+empathy_map_view_constructor (GType type,
+    guint n_construct_params,
+    GObjectConstructParam *construct_params)
+{
+  static GObject *window = NULL;
+
+  if (window != NULL)
+    return window;
+
+  window = G_OBJECT_CLASS (empathy_map_view_parent_class)->constructor (
+      type, n_construct_params, construct_params);
+
+  g_object_add_weak_pointer (window, (gpointer) &window);
+
+  return window;
+}
+
+static void
+empathy_map_view_finalize (GObject *object)
+{
+  EmpathyMapViewPriv *priv = GET_PRIV (object);
+  GHashTableIter iter;
+  gpointer contact;
+
+  g_source_remove (priv->timeout_id);
+
+  g_hash_table_iter_init (&iter, priv->markers);
+  while (g_hash_table_iter_next (&iter, &contact, NULL))
+    g_signal_handlers_disconnect_by_func (contact,
+        map_view_contact_location_notify, object);
+
+  g_hash_table_unref (priv->markers);
+  g_object_unref (priv->aggregator);
+  g_object_unref (priv->layer);
+  g_hash_table_unref (priv->contacts);
+
+  G_OBJECT_CLASS (empathy_map_view_parent_class)->finalize (object);
+}
+
+static void
+empathy_map_view_class_init (EmpathyMapViewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructor = empathy_map_view_constructor;
+  object_class->finalize = empathy_map_view_finalize;
+
+  g_type_class_add_private (object_class, sizeof (EmpathyMapViewPriv));
+}
+
+static void
+empathy_map_view_init (EmpathyMapView *self)
 {
-  static EmpathyMapView *window = NULL;
+  EmpathyMapViewPriv *priv;
   GtkBuilder *gui;
   GtkWidget *sw;
   GtkWidget *embed;
   GtkWidget *throbber_holder;
   gchar *filename;
-  GtkTreeModel *model;
-  EmpathyContactList *list_iface;
-  EmpathyContactListStore *list_store;
+  GPtrArray *contacts, *empty;
+  GtkWidget *main_vbox;
 
-  if (window)
-    {
-      empathy_window_present (GTK_WINDOW (window->window));
-      return window->window;
-    }
+  priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+      EMPATHY_TYPE_MAP_VIEW, EmpathyMapViewPriv);
 
-  window = g_slice_new0 (EmpathyMapView);
+  gtk_window_set_title (GTK_WINDOW (self), _("Contact Map View"));
+  gtk_window_set_role (GTK_WINDOW (self), "map_view");
+  gtk_window_set_default_size (GTK_WINDOW (self), 512, 384);
+  gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER);
 
   /* Set up interface */
   filename = empathy_file_lookup ("empathy-map-view.ui", "src");
   gui = empathy_builder_get_file (filename,
-     "map_view", &window->window,
-     "zoom_in", &window->zoom_in,
-     "zoom_out", &window->zoom_out,
+     "main_vbox", &main_vbox,
+     "zoom_in", &priv->zoom_in,
+     "zoom_out", &priv->zoom_out,
      "map_scrolledwindow", &sw,
      "throbber", &throbber_holder,
      NULL);
   g_free (filename);
 
-  empathy_builder_connect (gui, window,
-      "map_view", "destroy", map_view_destroy_cb,
-      "map_view", "key-press-event", map_view_key_press_cb,
+  gtk_container_add (GTK_CONTAINER (self), main_vbox);
+
+  empathy_builder_connect (gui, self,
       "zoom_in", "clicked", map_view_zoom_in_cb,
       "zoom_out", "clicked", map_view_zoom_out_cb,
       "zoom_fit", "clicked", map_view_zoom_fit_cb,
       NULL);
 
-  g_object_unref (gui);
-
-  /* Clear the static pointer to window if the dialog is destroyed */
-  g_object_add_weak_pointer (G_OBJECT (window->window), (gpointer *) &window);
+  g_signal_connect (self, "key-press-event",
+      G_CALLBACK (map_view_key_press_cb), self);
 
-  list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
-  list_store = empathy_contact_list_store_new (list_iface);
-  empathy_contact_list_store_set_show_groups (list_store, FALSE);
-  empathy_contact_list_store_set_show_avatars (list_store, TRUE);
-  g_object_unref (list_iface);
-
-  window->throbber = ephy_spinner_new ();
-  ephy_spinner_set_size (EPHY_SPINNER (window->throbber),
-      GTK_ICON_SIZE_LARGE_TOOLBAR);
-  gtk_widget_show (window->throbber);
-  gtk_container_add (GTK_CONTAINER (throbber_holder), window->throbber);
+  g_object_unref (gui);
 
-  window->list_store = list_store;
+  priv->throbber = gtk_spinner_new ();
+  gtk_widget_set_size_request (priv->throbber, 16, 16);
+  gtk_container_add (GTK_CONTAINER (throbber_holder), priv->throbber);
 
   /* Set up map view */
   embed = gtk_champlain_embed_new ();
-  window->map_view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (embed));
-  g_object_set (G_OBJECT (window->map_view), "zoom-level", 1,
-     "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL);
-  champlain_view_center_on (window->map_view, 36, 0);
+  priv->map_view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (embed));
+  g_object_set (G_OBJECT (priv->map_view),
+     "zoom-level", 1,
+     "kinetic-mode", TRUE,
+     NULL);
+  champlain_view_center_on (priv->map_view, 36, 0);
 
   gtk_container_add (GTK_CONTAINER (sw), embed);
   gtk_widget_show_all (embed);
 
-  window->layer = g_object_ref (champlain_layer_new ());
-  champlain_view_add_layer (window->map_view, window->layer);
+  priv->layer = g_object_ref (champlain_marker_layer_new ());
+  champlain_view_add_layer (priv->map_view, CHAMPLAIN_LAYER (priv->layer));
 
-  g_signal_connect (window->map_view, "notify::state",
-      G_CALLBACK (map_view_state_changed), window);
+  g_signal_connect (priv->map_view, "notify::state",
+      G_CALLBACK (map_view_state_changed), self);
 
   /* Set up contact list. */
-  window->markers = g_hash_table_new_full (NULL, NULL,
+  priv->markers = g_hash_table_new_full (NULL, NULL,
       (GDestroyNotify) g_object_unref, NULL);
 
-  model = GTK_TREE_MODEL (window->list_store);
-  gtk_tree_model_foreach (model, map_view_contacts_foreach, window);
+  priv->aggregator = empathy_connection_aggregator_dup_singleton ();
+  priv->contacts = g_hash_table_new_full (NULL, NULL, g_object_unref,
+      g_object_unref);
 
-  empathy_window_present (GTK_WINDOW (window->window));
+  tp_g_signal_connect_object (priv->aggregator, "contact-list-changed",
+      G_CALLBACK (contact_list_changed_cb), self, 0);
 
-  /* Set up time updating loop */
-  window->timeout_id = g_timeout_add_seconds (5,
-      (GSourceFunc) map_view_tick, window);
+  contacts = empathy_connection_aggregator_dup_all_contacts (priv->aggregator);
+  empty = g_ptr_array_new ();
+
+  contact_list_changed_cb (priv->aggregator, contacts, empty, self);
 
-  return window->window;
+  g_ptr_array_unref (contacts);
+  g_ptr_array_unref (empty);
+
+  /* Set up time updating loop */
+  priv->timeout_id = g_timeout_add_seconds (5,
+      (GSourceFunc) map_view_tick, self);
 }
 
+GtkWidget *
+empathy_map_view_show (void)
+{
+  GtkWidget *window;
+
+  window = g_object_new (EMPATHY_TYPE_MAP_VIEW, NULL);
+  gtk_widget_show_all (window);
+  empathy_window_present (GTK_WINDOW (window));
+
+  return window;
+}