gtk_widget_destroy(GTK_WIDGET(dialog));
if (i == GTK_RESPONSE_OK) {
- /* delete dpoi->poi_id */
- if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id) ||
- SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid)) {
- MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting POI"));
- sqlite3_reset(_stmt_delete_poi_by_catid);
- return FALSE;
- }
- sqlite3_reset(_stmt_delete_poi_by_catid);
-
- if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id)
- || SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) {
- MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting category"));
- sqlite3_reset(_stmt_delete_cat);
- return FALSE;
- }
- sqlite3_reset(_stmt_delete_cat);
-
+ if (poi_category_delete(dpoi)==FALSE)
+ MACRO_BANNER_SHOW_INFO(_window, _("Problem deleting category or POI"));
gtk_widget_hide_all(dpoi->dialog);
map_force_redraw();
}
printf("%s()\n", __PRETTY_FUNCTION__);
if (cat_id > 0) {
- if (SQLITE_OK !=
- sqlite3_bind_double(_stmt_select_cat, 1, cat_id)
+ 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 (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."));
+ 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."));
+ 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);
+ 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);
+ 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"));
+ if (poi_update(poi.poi_id, poi.cat_id, poi_label, poi_desc)==FALSE) {
+ 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"));
+ if (poi_add(poi.lat, poi.lon, poi.cat_id, poi_label, poi_desc)==FALSE) {
+ MACRO_BANNER_SHOW_INFO(_window, _("Problem adding POI"));
} else {
MACRO_MAP_RENDER_DATA();
}
- sqlite3_reset(_stmt_insert_poi);
}
break;
}
sqlite3_stmt *sql_cat;
gint i;
-g_printf("Checking default categories...");
+g_printf("Checking default categories\n");
sqlite3_prepare(db,"insert into category (cat_id, label, desc, enabled)"
" values (?, ?, ?, 1)",
-1, &sql_cat, NULL);
return FALSE;
}
sqlite3_reset(_stmt_delete_poi_by_catid);
+sqlite3_clear_bindings(_stmt_delete_poi_by_catid);
if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
SQLITE_DONE != sqlite3_step(_stmt_delete_cat)) {
return FALSE;
}
sqlite3_reset(_stmt_delete_cat);
+sqlite3_clear_bindings(_stmt_delete_cat);
return TRUE;
}
return FALSE;
} else {
sqlite3_reset(_stmt_delete_poi);
+ sqlite3_clear_bindings(_stmt_delete_poi);
}
return TRUE;
}
+gboolean
+poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc)
+{
+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)) {
+ return FALSE;
+ }
+sqlite3_reset(_stmt_update_poi);
+sqlite3_clear_bindings(_stmt_update_poi);
+return TRUE;
+}
+
+gboolean
+poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc)
+{
+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)) {
+ return FALSE;
+ }
+sqlite3_reset(_stmt_insert_poi);
+sqlite3_clear_bindings(_stmt_insert_poi);
+return TRUE;
+}
+