]> err.no Git - mapper/commitdiff
Use generic search interface
authorKaj-Michael Lang <milang@onion.tal.org>
Wed, 31 Oct 2007 13:12:36 +0000 (15:12 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Wed, 31 Oct 2007 13:12:36 +0000 (15:12 +0200)
src/Makefile.am
src/cb.c
src/cb.h
src/mapper-types.h
src/osm-db.h
src/poi-gui.c
src/poi-gui.h
src/poi.c
src/ui-common.c

index 9a21f5634842b4712679f38e7b3e2c810964e6c4..8ceb777131df8a5835d8b90b25bbcb015212fcfe 100644 (file)
@@ -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)
index 1c34384b5d859408bbd7ab3c73ed3063044e6790..01fe720a3fb437cc2a2ed49f00a3c48408a6ce59 100644 (file)
--- 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)
 {
index 53c2105dabe00a554ffa6e8b49c147ee1a84203a..89beba777f551c1b74dc527a54839c60925a053f 100644 (file)
--- 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);
index 5e005ac4129864ae90557fa933a151b324cfeda1..5ebd7d923584ace182bb8449e641cd09cd168e23 100644 (file)
@@ -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,
index 2f9a0728e3acb63fd6ac64de8706c0399f29e4d7..9a3292e15ee6d004b91c019e546feed64acc1616 100644 (file)
@@ -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);
 
index 965caa8c2d5602b803dba2a9ac714e6c63a666b7..cef63ac24bef597a34ca4fd4006bdc0027e5f319 100644 (file)
@@ -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;
index 8c1cc3bb47b6621ead4e68393aa459ea550fbf4a..529576202ace45c893fb7bad00f988ec07586bf7 100644 (file)
 #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
index 8f61d619f048e2ce9cbaa8626c5588653db8b072..5f415607f99480abeb99db3c0c987c7748822cd9 100644 (file)
--- 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++;
 }
index 7310fda67bf9b16be6e62f9a58ec5e1f36688560..10c639a87c3bfc3236a629d437617fcbabc74dfb 100644 (file)
@@ -142,7 +142,7 @@ static const gchar *mapper_ui =
 "      <menuitem action='goto_destination'/>"
 "      <menuitem action='goto_gps'/>"
 "      <separator/>"
-"      <menuitem action='goto_address'/>"
+"      <menuitem action='search_address'/>"
 "      <menuitem action='goto_latlon'/>"
 "      <menuitem action='goto_nearpoi'/>"
 "      <menuitem action='goto_nextway'/>"
@@ -168,16 +168,15 @@ static const gchar *mapper_ui =
 "    <separator/>"
 "    <toolitem action='poi_add'/>"
 "    <toolitem action='poi_quick_add'/>"
-"    <toolitem action='poi_search'/>"
 "    <separator/>"
-#if 0
-"    <toolitem action='view_fullscreen'/>"
+"    <toolitem action='search_address'/>"
 "    <separator/>"
-#endif
 "    <toolitem action='view_zoom_in'/>"
 "    <toolitem action='view_zoom_out'/>"
+#ifdef WITH_DEVICE_770
 "    <toolitem action='view_zoom_normal'/>"
 "    <toolitem action='view_zoom_auto'/>"
+#endif
 "    <separator/>"
 "  </toolbar>"
 "</ui>";
@@ -234,7 +233,7 @@ static GtkActionEntry ui_entries[] = {
        {"goto_home", GTK_STOCK_HOME, N_("_Home"), "<control>H", NULL, G_CALLBACK(menu_cb_goto_home) },
        {"goto_destination", GTK_STOCK_JUMP_TO, N_("_Destination"), "<control>J", NULL, G_CALLBACK(menu_cb_goto_destination) },
        {"goto_gps", NULL, N_("_GPS"), "<control>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) },