2017-02-01 18:01:02 +01:00
|
|
|
|
#include "MasterController.h"
|
2019-08-24 20:47:32 +02:00
|
|
|
|
#include "ConnectionController.h"
|
2018-11-08 21:50:49 +01:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
QString GetUserConfigDatabaseName()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
|
QDir dir(path);
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
|
dir.mkpath(".");
|
|
|
|
|
|
}
|
|
|
|
|
|
path += "/pglabuser.db";
|
|
|
|
|
|
return path;
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-11-08 21:50:49 +01:00
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
MasterController::MasterController(QObject *parent) : QObject(parent)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MasterController::~MasterController()
|
2019-08-19 10:05:05 +02:00
|
|
|
|
{}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
void MasterController::init()
|
|
|
|
|
|
{
|
2018-11-08 21:50:49 +01:00
|
|
|
|
m_userConfigDatabase = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
|
|
m_userConfigDatabase.setDatabaseName(GetUserConfigDatabaseName());
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_userConfigDatabase.open()) {
|
|
|
|
|
|
qDebug() << "Error: connection with database fail";
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
qDebug() << "Database: connection ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-19 10:05:05 +02:00
|
|
|
|
m_connectionController = new ConnectionController(this);
|
|
|
|
|
|
m_connectionController->init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionController *MasterController::connectionController()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_connectionController;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QSqlDatabase& MasterController::userConfigDatabase()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_userConfigDatabase;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|