Password is no longer saved with the connection list. Password is not entered along with other connection credentials. Password is now asked for when required. Still working on saving the password and auto retrieving it from the password manager.
136 lines
3.3 KiB
C++
136 lines
3.3 KiB
C++
#include "MasterController.h"
|
|
#include "ConnectionManagerWindow.h"
|
|
#include "ConnectionList.h"
|
|
#include "ConnectionListModel.h"
|
|
#include "MainWindow.h"
|
|
#include "ServerWindow.h"
|
|
#include "BackupDialog.h"
|
|
#include "PasswordPromptDialog.h"
|
|
|
|
|
|
MasterController::MasterController(QObject *parent) : QObject(parent)
|
|
{}
|
|
|
|
MasterController::~MasterController()
|
|
{
|
|
delete m_connectionManagerWindow;
|
|
delete m_connectionListModel;
|
|
delete m_connectionList;
|
|
}
|
|
|
|
void MasterController::init()
|
|
{
|
|
m_connectionList = new ConnectionList;
|
|
m_connectionList->load();
|
|
m_connectionListModel = new ConnectionListModel(m_connectionList, this);
|
|
|
|
m_connectionManagerWindow = new ConnectionManagerWindow(this, nullptr);
|
|
m_connectionManagerWindow->show();
|
|
|
|
}
|
|
|
|
void MasterController::showConnectionManager()
|
|
{
|
|
m_connectionManagerWindow->show();
|
|
}
|
|
|
|
void MasterController::openSqlWindowForConnection(size_t connection_index)
|
|
{
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void MasterController::openBackupDlgForConnection(int connection_index)
|
|
{
|
|
auto res = m_connectionListModel->get(connection_index);
|
|
if (res.valid()) {
|
|
auto cc = res.get();
|
|
retrieveConnectionPassword(cc);
|
|
m_connectionListModel->save(connection_index, cc);
|
|
|
|
auto w = new BackupDialog(nullptr); //new ServerWindow(this, nullptr);
|
|
w->setAttribute( Qt::WA_DeleteOnClose );
|
|
w->setConfig(cc);
|
|
w->show();
|
|
}
|
|
}
|
|
|
|
void MasterController::openServerWindowForConnection(int connection_index)
|
|
{
|
|
auto res = m_connectionListModel->get(connection_index);
|
|
if (res.valid()) {
|
|
auto cc = res.get();
|
|
retrieveConnectionPassword(cc);
|
|
m_connectionListModel->save(connection_index, cc);
|
|
|
|
auto w = new ServerWindow(this, nullptr);
|
|
w->setAttribute( Qt::WA_DeleteOnClose );
|
|
w->setConfig(cc);
|
|
w->show();
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|