]> err.no Git - mapper/commitdiff
Move more direct sqlite handling from poi-gui.c to poi.c
authorKaj-Michael Lang <milang@angel.tal.org>
Fri, 20 Jul 2007 14:49:16 +0000 (17:49 +0300)
committerKaj-Michael Lang <milang@angel.tal.org>
Fri, 20 Jul 2007 14:49:16 +0000 (17:49 +0300)
src/poi-gui.c
src/poi.c

index f67ab5394518a95ad68d995159a3eb877b0152e5..258039806c01e41ddcc9c01d1e116b08ce570a02 100644 (file)
@@ -51,23 +51,8 @@ gboolean category_delete(GtkWidget * widget, DeletePOI * dpoi)
        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();
        }
@@ -95,8 +80,7 @@ gboolean category_dialog(guint cat_id)
        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);
@@ -890,70 +874,38 @@ gboolean poi_dialog(POIAction action, guint unitx, guint unity)
                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;
        }
index be8c04899f3c1805bac9faf090698c0f427243e8..dbe860e8e8f69b93f238ed9ccb00d7f35a8a41c4 100644 (file)
--- a/src/poi.c
+++ b/src/poi.c
@@ -85,7 +85,7 @@ poi_cb_populate_categories(sqlite3 *db)
 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);
@@ -297,6 +297,7 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1, dpoi->id)
                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)) {
@@ -304,6 +305,7 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
        return FALSE;
 }
 sqlite3_reset(_stmt_delete_cat);
+sqlite3_clear_bindings(_stmt_delete_cat);
 return TRUE;
 }
 
@@ -317,7 +319,39 @@ if (SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
        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;
+}
+