Made slow part of MainWindow initialization asynchronous.

This commit is contained in:
eelke 2017-12-25 15:33:10 +01:00
parent 6d4662aa98
commit 554f138d6d
3 changed files with 27 additions and 11 deletions

View file

@ -14,7 +14,7 @@
#include "QueryTab.h"
#include "util.h"
#include "MasterController.h"
#include "OpenDatabase.h"
#include "WorkManager.h"
namespace pg = Pgsql;
@ -56,13 +56,31 @@ void MainWindow::setConfig(const ConnectionConfig &config)
{
m_config = config;
try {
auto res = OpenDatabase::createOpenDatabase(config);
//if (res.valid()) {
m_database = res.get();
QString title = "pglab - ";
title += m_config.name().c_str();
setWindowTitle(title);
WorkManager::getWorkManager()->addWork(
[config, this]() {
auto res = OpenDatabase::createOpenDatabase(config);
QueueTask([this, res] () {
catalogLoaded(res);
});
});
} catch (std::runtime_error &ex) {
QMessageBox::critical(this, "Error reading database",
QString::fromUtf8(ex.what()));
close();
}
}
void MainWindow::catalogLoaded(Expected<OpenDatabase::OpenDatabaseSPtr> res)
{
try {
m_database = res.get();
auto tt = new TablesPage(this);
tt->setCatalog(m_database->catalogue());
ui->tabWidget->addTab(tt, "Tables");
@ -70,10 +88,6 @@ void MainWindow::setConfig(const ConnectionConfig &config)
newSqlPage();
} catch (std::runtime_error &ex) {
// QMessageBox msgBox;
// msgBox.setText(QString::fromUtf8(ex.what()));
// msgBox.exec();
QMessageBox::critical(this, "Error reading database",
QString::fromUtf8(ex.what()));