Add Common::databasePath which also allows overriding it
This commit is contained in:
parent
13fb901044
commit
8de07b703c
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
void printUsage(QString argv0)
|
void printUsage(QString argv0)
|
||||||
{
|
{
|
||||||
qInfo() << "Usage: " << argv0 << "command";
|
qInfo() << "Usage:" << argv0 << "command";
|
||||||
}
|
}
|
||||||
|
|
||||||
Command *commandFromName(QString name, SqliteDbService &dbService)
|
Command *commandFromName(QString name, SqliteDbService &dbService)
|
||||||
@ -66,11 +66,10 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString commandName = args.first();
|
QString connectionString = Common::databasePath();
|
||||||
QSettings settings;
|
|
||||||
QString connectionString = settings.value("dbpath").toString();
|
|
||||||
DatabaseFactory dbFactory(connectionString);
|
DatabaseFactory dbFactory(connectionString);
|
||||||
SqliteDbService dbService(dbFactory);
|
SqliteDbService dbService(dbFactory);
|
||||||
|
QString commandName = args.first();
|
||||||
Command *cmd = commandFromName(commandName, dbService);
|
Command *cmd = commandFromName(commandName, dbService);
|
||||||
if(cmd != nullptr)
|
if(cmd != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -16,13 +16,15 @@
|
|||||||
#include "clicklabel.h"
|
#include "clicklabel.h"
|
||||||
#include "../shared/sqlitesearch.h"
|
#include "../shared/sqlitesearch.h"
|
||||||
#include "../shared/qssgeneralexception.h"
|
#include "../shared/qssgeneralexception.h"
|
||||||
|
#include "../shared/common.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
db = QSqlDatabase::addDatabase("QSQLITE");
|
db = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
db.setDatabaseName(settings.value("dbpath").toString());
|
db.setDatabaseName(Common::databasePath());
|
||||||
if(!db.open())
|
if(!db.open())
|
||||||
{
|
{
|
||||||
qDebug() << "failed to open database";
|
qDebug() << "failed to open database";
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <QProcessEnvironment>
|
||||||
|
#include <QSettings>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
void Common::setupAppInfo()
|
void Common::setupAppInfo()
|
||||||
@ -6,3 +8,14 @@ void Common::setupAppInfo()
|
|||||||
QCoreApplication::setOrganizationDomain("quitesimple.org");
|
QCoreApplication::setOrganizationDomain("quitesimple.org");
|
||||||
QCoreApplication::setApplicationName("qss");
|
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;
|
||||||
|
}
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
void setupAppInfo();
|
void setupAppInfo();
|
||||||
}
|
QString databasePath();
|
||||||
|
} // namespace Common
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user