From: Kaj-Michael Lang Date: Tue, 19 Jun 2007 09:32:57 +0000 (+0300) Subject: The database is not specific to POIs only so rename/move variables. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd2029e85dd747e0496a6130e7dd92cba385bf68;p=mapper The database is not specific to POIs only so rename/move variables. --- diff --git a/src/cb.c b/src/cb.c index 7d91d98..83d3bfb 100644 --- a/src/cb.c +++ b/src/cb.c @@ -31,6 +31,7 @@ #include "mapper-types.h" #include "bt.h" #include "ui-common.h" +#include "db.h" #include "cb.h" diff --git a/src/config.c b/src/config.c index 0aba52a..29b7ef9 100644 --- a/src/config.c +++ b/src/config.c @@ -371,8 +371,8 @@ config_save() } /* Save POI database. */ - if (_poi_db) - gconf_client_set_string(gconf_client, GCONF_KEY_POI_DB, _poi_db, NULL); + if (_mapper_db) + gconf_client_set_string(gconf_client, GCONF_KEY_POI_DB, _mapper_db, NULL); else gconf_client_unset(gconf_client, GCONF_KEY_POI_DB, NULL); @@ -727,15 +727,15 @@ void config_init() } /* Get POI Database. Default is in REPO_DEFAULT_CACHE_BASE */ - _poi_db = gconf_client_get_string(gconf_client, GCONF_KEY_POI_DB, NULL); - if (_poi_db == NULL) { + _mapper_db = gconf_client_get_string(gconf_client, GCONF_KEY_POI_DB, NULL); + if (_mapper_db == NULL) { gchar *poi_base = gnome_vfs_expand_initial_tilde(REPO_DEFAULT_CACHE_BASE); - _poi_db = + _mapper_db = gnome_vfs_uri_make_full_from_relative(poi_base, "poi.db"); g_free(poi_base); } - poi_db_connect(&_db, _poi_db); + poi_db_connect(&_db, _mapper_db); _poi_zoom = gconf_client_get_int(gconf_client, GCONF_KEY_POI_ZOOM, NULL); diff --git a/src/db.c b/src/db.c index 29ef530..c8045b2 100644 --- a/src/db.c +++ b/src/db.c @@ -6,6 +6,9 @@ #include "db.h" #include "utils.h" +sqlite3 *_db=NULL; +gchar *_mapper_db=NULL; + /** * A simple check to test if a table exists * @@ -42,7 +45,7 @@ return TRUE; * Connect to given sqlite database * */ -gboolean db_connect(sqlite3 **ndb, const gchar *db_file) +gboolean db_connect(sqlite3 **ndb, const gchar *mapper_db) { sqlite3 *db; @@ -58,10 +61,10 @@ if (db) { db = NULL; } -if (!db_file) +if (!mapper_db) return FALSE; -if (SQLITE_OK != (sqlite3_open(db_file, &db))) { +if (SQLITE_OK != (sqlite3_open(mapper_db, &db))) { sqlite3_close(db); db = NULL; *ndb=db; diff --git a/src/db.h b/src/db.h index ea53d82..9c84608 100644 --- a/src/db.h +++ b/src/db.h @@ -4,7 +4,10 @@ #ifndef _MAPPER_DB_H #define _MAPPER_DB_H -gboolean db_connect(sqlite3 **db, const gchar *poi_db); +sqlite3 *_db; +gchar *_mapper_db; + +gboolean db_connect(sqlite3 **db, const gchar *mapper_db); gboolean db_check(sqlite3 *db, const gchar *table); gboolean db_close(sqlite3 **db); diff --git a/src/map-poi.c b/src/map-poi.c index 040dd63..7f55a13 100644 --- a/src/map-poi.c +++ b/src/map-poi.c @@ -12,6 +12,7 @@ #include "settings.h" #include "mapper-types.h" #include "ui-common.h" +#include "db.h" #define POI_FONT_SIZE (10) diff --git a/src/mapper.c b/src/mapper.c index a77ded4..85bcd45 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -75,6 +75,7 @@ #include "map.h" #include "bt.h" #include "ui-common.h" +#include "db.h" #include "cb.h" gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,}; @@ -174,10 +175,7 @@ void mapper_destroy(void) rcvr_disconnect(); /* _program and widgets have already been destroyed. */ - if (_db) { - sqlite3_close(_db); - _db = NULL; - } + db_close(&_db); MACRO_PATH_FREE(_track); MACRO_PATH_FREE(_route); diff --git a/src/poi.c b/src/poi.c index 5ba26d3..5ed882e 100644 --- a/src/poi.c +++ b/src/poi.c @@ -29,9 +29,6 @@ #include "settings.h" #include "db.h" -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; diff --git a/src/poi.h b/src/poi.h index a38b2ad..6f5ef0a 100644 --- a/src/poi.h +++ b/src/poi.h @@ -107,11 +107,9 @@ struct _DeletePOI { guint id; }; -/** POI */ -sqlite3 *_db; -gchar *_poi_db; guint _poi_zoom; +/* POI SQL statements */ sqlite3_stmt *_stmt_select_poi; sqlite3_stmt *_stmt_select_nearest_poi; sqlite3_stmt *_stmt_insert_poi; @@ -120,6 +118,7 @@ sqlite3_stmt *_stmt_delete_poi; sqlite3_stmt *_stmt_delete_poi_by_catid; sqlite3_stmt *_stmt_nextlabel_poi; +/* Category SQL statements */ sqlite3_stmt *_stmt_select_cat; sqlite3_stmt *_stmt_insert_cat; sqlite3_stmt *_stmt_update_cat; diff --git a/src/settings-gui.c b/src/settings-gui.c index c5a46b9..69112e6 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -30,6 +30,7 @@ #include "bt.h" #include "ui-common.h" #include "settings.h" +#include "db.h" #include "hildon-wrappers.h" @@ -400,7 +401,7 @@ gboolean settings_dialog() GtkWidget *btn_buttons; GtkWidget *btn_colors; - GtkWidget *txt_poi_db; + GtkWidget *txt_mapper_db; GtkWidget *btn_browsepoi; GtkWidget *num_poi_zoom; GtkWidget *chk_speed_limit_on; @@ -688,7 +689,7 @@ gboolean settings_dialog() hbox = gtk_hbox_new(FALSE, 4), 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4); gtk_box_pack_start(GTK_BOX(hbox), - txt_poi_db = gtk_entry_new(), TRUE, TRUE, 0); + txt_mapper_db = gtk_entry_new(), TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), btn_browsepoi = gtk_button_new_with_label(_("Browse...")), FALSE, @@ -716,7 +717,7 @@ gboolean settings_dialog() G_CALLBACK(settings_dialog_colors), dialog); browse_info.dialog = dialog; - browse_info.txt = txt_poi_db; + browse_info.txt = txt_mapper_db; g_signal_connect(G_OBJECT(btn_browsepoi), "clicked", G_CALLBACK(settings_dialog_browse_forfile), &browse_info); @@ -724,8 +725,8 @@ gboolean settings_dialog() /* Initialize fields. */ if (_rcvr_mac) gtk_entry_set_text(GTK_ENTRY(txt_rcvr_mac), _rcvr_mac); - if (_poi_db) - gtk_entry_set_text(GTK_ENTRY(txt_poi_db), _poi_db); + if (_mapper_db) + gtk_entry_set_text(GTK_ENTRY(txt_mapper_db), _mapper_db); hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(num_poi_zoom), _poi_zoom); @@ -825,12 +826,12 @@ gboolean settings_dialog() poi_db_disconnect(&_db); _db = NULL; } - g_free(_poi_db); - if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_poi_db)))) { - _poi_db = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_poi_db))); - poi_db_connect(&_db, _poi_db); + g_free(_mapper_db); + if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)))) { + _mapper_db = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db))); + poi_db_connect(&_db, _mapper_db); } else { - _poi_db = NULL; + _mapper_db = NULL; } /* Sensitize menus based on whether we have a POI database conn. */ diff --git a/src/ui-common.c b/src/ui-common.c index fa455f1..90be9c0 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -31,6 +31,7 @@ #include "mapper-types.h" #include "bt.h" #include "ui-common.h" +#include "db.h" /* Callbacks */ #include "cb.h"