From: Kaj-Michael Lang Date: Fri, 11 Apr 2008 10:23:54 +0000 (+0300) Subject: Use the generic image cache system for POI icons X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e17cc9d4a181dfd410e431fd31f4805f61a0bfee;p=mapper Use the generic image cache system for POI icons --- diff --git a/src/poi.c b/src/poi.c index 5661121..1a1b02f 100644 --- a/src/poi.c +++ b/src/poi.c @@ -27,6 +27,7 @@ #include "osm.h" #include "osm-db.h" #include "latlon.h" +#include "image-cache.h" static sqlite3 *poidb; @@ -34,8 +35,7 @@ static sqlite3 *poidb; static gchar *theme="square"; static gchar *theme_base=DATADIR "/icons/map-icons"; -/* Hash table for caching POI icons */ -static GHashTable *poi_icon_hash = NULL; +static ImageCache *poi_ic=NULL; struct _poi_categories { node_type_t type; @@ -362,19 +362,15 @@ poi_db_prepare(sqlite3 *db) void poi_icon_hash_clear(void) { -#if (GLIB_CHECK_VERSION (2, 12, 0)) -g_hash_table_remove_all(poi_icon_hash); -#else -g_hash_table_foreach_remove(poi_icon_hash, gtk_true, NULL); -#endif +image_cache_clear(poi_ic); } void poi_deinit(sqlite3 *db) { -if (poi_icon_hash) { - g_hash_table_destroy(poi_icon_hash); - poi_icon_hash=NULL; +if (poi_ic) { + image_cache_free(poi_ic); + poi_ic=NULL; } sqlite3_finalize(poisql.select_quick_cat); @@ -397,12 +393,12 @@ sqlite3_finalize(poisql.select_poi_search_cat); gboolean poi_init(sqlite3 **db) { -if (!poi_icon_hash) - poi_icon_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - if (!db || !*db) return FALSE; +if (!poi_ic) + poi_ic=image_cache_new(128); + poidb=*db; poi_db_create(poidb); if (poi_db_prepare(poidb)==FALSE) { @@ -707,7 +703,7 @@ return TRUE; gboolean poi_get_list_inside(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2, GtkListStore **store, guint *num_poi) { -static active=FALSE; +static gboolean active=FALSE; GtkTreeIter iter; gchar tmp1[16], tmp2[16]; @@ -903,13 +899,10 @@ return NULL; } GdkPixbuf * -poi_get_icon(gchar *icon, gboolean big) +poi_get_icon(const gchar *icon, gboolean big) { -static guint hit=0; -static guint miss=0; -gchar buffer[256]; -GdkPixbuf *pixbuf; -GError *error = NULL; +gchar buffer[128]; +gchar key[32]; if (icon==NULL) return NULL; @@ -917,23 +910,10 @@ if (icon==NULL) if (strlen(icon)==0) return NULL; -g_snprintf(buffer, sizeof(buffer), "%s/%s.%s/%s.png", - theme_base, theme, (big==TRUE) ? "big" : "small", icon); - -pixbuf=g_hash_table_lookup(poi_icon_hash, buffer); -if (pixbuf) { - hit++; - return pixbuf; -} -miss++; - -pixbuf=gdk_pixbuf_new_from_file(buffer, &error); - -if (error) - return NULL; +g_snprintf(buffer, sizeof(buffer), "%s/%s.%s/%s.png", theme_base, theme, (big==TRUE) ? "big" : "small", icon); +g_snprintf(key, sizeof(key), "%s:%s:%s", theme, (big==TRUE) ? "big" : "small", icon); -g_hash_table_insert(poi_icon_hash, g_strdup(buffer), pixbuf); -return pixbuf; +return image_cache_get(poi_ic, key, buffer); } GtkListStore *