#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <fcntl.h>
-
#include <libintl.h>
#include <locale.h>
-#include <sqlite3.h>
-
#include "utils.h"
#include "poi.h"
#include "gps.h"
#include "ui-common.h"
#include "settings.h"
+#define POI_QUICK_BUTTONS (9)
+
guint _poi_zoom = 6;
-gboolean select_poi(guint unitx, guint unity, PoiInfo * poi);
+gboolean select_poi(guint unitx, guint unity, PoiInfo *poi);
-gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi)
+gboolean category_delete(GtkWidget * widget, DeletePOI *dpoi)
{
GtkWidget *dialog;
guint i;
gboolean category_dialog(guint cat_id)
{
- gchar *cat_label = NULL, *cat_desc = NULL;
- guint cat_enabled;
GtkWidget *dialog;
GtkWidget *table;
GtkWidget *label;
GtkTextIter begin, end;
gboolean results = TRUE;
DeletePOI dpoi = { NULL, NULL, 0 };
+ poi_category *c;
+
printf("%s()\n", __PRETTY_FUNCTION__);
if (cat_id > 0) {
- if (SQLITE_OK != sqlite3_bind_double(_stmt_select_cat, 1, cat_id)
- || SQLITE_ROW != sqlite3_step(_stmt_select_cat)) {
- vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
- sqlite3_reset(_stmt_select_cat);
+ if (poi_category_get(cat_id, &c)==FALSE)
return FALSE;
- }
-
- cat_label = g_strdup(sqlite3_column_text(_stmt_select_cat, 0));
- cat_desc = g_strdup(sqlite3_column_text(_stmt_select_cat, 1));
- cat_enabled = sqlite3_column_int(_stmt_select_cat, 2);
-
- sqlite3_reset(_stmt_select_cat);
dialog = gtk_dialog_new_with_buttons(_("Edit Category"),
GTK_WINDOW(_window),
gtk_container_add(GTK_CONTAINER
(GTK_DIALOG(dialog)->action_area),
- btn_delete =
- gtk_button_new_with_label(_("Delete")));
+ btn_delete = gtk_button_new_with_label(_("Delete")));
dpoi.dialog = dialog;
- dpoi.txt_label = g_strdup(cat_label);
- dpoi.id = cat_id;
+ dpoi.txt_label = g_strdup(c->label);
+ dpoi.id = c->id;
- g_signal_connect(G_OBJECT(btn_delete), "clicked",
- G_CALLBACK(category_delete), &dpoi);
+ g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(category_delete), &dpoi);
- gtk_dialog_add_button(GTK_DIALOG(dialog),
- GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
} else {
- cat_enabled = 1;
- cat_label = g_strdup("");
- cat_id = 0;
- cat_desc = g_strdup("");
+ c=poi_category_new();
+ c->enabled = 1;
+ c->label = g_strdup("");
+ c->id = 0;
+ c->desc = g_strdup("");
dialog = gtk_dialog_new_with_buttons(_("Add Category"),
GTK_WINDOW(_window),
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
- gtk_table_attach(GTK_TABLE(table),
- label = gtk_label_new(_("Label")),
+ gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")),
0, 1, 0, 1, GTK_FILL, 0, 2, 4);
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
gtk_table_attach(GTK_TABLE(table),
txt_label = gtk_entry_new(),
1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
- gtk_table_attach(GTK_TABLE(table),
- label = gtk_label_new(_("Description")),
+ gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")),
0, 1, 1, 2, GTK_FILL, 0, 2, 4);
gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
txt_scroll = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
- GTK_SHADOW_IN);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll), GTK_SHADOW_IN);
gtk_table_attach(GTK_TABLE(table),
- txt_scroll,
- 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
+ txt_scroll, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
GTK_POLICY_AUTOMATIC,
desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
gtk_table_attach(GTK_TABLE(table),
- chk_enabled =
- gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2,
+ chk_enabled = gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2,
3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
/* label */
- gtk_entry_set_text(GTK_ENTRY(txt_label), cat_label);
+ gtk_entry_set_text(GTK_ENTRY(txt_label), c->label);
/* desc */
- gtk_text_buffer_set_text(desc_txt, cat_desc, -1);
+ gtk_text_buffer_set_text(desc_txt, c->desc, -1);
/* enabled */
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled),
- (cat_enabled == 1 ? TRUE : FALSE));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled), (c->enabled == 1 ? TRUE : FALSE));
- g_free(cat_label);
- cat_label = NULL;
- g_free(cat_desc);
- cat_desc = NULL;
+ poi_category_free(c);
gtk_widget_show_all(dialog);
while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
- cat_label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
- else {
- popup_error(dialog,
- _("Please specify a name for the category."));
+ if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) {
+ c=poi_category_new();
+ c->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
+ } else {
+ popup_error(dialog,_("Please specify a name for the category."));
continue;
}
gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0);
gtk_text_buffer_get_end_iter(desc_txt, &end);
- cat_desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
-
- cat_enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
-
- if (cat_id > 0) {
- /* edit category */
- if (SQLITE_OK !=
- sqlite3_bind_text(_stmt_update_cat, 1, cat_label,
- -1, g_free)
- || SQLITE_OK != sqlite3_bind_text(_stmt_update_cat,
- 2, cat_desc, -1,
- g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat,
- 3, cat_enabled)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat,
- 4, cat_id)
- || SQLITE_DONE != sqlite3_step(_stmt_update_cat)) {
- MACRO_BANNER_SHOW_INFO(_window,
- _("Problem updating category"));
- results = FALSE;
- }
- sqlite3_reset(_stmt_update_cat);
- } else {
- /* add category */
- if (SQLITE_OK !=
- sqlite3_bind_text(_stmt_insert_cat, 1, cat_label,
- -1, g_free)
- || SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat,
- 2, cat_desc, -1,
- g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat,
- 3, cat_enabled)
- || SQLITE_DONE != sqlite3_step(_stmt_insert_cat)) {
- MACRO_BANNER_SHOW_INFO(_window,
- _("Problem adding category"));
- results = FALSE;
- }
- sqlite3_reset(_stmt_insert_cat);
- }
- break;
+ c->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
+ c->enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
+
+ results=poi_category_update(cat_id, c);
+
+ if (results==FALSE)
+ MACRO_BANNER_SHOW_INFO(_window, _("Problem updating category"));
+ poi_category_free(c);
}
g_free(dpoi.txt_label);
-
g_object_unref(desc_txt);
-
gtk_widget_hide_all(dialog);
vprintf("%s(): return\n", __PRETTY_FUNCTION__);
cat_enabled ^= 1;
- if (SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 1, cat_enabled) ||
- SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 2, cat_id) ||
- SQLITE_DONE != sqlite3_step(_stmt_toggle_cat)) {
+ if (poi_category_toggle(cat_id, cat_enabled)==FALSE) {
MACRO_BANNER_SHOW_INFO(_window, _("Problem updating Category"));
- } else
- gtk_list_store_set(GTK_LIST_STORE(model), &iter,
- CAT_ENABLED, cat_enabled, -1);
-
- sqlite3_reset(_stmt_toggle_cat);
-
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
-}
-
-static GtkListStore *
-category_generate_store()
-{
- GtkTreeIter iter;
- GtkListStore *store;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- store = gtk_list_store_new(CAT_NUM_COLUMNS,
- G_TYPE_UINT,
- G_TYPE_BOOLEAN,
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
-
- while (SQLITE_ROW == sqlite3_step(_stmt_selall_cat)) {
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- CAT_ID, sqlite3_column_int(_stmt_selall_cat, 0),
- CAT_ENABLED, sqlite3_column_int(_stmt_selall_cat, 3),
- CAT_LABEL, sqlite3_column_text(_stmt_selall_cat, 1),
- CAT_DESC, sqlite3_column_text(_stmt_selall_cat, 2),
- CAT_POI_CNT, sqlite3_column_int(_stmt_selall_cat, 6), -1);
+ } else {
+ gtk_list_store_set(GTK_LIST_STORE(model), &iter, CAT_ENABLED, cat_enabled, -1);
}
- sqlite3_reset(_stmt_selall_cat);
- vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
- return store;
+ vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
}
gboolean
printf("%s()\n", __PRETTY_FUNCTION__);
if (category_dialog(0)) {
- store = category_generate_store();
+ store = poi_category_generate_store();
gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
GTK_TREE_MODEL(store));
g_object_unref(G_OBJECT(store));
memset(&val, 0, sizeof(val));
gtk_tree_model_get_value(store, &iter, 0, &val);
if (category_dialog(g_value_get_uint(&val))) {
- GtkListStore *new_store = category_generate_store();
+ GtkListStore *new_store = poi_category_generate_store();
gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
GTK_TREE_MODEL(new_store));
g_object_unref(G_OBJECT(new_store));
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
btn_add = gtk_button_new_with_label(_("Add")));
- store = category_generate_store();
+ store = poi_category_generate_store();
if (!store)
return TRUE;
return TRUE;
}
-gboolean poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
+gboolean
+poi_delete_confirm(GtkWidget * widget, DeletePOI * dpoi)
{
GtkWidget *dialog;
guint i;
return TRUE;
}
-gboolean select_poi(guint unitx, guint unity, PoiInfo * poi)
+gboolean
+select_poi(guint unitx, guint unity, PoiInfo *poi)
{
GtkWidget *dialog;
GtkWidget *list;
if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE)
return FALSE;
- g_printf("N: %d\n", num_cats);
-
switch (num_cats) {
case 0:
MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
gboolean has_active = FALSE;
printf("%s()\n", __PRETTY_FUNCTION__);
- store = GTK_LIST_STORE(gtk_combo_box_get_model
- (GTK_COMBO_BOX(cmb_category)));
+ store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)));
gtk_list_store_clear(store);
- while (SQLITE_ROW == sqlite3_step(_stmt_selall_cat)) {
+ while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
GtkTreeIter iter;
- guint cid = sqlite3_column_int(_stmt_selall_cat, 0);
+ guint cid = sqlite3_column_int(poisql.selall_cat, 0);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
0, cid,
- 1, sqlite3_column_text(_stmt_selall_cat, 1),
+ 1, sqlite3_column_text(poisql.selall_cat, 1),
-1);
if (cid == cat_id) {
active = iter;
has_active = TRUE;
}
}
- sqlite3_reset(_stmt_selall_cat);
+ sqlite3_reset(poisql.selall_cat);
if (!has_active)
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active);
gtk_container_add(GTK_CONTAINER
(GTK_DIALOG(dialog)->action_area),
- btn_delete =
- gtk_button_new_with_label(_("Delete")));
+ btn_delete = gtk_button_new_with_label(_("Delete")));
dpoi.dialog = dialog;
dpoi.txt_label = g_strdup(poi.label);
gtk_dialog_add_button(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
} else {
- if (SQLITE_ROW == sqlite3_step(_stmt_nextlabel_poi))
- poi.label = g_strdup_printf("Point%06d",
- sqlite3_column_int
- (_stmt_nextlabel_poi, 0));
- sqlite3_reset(_stmt_nextlabel_poi);
+ if (SQLITE_ROW == sqlite3_step(poisql.nextlabel_poi))
+ poi.label = g_strdup_printf("Point%06d", sqlite3_column_int(poisql.nextlabel_poi, 0));
+ sqlite3_reset(poisql.nextlabel_poi);
unit2latlon(unitx, unity, poi.lat, poi.lon);
gtk_widget_show_all(dialog);
while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- const gchar *poi_label = NULL;
+ gchar *poi_label = NULL;
gchar *poi_desc = NULL;
GtkTreeIter iter;
vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
return TRUE;
}
+
+gboolean
+poi_quick_dialog(gdouble lat, gdouble lon)
+{
+GtkWidget *dialog;
+GtkWidget *table;
+GtkWidget *buttons[POI_QUICK_BUTTONS];
+guint x,y;
+
+dialog = gtk_dialog_new_with_buttons(_("Quick POI"),
+ GTK_WINDOW(_window),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ NULL);
+
+gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
+ table = gtk_table_new(3, 3, FALSE), TRUE, TRUE, 0);
+
+for (x=0;x<3;x++) {
+ for (y=0;y<3;y++) {
+ gchar *btnlabel;
+
+ btnlabel=g_strdup_printf("(%d)", (x+y));
+ buttons[x+y]=gtk_button_new_with_label(btnlabel);
+ gtk_table_attach(GTK_TABLE(table),
+ buttons[x+y], x, x+1, y, y+1, GTK_FILL, 0, 2, 4);
+ g_free(btnlabel);
+ }
+}
+
+gtk_widget_show_all(dialog);
+
+if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
+ g_printf("Wee!");
+}
+gtk_widget_destroy(dialog);
+
+return TRUE;
+}
#include <fcntl.h>
#include <gconf/gconf-client.h>
#include <libxml/parser.h>
-
#include <libintl.h>
#include <locale.h>
-
#include <sqlite3.h>
#include "utils.h"
#include "db.h"
#include "osm.h"
-struct sql_poi_stmt {
- sqlite3_stmt *select_poi;
- sqlite3_stmt *select_nearest_poi;
- sqlite3_stmt *insert_poi;
- sqlite3_stmt *update_poi;
- sqlite3_stmt *delete_poi;
- sqlite3_stmt *delete_poi_by_catid;
- sqlite3_stmt *nextlabel_poi;
- sqlite3_stmt *select_cat;
- sqlite3_stmt *insert_cat;
- sqlite3_stmt *update_cat;
- sqlite3_stmt *delete_cat;
- sqlite3_stmt *toggle_cat;
- sqlite3_stmt *selall_cat;
- sqlite3_stmt *select_quick_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;
-sqlite3_stmt *_stmt_update_poi = NULL;
-sqlite3_stmt *_stmt_delete_poi = NULL;
-sqlite3_stmt *_stmt_delete_poi_by_catid = NULL;
-sqlite3_stmt *_stmt_nextlabel_poi = NULL;
-
-sqlite3_stmt *_stmt_select_cat = NULL;
-sqlite3_stmt *_stmt_insert_cat = NULL;
-sqlite3_stmt *_stmt_update_cat = NULL;
-sqlite3_stmt *_stmt_delete_cat = NULL;
-sqlite3_stmt *_stmt_toggle_cat = NULL;
-sqlite3_stmt *_stmt_selall_cat = NULL;
-
struct _poi_categories {
node_type_t type;
gchar *name, *desc;
};
+
static struct _poi_categories default_poi_categories[] = {
{NODE_AMENITY_PARKING, "Parking", "Parking place for vehicles." },
{NODE_AMENITY_FUEL, "Fuel", "Stations for purchasing fuel for vehicles." },
- {NODE_AMENITY_FUEL, "Speed Cam", "Automatic speed cameras." },
+ {NODE_AMENITY_SPEEDCAM, "Speed Cam", "Automatic speed cameras." },
{NODE_AMENITY_HOSPITAL, "Hospital", "" },
{NODE_AMENITY_PHARMACY, "Pharmacy", "Place to get drugs." },
{NODE_AMENITY_POLICE, "Police", "Police station"},
{NODE_POI_END, NULL, NULL }
};
-gboolean
-poi_cb_populate_categories(sqlite3 *db)
+static gboolean
+poi_populate_categories(sqlite3 *db)
{
sqlite3_stmt *sql_cat;
gint i;
sqlite3_free_table(pszResult);
/* Make sure default categories exists */
- poi_cb_populate_categories(db);
+ poi_populate_categories(db);
return TRUE;
}
" where p.lat between ? and ? "
" and p.lon between ? and ? "
" and c.enabled = 1 and p.cat_id = c.cat_id",
- -1, &_stmt_select_poi, NULL);
+ -1, &poisql.select_poi, NULL);
/* select nearest pois */
sqlite3_prepare_v2(db,
" 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, &_stmt_select_nearest_poi, NULL);
+ -1, &poisql.select_nearest_poi, NULL);
/* insert poi */
sqlite3_prepare_v2(db,
"insert into poi (lat, lon, label, desc, cat_id, public)"
- " values (?, ?, ?, ?, ?, 1)", -1, &_stmt_insert_poi, NULL);
+ " values (?, ?, ?, ?, ?, 1)", -1, &poisql.insert_poi, NULL);
/* update poi */
sqlite3_prepare_v2(db, "update poi set label = ?, desc = ?, "
"cat_id = ? where poi_id = ?",
- -1, &_stmt_update_poi, NULL);
+ -1, &poisql.update_poi, NULL);
/* delete from poi */
sqlite3_prepare_v2(db, "delete from poi where poi_id = ?",
- -1, &_stmt_delete_poi, NULL);
+ -1, &poisql.delete_poi, NULL);
/* delete from poi by cat_id */
sqlite3_prepare_v2(db, "delete from poi where cat_id = ?",
- -1, &_stmt_delete_poi_by_catid, NULL);
+ -1, &poisql.delete_poi_by_catid, NULL);
/* get next poilabel */
sqlite3_prepare_v2(db, "select ifnull(max(poi_id) + 1,1) from poi",
- -1, &_stmt_nextlabel_poi, NULL);
+ -1, &poisql.nextlabel_poi, NULL);
/* select from category */
sqlite3_prepare_v2(db,
"select c.label, c.desc, c.enabled"
" from category c where c.cat_id = ?",
- -1, &_stmt_select_cat, NULL);
+ -1, &poisql.select_cat, NULL);
/* insert into category */
sqlite3_prepare_v2(db,
"insert into category (label, desc, enabled)"
- " values (?, ?, ?)", -1, &_stmt_insert_cat, NULL);
+ " values (?, ?, ?)", -1, &poisql.insert_cat, NULL);
/* update category */
sqlite3_prepare_v2(db,
"update category set label = ?, desc = ?,"
" enabled = ? where poi_id = ?",
- -1, &_stmt_update_cat, NULL);
+ -1, &poisql.update_cat, NULL);
/* delete from category */
sqlite3_prepare_v2(db,"delete from category where cat_id = ?",
- -1, &_stmt_delete_cat, NULL);
+ -1, &poisql.delete_cat, NULL);
/* enable category */
sqlite3_prepare_v2(db,
"update category set enabled = ?"
- " where cat_id = ?", -1, &_stmt_toggle_cat, NULL);
+ " where cat_id = ?", -1, &poisql.toggle_cat, NULL);
/* select all category */
sqlite3_prepare_v2(db,
"select c.cat_id, c.label, c.desc, c.enabled, c.icon, c.color,"
" from category c"
" left outer join poi p on c.cat_id = p.cat_id"
" group by c.cat_id, c.label, c.desc, c.enabled "
- " order by c.priority,c.label", -1, &_stmt_selall_cat, NULL);
+ " order by c.priority,c.label", -1, &poisql.selall_cat, NULL);
/* Select quick categories */
sqlite3_prepare_v2(db,
PoiInfo *
poi_new(void)
{
-PoiInfo *p;
-
return g_slice_new0(PoiInfo);
}
g_slice_free(PoiInfo, p);
}
+poi_category *
+poi_category_new(void)
+{
+return g_slice_new0(poi_category);
+}
+
+void
+poi_category_free(poi_category *c)
+{
+if (c->label)
+ g_free(c->label);
+if (c->desc)
+ g_free(c->desc);
+g_slice_free(poi_category, c);
+}
+
+gboolean
+poi_category_toggle(gint cat_id, gboolean cat_enabled)
+{
+if (SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 1, cat_enabled) ||
+ SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 2, cat_id) ||
+ SQLITE_DONE != sqlite3_step(poisql.toggle_cat)) {
+ return FALSE;
+ }
+return TRUE;
+}
+
gboolean
-poi_category_update(gint cat_id, gchar *cat_label, gchar *cat_desc, gint cat_enabled)
+poi_category_get(gint 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)) {
+ vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
+ sqlite3_reset(poisql.select_cat);
+ return FALSE;
+}
+
+cc=poi_category_new();
+cc->id=cat_id;
+cc->label = g_strdup(sqlite3_column_text(poisql.select_cat, 0));
+cc->desc = g_strdup(sqlite3_column_text(poisql.select_cat, 1));
+cc->enabled = sqlite3_column_int(poisql.select_cat, 2);
+
+sqlite3_reset(poisql.select_cat);
+sqlite3_clear_bindings(poisql.select_cat);
+*c=cc;
+return TRUE;
+}
+
+gboolean
+poi_category_update(gint cat_id, poi_category *c)
{
gboolean results=TRUE;
if (cat_id > 0) {
/* edit category */
if (SQLITE_OK !=
- sqlite3_bind_text(_stmt_update_cat, 1, cat_label, -1,
- g_free)
- || SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 2,
- cat_desc, -1, g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 3,
- cat_enabled)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 4,
- cat_id)
- || SQLITE_DONE != sqlite3_step(_stmt_update_cat)) {
+ sqlite3_bind_text(poisql.update_cat, 1, c->label, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 2, c->desc, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 3, c->enabled)
+ || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 4, c->id)
+ || SQLITE_DONE != sqlite3_step(poisql.update_cat)) {
results = FALSE;
}
- sqlite3_reset(_stmt_update_cat);
- sqlite3_clear_bindings(_stmt_update_cat);
+ sqlite3_reset(poisql.update_cat);
+ sqlite3_clear_bindings(poisql.update_cat);
} else {
/* add category */
if (SQLITE_OK !=
- sqlite3_bind_text(_stmt_insert_cat, 1, cat_label, -1,
- g_free)
- || SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 2,
- cat_desc, -1, g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat, 3,
- cat_enabled)
- || SQLITE_DONE != sqlite3_step(_stmt_insert_cat)) {
+ sqlite3_bind_text(poisql.insert_cat, 1, c->label, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 2, c->desc, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_int(poisql.insert_cat, 3, c->enabled)
+ || SQLITE_DONE != sqlite3_step(poisql.insert_cat)) {
results = FALSE;
}
- sqlite3_reset(_stmt_insert_cat);
- sqlite3_clear_bindings(_stmt_insert_cat);
+ sqlite3_reset(poisql.insert_cat);
+ sqlite3_clear_bindings(poisql.insert_cat);
}
return results;
}
if (!_db)
return FALSE;
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id)
- || SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid)) {
- sqlite3_reset(_stmt_delete_poi_by_catid);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, dpoi->id)
+ || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) {
+ sqlite3_reset(poisql.delete_poi_by_catid);
return FALSE;
}
-sqlite3_reset(_stmt_delete_poi_by_catid);
-sqlite3_clear_bindings(_stmt_delete_poi_by_catid);
+sqlite3_reset(poisql.delete_poi_by_catid);
+sqlite3_clear_bindings(poisql.delete_poi_by_catid);
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
- SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) {
- sqlite3_reset(_stmt_delete_cat);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, dpoi->id) ||
+ SQLITE_DONE != sqlite3_step(poisql.delete_cat)) {
+ sqlite3_reset(poisql.delete_cat);
return FALSE;
}
-sqlite3_reset(_stmt_delete_cat);
-sqlite3_clear_bindings(_stmt_delete_cat);
+sqlite3_reset(poisql.delete_cat);
+sqlite3_clear_bindings(poisql.delete_cat);
return TRUE;
}
if (!_db)
return FALSE;
-if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
- SQLITE_DONE != sqlite3_step(_stmt_delete_poi)) {
- sqlite3_reset(_stmt_delete_poi);
+if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, dpoi->id) ||
+ SQLITE_DONE != sqlite3_step(poisql.delete_poi)) {
+ sqlite3_reset(poisql.delete_poi);
return FALSE;
} else {
- sqlite3_reset(_stmt_delete_poi);
- sqlite3_clear_bindings(_stmt_delete_poi);
+ sqlite3_reset(poisql.delete_poi);
+ sqlite3_clear_bindings(poisql.delete_poi);
}
return TRUE;
}
poi_get_list(guint unitx, guint unity, GtkListStore **_store, guint *_num_cats)
{
guint x, y;
-gfloat lat1, lon1, lat2, lon2;
+gdouble lat1, lon1, lat2, lon2;
GtkListStore *store;
GtkTreeIter iter;
gchar tmp1[16], tmp2[16];
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_DOUBLE, /* Latitude */
+ G_TYPE_DOUBLE, /* Longitude */
G_TYPE_STRING, /* Lat/Lon */
G_TYPE_STRING, /* POI Label */
G_TYPE_STRING, /* POI Desc. */
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");
+if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) ||
+ SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2, lat2) ||
+ SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon1) ||
+ SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon2)) {
+ g_printerr("Failed to bind values for poisql.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);
+while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) {
+ gdouble lat, lon;
+ lat = sqlite3_column_double(poisql.select_poi, 0);
+ lon = sqlite3_column_double(poisql.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));
+ sqlite3_column_text(poisql.select_poi, 3),
+ sqlite3_column_text(poisql.select_poi, 4),
+ sqlite3_column_text(poisql.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_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(_stmt_select_poi, 3),
- POI_DESC, sqlite3_column_text(_stmt_select_poi, 4),
- POI_CATLAB, sqlite3_column_text(_stmt_select_poi, 6),
+ 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),
-1);
num_cats++;
}
-g_printf("N: %d\n", num_cats);
-sqlite3_reset(_stmt_select_poi);
-sqlite3_clear_bindings(_stmt_select_poi);
+sqlite3_reset(poisql.select_poi);
+sqlite3_clear_bindings(poisql.select_poi);
*_store=store;
*_num_cats=num_cats;
return TRUE;
if (!_db)
return FALSE;
-if (SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 1, poi_label, -1, SQLITE_STATIC)
- || SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 2, poi_desc, -1, g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 3, cat_id)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi, 4, poi_id)
- || SQLITE_DONE != sqlite3_step(_stmt_update_poi)) {
+if (SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 1, poi_label, -1, SQLITE_STATIC)
+ || SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 2, poi_desc, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 3, cat_id)
+ || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 4, poi_id)
+ || SQLITE_DONE != sqlite3_step(poisql.update_poi)) {
return FALSE;
}
-sqlite3_reset(_stmt_update_poi);
-sqlite3_clear_bindings(_stmt_update_poi);
+sqlite3_reset(poisql.update_poi);
+sqlite3_clear_bindings(poisql.update_poi);
return TRUE;
}
if (!_db)
return FALSE;
-if (SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, lat)
- || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, lon)
- || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi_label, -1, g_free)
- || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi_desc, -1, g_free)
- || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5, cat_id)
- || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)) {
+if (SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 1, lat)
+ || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 2, lon)
+ || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 3, poi_label, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 4, poi_desc, -1, g_free)
+ || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 5, cat_id)
+ || SQLITE_DONE != sqlite3_step(poisql.insert_poi)) {
return FALSE;
}
-sqlite3_reset(_stmt_insert_poi);
-sqlite3_clear_bindings(_stmt_insert_poi);
+sqlite3_reset(poisql.insert_poi);
+sqlite3_clear_bindings(poisql.insert_poi);
return TRUE;
}
if (!_db)
return FALSE;
-sqlite3_reset(_stmt_select_nearest_poi);
-sqlite3_clear_bindings(_stmt_select_nearest_poi);
+sqlite3_reset(poisql.select_nearest_poi);
+sqlite3_clear_bindings(poisql.select_nearest_poi);
-if (SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
- && SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 2, lon)
- && SQLITE_ROW == sqlite3_step(_stmt_select_nearest_poi)) {
+if (SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 1, lat)
+ && SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 2, lon)
+ && SQLITE_ROW == sqlite3_step(poisql.select_nearest_poi)) {
p=poi_new();
- p->lat = sqlite3_column_double(_stmt_select_nearest_poi, 0);
- p->lon = sqlite3_column_double(_stmt_select_nearest_poi, 1);
- _poi_label = sqlite3_column_text(_stmt_select_nearest_poi, 2);
- _cat_label = sqlite3_column_text(_stmt_select_nearest_poi, 3);
+ p->lat = sqlite3_column_double(poisql.select_nearest_poi, 0);
+ p->lon = sqlite3_column_double(poisql.select_nearest_poi, 1);
+ _poi_label = sqlite3_column_text(poisql.select_nearest_poi, 2);
+ _cat_label = sqlite3_column_text(poisql.select_nearest_poi, 3);
p->label=g_strdup(_poi_label);
p->cat_label=g_strdup(_cat_label);
g_printf("%f %f %s %s\n", p->lat, p->lon, p->label, p->cat_label);
}
return NULL;
}
+
+GtkListStore *
+poi_category_generate_store()
+{
+GtkTreeIter iter;
+GtkListStore *store;
+printf("%s()\n", __PRETTY_FUNCTION__);
+
+store = gtk_list_store_new(CAT_NUM_COLUMNS,
+ G_TYPE_UINT,
+ G_TYPE_BOOLEAN,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
+
+while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ CAT_ID, sqlite3_column_int(poisql.selall_cat, 0),
+ CAT_ENABLED, sqlite3_column_int(poisql.selall_cat, 3),
+ CAT_LABEL, sqlite3_column_text(poisql.selall_cat, 1),
+ CAT_DESC, sqlite3_column_text(poisql.selall_cat, 2),
+ CAT_POI_CNT, sqlite3_column_int(poisql.selall_cat, 6), -1);
+}
+sqlite3_reset(poisql.selall_cat);
+sqlite3_clear_bindings(poisql.selall_cat);
+
+vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
+return store;
+}