pgLab/pglab/ConnectionManagerWindow.cpp
eelke b09e8a6d4b ConnectionManager overhaul
- connection settings are now changed by seperate component currently called in a seperate window
- old settings pane on the right of the connections had been removed
- new edit config button added between new connection and remove connection
2019-08-24 20:47:32 +02:00

98 lines
2.6 KiB
C++

#include "ConnectionManagerWindow.h"
#include "ui_ConnectionManagerWindow.h"
#include "MasterController.h"
#include "ConnectionController.h"
#include <QMessageBox>
#include <QStandardItemModel>
#include "ConnectionListModel.h"
#include <QDir>
#include <QStandardPaths>
QString pskFileName()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(".");
}
path += "/psk.ini";
return path;
}
ConnectionManagerWindow::ConnectionManagerWindow(MasterController *master, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::ConnectionManagerWindow)
, m_masterController(master)
, m_connectionController(master->connectionController())
{
ui->setupUi(this);
ui->listView->setModel(m_connectionController->getConnectionListModel());
}
ConnectionManagerWindow::~ConnectionManagerWindow()
{
delete ui;
}
void ConnectionManagerWindow::on_actionAdd_Connection_triggered()
{
m_connectionController->createConnection();
}
void ConnectionManagerWindow::on_actionDelete_connection_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
if (ci.isValid()) {
auto res = QMessageBox::question(this, "pglab",
tr("Are you sure you want to remove this connection?"), QMessageBox::Yes, QMessageBox::No);
if (res == QMessageBox::Yes) {
auto clm = m_connectionController->getConnectionListModel();
clm->removeRow(ci.row());
}
}
}
void ConnectionManagerWindow::on_actionConnect_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
if (ci.isValid()) {
m_connectionController->openSqlWindowForConnection(ci.row());
}
}
void ConnectionManagerWindow::on_actionQuit_application_triggered()
{
auto res = QMessageBox::question(this, "pglab",
tr("Close all windows?"), QMessageBox::Yes, QMessageBox::No);
if (res == QMessageBox::Yes) {
QApplication::quit();
}
}
void ConnectionManagerWindow::on_actionBackup_database_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
m_connectionController->openBackupDlgForConnection(ci.row());
}
void ConnectionManagerWindow::on_actionManage_server_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
m_connectionController->openServerWindowForConnection(ci.row());
}
void ConnectionManagerWindow::on_listView_activated(const QModelIndex &index)
{
if (index.isValid()) {
m_connectionController->openSqlWindowForConnection(index.row());
}
}
void ConnectionManagerWindow::on_actionConfigure_connection_triggered()
{
auto ci = ui->listView->selectionModel()->currentIndex();
m_connectionController->editConnection(ci.row());
}