]> err.no Git - mapper/commitdiff
Use predefined id numbers from osm.h for categories.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 16 Jul 2007 13:30:46 +0000 (16:30 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 16 Jul 2007 13:30:46 +0000 (16:30 +0300)
Remove the old categories.
Check default categories every time we start.

src/poi.c

index 95b87f17dce5b21de7ec5d52850479b66d4be823..be8c04899f3c1805bac9faf090698c0f427243e8 100644 (file)
--- a/src/poi.c
+++ b/src/poi.c
@@ -28,6 +28,7 @@
 #include "mapper-types.h"
 #include "settings.h"
 #include "db.h"
+#include "osm.h"
 
 sqlite3_stmt *_stmt_select_poi = NULL;
 sqlite3_stmt *_stmt_select_nearest_poi = NULL;
@@ -44,6 +45,65 @@ 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_HOSPITAL, "Hospital", "" },
+       {NODE_AMENITY_PHARMACY, "Pharmacy", ""},
+       {NODE_AMENITY_POLICE, "Police", "Police station"},
+       {NODE_AMENITY_HOTEL, "Hotel", "Places to stay temporarily or for the night."},
+       {NODE_AMENITY_HOSTEL, "Hostel", "Places to stay temporarily or for the night."},
+       {NODE_AMENITY_ATM, "ATM", "Automatic Teller Machine/Cashpoint."},
+       {NODE_AMENITY_BANK, "Bank", "Place to take care of your money."},
+       {NODE_AMENITY_POST, "Post office", "Place to handle mail."},
+       {NODE_AMENITY_POST_BOX, "Post box", "Send letters."},
+       {NODE_AMENITY_TAXI, "Taxi station", "Get a Taxi here."},
+       {NODE_AMENITY_RAILWAY_STATION, "Railway station", "Transportation by train."},
+       {NODE_AMENITY_RAILWAY_HALT, "Railway halt", ""},
+       {NODE_AMENITY_BUS_STATION, "Bus station", "Transportation by bus."},
+       {NODE_AMENITY_BOAT, "Harbour", "Transportation by boat."},
+       {NODE_AMENITY_AIRPORT, "Airport", "Transportation by air."},
+       {NODE_AMENITY_FOOD, "Restaurant, Fast food", "Places to eat or drink."},
+       {NODE_AMENITY_PUB, "Pub, Disco, Club", "Place to drink and party."},
+       {NODE_AMENITY_CINEMA, "Cinema", "Place to see movies"},
+       {NODE_AMENITY_THEATRE, "Theatre", "Place to see people performing"},
+       {NODE_AMENITY_SHOP, "Shopping", "Places to shop or acquire services."},
+       {NODE_AMENITY_POW, "Place of Worchip", ""},
+       {NODE_AMENITY_COLLEGE, "College Campus/Building", ""},
+       {NODE_AMENITY_SCHOOL, "School", ""},
+       {NODE_AMENITY_GENERIC, "Other", "Miscellaneous category for everything else."},
+       {NODE_POI_END, NULL, NULL }
+};
+
+gboolean
+poi_cb_populate_categories(sqlite3 *db)
+{
+sqlite3_stmt *sql_cat;
+gint i;
+
+g_printf("Checking default categories...");
+sqlite3_prepare(db,"insert into category (cat_id, label, desc, enabled)"
+                       " values (?, ?, ?, 1)", 
+                       -1, &sql_cat, NULL);
+
+for (i=0; default_poi_categories[i].name; i++) {
+       sqlite3_bind_int(sql_cat, 1, default_poi_categories[i].type);
+       sqlite3_bind_text(sql_cat, 2, default_poi_categories[i].name , -1, SQLITE_TRANSIENT);
+       sqlite3_bind_text(sql_cat, 3, default_poi_categories[i].desc , -1, SQLITE_TRANSIENT);
+       sqlite3_step(sql_cat);
+       sqlite3_reset(sql_cat);
+       sqlite3_clear_bindings(sql_cat);
+}
+
+sqlite3_finalize(sql_cat);
+
+return TRUE;
+}
+
 gboolean
 poi_db_create(sqlite3 *db)
 {
@@ -55,72 +115,28 @@ poi_db_create(sqlite3 *db)
 
                g_printf("Creating initial tables\n");
 
-               create_sql =
-                   sqlite3_mprintf
-                   ("create table poi (poi_id integer PRIMARY KEY, "
+               create_sql = sqlite3_mprintf
+                   ("create table poi "
+                       "(poi_id integer PRIMARY KEY, "
                        "lat real, "
                        "lon real, "
                        "elev real, "
                        "label text, "
                        "desc text, "
                        "public integer, "
+                       "source integer default 0, "
+                       "osm_id integer default 0, "
+                       "priority integer default 2, "
                        "cat_id integer);"
                     "create table category (cat_id integer PRIMARY KEY,"
                        "label text, "
                        "desc text, "
                        "icon text, "
                        "color char(7), "
-                       "enabled integer);"
-                    /* Add some default categories... */
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); "
-                    "insert into category (label, desc, enabled) "
-                    "values ('%q', '%q', 1); ",
-                    _("Fuel"),
-                    _("Stations for purchasing fuel for vehicles."),
-                    _("Residence"),
-                    _("Houses, apartments, or other residences of import."),
-                    _("Dining"),
-                    _("Places to eat or drink."),
-                    _("Shopping/Services"),
-                    _("Places to shop or acquire services."),
-                    _("Recreation"),
-                    _("Indoor or Outdoor places to have fun."),
-                    _("Transportation"),
-                    _("Bus stops, airports, train stations, etc."),
-                    _("Lodging"),
-                    _("Places to stay temporarily or for the night."),
-                    _("School"),
-                    _("Elementary schools, college campuses, etc."),
-                    _("Business"),
-                    _("General places of business."),
-                    _("Landmark"),
-                    _("General landmarks."),
-                    _("Other"),
-                    _("Miscellaneous category for everything else."));
+                       "enabled integer);");
 
-               if (SQLITE_OK !=
-                   sqlite3_exec(db, create_sql, NULL, NULL, &perror)
-                   && (SQLITE_OK !=
-                       sqlite3_get_table(db, "select label from poi limit 1",
+               if (SQLITE_OK != sqlite3_exec(db, create_sql, NULL, NULL, NULL)
+                   && (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
                                          &pszResult, &nRow, &nColumn, NULL))) {
                        g_printf("%s:\n%s",_("Failed to open or create database"),sqlite3_errmsg(db));
                        sqlite3_close(db);
@@ -130,6 +146,8 @@ poi_db_create(sqlite3 *db)
        } else
                sqlite3_free_table(pszResult);
 
+       /* Make sure default categories exists */
+       poi_cb_populate_categories(db);
        return TRUE;
 }
 
@@ -162,8 +180,7 @@ poi_db_prepare(sqlite3 *db)
                        "insert into poi (lat, lon, label, desc, cat_id, public)"
                        " values (?, ?, ?, ?, ?, 1)", -1, &_stmt_insert_poi, NULL);
        /* update poi */
-       sqlite3_prepare(db,
-                       "update poi set label = ?, desc = ?, "
+       sqlite3_prepare(db, "update poi set label = ?, desc = ?, "
                        "cat_id = ? where poi_id = ?",
                        -1, &_stmt_update_poi, NULL);
        /* delete from poi */
@@ -252,6 +269,7 @@ if (cat_id > 0) {
                        results = FALSE;
                }
                sqlite3_reset(_stmt_update_cat);
+               sqlite3_clear_bindings(_stmt_update_cat);
        } else {
                /* add category */
                if (SQLITE_OK !=
@@ -265,6 +283,7 @@ if (cat_id > 0) {
                        results = FALSE;
                }
                sqlite3_reset(_stmt_insert_cat);
+               sqlite3_clear_bindings(_stmt_insert_cat);
        }
 return results;
 }