]> err.no Git - mapper/commitdiff
More POI search work. Goto works.
authorKaj-Michael Lang <milang@onion.tal.org>
Mon, 29 Oct 2007 14:44:57 +0000 (16:44 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Mon, 29 Oct 2007 14:44:57 +0000 (16:44 +0200)
src/poi-gui.c
src/poi.c
src/poi.h

index 32dd858a566e2536b57cfb0c10dcc4d267b7ba04..15fc86ee3f267018d8426fa3acdb6012b2401931 100644 (file)
 
 #define POI_QUICK_BUTTONS (9)
 
+typedef struct _poi_search_query poi_search_query;
+struct _poi_search_query {
+       gdouble lat;
+       gdouble lon;
+       guint cat_id;
+       gchar *query;
+};
+
 typedef struct _PoiCategoryEditInfo PoiCategoryEditInfo;
 struct _PoiCategoryEditInfo {
        GtkWidget *cmb_category;
@@ -254,7 +262,7 @@ return results;
 }
 
 static void 
-category_toggled_cb(GtkCellRendererToggle * cell, gchar * path, gpointer data)
+category_toggled_cb(GtkCellRendererToggle *cell, gchar *path, gpointer data)
 {
 GtkTreeIter iter;
 gboolean cat_enabled;
@@ -329,7 +337,7 @@ dialog = gtk_dialog_new_with_buttons(_("POI Categories"),
                             GTK_DIALOG_MODAL, GTK_STOCK_OK,
                             GTK_RESPONSE_ACCEPT, NULL);
 
-       help_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT);
+help_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT);
 
 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_edit = gtk_button_new_with_label(_("Edit")));
 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_add = gtk_button_new_with_label(_("Add")));
@@ -425,6 +433,23 @@ return TRUE;
 static gboolean
 poi_goto_cb(GtkWidget *widget, gpointer data)
 {
+GtkTreeIter iter;
+gdouble lat, lon;
+GtkTreeView *tree=GTK_TREE_VIEW(data);
+GtkTreeModel *model = GTK_TREE_MODEL(data);
+
+if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), NULL, &iter))
+       return TRUE;
+
+model=gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
+if (!model)
+       return TRUE;
+
+gtk_tree_model_get(model, &iter, POI_LAT, &lat, -1);
+gtk_tree_model_get(model, &iter, POI_LON, &lon, -1);
+
+map_center_latlon(lat, lon);
+
 return TRUE;
 }
 
@@ -504,8 +529,8 @@ gtk_tree_view_column_set_sort_column_id (column, POI_CATLAB);
 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
 
 g_signal_connect(G_OBJECT(btn_search), "clicked", G_CALLBACK(poi_search_do_cb), NULL);
-g_signal_connect(G_OBJECT(btn_goto), "clicked", G_CALLBACK(poi_goto_cb), NULL);
-g_signal_connect(G_OBJECT(btn_route_to), "clicked", G_CALLBACK(poi_route_to_cb), NULL);
+g_signal_connect(G_OBJECT(btn_goto), "clicked", G_CALLBACK(poi_goto_cb), list);
+g_signal_connect(G_OBJECT(btn_route_to), "clicked", G_CALLBACK(poi_route_to_cb), list);
 
 gtk_widget_show_all(dialog);
 
index dc3afda0d2c49f681d24ba836f5ce567010869e9..a0d10b71a435df891e091af5af84a49ec1e80353 100644 (file)
--- a/src/poi.c
+++ b/src/poi.c
@@ -205,17 +205,6 @@ poi_db_prepare(sqlite3 *db)
                        " and c.enabled = 1 and p.cat_id = c.cat_id",
                        -1, &poisql.select_poi, NULL);
 
-       /* select nearest pois */
-       sqlite3_prepare_v2(db,
-                       "select p.lat, p.lon, p.label, c.label, c.icon, c.color"
-                       " from poi p, category c "
-                       " where c.enabled = 1 and p.cat_id = c.cat_id "
-                       " and p.lat between $LAT-0.10 and $LAT+0.10 "
-                       " 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, &poisql.select_nearest_poi, NULL);
-
        /* Search POI label */
        sqlite3_prepare_v2(db,
                        "select p.lat, p.lon, p.poi_id, p.label, p.desc,"
@@ -236,6 +225,17 @@ poi_db_prepare(sqlite3 *db)
                        " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? and c.cat_id = ? order by p.label",
                        -1, &poisql.select_poi_search_cat, NULL);
 
+       /* select nearest pois */
+       sqlite3_prepare_v2(db,
+                       "select p.lat, p.lon, p.label, c.label, c.icon, c.color"
+                       " from poi p, category c "
+                       " where c.enabled = 1 and p.cat_id = c.cat_id "
+                       " and p.lat between $LAT-0.10 and $LAT+0.10 "
+                       " 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, &poisql.select_nearest_poi, NULL);
+
        /* insert poi */
        sqlite3_prepare_v2(db,
                        "insert into poi (lat, lon, label, desc, cat_id, public)"
@@ -372,8 +372,7 @@ poi_category_get(guint 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)) {
+if (SQLITE_OK != sqlite3_bind_int(poisql.select_cat, 1, cat_id) || SQLITE_ROW != sqlite3_step(poisql.select_cat)) {
        sqlite3_reset(poisql.select_cat);
        return FALSE;
 }
@@ -461,6 +460,100 @@ sqlite3_clear_bindings(poisql.delete_poi);
 return TRUE;
 }
 
+gboolean
+poi_search(poi_search_type pst, gdouble lat, gdouble lon, gchar *text, guint cat, GtkListStore **store)
+{
+GtkTreeIter iter;
+sqlite3_stmt *sql;
+gchar *ltext=NULL;
+guint rows=0;
+gchar tmp1[16], tmp2[16];
+
+if (!_db)
+       return FALSE;
+
+switch (pst) {
+       case POI_SEARCH_NEAR:
+               if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat-0.5) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2, lat+0.5) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon-0.5) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon+0.5)) {
+                               g_printerr("Failed to bind values for poisql.select_poi\n");
+                               return FALSE;
+               }
+               sql=&poisql.select_poi;
+       break;
+       case POI_SEARCH_TEXT:
+               ltext=g_strdup_printf("%s%%", text);
+               
+               if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 1, lat-4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 2, lat+4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 3, lon-4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search, 4, lon+4) ||
+                       SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search,   5, ltext, -1, SQLITE_STATIC)) {
+                               g_printerr("Failed to bind values for poisql.select_poi_search\n");
+                               return FALSE;
+               }
+               sql=&poisql.select_poi_search;
+       break;
+       case POI_SEARCH_TEXT_CAT:
+               ltext=g_strdup_printf("%s%%", text);
+
+               if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 1, lat-4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 2, lat+4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 3, lon-4) ||
+                   SQLITE_OK != sqlite3_bind_double(poisql.select_poi_search_cat, 4, lon+4) ||
+                   SQLITE_OK != sqlite3_bind_int(poisql.select_poi_search_cat,    6, cat) ||
+                       SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search_cat,   5, ltext, -1, SQLITE_STATIC)) {
+                               g_printerr("Failed to bind values for poisql.select_poi_search_cat\n");
+                               return FALSE;
+               }
+               sql=&poisql.select_poi_search_cat;
+       break;
+       default:
+               g_assert_not_reached();
+               return FALSE;
+       break;
+}
+
+*store = gtk_list_store_new(POI_NUM_COLUMNS, 
+                               G_TYPE_INT,     /* POI ID */
+                               G_TYPE_INT,     /* Category ID */
+                               G_TYPE_DOUBLE,  /* Latitude */
+                               G_TYPE_DOUBLE,  /* Longitude */
+                               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;
+
+       rlat=sqlite3_column_double(sql, 0);
+       rlon=sqlite3_column_double(sql, 1);
+       lat_format(rlat, tmp1);
+       lon_format(rlon, tmp2);
+
+       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, lat, 
+               POI_LON, lon, 
+               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),
+               -1);
+       rows++;
+}
+sqlite3_reset(sql);
+sqlite3_clear_bindings(sql);
+if (ltext)
+       g_free(ltext);
+return TRUE;
+}
+
 gboolean
 poi_get_list_near(guint unitx, guint unity, GtkListStore **store, guint *_num_cats)
 {
index 80b8d83a038f3f2962ba8f13e16f0daafab92d71..5afc924bd2916da32f64418ace515341e267abcf 100644 (file)
--- a/src/poi.h
+++ b/src/poi.h
@@ -15,6 +15,12 @@ typedef enum {
        POI_TYPE_LANDMARK=1,
 } poi_types_e;
 
+typedef enum {
+       POI_SEARCH_NEAR=0,
+       POI_SEARCH_TEXT,
+       POI_SEARCH_TEXT_CAT,
+} poi_search_type;
+
 typedef struct _poi_db poi_db;
 struct _poi_db {
        sqlite3 *db;
@@ -86,6 +92,8 @@ gboolean poi_update(guint poi_id, guint cat_id, gchar *poi_label, gchar *poi_des
 gboolean poi_add(gdouble lat, gdouble lon, guint cat_id, gchar *poi_label, gchar *poi_desc);
 gboolean poi_delete(guint id);
 
+gboolean poi_search(poi_search_type pst, gdouble lat, gdouble lon, gchar *text, guint cat, GtkListStore **store);
+
 poi_category *poi_category_new(void);
 void poi_category_free(poi_category *c);
 gboolean poi_category_get(guint cat_id, poi_category **c);