From: Kaj-Michael Lang Date: Sun, 22 Jul 2007 16:00:13 +0000 (+0300) Subject: Move more poi db handling from cb.c to poi.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d08382319d2030702646cab4e46c5960811f26ea;p=mapper Move more poi db handling from cb.c to poi.c Remove table def comments, they are in docs now. --- diff --git a/src/cb.c b/src/cb.c index e8dce37..576540a 100644 --- a/src/cb.c +++ b/src/cb.c @@ -268,9 +268,7 @@ gboolean menu_cb_show_velvec(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); - _show_velvec = - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM - (_menu_show_velvec_item)); + _show_velvec = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_velvec_item)); map_move_mark(); vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); @@ -281,9 +279,7 @@ gboolean menu_cb_show_poi(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); - _show_poi = - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM - (_menu_show_poi_item)); + _show_poi = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_show_poi_item)); map_force_redraw(); vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); @@ -294,9 +290,7 @@ gboolean menu_cb_gps_show_info(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); - _gps_info = - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM - (_menu_gps_show_info_item)); + _gps_info = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(_menu_gps_show_info_item)); gps_show_info(); @@ -425,8 +419,7 @@ gboolean menu_cb_goto_latlon(GtkAction * action) latlon2unit(lat, lon, unitx, unity); if (_center_mode > 0) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM - (_menu_ac_none_item), - TRUE); + (_menu_ac_none_item), TRUE); map_center_unit(unitx, unity); break; } @@ -489,50 +482,42 @@ gboolean menu_cb_goto_nextway(GtkAction * action) gboolean menu_cb_goto_nearpoi(GtkAction * action) { - printf("%s()\n", __PRETTY_FUNCTION__); +gdouble lat, lon; +PoiInfo *p; - if (_db) { - gfloat lat, lon; +printf("%s()\n", __PRETTY_FUNCTION__); - if (_center_mode > 0) { - /* Auto-Center is enabled - use the GPS position. */ - unit2latlon(_pos.unitx, _pos.unity, lat, lon); - } else { - /* Auto-Center is disabled - use the view center. */ - unit2latlon(_center.unitx, _center.unity, lat, lon); - } +if (_center_mode > 0) { + /* Auto-Center is enabled - use the GPS position. */ + unit2latlon(_pos.unitx, _pos.unity, lat, lon); +} else { + /* Auto-Center is disabled - use the view center. */ + unit2latlon(_center.unitx, _center.unity, lat, lon); +} - 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)) { - guint unitx, unity; - gchar *banner; - const gchar *poi_label, *cat_label; +p=poi_find_nearest(lat, lon); - lat = sqlite3_column_double(_stmt_select_nearest_poi, 0); - 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); +if (p) { + guint unitx, unity; + gchar *banner; - latlon2unit(lat, lon, unitx, unity); - banner = g_strdup_printf("%s (%s)", poi_label, cat_label); - MACRO_BANNER_SHOW_INFO(_window, banner); - g_free(banner); + latlon2unit(p->lat, p->lon, unitx, unity); + banner = g_strdup_printf("%s (%s)", p->label, p->cat_label); + g_printf("%s\n", banner); + MACRO_BANNER_SHOW_INFO(_window, banner); + g_free(banner); + poi_free(p); - if (_center_mode > 0) - gtk_check_menu_item_set_active - (GTK_CHECK_MENU_ITEM(_menu_ac_none_item), - TRUE); + if (_center_mode > 0) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(_menu_ac_none_item), TRUE); - map_center_unit(unitx, unity); - } else { - MACRO_BANNER_SHOW_INFO(_window, _("No POIs found.")); - } - sqlite3_reset(_stmt_select_nearest_poi); - } + map_center_unit(unitx, unity); +} else { + MACRO_BANNER_SHOW_INFO(_window, _("No POIs found.")); +} - vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); - return TRUE; +vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); +return TRUE; } gboolean menu_cb_maps_repoman(GtkAction * action) @@ -1360,8 +1345,7 @@ gboolean cmenu_cb_way_delete(GtkAction * action) snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of waypoint"), way->desc); - confirm = - hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); + confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { Point *pdel_min, *pdel_max, *pdel_start, *pdel_end; diff --git a/src/poi.c b/src/poi.c index ff1fd90..fb21849 100644 --- a/src/poi.c +++ b/src/poi.c @@ -274,12 +274,28 @@ if (db_connect(db, poi_db)) { return FALSE; } +PoiInfo * +poi_new(void) +{ +PoiInfo *p; + +return g_slice_new0(PoiInfo); +} + +void +poi_free(PoiInfo *p) +{ +g_slice_free(PoiInfo, p); +} + gboolean -poi_category_update(gint cat_id, gchar * cat_label, gchar * cat_desc, - gint cat_enabled) +poi_category_update(gint cat_id, gchar *cat_label, gchar *cat_desc, gint cat_enabled) { gboolean results=TRUE; +if (!_db) + return FALSE; + if (cat_id > 0) { /* edit category */ if (SQLITE_OK != @@ -317,6 +333,9 @@ return results; gboolean 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); @@ -339,6 +358,9 @@ return TRUE; gboolean 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); @@ -360,6 +382,9 @@ GtkTreeIter iter; gchar tmp1[16], tmp2[16]; gint num_cats=0; +if (!_db) + return FALSE; + store = gtk_list_store_new(POI_NUM_COLUMNS, G_TYPE_INT, /* POI ID */ G_TYPE_INT, /* Category ID */ G_TYPE_FLOAT, /* Latitude */ @@ -422,6 +447,9 @@ return TRUE; gboolean 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) @@ -437,6 +465,9 @@ return TRUE; gboolean 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) @@ -450,3 +481,32 @@ sqlite3_clear_bindings(_stmt_insert_poi); return TRUE; } +PoiInfo * +poi_find_nearest(gdouble lat, gdouble lon) +{ +const gchar *_poi_label, *_cat_label; +PoiInfo *p; + +if (!_db) + return FALSE; + +sqlite3_reset(_stmt_select_nearest_poi); +sqlite3_clear_bindings(_stmt_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)) { + + 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->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); + return p; +} +return NULL; +} diff --git a/src/poi.h b/src/poi.h index 35e73be..485cfc5 100644 --- a/src/poi.h +++ b/src/poi.h @@ -1,67 +1,8 @@ /* - -POI table definitions: - --- public POIs from different sources --- (Fuel, pubs, museums, etc) --- -create table poi ( - poi_id integer PRIMARY KEY, - cat_id integer, - source int, - source_id int, - type int, - lat real, - lon real, - elev real, - label text, - desc text, - wikipedia text, - url text, - phone varchar(64), - email varchar(64), -); - --- type: --- 0=POI --- 1=Landmark - --- Shared categories for POIs and landmarks -create table category ( - cat_id integer PRIMARY KEY, - pcat_id int, - priority int, - label text, - desc text, - color char(6), - icon varchar(32), - enabled integer -); - -Categories: -Fuel - - Esso, Teboil, BP, Nest, etc -Parking -Residence -Dining - - Restaurant -Fast food -Shopping/Services -Recreation -Transportation - - Bus - - Train - - Boat/Ferry - - Plane -Lodging - - Hotell - - Motell -School -Business -Landmark -Other - -*/ + * POI definitions + * + * See docs for table definitions. + */ #ifndef _MAPPER_POI_H #define _MAPPER_POI_H @@ -97,6 +38,8 @@ struct _PoiInfo { gfloat lon; gchar *label; gchar *desc; + gchar *cat_label; + gchar *cat_desc; }; /** Data used during action: add or edit category/poi **/ @@ -132,6 +75,7 @@ gboolean poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar gboolean poi_delete(DeletePOI * dpoi); gboolean poi_category_delete(DeletePOI * dpoi); gboolean poi_category_update(gint cat_id, gchar * cat_label, gchar * cat_desc, gint cat_enabled); +PoiInfo *poi_find_nearest(gdouble lat, gdouble lon); #endif