#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>
GtkWidget *throbber;
ChamplainView *map_view;
ChamplainLayer *layer;
+ guint timeout_id;
} EmpathyMapView;
static void
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;
}
}
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
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);
location = empathy_contact_get_location (contact);
- if (location == NULL)
+ if (location == NULL || g_hash_table_size (location) == 0)
return FALSE;
marker = champlain_marker_new ();
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",
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);
{
GList *item;
+ g_source_remove (window->timeout_id);
+
item = clutter_container_get_children (CLUTTER_CONTAINER (window->layer));
while (item != NULL)
{
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)
{
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;
}