From: Kaj-Michael Lang Date: Wed, 31 Oct 2007 13:12:36 +0000 (+0200) Subject: Use generic search interface X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39526c15f744750583a8ec014a3dc29ea75e7648;p=mapper Use generic search interface --- diff --git a/src/Makefile.am b/src/Makefile.am index 9a21f56..8ceb777 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,6 +74,7 @@ mapper_SOURCES = utils.c \ speak.c \ audio-note.c \ help.c \ + search.c \ mapper.c osm2db_CFLAGS = $(EXPAT_CFLAGS) $(SQLITE_CFLAGS) $(GLIBGTK_CFLAGS) diff --git a/src/cb.c b/src/cb.c index 1c34384..01fe720 100644 --- a/src/cb.c +++ b/src/cb.c @@ -35,6 +35,7 @@ #include "poi-gui.h" #include "gps-panels.h" #include "gps-conn.h" +#include "search.h" #include "help.h" gboolean @@ -989,7 +990,7 @@ gdouble lat, lon; unit2latlon(_center.unitx, _center.unity, lat, lon); -poi_search_dialog(NULL, &poi, lat, lon); +mapper_search_dialog(SEARCH_TYPE_POI, lat, lon); return TRUE; } @@ -1016,6 +1017,16 @@ else return TRUE; } +gboolean +menu_cb_search_address(GtkAction *action) +{ +gdouble lat, lon; + +unit2latlon(_center.unitx, _center.unity, lat, lon); +mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon); +return TRUE; +} + gboolean cmenu_cb_loc_set_home(GtkAction * action) { diff --git a/src/cb.h b/src/cb.h index 53c2105..89beba7 100644 --- a/src/cb.h +++ b/src/cb.h @@ -88,6 +88,7 @@ gboolean cmenu_cb_loc_set_destination(GtkAction *action); gboolean cb_poi_add(GtkAction * action); gboolean cb_poi_search(GtkAction *action); +gboolean menu_cb_search_address(GtkAction *action); /* Callbacks for the "Waypoint" context menu. */ gboolean cmenu_cb_way_show_latlon(GtkAction * action); diff --git a/src/mapper-types.h b/src/mapper-types.h index 5e005ac..5ebd7d9 100644 --- a/src/mapper-types.h +++ b/src/mapper-types.h @@ -8,6 +8,20 @@ #ifndef _MAPPER_TYPES_H #define _MAPPER_TYPES_H +/** Generic search item list indexes */ +typedef enum { + ITEM_ID, + ITEM_CATID, + ITEM_LAT, + ITEM_LON, + ITEM_DIST, + ITEM_LATLON, + ITEM_LABEL, + ITEM_DESC, + ITEM_CATLAB, + ITEM_NUM_COLUMNS +} item_list_id; + /** This enumerated type defines the supported types of repositories. */ typedef enum { REPOTYPE_NONE, /* No URL set. */ @@ -68,19 +82,6 @@ typedef enum { CAT_NUM_COLUMNS } CategoryList; -/** POI list **/ -typedef enum { - POI_POIID, - POI_CATID, - POI_LAT, - POI_LON, - POI_LATLON, - POI_LABEL, - POI_DESC, - POI_CATLAB, - POI_NUM_COLUMNS -} POIList; - /** This enum defines the possible units we can use. */ typedef enum { UNITS_KM, diff --git a/src/osm-db.h b/src/osm-db.h index 2f9a072..9a3292e 100644 --- a/src/osm-db.h +++ b/src/osm-db.h @@ -32,6 +32,8 @@ void osm_deinit(void); void osm_set_way_range_from_speed(gfloat speed); void osm_set_way_range(guint sr); +gboolean osm_way_search(gdouble lat, gdouble lon, gchar *text, GtkListStore **store); + void osm_progress_set_widget(sqlite3 *db, GtkProgressBar *w); gboolean osm_db_prepare(sqlite3 *db); diff --git a/src/poi-gui.c b/src/poi-gui.c index 965caa8..cef63ac 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -128,7 +128,7 @@ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cmb), renderer, "text", 1, NULL); return cmb; } -static void +void poi_category_combo_populate(GtkWidget *cmb_category, guint cat_id, gboolean add_na) { GtkTreeIter active; @@ -501,8 +501,8 @@ model=gtk_tree_view_get_model(GTK_TREE_VIEW(sd->list)); if (!model) return TRUE; -gtk_tree_model_get(model, &iter, POI_LAT, &lat, -1); -gtk_tree_model_get(model, &iter, POI_LON, &lon, -1); +gtk_tree_model_get(model, &iter, ITEM_LAT, &lat, -1); +gtk_tree_model_get(model, &iter, ITEM_LON, &lon, -1); map_center_latlon(lat, lon); map_update_location_from_center(); @@ -527,8 +527,8 @@ if (!model) return TRUE; _dest.valid=TRUE; -gtk_tree_model_get(model, &iter, POI_LAT, &_dest.lat, -1); -gtk_tree_model_get(model, &iter, POI_LON, &_dest.lon, -1); +gtk_tree_model_get(model, &iter, ITEM_LAT, &_dest.lat, -1); +gtk_tree_model_get(model, &iter, ITEM_LON, &_dest.lon, -1); map_update_location_from_center(); @@ -596,20 +596,20 @@ gtk_container_add(GTK_CONTAINER(sw), sd.list); gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(sd.list)), GTK_SELECTION_SINGLE); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(sd.list), TRUE); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(sd.list), TRUE); -gtk_tree_view_set_search_column (GTK_TREE_VIEW(sd.list), POI_LABEL); +gtk_tree_view_set_search_column (GTK_TREE_VIEW(sd.list), ITEM_LABEL); renderer = gtk_cell_renderer_text_new(); -column = gtk_tree_view_column_new_with_attributes(_("Location"), renderer, "text", POI_LATLON, NULL); +column = gtk_tree_view_column_new_with_attributes(_("Location"), renderer, "text", ITEM_LATLON, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); renderer = gtk_cell_renderer_text_new(); -column = gtk_tree_view_column_new_with_attributes(_("Label"), renderer, "text", POI_LABEL, NULL); -gtk_tree_view_column_set_sort_column_id (column, POI_LABEL); +column = gtk_tree_view_column_new_with_attributes(_("Label"), renderer, "text", ITEM_LABEL, NULL); +gtk_tree_view_column_set_sort_column_id (column, ITEM_LABEL); gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); renderer = gtk_cell_renderer_text_new(); -column = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text", POI_CATLAB, NULL); -gtk_tree_view_column_set_sort_column_id (column, POI_CATLAB); +column = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text", ITEM_CATLAB, NULL); +gtk_tree_view_column_set_sort_column_id (column, ITEM_CATLAB); gtk_tree_view_append_column(GTK_TREE_VIEW(sd.list), column); g_signal_connect(G_OBJECT(btn_search), "clicked", G_CALLBACK(poi_search_do_cb), &sd); @@ -620,12 +620,12 @@ gtk_widget_show_all(sd.dialog); while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(sd.dialog))) { if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(sd.list)), NULL, &iter)) { - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_POIID, &(poi->poi_id), -1); - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_CATID, &(poi->cat_id), -1); - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LAT, &(poi->lat), -1); - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LON, &(poi->lon), -1); - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_LABEL, &(poi->label), -1); - gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, POI_DESC, &(poi->desc), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_ID, &(poi->poi_id), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_CATID, &(poi->cat_id), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_LAT, &(poi->lat), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_LON, &(poi->lon), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_LABEL, &(poi->label), -1); + gtk_tree_model_get(GTK_TREE_MODEL(sd.store), &iter, ITEM_DESC, &(poi->desc), -1); selected = TRUE; break; } else { @@ -658,12 +658,12 @@ case 1: gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, - POI_POIID, &(poi->poi_id), - POI_CATID, &(poi->cat_id), - POI_LAT, &(poi->lat), - POI_LON, &(poi->lon), - POI_LABEL, &(poi->label), - POI_DESC, &(poi->desc), -1); + ITEM_ID, &(poi->poi_id), + ITEM_CATID, &(poi->cat_id), + ITEM_LAT, &(poi->lat), + ITEM_LON, &(poi->lon), + ITEM_LABEL, &(poi->label), + ITEM_DESC, &(poi->desc), -1); g_object_unref(G_OBJECT(store)); return TRUE; break; diff --git a/src/poi-gui.h b/src/poi-gui.h index 8c1cc3b..5295762 100644 --- a/src/poi-gui.h +++ b/src/poi-gui.h @@ -29,10 +29,14 @@ #include "poi.h" gboolean poi_select(guint unitx, guint unity, poi_info *poi); -gboolean poi_category_dialog(guint cat_id); -gboolean poi_category_list(); gboolean poi_dialog(POIAction action, guint unitx, guint unity); gboolean poi_search_dialog(GtkListStore *store, poi_info *poi, gdouble lat, gdouble lon); gboolean poi_quick_dialog(guint unitx, guint unity); +gboolean poi_category_dialog(guint cat_id); +gboolean poi_category_list(); + +void poi_category_combo_populate(GtkWidget *cmb_category, guint cat_id, gboolean add_na); +GtkWidget *category_combo_new(void); + #endif diff --git a/src/poi.c b/src/poi.c index 8f61d61..5f41560 100644 --- a/src/poi.c +++ b/src/poi.c @@ -28,6 +28,7 @@ #include "db.h" #include "osm.h" #include "osm-db.h" +#include "latlon.h" static sqlite3 *poidb; @@ -531,34 +532,38 @@ switch (pst) { break; } -*store = gtk_list_store_new(POI_NUM_COLUMNS, +*store = gtk_list_store_new(ITEM_NUM_COLUMNS, G_TYPE_INT, /* POI ID */ G_TYPE_INT, /* Category ID */ G_TYPE_DOUBLE, /* Latitude */ G_TYPE_DOUBLE, /* Longitude */ + G_TYPE_DOUBLE, /* Distance */ G_TYPE_STRING, /* Lat/Lon */ G_TYPE_STRING, /* POI Label */ G_TYPE_STRING, /* POI Desc. */ G_TYPE_STRING); /* Category Label */ while (SQLITE_ROW == sqlite3_step(sql)) { - gdouble rlat, rlon; + gdouble rlat, rlon, dist; rlat=sqlite3_column_double(sql, 0); rlon=sqlite3_column_double(sql, 1); lat_format(rlat, tmp1); lon_format(rlon, tmp2); + dist=calculate_distance(lat, lon, rlat, rlon); + gtk_list_store_append(*store, &iter); gtk_list_store_set(*store, &iter, - POI_POIID, sqlite3_column_int(sql, 2), - POI_CATID, sqlite3_column_int(sql, 5), - POI_LAT, rlat, - POI_LON, rlon, - POI_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2), - POI_LABEL, sqlite3_column_text(sql, 3), - POI_DESC, sqlite3_column_text(sql, 4), - POI_CATLAB, sqlite3_column_text(sql, 6), + ITEM_ID, sqlite3_column_int(sql, 2), + ITEM_CATID, sqlite3_column_int(sql, 5), + ITEM_LAT, rlat, + ITEM_LON, rlon, + ITEM_DIST, dist, + ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2), + ITEM_LABEL, sqlite3_column_text(sql, 3), + ITEM_DESC, sqlite3_column_text(sql, 4), + ITEM_CATLAB, sqlite3_column_text(sql, 6), -1); rows++; } @@ -602,18 +607,19 @@ if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) || return FALSE; } -*store = gtk_list_store_new(POI_NUM_COLUMNS, +*store = gtk_list_store_new(ITEM_NUM_COLUMNS, G_TYPE_INT, /* POI ID */ G_TYPE_INT, /* Category ID */ G_TYPE_DOUBLE, /* Latitude */ G_TYPE_DOUBLE, /* Longitude */ + G_TYPE_DOUBLE, /* Dist */ G_TYPE_STRING, /* Lat/Lon */ - G_TYPE_STRING, /* POI Label */ - G_TYPE_STRING, /* POI Desc. */ + G_TYPE_STRING, /* Label */ + G_TYPE_STRING, /* Desc. */ G_TYPE_STRING); /* Category Label */ while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) { - gdouble lat, lon; + gdouble lat, lon, dist=0; lat = sqlite3_column_double(poisql.select_poi, 0); lon = sqlite3_column_double(poisql.select_poi, 1); @@ -622,14 +628,15 @@ while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) { gtk_list_store_append(*store, &iter); gtk_list_store_set(*store, &iter, - 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(poisql.select_poi, 3), - POI_DESC, sqlite3_column_text(poisql.select_poi, 4), - POI_CATLAB, sqlite3_column_text(poisql.select_poi, 6), + ITEM_ID, sqlite3_column_int(poisql.select_poi, 2), + ITEM_CATID, sqlite3_column_int(poisql.select_poi, 5), + ITEM_LAT, lat, + ITEM_LON, lon, + ITEM_DIST, dist, + ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2), + ITEM_LABEL, sqlite3_column_text(poisql.select_poi, 3), + ITEM_DESC, sqlite3_column_text(poisql.select_poi, 4), + ITEM_CATLAB, sqlite3_column_text(poisql.select_poi, 6), -1); num_cats++; } diff --git a/src/ui-common.c b/src/ui-common.c index 7310fda..10c639a 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -142,7 +142,7 @@ static const gchar *mapper_ui = " " " " " " -" " +" " " " " " " " @@ -168,16 +168,15 @@ static const gchar *mapper_ui = " " " " " " -" " " " -#if 0 -" " +" " " " -#endif " " " " +#ifdef WITH_DEVICE_770 " " " " +#endif " " " " ""; @@ -234,7 +233,7 @@ static GtkActionEntry ui_entries[] = { {"goto_home", GTK_STOCK_HOME, N_("_Home"), "H", NULL, G_CALLBACK(menu_cb_goto_home) }, {"goto_destination", GTK_STOCK_JUMP_TO, N_("_Destination"), "J", NULL, G_CALLBACK(menu_cb_goto_destination) }, {"goto_gps", NULL, N_("_GPS"), "G", NULL, G_CALLBACK(menu_cb_goto_gps) }, - {"goto_address", GTK_STOCK_FIND, N_("Address..."), NULL, NULL, NULL }, + {"search_address", GTK_STOCK_FIND, N_("Address..."), NULL, NULL, G_CALLBACK(menu_cb_search_address) }, {"goto_latlon", NULL, N_("Lat/Lon"), NULL, NULL, G_CALLBACK(menu_cb_goto_latlon) }, {"goto_nextway", NULL, N_("Next Waypoint"), NULL, NULL, G_CALLBACK(menu_cb_goto_nextway) }, {"goto_nearpoi", NULL, N_("Near POI"), NULL, NULL, G_CALLBACK(menu_cb_goto_nearpoi) },