From 277cd9c42db1048ccf6bdef41270b21c0fc8b70f Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 10 Jan 2008 14:19:48 +0200 Subject: [PATCH] Add POI category icon to category view. --- src/map-poi.c | 37 +------------------------------------ src/poi-gui.c | 10 +++++++--- src/poi.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- src/poi.h | 2 ++ 4 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/map-poi.c b/src/map-poi.c index 1614881..a0327a6 100644 --- a/src/map-poi.c +++ b/src/map-poi.c @@ -42,20 +42,12 @@ #define POI_FONT_SIZE_BIG (10) #define POI_FONT_SIZE_SMALL (8) -/* Hash table for caching POI icons */ -static GHashTable *poi_icon_hash = NULL; - /* POI icon text pango stuff */ static PangoContext *context = NULL; static PangoLayout *layout = NULL; static PangoFontDescription *fontdesc = NULL; static GdkGC *poi_gc; - -/* POI Icon theme. "classic" or "square". Should be made into a configuration option */ -static gchar *theme="square"; - static GtkListStore *poi_store=NULL; - static gint last_zoom=-1; static guint prev_ux=0, prev_uy=0; @@ -64,7 +56,6 @@ static guint prev_ux=0, prev_uy=0; gboolean map_poi_init(GtkWidget *map_widget) { -poi_icon_hash=g_hash_table_new(g_str_hash, g_str_equal); context=gtk_widget_get_pango_context(map_widget); layout=pango_layout_new(context); fontdesc=pango_font_description_new(); @@ -87,32 +78,6 @@ pango_layout_get_pixel_size(layout, &w, &h); gdk_draw_layout(_map_pixmap, gc, x-(w>>1), y-h-_draw_width, layout); } -static GdkPixbuf * -map_poi_get_icon(gchar *icon) -{ -gchar buffer[100]; -GdkPixbuf *pixbuf; -GError *error = NULL; - -if (icon==NULL) - return NULL; - -g_snprintf(buffer, sizeof(buffer), DATADIR "/map-icons/%s.%s/%s.png", - theme, (_zoom<2) ? "big" : "small", icon); - -pixbuf = g_hash_table_lookup(poi_icon_hash, buffer); -if (pixbuf) - return pixbuf; - -pixbuf=gdk_pixbuf_new_from_file(buffer, &error); - -if (error) - return NULL; - -g_hash_table_insert(poi_icon_hash, g_strdup(buffer), pixbuf); -return pixbuf; -} - /** * Set POI color from given #rrggbb string, fallback to default if it fails */ @@ -270,7 +235,7 @@ while (valid) { ITEM_COLOR, &color, -1); - pixbuf=map_poi_get_icon(icon); + pixbuf=poi_get_icon(icon, _zoom<2 ? TRUE : FALSE); gc=map_set_poi_fg_color_from_string(color, _gc[COLORABLE_POI]); latlon2unit(lat1, lon1, unitx, unity); diff --git a/src/poi-gui.c b/src/poi-gui.c index bb3cfff..73a2de2 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -366,16 +366,16 @@ help_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_edit = gtk_button_new_with_label(_("Edit"))); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_add = gtk_button_new_with_label(_("Add"))); -store = poi_category_generate_store(); +store=poi_category_generate_store(); if (!store) return TRUE; -sw = gtk_scrolled_window_new(NULL, NULL); +sw=gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0); -tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); +tree_view=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); /* Maemo-related? */ g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL); gtk_container_add(GTK_CONTAINER(sw), tree_view); @@ -396,6 +396,10 @@ gtk_tree_view_column_set_sort_column_id (column, CAT_ENABLED); g_object_unref(G_OBJECT(store)); +renderer = gtk_cell_renderer_pixbuf_new(); +column = gtk_tree_view_column_new_with_attributes(_("Icon"), renderer, "pixbuf", CAT_ICON, NULL); +gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Label"), renderer, "text", CAT_LABEL, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); diff --git a/src/poi.c b/src/poi.c index d6cd824..0ef634e 100644 --- a/src/poi.c +++ b/src/poi.c @@ -32,6 +32,12 @@ static sqlite3 *poidb; +/* POI Icon theme. "classic" or "square". Should be made into a configuration option */ +static gchar *theme="square"; + +/* Hash table for caching POI icons */ +static GHashTable *poi_icon_hash = NULL; + struct _poi_categories { node_type_t type; const gchar *name, *desc, *icon, *color; @@ -363,6 +369,9 @@ sqlite3_finalize(poisql.select_poi_search_cat); gboolean poi_init(sqlite3 **db) { +if (!poi_icon_hash) + poi_icon_hash=g_hash_table_new(g_str_hash, g_str_equal); + if (!db || !*db) return FALSE; @@ -836,6 +845,35 @@ if (SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 1, lat) return NULL; } +GdkPixbuf * +poi_get_icon(gchar *icon, gboolean big) +{ +gchar buffer[100]; +GdkPixbuf *pixbuf; +GError *error = NULL; + +if (icon==NULL) + return NULL; + +if (strlen(icon)==0) + return NULL; + +g_snprintf(buffer, sizeof(buffer), DATADIR "/map-icons/%s.%s/%s.png", + theme, (big==TRUE) ? "big" : "small", icon); + +pixbuf=g_hash_table_lookup(poi_icon_hash, buffer); +if (pixbuf) + return pixbuf; + +pixbuf=gdk_pixbuf_new_from_file(buffer, &error); + +if (error) + return NULL; + +g_hash_table_insert(poi_icon_hash, g_strdup(buffer), pixbuf); +return pixbuf; +} + GtkListStore * poi_category_generate_store(void) { @@ -845,11 +883,13 @@ GtkListStore *store; if (!poidb) return NULL; -store=gtk_list_store_new(CAT_NUM_COLUMNS, +store=gtk_list_store_new(CAT_NUM_COLUMNS, /* pixbuf */ G_TYPE_UINT, G_TYPE_BOOLEAN, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_UINT); + G_TYPE_STRING, + G_TYPE_UINT, + GDK_TYPE_PIXBUF); while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) { gtk_list_store_append(store, &iter); @@ -858,7 +898,9 @@ while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) { CAT_ENABLED, sqlite3_column_int(poisql.selall_cat, 3), CAT_LABEL, sqlite3_column_text(poisql.selall_cat, 1), CAT_DESC, sqlite3_column_text(poisql.selall_cat, 2), - CAT_POI_CNT, sqlite3_column_int(poisql.selall_cat, 6), -1); + CAT_POI_CNT, sqlite3_column_int(poisql.selall_cat, 6), + CAT_ICON, poi_get_icon(sqlite3_column_text(poisql.selall_cat, 4),TRUE), + -1); } sqlite3_reset(poisql.selall_cat); diff --git a/src/poi.h b/src/poi.h index 0f31507..b30e234 100644 --- a/src/poi.h +++ b/src/poi.h @@ -134,6 +134,8 @@ gboolean poi_category_delete(guint id); gboolean poi_category_update(guint cat_id, poi_category *c); gboolean poi_category_toggle(guint cat_id, gboolean cat_enabled); +GdkPixbuf *poi_get_icon(gchar *icon, gboolean big); + GtkListStore *poi_category_generate_store(void); #endif -- 2.39.5