#include "settings.h"
guint _poi_zoom = 6;
+gboolean select_poi(guint unitx, guint unity, PoiInfo * poi);
+
gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi)
{
gboolean select_poi(guint unitx, guint unity, PoiInfo * poi)
{
- guint x, y;
- gfloat lat1, lon1, lat2, lon2;
GtkWidget *dialog;
GtkWidget *list;
GtkWidget *sw;
GtkListStore *store;
GtkTreeIter iter;
gboolean selected = FALSE;
- gchar tmp1[16], tmp2[16];
- guint num_cats = 0;
+ guint num_cats;
printf("%s()\n", __PRETTY_FUNCTION__);
- x = unitx - pixel2unit(3 * _draw_width);
- y = unity + pixel2unit(3 * _draw_width);
- unit2latlon(x, y, lat1, lon1);
-
- x = unitx + pixel2unit(3 * _draw_width);
- y = unity - pixel2unit(3 * _draw_width);
- unit2latlon(x, y, lat2, lon2);
-
- store = gtk_list_store_new(POI_NUM_COLUMNS, G_TYPE_INT, /* POI ID */
- G_TYPE_INT, /* Category ID */
- G_TYPE_FLOAT, /* Latitude */
- G_TYPE_FLOAT, /* Longitude */
- G_TYPE_STRING, /* Lat/Lon */
- G_TYPE_STRING, /* POI Label */
- G_TYPE_STRING, /* POI Desc. */
- G_TYPE_STRING); /* Category Label */
-
- if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
- SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
- SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
- SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2)) {
- g_printerr("Failed to bind values for _stmt_select_poi");
+ if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE)
return FALSE;
- }
- while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
- gfloat lat, lon;
- lat = sqlite3_column_double(_stmt_select_poi, 0);
- lon = sqlite3_column_double(_stmt_select_poi, 1);
- printf("Found POI: %f, %f, %s, %s, %s\n",
- lat,
- lon,
- sqlite3_column_text(_stmt_select_poi, 3),
- sqlite3_column_text(_stmt_select_poi, 4),
- sqlite3_column_text(_stmt_select_poi, 6));
- lat_format(lat, tmp1);
- lon_format(lon, tmp2);
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- POI_POIID,
- sqlite3_column_int(_stmt_select_poi, 2),
- POI_CATID,
- sqlite3_column_int(_stmt_select_poi, 5),
- POI_LAT, lat, POI_LON, lon, POI_LATLON,
- g_strdup_printf("%s, %s", tmp1, tmp2),
- POI_LABEL,
- sqlite3_column_text(_stmt_select_poi, 3),
- POI_DESC,
- sqlite3_column_text(_stmt_select_poi, 4),
- POI_CATLAB,
- sqlite3_column_text(_stmt_select_poi, 6),
- -1);
- num_cats++;
- }
- sqlite3_reset(_stmt_select_poi);
+ g_printf("N: %d\n", num_cats);
switch (num_cats) {
case 0:
- g_object_unref(G_OBJECT(store));
MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
+ g_object_unref(G_OBJECT(store));
return FALSE;
- break;
+ break;
case 1:
- /* iter is still set to the most-recently added POI. */
+ 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_DESC, &(poi->desc), -1);
g_object_unref(G_OBJECT(store));
return TRUE;
- break;
+ break;
}
/* There are at least 2 matching POI's - let the user select one. */
sw, TRUE, TRUE, 0);
list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
- g_object_unref(G_OBJECT(store));
gtk_container_add(GTK_CONTAINER(sw), list);
+ g_object_unref(G_OBJECT(store));
gtk_tree_selection_set_mode(gtk_tree_view_get_selection
(GTK_TREE_VIEW(list)),
GTK_SELECTION_SINGLE);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), TRUE);
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (list), TRUE);
+ gtk_tree_view_set_search_column (GTK_TREE_VIEW (list), POI_LABEL);
renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("Location"), renderer,
+ column = gtk_tree_view_column_new_with_attributes(_("Location"), renderer,
"text", POI_LATLON, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("Label"), renderer,
+ 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);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("Category"), renderer,
+ 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);
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
gtk_widget_show_all(dialog);
while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- if (gtk_tree_selection_get_selected
- (gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), NULL,
- &iter)) {
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_POIID, &(poi->poi_id), -1);
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_CATID, &(poi->cat_id), -1);
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_LATLON, &(poi->lat), -1);
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_LATLON, &(poi->lon), -1);
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_LABEL, &(poi->label), -1);
- gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
- POI_DESC, &(poi->desc), -1);
+ if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), NULL, &iter)) {
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_POIID, &(poi->poi_id), -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_CATID, &(poi->cat_id), -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LAT, &(poi->lat), -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LON, &(poi->lon), -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_LABEL, &(poi->label), -1);
+ gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, POI_DESC, &(poi->desc), -1);
selected = TRUE;
break;
- } else
+ } else {
popup_error(dialog, _("Select one POI from the list."));
+ }
}
gtk_widget_destroy(dialog);
gboolean has_active = FALSE;
printf("%s()\n", __PRETTY_FUNCTION__);
- store =
- GTK_LIST_STORE(gtk_combo_box_get_model
+ store = GTK_LIST_STORE(gtk_combo_box_get_model
(GTK_COMBO_BOX(cmb_category)));
gtk_list_store_clear(store);
#include "db.h"
#include "osm.h"
+struct sql_poi_stmt {
+ sqlite3_stmt *_stmt_select_poi;
+ sqlite3_stmt *_stmt_select_nearest_poi;
+ sqlite3_stmt *_stmt_insert_poi;
+ sqlite3_stmt *_stmt_update_poi;
+ sqlite3_stmt *_stmt_delete_poi;
+ sqlite3_stmt *_stmt_delete_poi_by_catid;
+ sqlite3_stmt *_stmt_nextlabel_poi;
+ sqlite3_stmt *_stmt_select_cat;
+ sqlite3_stmt *_stmt_insert_cat;
+ sqlite3_stmt *_stmt_update_cat;
+ sqlite3_stmt *_stmt_delete_cat;
+ sqlite3_stmt *_stmt_toggle_cat;
+ sqlite3_stmt *_stmt_selall_cat;
+};
+static struct sql_poi_stmt poisql;
+
sqlite3_stmt *_stmt_select_poi = NULL;
sqlite3_stmt *_stmt_select_nearest_poi = NULL;
sqlite3_stmt *_stmt_insert_poi = NULL;
}
gboolean
-poi_category_delete(DeletePOI * dpoi)
+poi_category_delete(DeletePOI *dpoi)
{
if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id)
|| SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid)) {
gboolean
-poi_delete(DeletePOI * dpoi)
+poi_delete(DeletePOI *dpoi)
{
if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
SQLITE_DONE != sqlite3_step(_stmt_delete_poi)) {
return TRUE;
}
+gboolean
+poi_get_list(guint unitx, guint unity, GtkListStore **_store, guint *_num_cats)
+{
+guint x, y;
+gfloat lat1, lon1, lat2, lon2;
+GtkListStore *store;
+GtkTreeIter iter;
+gchar tmp1[16], tmp2[16];
+gint num_cats=0;
+
+store = gtk_list_store_new(POI_NUM_COLUMNS, G_TYPE_INT, /* POI ID */
+ G_TYPE_INT, /* Category ID */
+ G_TYPE_FLOAT, /* Latitude */
+ G_TYPE_FLOAT, /* Longitude */
+ G_TYPE_STRING, /* Lat/Lon */
+ G_TYPE_STRING, /* POI Label */
+ G_TYPE_STRING, /* POI Desc. */
+ G_TYPE_STRING); /* Category Label */
+
+x = unitx - pixel2unit(3 * _draw_width);
+y = unity + pixel2unit(3 * _draw_width);
+unit2latlon(x, y, lat1, lon1);
+
+x = unitx + pixel2unit(3 * _draw_width);
+y = unity - pixel2unit(3 * _draw_width);
+unit2latlon(x, y, lat2, lon2);
+
+if (SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
+ SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
+ SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
+ SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2)) {
+ g_printerr("Failed to bind values for _stmt_select_poi\n");
+ return FALSE;
+}
+
+while (SQLITE_ROW == sqlite3_step(_stmt_select_poi)) {
+ gfloat lat, lon;
+ lat = sqlite3_column_double(_stmt_select_poi, 0);
+ lon = sqlite3_column_double(_stmt_select_poi, 1);
+ g_printf("Found POI(%d): %f, %f, %s, %s, %s\n",
+ num_cats,
+ lat,
+ lon,
+ sqlite3_column_text(_stmt_select_poi, 3),
+ sqlite3_column_text(_stmt_select_poi, 4),
+ sqlite3_column_text(_stmt_select_poi, 6));
+
+ lat_format(lat, tmp1);
+ lon_format(lon, tmp2);
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ POI_POIID, sqlite3_column_int(_stmt_select_poi, 2),
+ POI_CATID, sqlite3_column_int(_stmt_select_poi, 5),
+ POI_LAT, lat, POI_LON, lon, POI_LATLON,
+ g_strdup_printf("%s, %s", tmp1, tmp2),
+ POI_LABEL, sqlite3_column_text(_stmt_select_poi, 3),
+ POI_DESC, sqlite3_column_text(_stmt_select_poi, 4),
+ POI_CATLAB, sqlite3_column_text(_stmt_select_poi, 6),
+ -1);
+ num_cats++;
+}
+g_printf("N: %d\n", num_cats);
+sqlite3_reset(_stmt_select_poi);
+sqlite3_clear_bindings(_stmt_select_poi);
+*_store=store;
+*_num_cats=num_cats;
+return TRUE;
+}
+
gboolean
poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc)
{