Skip to content

Commit

Permalink
[MainWindow] Status bar now showing database update progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed May 7, 2020
1 parent ecbd66f commit f9574fe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/ContentData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

ContentData::ContentData() : m_database(*this) {
connect(&m_database.loader(), &DatabaseLoader::updateFinished, this, &ContentData::update);
connect(&m_database.loader(), &DatabaseLoader::updateFinished, this, &ContentData::windowRefeshRequested);
}

void ContentData::openDatabase(const QString &path) {
Expand All @@ -45,6 +44,7 @@ void ContentData::updateDatabase() {
stopDatabaseUpdate();

emit databaseUpdateStarted();
emit stateChanged("Updating database...");

m_databaseThread = new DatabaseThread(&m_database);
connect(m_databaseThread, &QThread::finished, this, &ContentData::databaseUpdateFinished);
Expand Down
17 changes: 17 additions & 0 deletions source/DatabaseLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,47 @@ void DatabaseLoader::update() const {

const auto &repositoryList = m_data.repositoryList();
for (auto &it : repositoryList) {
emit stateChanged("Loading users from repository '" + it.second.name() + "'...");

updateModel<ContentUser>(it.second, "/api/user",
std::bind(&ContentData::getUser, &m_data, _1),
std::bind(&ContentData::setUser, &m_data, _1, _2),
std::bind(&ContentData::userList, &m_data));

emit updateProgressed(20);
emit stateChanged("Loading news from repository '" + it.second.name() + "'...");

updateModel<ContentNewsArticle>(it.second, "/api/news",
std::bind(&ContentData::getNewsArticle, &m_data, _1),
std::bind(&ContentData::setNewsArticle, &m_data, _1, _2),
std::bind(&ContentData::newsArticleList, &m_data));

emit updateProgressed(40);
emit stateChanged("Loading engine versions from repository '" + it.second.name() + "'...");

updateModel<ContentEngineVersion>(it.second, "/api/version",
std::bind(&ContentData::getEngineVersion, &m_data, _1),
std::bind(&ContentData::setEngineVersion, &m_data, _1, _2),
std::bind(&ContentData::engineVersionList, &m_data));

emit updateProgressed(60);
emit stateChanged("Loading mods from repository '" + it.second.name() + "'...");

updateModel<ContentMod>(it.second, "/api/mod",
std::bind(&ContentData::getMod, &m_data, _1),
std::bind(&ContentData::setMod, &m_data, _1, _2),
std::bind(&ContentData::modList, &m_data));

emit updateProgressed(80);
emit stateChanged("Loading mod versions from repository '" + it.second.name() + "'...");

updateModel<ContentModVersion>(it.second, "/api/mod/version",
std::bind(&ContentData::getModVersion, &m_data, _1),
std::bind(&ContentData::setModVersion, &m_data, _1, _2),
std::bind(&ContentData::modVersionList, &m_data));

emit updateProgressed(100);
emit stateChanged("Done.");
}

emit updateFinished();
Expand Down
2 changes: 2 additions & 0 deletions source/DatabaseLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class DatabaseLoader : public QObject {
void updateProgressed(int value) const;
void updateFinished() const;

void stateChanged(const QString &state, int timeout = 0) const;

private:
ContentData &m_data;

Expand Down
11 changes: 11 additions & 0 deletions source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QKeyEvent>
#include <QMenuBar>
#include <QMessageBox>
#include <QProgressBar>
#include <QStandardPaths>
#include <QStatusBar>

Expand Down Expand Up @@ -110,9 +111,19 @@ void MainWindow::setupTabs() {
}

void MainWindow::setupStatusBar() {
QProgressBar *dbUpdateBar = new QProgressBar;
dbUpdateBar->hide();
dbUpdateBar->setRange(0, 100);
connect(&m_contentData, &ContentData::databaseUpdateStarted, dbUpdateBar, &QWidget::show);
connect(&m_contentData, &ContentData::databaseUpdateStopped, dbUpdateBar, &QWidget::hide);

QStatusBar *statusBar = QMainWindow::statusBar();
statusBar->addPermanentWidget(dbUpdateBar);

// connect(&m_session, &Session::stateChanged, statusBar, &QStatusBar::showMessage);
connect(&m_contentData, &ContentData::stateChanged, statusBar, &QStatusBar::showMessage);
connect(&m_contentData.database().loader(), &DatabaseLoader::stateChanged, statusBar, &QStatusBar::showMessage);
connect(&m_contentData.database().loader(), &DatabaseLoader::updateProgressed, dbUpdateBar, &QProgressBar::setValue);
}

void MainWindow::setupMenuBar() {
Expand Down

0 comments on commit f9574fe

Please sign in to comment.