Most of functionality for connections in tree works now. Old list largely removed.

This commit is contained in:
eelke 2019-08-27 20:12:00 +02:00
parent 8840d3bcbb
commit b3a98f6dc0
10 changed files with 399 additions and 158 deletions

View file

@ -19,7 +19,6 @@ ConnectionController::~ConnectionController()
{
delete m_connectionManagerWindow;
delete m_connectionTreeModel;
delete m_connectionListModel;
}
void ConnectionController::init()
@ -30,8 +29,6 @@ void ConnectionController::init()
m_passwordManager = std::make_shared<PasswordManager>();
m_connectionListModel = new ConnectionListModel(this);
m_connectionListModel->load();
m_connectionTreeModel = new ConnectionTreeModel(this, m_masterController->userConfigDatabase());
m_connectionTreeModel->load();
@ -45,37 +42,47 @@ void ConnectionController::showConnectionManager()
m_connectionManagerWindow->show();
}
void ConnectionController::openSqlWindowForConnection(int connection_index)
namespace {
ConnectionConfig* getConfigFromModelIndex(QModelIndex index)
{
if (!index.isValid())
return nullptr;
auto node = static_cast<ConnectionNode*>(index.internalPointer());
return dynamic_cast<ConnectionConfig*>(node);
}
}
void ConnectionController::openSqlWindowForConnection(QModelIndex index)
{
auto config = getConfigFromModelIndex(index);
if (config) {
auto res = m_connectionListModel->get(connection_index);
if (res.valid()) {
auto cc = res.get();
if (retrieveConnectionPassword(cc)) {
m_connectionListModel->save(cc);
if (retrieveConnectionPassword(*config)) {
m_connectionTreeModel->save(*config);
// TODO instead of directly openening the mainwindow
// do async connect and only open window when we have
// working connection
auto w = new DatabaseWindow(m_masterController, nullptr);
w->setAttribute( Qt::WA_DeleteOnClose );
w->setConfig(cc);
w->setConfig(*config);
w->showMaximized();
}
}
}
void ConnectionController::openBackupDlgForConnection(int connection_index)
void ConnectionController::openBackupDlgForConnection(QModelIndex index)
{
auto res = m_connectionListModel->get(connection_index);
if (res.valid()) {
auto cc = res.get();
if (retrieveConnectionPassword(cc)) {
m_connectionListModel->save(cc);
auto config = getConfigFromModelIndex(index);
if (config) {
if (retrieveConnectionPassword(*config)) {
m_connectionTreeModel->save(*config);
auto w = new BackupDialog(nullptr); //new ServerWindow(this, nullptr);
w->setAttribute( Qt::WA_DeleteOnClose );
w->setConfig(cc);
w->setConfig(*config);
w->show();
}
}
@ -88,25 +95,23 @@ void ConnectionController::createConnection()
ConnectionConfigurationWidget::editExistingInWindow(this, cc);
}
void ConnectionController::editConnection(int connection_index)
void ConnectionController::editConnection(QModelIndex index)
{
auto res = m_connectionListModel->get(connection_index);
if (res.valid()) {
auto cc = res.get();
ConnectionConfigurationWidget::editExistingInWindow(this, cc);
auto config = getConfigFromModelIndex(index);
if (config) {
ConnectionConfigurationWidget::editExistingInWindow(this, *config);
}
}
void ConnectionController::openServerWindowForConnection(int connection_index)
void ConnectionController::openServerWindowForConnection(QModelIndex index)
{
auto res = m_connectionListModel->get(connection_index);
if (res.valid()) {
auto cc = res.get();
if (retrieveConnectionPassword(cc)) {
m_connectionListModel->save(cc);
auto config = getConfigFromModelIndex(index);
if (config) {
if (retrieveConnectionPassword(*config)) {
m_connectionTreeModel->save(*config);
auto w = new ServerWindow(m_masterController, nullptr);
w->setAttribute( Qt::WA_DeleteOnClose );
w->setConfig(cc);
w->setConfig(*config);
w->show();
}
}
@ -129,7 +134,7 @@ bool ConnectionController::retrieveConnectionPassword(ConnectionConfig &cc)
}
// Geen else hier want als voorgaande blok niet geretourneerd heeft moeten we wachtwoord
// ook aan de gebruiker vragen zoals hier gebeurd.
QString str = ConnectionListModel::makeLongDescription(cc);
QString str = cc.makeLongDescription();
auto dlg = std::make_unique<PasswordPromptDialog>(PasswordPromptDialog::SaveOption, nullptr);
dlg->setCaption(tr("Connection password prompt"));
dlg->setDescription(QString(tr("Please provide password for connection %1")).arg(str));