pgLab/pglab/ServerWindow.cpp
eelke ecae0464f9 Fix: openening not accessible database crashes program.
OpenDatabase::createOpenDatabase now uses QException derived exception to report failure.
This makes it possible to catch the exception in a background thread and rethrow it when the Future is read.
Which makes it possible for the database window to properly report the problem.
2019-01-29 19:42:32 +01:00

45 lines
1.1 KiB
C++

#include "ServerWindow.h"
#include "ui_ServerWindow.h"
#include "OpenDatabase.h"
#include "DatabasesTableModel.h"
#include "RolesTableModel.h"
#include "catalog/PgDatabaseCatalog.h"
#include <QDebug>
ServerWindow::ServerWindow(MasterController *master, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::ServerWindow)
, m_masterController(master)
{
ui->setupUi(this);
m_databasesModel = new DatabasesTableModel(this);
ui->databasesTableView->setModel(m_databasesModel);
m_rolesModel = new RolesTableModel(this);
ui->rolesTableView->setModel(m_rolesModel);
}
ServerWindow::~ServerWindow()
{
delete ui;
}
void ServerWindow::setConfig(const ConnectionConfig &config)
{
m_config = config;
try {
m_database = OpenDatabase::createOpenDatabase(config);
auto cat = m_database->catalog();
if (cat) {
m_databasesModel->setDatabaseList(cat);
m_rolesModel->setRoleList(cat->authIds());
}
}
catch (const OpenDatabaseException &ex) {
qWarning() << ex.text();
}
QString title = "pglab - ";
title += m_config.name().c_str();
setWindowTitle(title);
}