#include "ui-common.h"
#include "poi.h"
-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;
-
-gboolean db_prepare(sqlite3 *db)
+gboolean db_check(sqlite3 *db, const gchar *table)
{
+gchar **pszResult;
+guint nRow, nColumn;
+gchar sql[64];
+snprintf(sql, sizeof(sql),"select count(*) from %s", table);
+
+if (SQLITE_OK != sqlite3_get_table(db, sql,
+ &pszResult, &nRow, &nColumn, NULL))
+ return FALSE;
+
+sqlite3_free_table(pszResult);
return TRUE;
}
-gboolean db_close(sqlite3 *db)
+gboolean db_close(sqlite3 **db)
{
-if (db) {
- sqlite3_close(db);
- db=NULL;
+if (db && *db) {
+ sqlite3_close(*db);
+ *db=NULL;
}
return TRUE;
}
-gboolean db_connect(sqlite3 **ndb, const gchar *poi_db)
+gboolean db_connect(sqlite3 **ndb, const gchar *db_file)
{
gchar buffer[100];
gchar *perror;
db = NULL;
}
- if (!poi_db)
+ if (!db_file)
return FALSE;
- if (SQLITE_OK != (sqlite3_open(poi_db, &db))) {
+ if (SQLITE_OK != (sqlite3_open(db_file, &db))) {
gchar buffer2[200];
snprintf(buffer2, sizeof(buffer2),
- "%s: %s", _("Problem with POI database"),
- sqlite3_errmsg(db));
+ "%s: %s", _("Problem with database"), sqlite3_errmsg(db));
sqlite3_close(db);
db = NULL;
+ *ndb=db;
popup_error(_window, buffer2);
return FALSE;
}
*ndb=db;
- if (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
- &pszResult, &nRow, &nColumn, NULL)) {
- gchar *create_sql;
-
- g_printf("Creating initial tables\n");
-
- create_sql =
- sqlite3_mprintf
- ("create table poi (poi_id integer PRIMARY KEY, lat real, "
- "lon real, label text, desc text, cat_id integer);"
- "create table category (cat_id integer PRIMARY KEY,"
- "label text, desc text, enabled integer);"
- /* Add some default categories... */
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); "
- "insert into category (label, desc, enabled) "
- "values ('%q', '%q', 1); ",
- _("Fuel"),
- _("Stations for purchasing fuel for vehicles."),
- _("Residence"),
- _("Houses, apartments, or other residences of import."),
- _("Dining"),
- _("Places to eat or drink."),
- _("Shopping/Services"),
- _("Places to shop or acquire services."),
- _("Recreation"),
- _("Indoor or Outdoor places to have fun."),
- _("Transportation"),
- _("Bus stops, airports, train stations, etc."),
- _("Lodging"),
- _("Places to stay temporarily or for the night."),
- _("School"),
- _("Elementary schools, college campuses, etc."),
- _("Business"),
- _("General places of business."),
- _("Landmark"),
- _("General landmarks."),
- _("Other"),
- _("Miscellaneous category for everything else."));
-
- if (SQLITE_OK !=
- sqlite3_exec(db, create_sql, NULL, NULL, &perror)
- && (SQLITE_OK !=
- sqlite3_get_table(db, "select label from poi limit 1",
- &pszResult, &nRow, &nColumn, NULL))) {
- snprintf(buffer, sizeof(buffer), "%s:\n%s",
- _("Failed to open or create database"),
- sqlite3_errmsg(db));
- sqlite3_close(db);
- db = NULL;
- popup_error(_window, buffer);
- return FALSE;
- }
- } else
- sqlite3_free_table(pszResult);
-
- /* Prepare our SQL statements. */
- /* select from poi */
- sqlite3_prepare(db,
- "select p.lat, p.lon, p.poi_id, p.label, p.desc,"
- " p.cat_id, c.label, c.desc"
- " from poi p, category c "
- " 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);
-
- /* select nearest pois */
- sqlite3_prepare(db,
- "select p.lat, p.lon, p.label, c.label"
- " from poi p, category c "
- " where c.enabled = 1 and p.cat_id = c.cat_id"
- " order by (($LAT - p.lat) * ($LAT - p.lat) "
- "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
- -1, &_stmt_select_nearest_poi, NULL);
-
- /* insert poi */
- sqlite3_prepare(db,
- "insert into poi (lat, lon, label, desc, cat_id)"
- " values (?, ?, ?, ?, ?)", -1, &_stmt_insert_poi, NULL);
- /* update poi */
- sqlite3_prepare(db,
- "update poi set label = ?, desc = ?, "
- "cat_id = ? where poi_id = ?",
- -1, &_stmt_update_poi, NULL);
- /* delete from poi */
- sqlite3_prepare(db,
- " delete from poi where poi_id = ?",
- -1, &_stmt_delete_poi, NULL);
- /* delete from poi by cat_id */
- sqlite3_prepare(db,
- "delete from poi where cat_id = ?",
- -1, &_stmt_delete_poi_by_catid, NULL);
- /* get next poilabel */
- sqlite3_prepare(db,
- "select ifnull(max(poi_id) + 1,1) from poi",
- -1, &_stmt_nextlabel_poi, NULL);
-
- /* select from category */
- sqlite3_prepare(db,
- "select c.label, c.desc, c.enabled"
- " from category c where c.cat_id = ?",
- -1, &_stmt_select_cat, NULL);
- /* insert into category */
- sqlite3_prepare(db,
- "insert into category (label, desc, enabled)"
- " values (?, ?, ?)", -1, &_stmt_insert_cat, NULL);
- /* update category */
- sqlite3_prepare(db,
- "update category set label = ?, desc = ?,"
- " enabled = ? where poi_id = ?",
- -1, &_stmt_update_cat, NULL);
- /* delete from category */
- sqlite3_prepare(db,
- "delete from category where cat_id = ?",
- -1, &_stmt_delete_cat, NULL);
- /* enable category */
- sqlite3_prepare(db,
- "update category set enabled = ?"
- " where cat_id = ?", -1, &_stmt_toggle_cat, NULL);
- /* select all category */
- sqlite3_prepare(db,
- "select c.cat_id, c.label, c.desc, c.enabled,"
- " count(p.poi_id)"
- " 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.label", -1, &_stmt_selall_cat, NULL);
-
printf("%s(): return\n", __PRETTY_FUNCTION__);
return TRUE;
}
#include <locale.h>
#include <math.h>
#include <errno.h>
-#include <sys/wait.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <fcntl.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <curl/multi.h>
#include <gconf/gconf-client.h>
#include <libxml/parser.h>
#include "map.h"
#include "mapper-types.h"
#include "settings.h"
+#include "db.h"
-guint _poi_zoom = 6;
sqlite3 *_db = NULL;
gchar *_poi_db = NULL;
+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;
+
+gboolean
+poi_db_create(sqlite3 *db)
+{
+ gchar **pszResult;
+ guint nRow, nColumn;
+ if (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
+ &pszResult, &nRow, &nColumn, NULL)) {
+ gchar *create_sql;
+
+ g_printf("Creating initial tables\n");
+
+ create_sql =
+ sqlite3_mprintf
+ ("create table poi (poi_id integer PRIMARY KEY, lat real, "
+ "lon real, label text, desc text, cat_id integer);"
+ "create table category (cat_id integer PRIMARY KEY,"
+ "label text, desc text, enabled integer);"
+ /* Add some default categories... */
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); "
+ "insert into category (label, desc, enabled) "
+ "values ('%q', '%q', 1); ",
+ _("Fuel"),
+ _("Stations for purchasing fuel for vehicles."),
+ _("Residence"),
+ _("Houses, apartments, or other residences of import."),
+ _("Dining"),
+ _("Places to eat or drink."),
+ _("Shopping/Services"),
+ _("Places to shop or acquire services."),
+ _("Recreation"),
+ _("Indoor or Outdoor places to have fun."),
+ _("Transportation"),
+ _("Bus stops, airports, train stations, etc."),
+ _("Lodging"),
+ _("Places to stay temporarily or for the night."),
+ _("School"),
+ _("Elementary schools, college campuses, etc."),
+ _("Business"),
+ _("General places of business."),
+ _("Landmark"),
+ _("General landmarks."),
+ _("Other"),
+ _("Miscellaneous category for everything else."));
+
+ if (SQLITE_OK !=
+ sqlite3_exec(&db, create_sql, NULL, NULL, &perror)
+ && (SQLITE_OK !=
+ sqlite3_get_table(db, "select label from poi limit 1",
+ &pszResult, &nRow, &nColumn, NULL))) {
+ g_printf("%s:\n%s",_("Failed to open or create database"),sqlite3_errmsg(db));
+ sqlite3_close(db);
+ db = NULL;
+ return FALSE;
+ }
+ } else
+ sqlite3_free_table(pszResult);
+
+}
+
+gboolean
+poi_db_prepare(sqlite3 *db)
+{
+ /* select from poi */
+ sqlite3_prepare(db,
+ "select p.lat, p.lon, p.poi_id, p.label, p.desc,"
+ " p.cat_id, c.label, c.desc"
+ " from poi p, category c "
+ " 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);
+
+ /* select nearest pois */
+ sqlite3_prepare(db,
+ "select p.lat, p.lon, p.label, c.label"
+ " from poi p, category c "
+ " where c.enabled = 1 and p.cat_id = c.cat_id"
+ " order by (($LAT - p.lat) * ($LAT - p.lat) "
+ "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
+ -1, &_stmt_select_nearest_poi, NULL);
+
+ /* insert poi */
+ sqlite3_prepare(db,
+ "insert into poi (lat, lon, label, desc, cat_id)"
+ " values (?, ?, ?, ?, ?)", -1, &_stmt_insert_poi, NULL);
+ /* update poi */
+ sqlite3_prepare(db,
+ "update poi set label = ?, desc = ?, "
+ "cat_id = ? where poi_id = ?",
+ -1, &_stmt_update_poi, NULL);
+ /* delete from poi */
+ sqlite3_prepare(db,
+ " delete from poi where poi_id = ?",
+ -1, &_stmt_delete_poi, NULL);
+ /* delete from poi by cat_id */
+ sqlite3_prepare(db,
+ "delete from poi where cat_id = ?",
+ -1, &_stmt_delete_poi_by_catid, NULL);
+ /* get next poilabel */
+ sqlite3_prepare(db,
+ "select ifnull(max(poi_id) + 1,1) from poi",
+ -1, &_stmt_nextlabel_poi, NULL);
+
+ /* select from category */
+ sqlite3_prepare(db,
+ "select c.label, c.desc, c.enabled"
+ " from category c where c.cat_id = ?",
+ -1, &_stmt_select_cat, NULL);
+ /* insert into category */
+ sqlite3_prepare(db,
+ "insert into category (label, desc, enabled)"
+ " values (?, ?, ?)", -1, &_stmt_insert_cat, NULL);
+ /* update category */
+ sqlite3_prepare(db,
+ "update category set label = ?, desc = ?,"
+ " enabled = ? where poi_id = ?",
+ -1, &_stmt_update_cat, NULL);
+ /* delete from category */
+ sqlite3_prepare(db,
+ "delete from category where cat_id = ?",
+ -1, &_stmt_delete_cat, NULL);
+ /* enable category */
+ sqlite3_prepare(db,
+ "update category set enabled = ?"
+ " where cat_id = ?", -1, &_stmt_toggle_cat, NULL);
+ /* select all category */
+ sqlite3_prepare(db,
+ "select c.cat_id, c.label, c.desc, c.enabled,"
+ " count(p.poi_id)"
+ " 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.label", -1, &_stmt_selall_cat, NULL);
+
+ return TRUE;
+}
+
+gboolean
+poi_db_connect(sqlite3 **db, const gchar *poi_db)
+{
+if (db_connect(db, poi_db)) {
+ poi_db_create(*db);
+ poi_db_prepare(*db);
+ return TRUE;
+}
+return FALSE;
+}
+
gboolean
poi_category_update(gint cat_id, gchar * cat_label, gchar * cat_desc,
gint cat_enabled)
{
- if (cat_id > 0) {
+gboolean results;
+
+if (cat_id > 0) {
/* edit category */
if (SQLITE_OK !=
sqlite3_bind_text(_stmt_update_cat, 1, cat_label, -1,
}
sqlite3_reset(_stmt_insert_cat);
}
+return results;
}
-gboolean poi_category_delete(DeletePOI * dpoi)
+gboolean
+poi_category_delete(DeletePOI * dpoi)
{
/* delete dpoi->poi_id */
if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1,
sqlite3_reset(_stmt_delete_cat);
}
-gboolean category_dialog(guint cat_id)
-{
- gchar *cat_label = NULL, *cat_desc = NULL;
- guint cat_enabled;
- GtkWidget *dialog;
- GtkWidget *table;
- GtkWidget *label;
- GtkWidget *txt_label;
- GtkWidget *txt_desc;
- GtkWidget *btn_delete = NULL;
- GtkWidget *txt_scroll;
- GtkWidget *chk_enabled;
- GtkTextBuffer *desc_txt;
- GtkTextIter begin, end;
- gboolean results = TRUE;
- DeletePOI dpoi = { NULL, NULL, 0 };
- 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);
- 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_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT, NULL);
-
- gtk_container_add(GTK_CONTAINER
- (GTK_DIALOG(dialog)->action_area),
- btn_delete =
- gtk_button_new_with_label(_("Delete")));
-
- dpoi.dialog = dialog;
- dpoi.txt_label = g_strdup(cat_label);
- dpoi.id = cat_id;
-
- 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);
- } else {
- cat_enabled = 1;
- cat_label = g_strdup("");
- cat_id = 0;
- cat_desc = g_strdup("");
-
- dialog = gtk_dialog_new_with_buttons(_("Add Category"),
- 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(6, 4, FALSE), TRUE, TRUE, 0);
-
- 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")),
- 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_table_attach(GTK_TABLE(table),
- 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,
- GTK_POLICY_AUTOMATIC);
-
- txt_desc = gtk_text_view_new();
- gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
-
- gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
- gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
-
- 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,
- 3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
-
- /* label */
- gtk_entry_set_text(GTK_ENTRY(txt_label), cat_label);
-
- /* desc */
- gtk_text_buffer_set_text(desc_txt, cat_desc, -1);
-
- /* enabled */
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled),
- (cat_enabled == 1 ? TRUE : FALSE));
-
- g_free(cat_label);
- cat_label = NULL;
- g_free(cat_desc);
- cat_desc = NULL;
-
- 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."));
- 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);
-
- break;
- }
-
- g_free(dpoi.txt_label);
-
- g_object_unref(desc_txt);
-
- gtk_widget_hide_all(dialog);
-
- vprintf("%s(): return\n", __PRETTY_FUNCTION__);
- return results;
-}
-
-void category_toggled(GtkCellRendererToggle * cell, gchar * path, gpointer data)
-{
- GtkTreeIter iter;
- gboolean cat_enabled;
- guint cat_id;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- GtkTreeModel *model = GTK_TREE_MODEL(data);
- if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
- return;
-
- gtk_tree_model_get(model, &iter, CAT_ENABLED, &cat_enabled, -1);
- gtk_tree_model_get(model, &iter, CAT_ID, &cat_id, -1);
-
- 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)) {
- 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__);
-}
-
-GtkListStore *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, 4), -1);
- }
- sqlite3_reset(_stmt_selall_cat);
-
- vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
- return store;
-}
-
-gboolean category_add(GtkWidget * widget, GtkWidget * tree_view)
+gboolean
+poi_delete(DeletePOI * dpoi)
{
- GtkListStore *store;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- if (category_dialog(0)) {
- store = generate_store();
- gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
- GTK_TREE_MODEL(store));
- g_object_unref(G_OBJECT(store));
- }
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
- return TRUE;
+guint i;
+
+if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
+ SQLITE_DONE != sqlite3_step(_stmt_delete_poi)) {
+ sqlite3_reset(_stmt_delete_poi);
+ return FALSE;
+} else {
+ sqlite3_reset(_stmt_delete_poi);
}
-
-gboolean category_edit(GtkWidget * widget, GtkWidget * tree_view)
-{
- GtkTreeIter iter;
- GtkTreeModel *store;
- GtkTreeSelection *selection;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- store = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view));
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
- if (gtk_tree_selection_get_selected(selection, &store, &iter)) {
- GValue val;
- 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 = generate_store();
- gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view),
- GTK_TREE_MODEL(new_store));
- g_object_unref(G_OBJECT(new_store));
- }
- }
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
- return TRUE;
-}
-
-gboolean category_list()
-{
- GtkWidget *dialog;
- GtkWidget *tree_view;
- GtkWidget *sw;
- GtkWidget *btn_edit;
- GtkWidget *btn_add;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkListStore *store;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- dialog = gtk_dialog_new_with_buttons(_("POI Categories"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL, GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT, NULL);
-
-#ifdef WITH_HILDON
- /* Enable the help button. */
- ossohelp_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT, _osso);
-#endif
-
- 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")));
-
- store = generate_store();
-
- if (!store)
- return TRUE;
-
- sw = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
- GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
- sw, TRUE, TRUE, 0);
-
- tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
- /* Maemo-related? */
- g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL);
- gtk_container_add(GTK_CONTAINER(sw), tree_view);
-
- gtk_tree_selection_set_mode(gtk_tree_view_get_selection
- (GTK_TREE_VIEW(tree_view)),
- GTK_SELECTION_SINGLE);
- gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE);
-
- renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("ID"), renderer, "text",
- CAT_ID, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
- gtk_tree_view_column_set_max_width(column, 1);
-
- renderer = gtk_cell_renderer_toggle_new();
- g_signal_connect(renderer, "toggled",
- G_CALLBACK(category_toggled), store);
- column =
- gtk_tree_view_column_new_with_attributes(_("Enabled"), renderer,
- "active", CAT_ENABLED,
- NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
-
- g_object_unref(G_OBJECT(store));
-
- renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("Label"), renderer,
- "text", CAT_LABEL, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
-
- renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("Description"), renderer,
- "text", CAT_DESC, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
-
- renderer = gtk_cell_renderer_text_new();
- column =
- gtk_tree_view_column_new_with_attributes(_("# POIs"), renderer,
- "text", CAT_POI_CNT, NULL);
- gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
-
- gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300);
- gtk_widget_show_all(dialog);
-
- g_signal_connect(G_OBJECT(btn_edit), "clicked",
- G_CALLBACK(category_edit), tree_view);
-
- g_signal_connect(G_OBJECT(btn_add), "clicked",
- G_CALLBACK(category_add), tree_view);
-
- while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- break;
- }
- gtk_widget_destroy(dialog);
-
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
- return TRUE;
-}
-
-gboolean menu_cb_category(GtkAction * action)
-{
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- if (category_list())
- map_force_redraw();
-
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
- return TRUE;
-}
-
-gboolean poi_delete(DeletePOI * dpoi)
-{
- guint i;
-
- if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
- SQLITE_DONE != sqlite3_step(_stmt_delete_poi)) {
- sqlite3_reset(_stmt_delete_poi);
- return FALSE;
- } else {
- sqlite3_reset(_stmt_delete_poi);
- }
-}
-
return TRUE;
}
-gboolean select_poi(guint unitx, guint unity, PoiInfo * poi)
-{
- guint x, y;
- gfloat lat1, lon1, lat2, lon2;
- GtkWidget *dialog;
- GtkWidget *list;
- GtkWidget *sw;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkListStore *store;
- GtkTreeIter iter;
- gboolean selected = FALSE;
- gchar tmp1[16], tmp2[16];
- guint num_cats = 0;
- 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");
- 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);
-
- switch (num_cats) {
- case 0:
- g_object_unref(G_OBJECT(store));
- MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
- return FALSE;
- break;
- case 1:
- /* iter is still set to the most-recently added POI. */
- 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);
- g_object_unref(G_OBJECT(store));
- return TRUE;
- break;
- }
-
- /* There are at least 2 matching POI's - let the user select one. */
- dialog = gtk_dialog_new_with_buttons(_("Select POI"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL, GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT, NULL);
-
- gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300);
-
- sw = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
- GTK_SHADOW_ETCHED_IN);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
- GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
- 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);
-
- 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);
-
- renderer = gtk_cell_renderer_text_new();
- 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,
- "text", POI_LABEL, 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(_("Category"), renderer,
- "text", POI_CATLAB, NULL);
- 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);
- selected = TRUE;
- break;
- } else
- popup_error(dialog, _("Select one POI from the list."));
- }
-
- gtk_widget_destroy(dialog);
-
- vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, selected);
- return selected;
-}
-
-void poi_populate_cat_combo(GtkWidget * cmb_category, guint cat_id)
-{
- GtkTreeIter active;
- GtkListStore *store;
- gboolean has_active = FALSE;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- 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)) {
- GtkTreeIter iter;
- guint cid = sqlite3_column_int(_stmt_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);
- if (cid == cat_id) {
- active = iter;
- has_active = TRUE;
- }
- }
- sqlite3_reset(_stmt_selall_cat);
-
- if (!has_active)
- gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active);
-
- gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &active);
-
- vprintf("%s(): return\n", __PRETTY_FUNCTION__);
-}
-
-typedef struct _PoiCategoryEditInfo PoiCategoryEditInfo;
-struct _PoiCategoryEditInfo {
- GtkWidget *cmb_category;
- guint cat_id;
-};
-
-gboolean poi_edit_cat(GtkWidget * widget, PoiCategoryEditInfo * data)
-{
- printf("%s()\n", __PRETTY_FUNCTION__);
- if (category_list())
- poi_populate_cat_combo(data->cmb_category, data->cat_id);
- vprintf("%s(): return\n", __PRETTY_FUNCTION__);
- return TRUE;
-}
-
-gboolean poi_dialog(POIAction action, guint unitx, guint unity)
-{
- PoiInfo poi;
- gchar slat1[10], slon1[10];
- gchar *p_latlon;
- GtkWidget *dialog;
- GtkWidget *table;
- GtkWidget *label;
- GtkWidget *txt_label;
- GtkWidget *cmb_category;
- GtkWidget *txt_desc;
- GtkWidget *btn_delete = NULL;
- GtkWidget *btn_catedit;
- GtkWidget *hbox;
- GtkWidget *txt_scroll;
- GtkTextBuffer *desc_txt;
- GtkTextIter begin, end;
- DeletePOI dpoi = { NULL, NULL, 0 };
- PoiCategoryEditInfo pcedit;
- printf("%s()\n", __PRETTY_FUNCTION__);
-
- if (action == ACTION_EDIT_POI) {
- if (!select_poi(unitx, unity, &poi)) {
- return FALSE;
- }
-
- dialog = gtk_dialog_new_with_buttons(_("Edit POI"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT, NULL);
-
- gtk_container_add(GTK_CONTAINER
- (GTK_DIALOG(dialog)->action_area),
- btn_delete =
- gtk_button_new_with_label(_("Delete")));
-
- dpoi.dialog = dialog;
- dpoi.txt_label = g_strdup(poi.label);
- dpoi.id = poi.poi_id;
-
- g_signal_connect(G_OBJECT(btn_delete), "clicked",
- G_CALLBACK(poi_delete), &dpoi);
-
- 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);
-
- unit2latlon(unitx, unity, poi.lat, poi.lon);
-
- poi.poi_id = 0;
- poi.cat_id = 0;
- poi.desc = g_strdup("");
-
- dialog = gtk_dialog_new_with_buttons(_("Add POI"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT, NULL);
- }
-
- /* Set the p_latlon string. */
- {
- gchar tmp1[16], tmp2[16];
- lat_format(poi.lat, tmp1);
- lon_format(poi.lon, tmp2);
- p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
- }
-
- 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(_("Lat, Lon")),
- 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),
- label = gtk_label_new(p_latlon),
- 1, 3, 0, 1, GTK_FILL, 0, 2, 4);
- gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
-
- gtk_table_attach(GTK_TABLE(table),
- label = gtk_label_new(_("Label")),
- 0, 1, 1, 2, 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, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
-
- gtk_table_attach(GTK_TABLE(table),
- label = gtk_label_new(_("Category")),
- 0, 1, 3, 4, GTK_FILL, 0, 2, 4);
- gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
- gtk_table_attach(GTK_TABLE(table),
- hbox = gtk_hbox_new(FALSE, 4),
- 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4);
- gtk_box_pack_start(GTK_BOX(hbox), cmb_category = gtk_combo_box_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_INT, /* Category ID */
- G_TYPE_STRING))), /* Category Label */
- FALSE, FALSE, 4);
- /* Set up the view for the combo box. */
- {
- GtkCellRenderer *renderer;
- renderer = gtk_cell_renderer_text_new();
- gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cmb_category),
- renderer, TRUE);
- gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cmb_category),
- renderer, "text", 1, NULL);
- }
-
- gtk_box_pack_start(GTK_BOX(hbox),
- btn_catedit =
- gtk_button_new_with_label(_("Edit Categories...")),
- FALSE, FALSE, 4);
-
- gtk_table_attach(GTK_TABLE(table),
- label = gtk_label_new(_("Description")),
- 0, 1, 5, 6, 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_table_attach(GTK_TABLE(table),
- txt_scroll,
- 1, 2, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 4);
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- txt_desc = gtk_text_view_new();
- gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
-
- gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
- gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
-
- desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
-
- /* label */
- gtk_entry_set_text(GTK_ENTRY(txt_label), poi.label);
-
- /* category */
- poi_populate_cat_combo(cmb_category, poi.cat_id);
-
- /* poi_desc */
- gtk_text_buffer_set_text(desc_txt, poi.desc, -1);
-
- /* Connect Signals */
- pcedit.cmb_category = cmb_category;
- pcedit.cat_id = poi.cat_id;
- g_signal_connect(G_OBJECT(btn_catedit), "clicked",
- G_CALLBACK(poi_edit_cat), &pcedit);
- gtk_widget_show_all(dialog);
-
- while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- const gchar *poi_label = NULL;
- gchar *poi_desc = NULL;
- GtkTreeIter iter;
-
- if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
- poi_label = gtk_entry_get_text(GTK_ENTRY(txt_label));
- else {
- popup_error(dialog,
- _("Please specify a name for the POI."));
- continue;
- }
-
- if (!gtk_combo_box_get_active_iter
- (GTK_COMBO_BOX(cmb_category), &iter)) {
- popup_error(dialog,
- _
- ("Please specify a category for the POI."));
- continue;
- }
-
- gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0);
- gtk_text_buffer_get_end_iter(desc_txt, &end);
- poi_desc =
- gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
-
- gtk_tree_model_get(gtk_combo_box_get_model
- (GTK_COMBO_BOX(cmb_category)), &iter, 0,
- &poi.cat_id, -1);
-
- if (action == ACTION_EDIT_POI) {
- /* edit poi */
- 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, poi.cat_id)
- || SQLITE_OK != sqlite3_bind_int(_stmt_update_poi,
- 4, poi.poi_id)
- || SQLITE_DONE != sqlite3_step(_stmt_update_poi)) {
- MACRO_BANNER_SHOW_INFO(_window,
- _
- ("Problem updating POI"));
- } else {
- MACRO_MAP_RENDER_DATA();
- }
- sqlite3_reset(_stmt_update_poi);
- } else {
- /* add poi */
- g_ascii_dtostr(slat1, sizeof(slat1), poi.lat);
- g_ascii_dtostr(slon1, sizeof(slon1), poi.lon);
- if (SQLITE_OK !=
- sqlite3_bind_double(_stmt_insert_poi, 1, poi.lat)
- || SQLITE_OK !=
- sqlite3_bind_double(_stmt_insert_poi, 2, poi.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, poi.cat_id)
- || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)) {
- MACRO_BANNER_SHOW_INFO(_window,
- _("Problem adding POI"));
- } else {
- MACRO_MAP_RENDER_DATA();
- }
- sqlite3_reset(_stmt_insert_poi);
- }
- break;
- }
-
- g_free(dpoi.txt_label);
-
- g_free(poi.label);
- g_free(poi.desc);
- g_free(p_latlon);
-
- gtk_widget_hide_all(dialog);
-
- vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
- return TRUE;
-}