]> err.no Git - mapper/commitdiff
POI handling cleanups.
authorKaj-Michael Lang <milang@angel.tal.org>
Wed, 8 Aug 2007 10:30:40 +0000 (13:30 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Wed, 8 Aug 2007 10:30:40 +0000 (13:30 +0300)
Use a struct for sql statements.
Fix POI edit lat/lon.
Move most direct sqlite handling from poi-gui.c to poi.c, a little is still missing.

src/map-poi.c
src/poi-gui.c
src/poi.c
src/poi.h

index 18ac055b2eac2cc17cf5903033afbbd1b11b798e..c640171e248c31d00dea51bb03c3ba0159f992cc 100644 (file)
@@ -87,19 +87,19 @@ unitx = x2unit(BUF_WIDTH_PIXELS);
 unity = y2unit(0);
 unit2latlon(unitx, unity, lat2, lon2);
 
-if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1)
-    || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2,lat2)
-    || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3,lon1)
-    || SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4,lon2)) {
-       g_printerr("Failed to bind values for _stmt_select_poi");
+if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1)
+    || SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2,lat2)
+    || SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3,lon1)
+    || SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4,lon2)) {
+       g_printerr("Failed to bind values for poisql.select_poi");
        return;
 }
 
-while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
-       lat1 = sqlite3_column_double(_stmt_select_poi, 0);
-       lon1 = sqlite3_column_double(_stmt_select_poi, 1);
-       gchar *poi_label = sqlite3_column_text(_stmt_select_poi, 3);
-       gchar *cat_label = g_utf8_strdown(sqlite3_column_text(_stmt_select_poi, 6), -1);
+while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) {
+       lat1 = sqlite3_column_double(poisql.select_poi, 0);
+       lon1 = sqlite3_column_double(poisql.select_poi, 1);
+       gchar *poi_label = sqlite3_column_text(poisql.select_poi, 3);
+       gchar *cat_label = g_utf8_strdown(sqlite3_column_text(poisql.select_poi, 6), -1);
 
        latlon2unit(lat1, lon1, unitx, unity);
        poix = unit2bufx(unitx);
@@ -128,7 +128,8 @@ while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
                                0, 0);
        }
 }
-sqlite3_reset(_stmt_select_poi);
+sqlite3_reset(poisql.select_poi);
+sqlite3_clear_bindings(poisql.select_poi);
 
 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
 }
index 59a3ed8c67dc05f2e441e12e77a10e0ceab708d3..56044514b6784e0cf9c6d389238358a96dbcd247 100644 (file)
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 #include <fcntl.h>
-
 #include <libintl.h>
 #include <locale.h>
 
-#include <sqlite3.h>
-
 #include "utils.h"
 #include "poi.h"
 #include "gps.h"
 #include "ui-common.h"
 #include "settings.h"
 
+#define POI_QUICK_BUTTONS (9)
+
 guint _poi_zoom = 6;
-gboolean select_poi(guint unitx, guint unity, PoiInfo * poi);
 
+gboolean select_poi(guint unitx, guint unity, PoiInfo *poi);
 
-gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi)
+gboolean category_delete(GtkWidget * widget, DeletePOI *dpoi)
 {
        GtkWidget *dialog;
        guint i;
@@ -61,8 +60,6 @@ gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi)
 
 gboolean category_dialog(guint cat_id)
 {
-       gchar *cat_label = NULL, *cat_desc = NULL;
-       guint cat_enabled;
        GtkWidget *dialog;
        GtkWidget *table;
        GtkWidget *label;
@@ -75,21 +72,13 @@ gboolean category_dialog(guint cat_id)
        GtkTextIter begin, end;
        gboolean results = TRUE;
        DeletePOI dpoi = { NULL, NULL, 0 };
+       poi_category *c;
+
        printf("%s()\n", __PRETTY_FUNCTION__);
 
        if (cat_id > 0) {
-               if (SQLITE_OK != sqlite3_bind_double(_stmt_select_cat, 1, cat_id)
-                   || SQLITE_ROW != sqlite3_step(_stmt_select_cat)) {
-                       vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
-                       sqlite3_reset(_stmt_select_cat);
+               if (poi_category_get(cat_id, &c)==FALSE)
                        return FALSE;
-               }
-
-               cat_label = g_strdup(sqlite3_column_text(_stmt_select_cat, 0));
-               cat_desc = g_strdup(sqlite3_column_text(_stmt_select_cat, 1));
-               cat_enabled = sqlite3_column_int(_stmt_select_cat, 2);
-
-               sqlite3_reset(_stmt_select_cat);
 
                dialog = gtk_dialog_new_with_buttons(_("Edit Category"),
                                                     GTK_WINDOW(_window),
@@ -99,23 +88,21 @@ gboolean category_dialog(guint cat_id)
 
                gtk_container_add(GTK_CONTAINER
                                  (GTK_DIALOG(dialog)->action_area),
-                                 btn_delete =
-                                 gtk_button_new_with_label(_("Delete")));
+                                 btn_delete = gtk_button_new_with_label(_("Delete")));
 
                dpoi.dialog = dialog;
-               dpoi.txt_label = g_strdup(cat_label);
-               dpoi.id = cat_id;
+               dpoi.txt_label = g_strdup(c->label);
+               dpoi.id = c->id;
 
-               g_signal_connect(G_OBJECT(btn_delete), "clicked",
-                                G_CALLBACK(category_delete), &dpoi);
+               g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(category_delete), &dpoi);
 
-               gtk_dialog_add_button(GTK_DIALOG(dialog),
-                                     GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
+               gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
        } else {
-               cat_enabled = 1;
-               cat_label = g_strdup("");
-               cat_id = 0;
-               cat_desc = g_strdup("");
+               c=poi_category_new();
+               c->enabled = 1;
+               c->label = g_strdup("");
+               c->id = 0;
+               c->desc = g_strdup("");
 
                dialog = gtk_dialog_new_with_buttons(_("Add Category"),
                                                     GTK_WINDOW(_window),
@@ -129,25 +116,21 @@ gboolean category_dialog(guint cat_id)
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
                           table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
 
-       gtk_table_attach(GTK_TABLE(table),
-                        label = gtk_label_new(_("Label")),
+       gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")),
                         0, 1, 0, 1, GTK_FILL, 0, 2, 4);
        gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
        gtk_table_attach(GTK_TABLE(table),
                         txt_label = gtk_entry_new(),
                         1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
 
-       gtk_table_attach(GTK_TABLE(table),
-                        label = gtk_label_new(_("Description")),
+       gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")),
                         0, 1, 1, 2, GTK_FILL, 0, 2, 4);
        gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
 
        txt_scroll = gtk_scrolled_window_new(NULL, NULL);
-       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
-                                           GTK_SHADOW_IN);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll), GTK_SHADOW_IN);
        gtk_table_attach(GTK_TABLE(table),
-                        txt_scroll,
-                        1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
+                        txt_scroll, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
 
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
                                       GTK_POLICY_AUTOMATIC,
@@ -162,84 +145,45 @@ gboolean category_dialog(guint cat_id)
        desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
 
        gtk_table_attach(GTK_TABLE(table),
-                        chk_enabled =
-                        gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2,
+                        chk_enabled = gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2,
                         3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
 
        /* label */
-       gtk_entry_set_text(GTK_ENTRY(txt_label), cat_label);
+       gtk_entry_set_text(GTK_ENTRY(txt_label), c->label);
 
        /* desc */
-       gtk_text_buffer_set_text(desc_txt, cat_desc, -1);
+       gtk_text_buffer_set_text(desc_txt, c->desc, -1);
 
        /* enabled */
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled),
-                                    (cat_enabled == 1 ? TRUE : FALSE));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled), (c->enabled == 1 ? TRUE : FALSE));
 
-       g_free(cat_label);
-       cat_label = NULL;
-       g_free(cat_desc);
-       cat_desc = NULL;
+       poi_category_free(c);
 
        gtk_widget_show_all(dialog);
 
        while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
-               if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
-                       cat_label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
-               else {
-                       popup_error(dialog,
-                                   _("Please specify a name for the category."));
+               if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) {
+                       c=poi_category_new();
+                       c->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
+               } else {
+                       popup_error(dialog,_("Please specify a name for the category."));
                        continue;
                }
 
                gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0);
                gtk_text_buffer_get_end_iter(desc_txt, &end);
-               cat_desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
-
-               cat_enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
-
-               if (cat_id > 0) {
-                       /* edit category */
-                       if (SQLITE_OK !=
-                           sqlite3_bind_text(_stmt_update_cat, 1, cat_label,
-                                             -1, g_free)
-                           || SQLITE_OK != sqlite3_bind_text(_stmt_update_cat,
-                                                             2, cat_desc, -1,
-                                                             g_free)
-                           || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat,
-                                                            3, cat_enabled)
-                           || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat,
-                                                            4, cat_id)
-                           || SQLITE_DONE != sqlite3_step(_stmt_update_cat)) {
-                               MACRO_BANNER_SHOW_INFO(_window,
-                                                      _("Problem updating category"));
-                               results = FALSE;
-                       }
-                       sqlite3_reset(_stmt_update_cat);
-               } else {
-                       /* add category */
-                       if (SQLITE_OK !=
-                           sqlite3_bind_text(_stmt_insert_cat, 1, cat_label,
-                                             -1, g_free)
-                           || SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat,
-                                                             2, cat_desc, -1,
-                                                             g_free)
-                           || SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat,
-                                                            3, cat_enabled)
-                           || SQLITE_DONE != sqlite3_step(_stmt_insert_cat)) {
-                               MACRO_BANNER_SHOW_INFO(_window,
-                                                      _("Problem adding category"));
-                               results = FALSE;
-                       }
-                       sqlite3_reset(_stmt_insert_cat);
-               }
-               break;
+               c->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
+               c->enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
+
+               results=poi_category_update(cat_id, c);
+
+               if (results==FALSE)
+                       MACRO_BANNER_SHOW_INFO(_window, _("Problem updating category"));
+               poi_category_free(c);
        }
 
        g_free(dpoi.txt_label);
-
        g_object_unref(desc_txt);
-
        gtk_widget_hide_all(dialog);
 
        vprintf("%s(): return\n", __PRETTY_FUNCTION__);
@@ -262,44 +206,13 @@ void category_toggled(GtkCellRendererToggle * cell, gchar * path, gpointer data)
 
        cat_enabled ^= 1;
 
-       if (SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 1, cat_enabled) ||
-           SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 2, cat_id) ||
-           SQLITE_DONE != sqlite3_step(_stmt_toggle_cat)) {
+       if (poi_category_toggle(cat_id, cat_enabled)==FALSE) {
                MACRO_BANNER_SHOW_INFO(_window, _("Problem updating Category"));
-       } else
-               gtk_list_store_set(GTK_LIST_STORE(model), &iter,
-                                  CAT_ENABLED, cat_enabled, -1);
-
-       sqlite3_reset(_stmt_toggle_cat);
-
-       vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
-}
-
-static GtkListStore *
-category_generate_store()
-{
-       GtkTreeIter iter;
-       GtkListStore *store;
-       printf("%s()\n", __PRETTY_FUNCTION__);
-
-       store = gtk_list_store_new(CAT_NUM_COLUMNS,
-                                  G_TYPE_UINT,
-                                  G_TYPE_BOOLEAN,
-                                  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
-
-       while (SQLITE_ROW == sqlite3_step(_stmt_selall_cat)) {
-               gtk_list_store_append(store, &iter);
-               gtk_list_store_set(store, &iter,
-                               CAT_ID, sqlite3_column_int(_stmt_selall_cat, 0), 
-                               CAT_ENABLED, sqlite3_column_int(_stmt_selall_cat, 3),
-                               CAT_LABEL, sqlite3_column_text(_stmt_selall_cat, 1),
-                               CAT_DESC, sqlite3_column_text(_stmt_selall_cat, 2),
-                               CAT_POI_CNT, sqlite3_column_int(_stmt_selall_cat, 6), -1);
+       } else {
+               gtk_list_store_set(GTK_LIST_STORE(model), &iter, CAT_ENABLED, cat_enabled, -1);
        }
-       sqlite3_reset(_stmt_selall_cat);
 
-       vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
-       return store;
+       vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
 }
 
 gboolean 
@@ -309,7 +222,7 @@ category_add(GtkWidget * widget, GtkWidget * tree_view)
        printf("%s()\n", __PRETTY_FUNCTION__);
 
        if (category_dialog(0)) {
-               store = category_generate_store();
+               store = poi_category_generate_store();
                gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
                                        GTK_TREE_MODEL(store));
                g_object_unref(G_OBJECT(store));
@@ -332,7 +245,7 @@ gboolean category_edit(GtkWidget * widget, GtkWidget * tree_view)
                memset(&val, 0, sizeof(val));
                gtk_tree_model_get_value(store, &iter, 0, &val);
                if (category_dialog(g_value_get_uint(&val))) {
-                       GtkListStore *new_store = category_generate_store();
+                       GtkListStore *new_store = poi_category_generate_store();
                        gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
                                                GTK_TREE_MODEL(new_store));
                        g_object_unref(G_OBJECT(new_store));
@@ -370,7 +283,7 @@ gboolean category_list()
        gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
                          btn_add = gtk_button_new_with_label(_("Add")));
 
-       store = category_generate_store();
+       store = poi_category_generate_store();
 
        if (!store)
                return TRUE;
@@ -453,7 +366,8 @@ gboolean menu_cb_category(GtkAction * action)
        return TRUE;
 }
 
-gboolean poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
+gboolean 
+poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
 {
        GtkWidget *dialog;
        guint i;
@@ -479,7 +393,8 @@ gboolean poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
        return TRUE;
 }
 
-gboolean select_poi(guint unitx, guint unity, PoiInfo * poi)
+gboolean 
+select_poi(guint unitx, guint unity, PoiInfo *poi)
 {
        GtkWidget *dialog;
        GtkWidget *list;
@@ -495,8 +410,6 @@ gboolean select_poi(guint unitx, guint unity, PoiInfo * poi)
        if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE)
                return FALSE;
 
-       g_printf("N: %d\n", num_cats);
-
        switch (num_cats) {
        case 0:
                MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
@@ -594,24 +507,23 @@ void poi_populate_cat_combo(GtkWidget * cmb_category, guint cat_id)
        gboolean has_active = FALSE;
        printf("%s()\n", __PRETTY_FUNCTION__);
 
-       store = GTK_LIST_STORE(gtk_combo_box_get_model
-                          (GTK_COMBO_BOX(cmb_category)));
+       store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)));
        gtk_list_store_clear(store);
 
-       while (SQLITE_ROW == sqlite3_step(_stmt_selall_cat)) {
+       while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
                GtkTreeIter iter;
-               guint cid = sqlite3_column_int(_stmt_selall_cat, 0);
+               guint cid = sqlite3_column_int(poisql.selall_cat, 0);
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter,
                                   0, cid,
-                                  1, sqlite3_column_text(_stmt_selall_cat, 1),
+                                  1, sqlite3_column_text(poisql.selall_cat, 1),
                                   -1);
                if (cid == cat_id) {
                        active = iter;
                        has_active = TRUE;
                }
        }
-       sqlite3_reset(_stmt_selall_cat);
+       sqlite3_reset(poisql.selall_cat);
 
        if (!has_active)
                gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active);
@@ -670,8 +582,7 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity)
 
                gtk_container_add(GTK_CONTAINER
                                  (GTK_DIALOG(dialog)->action_area),
-                                 btn_delete =
-                                 gtk_button_new_with_label(_("Delete")));
+                                 btn_delete = gtk_button_new_with_label(_("Delete")));
 
                dpoi.dialog = dialog;
                dpoi.txt_label = g_strdup(poi.label);
@@ -683,11 +594,9 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity)
                gtk_dialog_add_button(GTK_DIALOG(dialog),
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
        } else {
-               if (SQLITE_ROW == sqlite3_step(_stmt_nextlabel_poi))
-                       poi.label = g_strdup_printf("Point%06d",
-                                                   sqlite3_column_int
-                                                   (_stmt_nextlabel_poi, 0));
-               sqlite3_reset(_stmt_nextlabel_poi);
+               if (SQLITE_ROW == sqlite3_step(poisql.nextlabel_poi))
+                       poi.label = g_strdup_printf("Point%06d", sqlite3_column_int(poisql.nextlabel_poi, 0));
+               sqlite3_reset(poisql.nextlabel_poi);
 
                unit2latlon(unitx, unity, poi.lat, poi.lon);
 
@@ -799,7 +708,7 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity)
        gtk_widget_show_all(dialog);
 
        while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
-               const gchar *poi_label = NULL;
+               gchar *poi_label = NULL;
                gchar *poi_desc = NULL;
                GtkTreeIter iter;
 
@@ -853,3 +762,45 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity)
        vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
        return TRUE;
 }
+
+gboolean
+poi_quick_dialog(gdouble lat, gdouble lon)
+{
+GtkWidget *dialog;
+GtkWidget *table;
+GtkWidget *buttons[POI_QUICK_BUTTONS];
+guint x,y;
+
+dialog = gtk_dialog_new_with_buttons(_("Quick POI"),
+               GTK_WINDOW(_window),
+                   GTK_DIALOG_MODAL,
+                   GTK_STOCK_OK,
+               GTK_RESPONSE_ACCEPT,
+                       GTK_STOCK_CANCEL,
+                       GTK_RESPONSE_REJECT,
+                       NULL);
+
+gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
+   table = gtk_table_new(3, 3, FALSE), TRUE, TRUE, 0);
+
+for (x=0;x<3;x++) {
+       for (y=0;y<3;y++) {
+               gchar *btnlabel;
+
+               btnlabel=g_strdup_printf("(%d)", (x+y));
+               buttons[x+y]=gtk_button_new_with_label(btnlabel);
+               gtk_table_attach(GTK_TABLE(table),
+                       buttons[x+y], x, x+1, y, y+1, GTK_FILL, 0, 2, 4);
+               g_free(btnlabel);
+       }
+}
+
+gtk_widget_show_all(dialog);
+
+if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
+       g_printf("Wee!");
+}
+gtk_widget_destroy(dialog);
+
+return TRUE;
+}
index edf384d33d0ad2e7fe58d25210d374b46f72fa80..728b0d40afe2f73388219200dfb1680d9b9ec094 100644 (file)
--- a/src/poi.c
+++ b/src/poi.c
 #include <fcntl.h>
 #include <gconf/gconf-client.h>
 #include <libxml/parser.h>
-
 #include <libintl.h>
 #include <locale.h>
-
 #include <sqlite3.h>
 
 #include "utils.h"
 #include "db.h"
 #include "osm.h"
 
-struct sql_poi_stmt {
-       sqlite3_stmt *select_poi;
-       sqlite3_stmt *select_nearest_poi;
-       sqlite3_stmt *insert_poi;
-       sqlite3_stmt *update_poi;
-       sqlite3_stmt *delete_poi;
-       sqlite3_stmt *delete_poi_by_catid;
-       sqlite3_stmt *nextlabel_poi;
-       sqlite3_stmt *select_cat;
-       sqlite3_stmt *insert_cat;
-       sqlite3_stmt *update_cat;
-       sqlite3_stmt *delete_cat;
-       sqlite3_stmt *toggle_cat;
-       sqlite3_stmt *selall_cat;
-       sqlite3_stmt *select_quick_cat;
-};
-static struct sql_poi_stmt poisql;
-
-sqlite3_stmt *_stmt_select_poi = NULL;
-sqlite3_stmt *_stmt_select_nearest_poi = NULL;
-sqlite3_stmt *_stmt_insert_poi = NULL;
-sqlite3_stmt *_stmt_update_poi = NULL;
-sqlite3_stmt *_stmt_delete_poi = NULL;
-sqlite3_stmt *_stmt_delete_poi_by_catid = NULL;
-sqlite3_stmt *_stmt_nextlabel_poi = NULL;
-
-sqlite3_stmt *_stmt_select_cat = NULL;
-sqlite3_stmt *_stmt_insert_cat = NULL;
-sqlite3_stmt *_stmt_update_cat = NULL;
-sqlite3_stmt *_stmt_delete_cat = NULL;
-sqlite3_stmt *_stmt_toggle_cat = NULL;
-sqlite3_stmt *_stmt_selall_cat = NULL;
-
 struct _poi_categories {
        node_type_t type;
        gchar *name, *desc;
 };
+
 static struct _poi_categories default_poi_categories[] = {
        {NODE_AMENITY_PARKING, "Parking", "Parking place for vehicles." },
        {NODE_AMENITY_FUEL, "Fuel", "Stations for purchasing fuel for vehicles." },
-       {NODE_AMENITY_FUEL, "Speed Cam", "Automatic speed cameras." },
+       {NODE_AMENITY_SPEEDCAM, "Speed Cam", "Automatic speed cameras." },
        {NODE_AMENITY_HOSPITAL, "Hospital", "" },
        {NODE_AMENITY_PHARMACY, "Pharmacy", "Place to get drugs." },
        {NODE_AMENITY_POLICE, "Police", "Police station"},
@@ -108,8 +74,8 @@ static struct _poi_categories default_poi_categories[] = {
        {NODE_POI_END, NULL, NULL }
 };
 
-gboolean
-poi_cb_populate_categories(sqlite3 *db)
+static gboolean
+poi_populate_categories(sqlite3 *db)
 {
 sqlite3_stmt *sql_cat;
 gint i;
@@ -178,7 +144,7 @@ poi_db_create(sqlite3 *db)
                sqlite3_free_table(pszResult);
 
        /* Make sure default categories exists */
-       poi_cb_populate_categories(db);
+       poi_populate_categories(db);
        return TRUE;
 }
 
@@ -193,7 +159,7 @@ poi_db_prepare(sqlite3 *db)
                        " where p.lat between ? and ? "
                        " and p.lon between ? and ? "
                        " and c.enabled = 1 and p.cat_id = c.cat_id",
-                       -1, &_stmt_select_poi, NULL);
+                       -1, &poisql.select_poi, NULL);
 
        /* select nearest pois */
        sqlite3_prepare_v2(db,
@@ -204,47 +170,47 @@ poi_db_prepare(sqlite3 *db)
                        " and p.lon between $LON-0.10 and $LAT+0.10 "
                        " order by (($LAT - p.lat) * ($LAT - p.lat) "
                        "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
-                       -1, &_stmt_select_nearest_poi, NULL);
+                       -1, &poisql.select_nearest_poi, NULL);
 
        /* insert poi */
        sqlite3_prepare_v2(db,
                        "insert into poi (lat, lon, label, desc, cat_id, public)"
-                       " values (?, ?, ?, ?, ?, 1)", -1, &_stmt_insert_poi, NULL);
+                       " values (?, ?, ?, ?, ?, 1)", -1, &poisql.insert_poi, NULL);
        /* update poi */
        sqlite3_prepare_v2(db, "update poi set label = ?, desc = ?, "
                        "cat_id = ? where poi_id = ?",
-                       -1, &_stmt_update_poi, NULL);
+                       -1, &poisql.update_poi, NULL);
        /* delete from poi */
        sqlite3_prepare_v2(db, "delete from poi where poi_id = ?",
-                       -1, &_stmt_delete_poi, NULL);
+                       -1, &poisql.delete_poi, NULL);
        /* delete from poi by cat_id */
        sqlite3_prepare_v2(db, "delete from poi where cat_id = ?",
-                       -1, &_stmt_delete_poi_by_catid, NULL);
+                       -1, &poisql.delete_poi_by_catid, NULL);
        /* get next poilabel */
        sqlite3_prepare_v2(db, "select ifnull(max(poi_id) + 1,1) from poi",
-                       -1, &_stmt_nextlabel_poi, NULL);
+                       -1, &poisql.nextlabel_poi, NULL);
 
        /* select from category */
        sqlite3_prepare_v2(db,
                        "select c.label, c.desc, c.enabled"
                        " from category c where c.cat_id = ?",
-                       -1, &_stmt_select_cat, NULL);
+                       -1, &poisql.select_cat, NULL);
        /* insert into category */
        sqlite3_prepare_v2(db,
                        "insert into category (label, desc, enabled)"
-                       " values (?, ?, ?)", -1, &_stmt_insert_cat, NULL);
+                       " values (?, ?, ?)", -1, &poisql.insert_cat, NULL);
        /* update category */
        sqlite3_prepare_v2(db,
                        "update category set label = ?, desc = ?,"
                        " enabled = ? where poi_id = ?",
-                       -1, &_stmt_update_cat, NULL);
+                       -1, &poisql.update_cat, NULL);
        /* delete from category */
        sqlite3_prepare_v2(db,"delete from category where cat_id = ?",
-                       -1, &_stmt_delete_cat, NULL);
+                       -1, &poisql.delete_cat, NULL);
        /* enable category */
        sqlite3_prepare_v2(db,
                        "update category set enabled = ?"
-                       " where cat_id = ?", -1, &_stmt_toggle_cat, NULL);
+                       " where cat_id = ?", -1, &poisql.toggle_cat, NULL);
        /* select all category */
        sqlite3_prepare_v2(db,
                        "select c.cat_id, c.label, c.desc, c.enabled, c.icon, c.color,"
@@ -252,7 +218,7 @@ poi_db_prepare(sqlite3 *db)
                        " from category c"
                        " left outer join poi p on c.cat_id = p.cat_id"
                        " group by c.cat_id, c.label, c.desc, c.enabled "
-                       " order by c.priority,c.label", -1, &_stmt_selall_cat, NULL);
+                       " order by c.priority,c.label", -1, &poisql.selall_cat, NULL);
 
        /* Select quick categories */
        sqlite3_prepare_v2(db,
@@ -297,8 +263,6 @@ return FALSE;
 PoiInfo *
 poi_new(void)
 {
-PoiInfo *p;
-
 return g_slice_new0(PoiInfo);
 }
 
@@ -308,8 +272,59 @@ poi_free(PoiInfo *p)
 g_slice_free(PoiInfo, p);
 }
 
+poi_category *
+poi_category_new(void)
+{
+return g_slice_new0(poi_category);
+}
+
+void
+poi_category_free(poi_category *c)
+{
+if (c->label)
+       g_free(c->label);
+if (c->desc)
+       g_free(c->desc);
+g_slice_free(poi_category, c);
+}
+
+gboolean
+poi_category_toggle(gint cat_id, gboolean cat_enabled) 
+{
+if (SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 1, cat_enabled) ||
+    SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 2, cat_id) ||
+    SQLITE_DONE != sqlite3_step(poisql.toggle_cat)) {
+               return FALSE;
+       }
+return TRUE;
+}
+
 gboolean
-poi_category_update(gint cat_id, gchar *cat_label, gchar *cat_desc, gint cat_enabled)
+poi_category_get(gint cat_id, poi_category **c)
+{
+poi_category *cc;
+
+if (SQLITE_OK != sqlite3_bind_int(poisql.select_cat, 1, cat_id)
+    || SQLITE_ROW != sqlite3_step(poisql.select_cat)) {
+       vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
+       sqlite3_reset(poisql.select_cat);
+       return FALSE;
+}
+
+cc=poi_category_new();
+cc->id=cat_id;
+cc->label = g_strdup(sqlite3_column_text(poisql.select_cat, 0));
+cc->desc = g_strdup(sqlite3_column_text(poisql.select_cat, 1));
+cc->enabled = sqlite3_column_int(poisql.select_cat, 2);
+
+sqlite3_reset(poisql.select_cat);
+sqlite3_clear_bindings(poisql.select_cat);
+*c=cc;
+return TRUE;
+}
+
+gboolean
+poi_category_update(gint cat_id, poi_category *c)
 {
 gboolean results=TRUE;
 
@@ -319,33 +334,26 @@ if (!_db)
 if (cat_id > 0) {
 /* edit category */
                if (SQLITE_OK !=
-                   sqlite3_bind_text(_stmt_update_cat, 1, cat_label, -1,
-                                     g_free)
-                   || SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 2,
-                                                     cat_desc, -1, g_free)
-                   || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 3,
-                                                    cat_enabled)
-                   || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 4,
-                                                    cat_id)
-                   || SQLITE_DONE != sqlite3_step(_stmt_update_cat)) {
+                   sqlite3_bind_text(poisql.update_cat, 1, c->label, -1, g_free)
+                   || SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 2, c->desc, -1, g_free)
+                   || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 3, c->enabled)
+                   || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 4, c->id)
+                   || SQLITE_DONE != sqlite3_step(poisql.update_cat)) {
                        results = FALSE;
                }
-               sqlite3_reset(_stmt_update_cat);
-               sqlite3_clear_bindings(_stmt_update_cat);
+               sqlite3_reset(poisql.update_cat);
+               sqlite3_clear_bindings(poisql.update_cat);
        } else {
                /* add category */
                if (SQLITE_OK !=
-                   sqlite3_bind_text(_stmt_insert_cat, 1, cat_label, -1,
-                                     g_free)
-                   || SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 2,
-                                                     cat_desc, -1, g_free)
-                   || SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat, 3,
-                                                    cat_enabled)
-                   || SQLITE_DONE != sqlite3_step(_stmt_insert_cat)) {
+                   sqlite3_bind_text(poisql.insert_cat, 1, c->label, -1, g_free)
+                   || SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 2, c->desc, -1, g_free)
+                   || SQLITE_OK != sqlite3_bind_int(poisql.insert_cat, 3, c->enabled)
+                   || SQLITE_DONE != sqlite3_step(poisql.insert_cat)) {
                        results = FALSE;
                }
-               sqlite3_reset(_stmt_insert_cat);
-               sqlite3_clear_bindings(_stmt_insert_cat);
+               sqlite3_reset(poisql.insert_cat);
+               sqlite3_clear_bindings(poisql.insert_cat);
        }
 return results;
 }
@@ -356,21 +364,21 @@ poi_category_delete(DeletePOI *dpoi)
 if (!_db)
        return FALSE;
 
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id)
-           || SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid)) {
-               sqlite3_reset(_stmt_delete_poi_by_catid);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, dpoi->id)
+           || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) {
+               sqlite3_reset(poisql.delete_poi_by_catid);
                return FALSE;
 }
-sqlite3_reset(_stmt_delete_poi_by_catid);
-sqlite3_clear_bindings(_stmt_delete_poi_by_catid);
+sqlite3_reset(poisql.delete_poi_by_catid);
+sqlite3_clear_bindings(poisql.delete_poi_by_catid);
 
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
-    SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) {
-       sqlite3_reset(_stmt_delete_cat);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, dpoi->id) ||
+    SQLITE_DONE != sqlite3_step(poisql.delete_cat)) {
+       sqlite3_reset(poisql.delete_cat);
        return FALSE;
 }
-sqlite3_reset(_stmt_delete_cat);
-sqlite3_clear_bindings(_stmt_delete_cat);
+sqlite3_reset(poisql.delete_cat);
+sqlite3_clear_bindings(poisql.delete_cat);
 return TRUE;
 }
 
@@ -381,13 +389,13 @@ poi_delete(DeletePOI *dpoi)
 if (!_db)
        return FALSE;
 
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
-    SQLITE_DONE != sqlite3_step(_stmt_delete_poi)) {
-       sqlite3_reset(_stmt_delete_poi);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, dpoi->id) ||
+    SQLITE_DONE != sqlite3_step(poisql.delete_poi)) {
+       sqlite3_reset(poisql.delete_poi);
        return FALSE;
 } else {
-       sqlite3_reset(_stmt_delete_poi);
-       sqlite3_clear_bindings(_stmt_delete_poi);
+       sqlite3_reset(poisql.delete_poi);
+       sqlite3_clear_bindings(poisql.delete_poi);
 }
 return TRUE;
 }
@@ -396,7 +404,7 @@ gboolean
 poi_get_list(guint unitx, guint unity, GtkListStore **_store, guint *_num_cats)
 {
 guint x, y;
-gfloat lat1, lon1, lat2, lon2;
+gdouble lat1, lon1, lat2, lon2;
 GtkListStore *store;
 GtkTreeIter iter;
 gchar tmp1[16], tmp2[16];
@@ -407,8 +415,8 @@ if (!_db)
 
 store = gtk_list_store_new(POI_NUM_COLUMNS, G_TYPE_INT,        /* POI ID */
                           G_TYPE_INT,  /* Category ID */
-                          G_TYPE_FLOAT,        /* Latitude */
-                          G_TYPE_FLOAT,        /* Longitude */
+                          G_TYPE_DOUBLE,       /* Latitude */
+                          G_TYPE_DOUBLE,       /* Longitude */
                           G_TYPE_STRING,       /* Lat/Lon */
                           G_TYPE_STRING,       /* POI Label */
                           G_TYPE_STRING,       /* POI Desc. */
@@ -422,43 +430,42 @@ x = unitx + pixel2unit(3 * _draw_width);
 y = unity - pixel2unit(3 * _draw_width);
 unit2latlon(x, y, lat2, lon2); 
 
-if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
-    SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
-    SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
-    SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2)) {
-       g_printerr("Failed to bind values for _stmt_select_poi\n");
+if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) ||
+    SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2, lat2) ||
+    SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon1) ||
+    SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon2)) {
+       g_printerr("Failed to bind values for poisql.select_poi\n");
        return FALSE;
 }
 
-while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
-       gfloat lat, lon;
-       lat = sqlite3_column_double(_stmt_select_poi, 0);
-       lon = sqlite3_column_double(_stmt_select_poi, 1);
+while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) {
+       gdouble lat, lon;
+       lat = sqlite3_column_double(poisql.select_poi, 0);
+       lon = sqlite3_column_double(poisql.select_poi, 1);
        g_printf("Found POI(%d): %f, %f, %s, %s, %s\n",
                num_cats,
                lat,
                lon,
-               sqlite3_column_text(_stmt_select_poi, 3),
-               sqlite3_column_text(_stmt_select_poi, 4),
-               sqlite3_column_text(_stmt_select_poi, 6));
+               sqlite3_column_text(poisql.select_poi, 3),
+               sqlite3_column_text(poisql.select_poi, 4),
+               sqlite3_column_text(poisql.select_poi, 6));
 
        lat_format(lat, tmp1);
        lon_format(lon, tmp2);
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter,
-               POI_POIID, sqlite3_column_int(_stmt_select_poi, 2),
-               POI_CATID, sqlite3_column_int(_stmt_select_poi, 5),
+               POI_POIID, sqlite3_column_int(poisql.select_poi, 2),
+               POI_CATID, sqlite3_column_int(poisql.select_poi, 5),
                POI_LAT, lat, POI_LON, lon, POI_LATLON,
                g_strdup_printf("%s, %s", tmp1, tmp2),
-               POI_LABEL, sqlite3_column_text(_stmt_select_poi, 3),
-               POI_DESC, sqlite3_column_text(_stmt_select_poi, 4),
-               POI_CATLAB, sqlite3_column_text(_stmt_select_poi, 6),
+               POI_LABEL, sqlite3_column_text(poisql.select_poi, 3),
+               POI_DESC, sqlite3_column_text(poisql.select_poi, 4),
+               POI_CATLAB, sqlite3_column_text(poisql.select_poi, 6),
                -1);
        num_cats++;
 }
-g_printf("N: %d\n", num_cats);
-sqlite3_reset(_stmt_select_poi);
-sqlite3_clear_bindings(_stmt_select_poi);
+sqlite3_reset(poisql.select_poi);
+sqlite3_clear_bindings(poisql.select_poi);
 *_store=store;
 *_num_cats=num_cats;
 return TRUE;
@@ -470,15 +477,15 @@ poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc)
 if (!_db)
        return FALSE;
 
-if (SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 1, poi_label, -1, SQLITE_STATIC)
-   || SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 2, poi_desc, -1, g_free)
-   || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 3, cat_id)
-   || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 4, poi_id)
-   || SQLITE_DONE != sqlite3_step(_stmt_update_poi)) {
+if (SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 1, poi_label, -1, SQLITE_STATIC)
+   || SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 2, poi_desc, -1, g_free)
+   || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 3, cat_id)
+   || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 4, poi_id)
+   || SQLITE_DONE != sqlite3_step(poisql.update_poi)) {
                return FALSE;
        }
-sqlite3_reset(_stmt_update_poi);
-sqlite3_clear_bindings(_stmt_update_poi);
+sqlite3_reset(poisql.update_poi);
+sqlite3_clear_bindings(poisql.update_poi);
 return TRUE;
 }
 
@@ -488,16 +495,16 @@ poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc
 if (!_db)
        return FALSE;
 
-if (SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, lat)
-    || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, lon)
-    || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi_label, -1, g_free)
-    || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi_desc, -1, g_free)
-    || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5, cat_id) 
-       || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)) {
+if (SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 1, lat)
+    || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 2, lon)
+    || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 3, poi_label, -1, g_free)
+    || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 4, poi_desc, -1, g_free)
+    || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 5, cat_id) 
+       || SQLITE_DONE != sqlite3_step(poisql.insert_poi)) {
                return FALSE;
        }
-sqlite3_reset(_stmt_insert_poi);
-sqlite3_clear_bindings(_stmt_insert_poi);
+sqlite3_reset(poisql.insert_poi);
+sqlite3_clear_bindings(poisql.insert_poi);
 return TRUE;
 }
 
@@ -510,19 +517,19 @@ PoiInfo *p;
 if (!_db)
        return FALSE;
 
-sqlite3_reset(_stmt_select_nearest_poi);
-sqlite3_clear_bindings(_stmt_select_nearest_poi);
+sqlite3_reset(poisql.select_nearest_poi);
+sqlite3_clear_bindings(poisql.select_nearest_poi);
 
-if (SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
-    && SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 2, lon)
-    && SQLITE_ROW == sqlite3_step(_stmt_select_nearest_poi)) {
+if (SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 1, lat)
+    && SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 2, lon)
+    && SQLITE_ROW == sqlite3_step(poisql.select_nearest_poi)) {
 
        p=poi_new();
 
-       p->lat = sqlite3_column_double(_stmt_select_nearest_poi, 0);
-       p->lon = sqlite3_column_double(_stmt_select_nearest_poi, 1);
-       _poi_label = sqlite3_column_text(_stmt_select_nearest_poi, 2);
-       _cat_label = sqlite3_column_text(_stmt_select_nearest_poi, 3);
+       p->lat = sqlite3_column_double(poisql.select_nearest_poi, 0);
+       p->lon = sqlite3_column_double(poisql.select_nearest_poi, 1);
+       _poi_label = sqlite3_column_text(poisql.select_nearest_poi, 2);
+       _cat_label = sqlite3_column_text(poisql.select_nearest_poi, 3);
        p->label=g_strdup(_poi_label);
        p->cat_label=g_strdup(_cat_label);
        g_printf("%f %f %s %s\n", p->lat, p->lon, p->label, p->cat_label);
@@ -530,3 +537,31 @@ if (SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
 }
 return NULL;
 }
+
+GtkListStore *
+poi_category_generate_store()
+{
+GtkTreeIter iter;
+GtkListStore *store;
+printf("%s()\n", __PRETTY_FUNCTION__);
+
+store = gtk_list_store_new(CAT_NUM_COLUMNS,
+                          G_TYPE_UINT,
+                          G_TYPE_BOOLEAN,
+                          G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
+
+while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
+       gtk_list_store_append(store, &iter);
+       gtk_list_store_set(store, &iter,
+                       CAT_ID, sqlite3_column_int(poisql.selall_cat, 0), 
+                       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);
+}
+sqlite3_reset(poisql.selall_cat);
+sqlite3_clear_bindings(poisql.selall_cat);
+
+vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
+return store;
+}
index b58dea133e2b1ff9b1902b2f9829a413b3361322..e08e0105178fe5fa0785066d37e8ef515162c6da 100644 (file)
--- a/src/poi.h
+++ b/src/poi.h
@@ -50,32 +50,51 @@ struct _DeletePOI {
        guint id;
 };
 
-guint _poi_zoom;
+typedef struct _poi_category poi_category;
+struct _poi_category {
+       gint id;
+       gint enabled;
+       gchar *label;
+       gchar *desc;
+};
 
-/* POI SQL statements */
-sqlite3_stmt *_stmt_select_poi;
-sqlite3_stmt *_stmt_select_nearest_poi;
-sqlite3_stmt *_stmt_insert_poi;
-sqlite3_stmt *_stmt_update_poi;
-sqlite3_stmt *_stmt_delete_poi;
-sqlite3_stmt *_stmt_delete_poi_by_catid;
-sqlite3_stmt *_stmt_nextlabel_poi;
+struct sql_poi_stmt {
+       sqlite3_stmt *select_poi;
+       sqlite3_stmt *select_nearest_poi;
+       sqlite3_stmt *insert_poi;
+       sqlite3_stmt *update_poi;
+       sqlite3_stmt *delete_poi;
+       sqlite3_stmt *delete_poi_by_catid;
+       sqlite3_stmt *nextlabel_poi;
+       sqlite3_stmt *select_cat;
+       sqlite3_stmt *insert_cat;
+       sqlite3_stmt *update_cat;
+       sqlite3_stmt *delete_cat;
+       sqlite3_stmt *toggle_cat;
+       sqlite3_stmt *selall_cat;
+       sqlite3_stmt *select_quick_cat;
+};
+struct sql_poi_stmt poisql;
 
-/* Category SQL statements */
-sqlite3_stmt *_stmt_select_cat;
-sqlite3_stmt *_stmt_insert_cat;
-sqlite3_stmt *_stmt_update_cat;
-sqlite3_stmt *_stmt_delete_cat;
-sqlite3_stmt *_stmt_toggle_cat;
-sqlite3_stmt *_stmt_selall_cat;
+guint _poi_zoom;
+
+gboolean poi_db_create(sqlite3 *db);
+gboolean poi_db_prepare(sqlite3 *db);
 
+PoiInfo *poi_new(void);
+void poi_free(PoiInfo *p);
 gboolean poi_get_list(guint unitx, guint unity, GtkListStore **store, guint *num_cats);
 gboolean poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc);
 gboolean poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc);
 gboolean poi_delete(DeletePOI * dpoi);
+
+poi_category *poi_category_new(void);
+void poi_category_free(poi_category *c);
+gboolean poi_category_get(gint cat_id, poi_category **c);
 gboolean poi_category_delete(DeletePOI * dpoi);
-gboolean poi_category_update(gint cat_id, gchar * cat_label, gchar * cat_desc, gint cat_enabled);
+gboolean poi_category_update(gint cat_id, poi_category *c);
 PoiInfo *poi_find_nearest(gdouble lat, gdouble lon);
-
+gboolean poi_category_toggle(gint cat_id, gboolean cat_enabled);
+GtkListStore *poi_category_generate_store();
 
 #endif