diff options
author | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
---|---|---|
committer | Teus Benschop <teusjannette@gmail.com> | 2017-10-06 12:24:31 +0200 |
commit | 90d2181239761f8950b95768d3b037843e9e8b50 (patch) | |
tree | 6cc667ab420cc04029de2de7e361d2305e214595 /src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp | |
parent | 1ea03c0fce8066c1e22188447b4a6ca4dcef1201 (diff) |
New upstream version 2.11.0
Diffstat (limited to 'src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp')
-rw-r--r-- | src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp new file mode 100644 index 0000000..b26e4cb --- /dev/null +++ b/src/frontend/bookshelfwizard/btbookshelfsourcesprogresspage.cpp @@ -0,0 +1,134 @@ +/********* +* +* This file is part of BibleTime's source code, http://www.bibletime.info/. +* +* Copyright 1999-2016 by the BibleTime developers. +* The BibleTime source code is licensed under the GNU General Public License version 2.0. +* +**********/ + +#include "frontend/bookshelfwizard/btbookshelfsourcesprogresspage.h" + +#include <QApplication> +#include <QDate> +#include <QHBoxLayout> +#include <QLabel> +#include <QProgressBar> +#include <QPushButton> +#include <QVBoxLayout> +#include "backend/btinstallbackend.h" +#include "backend/btsourcesthread.h" +#include "backend/config/btconfig.h" +#include "frontend/bookshelfwizard/btbookshelfwizardenums.h" +#include "frontend/bookshelfwizard/btbookshelfwizard.h" +#include "util/btconnect.h" + + +namespace { +QString const lastUpdate = "GUI/BookshelfWizard/lastUpdate"; +} + +BtBookshelfSourcesProgressPage::BtBookshelfSourcesProgressPage(QWidget * parent) + : BtBookshelfWizardPage(parent) +{ + // Setup UI: + QVBoxLayout * const vLayout = new QVBoxLayout(this); + vLayout->setObjectName(QStringLiteral("verticalLayout")); + + vLayout->addItem(new QSpacerItem(20, + 40, + QSizePolicy::Minimum, + QSizePolicy::Expanding)); + + m_msgLabel = new QLabel(this); + m_msgLabel->setAlignment(Qt::AlignCenter); + m_msgLabel->setObjectName(QStringLiteral("msgLabel")); + m_msgLabel->setWordWrap(true); + vLayout->addWidget(m_msgLabel); + + m_progressBar = new QProgressBar(this); + m_progressBar->setObjectName("progressBar"); + m_progressBar->setMinimum(0); + m_progressBar->setMaximum(100); + vLayout->addWidget(m_progressBar, Qt::AlignCenter); + + QHBoxLayout * const horizontalLayout = new QHBoxLayout(); + m_stopButton = new QPushButton(this); + horizontalLayout->addSpacerItem( + new QSpacerItem(1, 1, QSizePolicy::Expanding)); + horizontalLayout->addWidget(m_stopButton); + horizontalLayout->addSpacerItem( + new QSpacerItem(1, 1, QSizePolicy::Expanding)); + vLayout->addLayout(horizontalLayout); + + vLayout->addItem(new QSpacerItem(20, + 40, + QSizePolicy::Minimum, + QSizePolicy::Expanding)); + + // Initialize connections: + BT_CONNECT(m_stopButton, &QPushButton::clicked, + this, &BtBookshelfSourcesProgressPage::slotStopInstall); +} + +void BtBookshelfSourcesProgressPage::destroyThread() noexcept { + if (m_thread) { + m_thread->stop(); + while (!m_thread->wait()) /* join */; + delete m_thread; + m_thread = nullptr; + } +} + +void BtBookshelfSourcesProgressPage::retranslateUi() { + m_stopButton->setText(tr("Stop")); + + setTitle(QApplication::translate( + "BookshelfWizard", "Updating Remote Libraries")); + setSubTitle(QApplication::translate( + "BookshelfWizard", + "Updating information from remote libraries.")); +} + +int BtBookshelfSourcesProgressPage::nextId() const { + if (btWizard().taskType() == WizardTaskType::updateWorks) + return WizardPage::updateWorksPage; + return WizardPage::sourcesPage; +} + +void BtBookshelfSourcesProgressPage::initializePage() { + destroyThread(); + + m_installCompleted = false; + m_thread = new BtSourcesThread(this); + BT_CONNECT(m_thread, &BtSourcesThread::percentComplete, + m_progressBar, &QProgressBar::setValue, + Qt::QueuedConnection); + BT_CONNECT(m_thread, &BtSourcesThread::showMessage, + m_msgLabel, &QLabel::setText, + Qt::QueuedConnection); + BT_CONNECT(m_thread, &BtSourcesThread::finished, + this, &BtBookshelfSourcesProgressPage::slotThreadFinished, + Qt::QueuedConnection); + m_thread->start(); + m_stopButton->setEnabled(true); + btWizard().downloadStarted(); + retranslateUi(); +} + +bool BtBookshelfSourcesProgressPage::isComplete() const +{ return m_installCompleted; } + +void BtBookshelfSourcesProgressPage::slotThreadFinished() { + m_stopButton->setDisabled(true); + if (m_thread->finishedSuccessfully()) + btConfig().setValue<QDate>(lastUpdate, QDate::currentDate()); + m_installCompleted = true; + emit QWizardPage::completeChanged(); + btWizard().downloadFinished(); +} + +void BtBookshelfSourcesProgressPage::slotStopInstall() { + m_stopButton->setDisabled(true); + m_thread->stop(); +} |