#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;
}
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;
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")));
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;
}
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);
" 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,"
" 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)"
{
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;
}
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)
{