From 34c828a45351f943ea4551c67f4a5a4b8531318d Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 24 May 2020 15:36:27 +0200 Subject: [PATCH] Add Common::databasePath which also allows overriding it --- cli/main.cpp | 7 +++---- gui/mainwindow.cpp | 4 +++- shared/common.cpp | 17 +++++++++++++++-- shared/common.h | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cli/main.cpp b/cli/main.cpp index bae01f6..70c9788 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -28,7 +28,7 @@ void printUsage(QString argv0) { - qInfo() << "Usage: " << argv0 << "command"; + qInfo() << "Usage:" << argv0 << "command"; } Command *commandFromName(QString name, SqliteDbService &dbService) @@ -66,11 +66,10 @@ int main(int argc, char *argv[]) exit(1); } - QString commandName = args.first(); - QSettings settings; - QString connectionString = settings.value("dbpath").toString(); + QString connectionString = Common::databasePath(); DatabaseFactory dbFactory(connectionString); SqliteDbService dbService(dbFactory); + QString commandName = args.first(); Command *cmd = commandFromName(commandName, dbService); if(cmd != nullptr) { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index f969aaf..0888cd4 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -16,6 +16,8 @@ #include "clicklabel.h" #include "../shared/sqlitesearch.h" #include "../shared/qssgeneralexception.h" +#include "../shared/common.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -24,7 +26,7 @@ MainWindow::MainWindow(QWidget *parent) : QSettings settings; db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName(settings.value("dbpath").toString()); + db.setDatabaseName(Common::databasePath()); if(!db.open()) { qDebug() << "failed to open database"; diff --git a/shared/common.cpp b/shared/common.cpp index 60fec1a..7767ed0 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -1,8 +1,21 @@ +#include +#include #include "common.h" void Common::setupAppInfo() { QCoreApplication::setOrganizationName("quitesimple.org"); - QCoreApplication::setOrganizationDomain("quitesimple.org"); - QCoreApplication::setApplicationName("qss"); + QCoreApplication::setOrganizationDomain("quitesimple.org"); + QCoreApplication::setApplicationName("qss"); +} + +QString Common::databasePath() +{ + QString env = QProcessEnvironment::systemEnvironment().value("QSS_DB_OVERRIDE"); + if(env == "") + { + QSettings settings; + return settings.value("dbpath").toString(); + } + return env; } diff --git a/shared/common.h b/shared/common.h index c6ec556..9a15624 100644 --- a/shared/common.h +++ b/shared/common.h @@ -5,5 +5,6 @@ namespace Common { void setupAppInfo(); + QString databasePath(); } #endif