]> git.0d.be Git - empathy.git/blobdiff - src/empathy-map-view.c
Update marker's label every second
[empathy.git] / src / empathy-map-view.c
index 99c496b233447e397571b1d564cd5c38c0a8b840..9eadee756de555a197fff5f494db44d47232c033 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <champlain/champlain.h>
 #include <champlain-gtk/champlain-gtk.h>
-#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-gtk/clutter-gtk.h>
 #include <telepathy-glib/util.h>
 
 #include <libempathy/empathy-contact.h>
@@ -54,6 +54,7 @@ typedef struct {
   GtkWidget *throbber;
   ChamplainView *map_view;
   ChamplainLayer *layer;
+  guint timeout_id;
 } EmpathyMapView;
 
 static void
@@ -83,7 +84,7 @@ map_view_marker_update_position (ChamplainMarker *marker,
   if (location == NULL ||
       g_hash_table_size (location) == 0)
   {
-    clutter_actor_hide (CLUTTER_ACTOR (marker));
+    champlain_base_marker_animate_out (CHAMPLAIN_BASE_MARKER (marker));
     return;
   }
 
@@ -103,8 +104,8 @@ map_view_marker_update_position (ChamplainMarker *marker,
     }
   lon = g_value_get_double (value);
 
-  clutter_actor_show (CLUTTER_ACTOR (marker));
   champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon);
+  champlain_base_marker_animate_in (CHAMPLAIN_BASE_MARKER (marker));
 }
 
 static void
@@ -155,23 +156,60 @@ marker_clicked_cb (ChamplainMarker *marker,
   return FALSE;
 }
 
+static void
+map_view_contacts_update_label (ChamplainMarker *marker)
+{
+  const gchar *name;
+  gchar *date;
+  gchar *label;
+  GValue *gtime;
+  time_t 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);
+  gtime = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
+
+  if (gtime != NULL)
+    {
+      time_t now;
+
+      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);
+
+      /* if location is older than a week */
+      if (now - loctime > (60 * 60 * 24 * 7))
+        clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 0.75 * 255);
+    }
+  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);
+
+  g_free (label);
+}
+
 static gboolean
 map_view_contacts_foreach (GtkTreeModel *model,
     GtkTreePath *path,
     GtkTreeIter *iter,
     gpointer user_data)
 {
-  EmpathyMapView *window = (EmpathyMapView*) user_data;
+  EmpathyMapView *window = (EmpathyMapView *) user_data;
   EmpathyContact *contact;
   ClutterActor *marker;
   ClutterActor *texture;
   GHashTable *location;
   GdkPixbuf *avatar;
-  const gchar *name;
-  gchar *date;
-  gchar *label;
-  GValue *gtime;
-  time_t time;
 
   gtk_tree_model_get (model, iter, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT,
      &contact, -1);
@@ -181,7 +219,7 @@ map_view_contacts_foreach (GtkTreeModel *model,
 
   location = empathy_contact_get_location (contact);
 
-  if (location == NULL)
+  if (location == NULL || g_hash_table_size (location) == 0)
     return FALSE;
 
   marker = champlain_marker_new ();
@@ -190,29 +228,18 @@ map_view_contacts_foreach (GtkTreeModel *model,
   if (avatar != NULL)
     {
       texture = clutter_texture_new ();
-      gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (texture), avatar);
+      gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (texture), avatar,
+          NULL);
       champlain_marker_set_image (CHAMPLAIN_MARKER (marker), texture);
       g_object_unref (avatar);
     }
   else
     champlain_marker_set_image (CHAMPLAIN_MARKER (marker), NULL);
 
-  name = empathy_contact_get_name (contact);
-  gtime = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP);
-  if (gtime != NULL)
-    {
-      time = g_value_get_int64 (gtime);
-      date = empathy_time_to_string_relative (time);
-      label = g_strconcat ("<b>", name, "</b>\n<small>", date, "</small>", NULL);
-      g_free (date);
-    }
-  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);
-  g_free (label);
+  g_object_set_data_full (G_OBJECT (marker), "contact",
+      g_object_ref (contact), g_object_unref);
+
+  map_view_contacts_update_label (CHAMPLAIN_MARKER (marker));
 
   clutter_actor_set_reactive (CLUTTER_ACTOR (marker), TRUE);
   g_signal_connect (marker, "button-release-event",
@@ -222,8 +249,6 @@ map_view_contacts_foreach (GtkTreeModel *model,
 
   g_signal_connect (contact, "notify::location",
       G_CALLBACK (map_view_contact_location_notify), marker);
-  g_object_set_data_full (G_OBJECT (marker), "contact",
-      g_object_ref (contact), g_object_unref);
 
   map_view_marker_update_position (CHAMPLAIN_MARKER (marker), contact);
 
@@ -237,6 +262,8 @@ map_view_destroy_cb (GtkWidget *widget,
 {
   GList *item;
 
+  g_source_remove (window->timeout_id);
+
   item = clutter_container_get_children (CLUTTER_CONTAINER (window->layer));
   while (item != NULL)
   {
@@ -256,6 +283,19 @@ map_view_destroy_cb (GtkWidget *widget,
   g_slice_free (EmpathyMapView, window);
 }
 
+static gboolean
+map_view_tick (EmpathyMapView *window)
+{
+  GList *marker;
+
+  marker = clutter_container_get_children (CLUTTER_CONTAINER (window->layer));
+
+  for (; marker; marker = marker->next)
+    map_view_contacts_update_label (marker->data);
+
+  return TRUE;
+}
+
 GtkWidget *
 empathy_map_view_show (void)
 {
@@ -334,6 +374,11 @@ empathy_map_view_show (void)
   gtk_tree_model_foreach (model, map_view_contacts_foreach, window);
 
   empathy_window_present (GTK_WINDOW (window->window), TRUE);
+
+  /* Set up time updating loop */
+  window->timeout_id = g_timeout_add_seconds (5,
+      (GSourceFunc) map_view_tick, window);
+
   return window->window;
 }