#include "osm.h"
#include "osm-db.h"
#include "latlon.h"
+#include "image-cache.h"
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;
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);
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) {
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];
}
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;
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 *