2017-02-01 18:01:02 +01:00
|
|
|
|
#include "MasterController.h"
|
2017-02-26 19:29:50 +01:00
|
|
|
|
#include "ConnectionManagerWindow.h"
|
|
|
|
|
|
#include "ConnectionList.h"
|
|
|
|
|
|
#include "ConnectionListModel.h"
|
2017-02-06 21:41:45 +01:00
|
|
|
|
#include "MainWindow.h"
|
2017-02-12 08:13:38 +01:00
|
|
|
|
#include "ServerWindow.h"
|
2017-03-05 21:23:36 +01:00
|
|
|
|
#include "BackupDialog.h"
|
2018-11-04 11:26:20 +01:00
|
|
|
|
#include "PasswordPromptDialog.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MasterController::MasterController(QObject *parent) : QObject(parent)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
MasterController::~MasterController()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_connectionManagerWindow;
|
|
|
|
|
|
delete m_connectionListModel;
|
2017-02-26 19:29:50 +01:00
|
|
|
|
delete m_connectionList;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MasterController::init()
|
|
|
|
|
|
{
|
2017-02-26 19:29:50 +01:00
|
|
|
|
m_connectionList = new ConnectionList;
|
|
|
|
|
|
m_connectionList->load();
|
|
|
|
|
|
m_connectionListModel = new ConnectionListModel(m_connectionList, this);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
m_connectionManagerWindow = new ConnectionManagerWindow(this, nullptr);
|
|
|
|
|
|
m_connectionManagerWindow->show();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MasterController::showConnectionManager()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_connectionManagerWindow->show();
|
|
|
|
|
|
}
|
2017-02-01 19:59:07 +01:00
|
|
|
|
|
2018-11-04 11:26:20 +01:00
|
|
|
|
void MasterController::openSqlWindowForConnection(size_t connection_index)
|
2017-02-01 19:59:07 +01:00
|
|
|
|
{
|
2018-11-04 11:26:20 +01:00
|
|
|
|
|
|
|
|
|
|
auto res = m_connectionListModel->get(connection_index);
|
|
|
|
|
|
if (res.valid()) {
|
|
|
|
|
|
auto cc = res.get();
|
|
|
|
|
|
|
|
|
|
|
|
m_connectionListModel->save(connection_index, cc);
|
|
|
|
|
|
if (retrieveConnectionPassword(cc)) {
|
|
|
|
|
|
// TODO instead of directly openening the mainwindow
|
|
|
|
|
|
// do async connect and only open window when we have
|
|
|
|
|
|
// working connection
|
|
|
|
|
|
auto w = new MainWindow(this, nullptr);
|
|
|
|
|
|
w->setAttribute( Qt::WA_DeleteOnClose );
|
|
|
|
|
|
w->setConfig(cc);
|
|
|
|
|
|
w->show();
|
|
|
|
|
|
}
|
2017-02-01 19:59:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-02-12 08:13:38 +01:00
|
|
|
|
|
2017-03-05 21:23:36 +01:00
|
|
|
|
void MasterController::openBackupDlgForConnection(int connection_index)
|
|
|
|
|
|
{
|
2018-11-04 11:26:20 +01:00
|
|
|
|
auto res = m_connectionListModel->get(connection_index);
|
|
|
|
|
|
if (res.valid()) {
|
|
|
|
|
|
auto cc = res.get();
|
|
|
|
|
|
retrieveConnectionPassword(cc);
|
|
|
|
|
|
m_connectionListModel->save(connection_index, cc);
|
|
|
|
|
|
|
2017-03-05 21:23:36 +01:00
|
|
|
|
auto w = new BackupDialog(nullptr); //new ServerWindow(this, nullptr);
|
|
|
|
|
|
w->setAttribute( Qt::WA_DeleteOnClose );
|
2018-11-04 11:26:20 +01:00
|
|
|
|
w->setConfig(cc);
|
2017-03-05 21:23:36 +01:00
|
|
|
|
w->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-12 08:13:38 +01:00
|
|
|
|
void MasterController::openServerWindowForConnection(int connection_index)
|
|
|
|
|
|
{
|
2018-11-04 11:26:20 +01:00
|
|
|
|
auto res = m_connectionListModel->get(connection_index);
|
|
|
|
|
|
if (res.valid()) {
|
|
|
|
|
|
auto cc = res.get();
|
|
|
|
|
|
retrieveConnectionPassword(cc);
|
|
|
|
|
|
m_connectionListModel->save(connection_index, cc);
|
|
|
|
|
|
|
2017-02-12 08:13:38 +01:00
|
|
|
|
auto w = new ServerWindow(this, nullptr);
|
|
|
|
|
|
w->setAttribute( Qt::WA_DeleteOnClose );
|
2018-11-04 11:26:20 +01:00
|
|
|
|
w->setConfig(cc);
|
2017-02-12 08:13:38 +01:00
|
|
|
|
w->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-04 11:26:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MasterController::retrieveConnectionPassword(ConnectionConfig &cc)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Look at config
|
|
|
|
|
|
// - is password required, how do we know?
|
|
|
|
|
|
// - IF is password stored in pskdb
|
|
|
|
|
|
// - ask pskdb for password
|
|
|
|
|
|
// - ELSE
|
|
|
|
|
|
// - ask user for password
|
|
|
|
|
|
QString str = ConnectionListModel::makeLongDescription(cc);
|
|
|
|
|
|
auto dlg = std::make_unique<PasswordPromptDialog>(nullptr);
|
|
|
|
|
|
dlg->setConnectionDescription(str);
|
|
|
|
|
|
int exec_result = dlg->exec();
|
|
|
|
|
|
|
|
|
|
|
|
if (exec_result == QDialog::Accepted) {
|
|
|
|
|
|
cc.setPassword(dlg->password().toUtf8().data());
|
|
|
|
|
|
// - IF user checked remember password
|
|
|
|
|
|
// - ask pskdb to store password
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MasterController::getPasswordFromPskdb(const std::string &password_id, std::string &password)
|
|
|
|
|
|
{
|
|
|
|
|
|
// func: getPasswordFromPskdb
|
|
|
|
|
|
// IF pskdb locked
|
|
|
|
|
|
// prompt user for pskdb passphrase
|
|
|
|
|
|
// unlock pskdb
|
|
|
|
|
|
// get pwd
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MasterController::storePasswordInPskdb(const std::string &password_id, const std::string password)
|
|
|
|
|
|
{
|
|
|
|
|
|
// func: storePasswordInPskdb
|
|
|
|
|
|
// IF pskdb not setup
|
|
|
|
|
|
// notify user and ask for passphrase
|
|
|
|
|
|
// init pskdb
|
|
|
|
|
|
// ELSE
|
|
|
|
|
|
// IF pskdb locked
|
|
|
|
|
|
// ask for passphrase
|
|
|
|
|
|
// unlock
|
|
|
|
|
|
// store pwd
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|