From bfa9ce7bd5b2182dea4e963d6354f4fb91e06f1c Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Thu, 25 Aug 2011 01:45:47 +0100 Subject: [PATCH] Move RtcomEventLogger DB path out into settings. Ideally, it'd be nice to have the location configurable. It also makes it available to other classes. Might revisit this later. --- DBBackends/RtcomEventLogger.cpp | 10 +++++----- DBBackends/RtcomEventLogger.h | 1 - Settings.cpp | 5 +++++ Settings.h | 6 ++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DBBackends/RtcomEventLogger.cpp b/DBBackends/RtcomEventLogger.cpp index aac4790..264b65a 100644 --- a/DBBackends/RtcomEventLogger.cpp +++ b/DBBackends/RtcomEventLogger.cpp @@ -54,7 +54,7 @@ QDebug operator<<(QDebug, GList &); QDebug operator<<(QDebug, QList &); RtcomEventLogger::RtcomEventLogger(const Settings &settings) : - m_Settings(settings), mk_DBPath("/.rtcom-eventlogger/el-v1.db") + m_Settings(settings) { RTComEl *el(rtcom_el_new()); if(NULL != el) @@ -77,7 +77,7 @@ RtcomEventLogger::RtcomEventLogger(const Settings &settings) : } RtcomEventLogger::RtcomEventLogger(const Settings &settings, const EventTypes::RtcomEvent &event) : - m_Settings(settings), mk_DBPath("/.rtcom-eventlogger/el-v1.db") + m_Settings(settings) { } @@ -340,10 +340,10 @@ void RtcomEventLogger::ClearInsertedIDs() void RtcomEventLogger::Reindex() { // Set up the database connection... - QSqlDatabase db(QSqlDatabase::addDatabase( "QSQLITE" )); + QSqlDatabase db(QSqlDatabase::addDatabase("QSQLITE")); - db.setDatabaseName( QDir::homePath() + mk_DBPath ); - if ( ! db.open() ) + db.setDatabaseName(CurrentSettings().DBPath()); + if(!db.open()) { throw std::runtime_error("Cannot open database: Unable to establish database connection"); } diff --git a/DBBackends/RtcomEventLogger.h b/DBBackends/RtcomEventLogger.h index a2a5053..d82814d 100644 --- a/DBBackends/RtcomEventLogger.h +++ b/DBBackends/RtcomEventLogger.h @@ -65,7 +65,6 @@ namespace DBBackends void Reindex(); const Settings &m_Settings; - const QString mk_DBPath; QHash m_ServiceIDs; diff --git a/Settings.cpp b/Settings.cpp index 0adaf34..cec9b44 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -18,6 +18,8 @@ #include "Settings.h" +#include + Settings::Settings() { // Default to console @@ -44,4 +46,7 @@ Settings::Settings() // It's OK to disable the radio by default setDisableCellular(true); + + // Where it lives... + DBPath(QDir::homePath() + "/.rtcom-eventlogger/el-v1.db"); } diff --git a/Settings.h b/Settings.h index c8bad92..b308b6f 100644 --- a/Settings.h +++ b/Settings.h @@ -70,6 +70,10 @@ private: // Is it OK to disable the cellular radio to prevent calls and messages? bool m_DisableCellular; + // RtcomEventLogger path + QString m_DBPath; + void DBPath(QString dbPath) { m_DBPath = dbPath; } + public: Settings(); @@ -101,6 +105,8 @@ public: bool const DisableCellular() const { return m_DisableCellular; } bool const setDisableCellular(const bool disableCellular) { return m_DisableCellular = disableCellular; } + + const QString &DBPath() const { return m_DBPath; } }; #endif // SETTINGS_H -- 1.7.9.5