summaryrefslogtreecommitdiff
path: root/src/mobile/bookshelfmanager/installprogress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mobile/bookshelfmanager/installprogress.cpp')
-rw-r--r--src/mobile/bookshelfmanager/installprogress.cpp154
1 files changed, 53 insertions, 101 deletions
diff --git a/src/mobile/bookshelfmanager/installprogress.cpp b/src/mobile/bookshelfmanager/installprogress.cpp
index dd113ec..034611b 100644
--- a/src/mobile/bookshelfmanager/installprogress.cpp
+++ b/src/mobile/bookshelfmanager/installprogress.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2014 by the BibleTime developers.
+* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -12,28 +12,34 @@
#include "installprogress.h"
+#include <QDebug>
+#include <QQuickItem>
#include "backend/btinstallbackend.h"
#include "backend/managers/cswordbackend.h"
#include "backend/btinstallthread.h"
#include "mobile/btmmain.h"
#include "mobile/ui/qtquick2applicationviewer.h"
#include "mobile/ui/viewmanager.h"
-#include <QQuickItem>
-#include <QDebug>
+#include "util/btassert.h"
+#include "util/btconnect.h"
+
namespace btm {
InstallProgress::InstallProgress(QObject* parent)
- : QObject(parent), m_progressObject(0) {
+ : QObject(parent), m_progressObject(nullptr),
+ m_thread(nullptr), m_nextInstallIndex(0) {
}
void InstallProgress::openProgress(const QList<CSwordModuleInfo*>& modules) {
if (modules.count() == 0)
return;
- if (m_progressObject == 0)
+ m_nextInstallIndex = 0;
+ m_modules = modules;
+ if (m_progressObject == nullptr)
findProgressObject();
- if (m_progressObject == 0)
+ if (m_progressObject == nullptr)
return;
QString destination = getSourcePath();
@@ -42,27 +48,24 @@ void InstallProgress::openProgress(const QList<CSwordModuleInfo*>& modules) {
setProperties();
- Q_FOREACH(const CSwordModuleInfo *module, modules) {
- const QString sourceName(module->property("installSourceName").toString());
- // create a thread for this module
- BtInstallThread* thread = new BtInstallThread(module->name(), sourceName, destination);
- m_waitingThreads.insert(sourceName, thread);
- m_threadsByModule.insert(module->name(), thread);
-
- QObject::connect(thread, SIGNAL(installStopped(QString, QString)),
- this, SLOT(slotOneItemStopped(QString, QString)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(installCompleted(QString, QString, int)),
- this, SLOT(slotOneItemCompleted(QString, QString, int)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(statusUpdated(QString, int)),
- this, SLOT(slotStatusUpdated(QString, int)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(downloadStarted(QString)),
- this, SLOT(slotDownloadStarted(QString)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(preparingInstall(QString, QString)),
- this, SLOT(slotInstallStarted(QString, QString)), Qt::QueuedConnection);
- }
-
- connect(m_progressObject, SIGNAL(cancel()), this, SLOT(slotStopInstall()));
- startThreads();
+ m_thread = new BtInstallThread(m_modules, destination, this);
+ // Connect the signals between the dialog, items and threads
+ BT_CONNECT(m_thread, SIGNAL(preparingInstall(int)),
+ this, SLOT(slotInstallStarted(int)),
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, SIGNAL(downloadStarted(int)),
+ this, SLOT(slotDownloadStarted(int)),
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, SIGNAL(statusUpdated(int, int)),
+ this, SLOT(slotStatusUpdated(int, int)),
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, SIGNAL(installCompleted(int, bool)),
+ this, SLOT(slotOneItemCompleted(int, bool)),
+ Qt::QueuedConnection);
+ BT_CONNECT(m_thread, SIGNAL(finished()),
+ this, SLOT(slotThreadFinished()),
+ Qt::QueuedConnection);
+ m_thread->start();
}
void InstallProgress::cancel() {
@@ -74,98 +77,47 @@ void InstallProgress::close() {
CSwordBackend::instance()->reloadModules(CSwordBackend::AddedModules);
}
-void InstallProgress::slotOneItemCompleted(QString module, QString source, int status) {
- QString message;
- //status comes from the sword installer.
- if (status != 0) {
- message = tr("Failed");
- }
- else {
- message = tr("Completed");
- }
- oneItemStoppedOrCompleted(module, source, message);
+void InstallProgress::slotStopInstall() {
+ m_thread->stopInstall();
}
-void InstallProgress::slotOneItemStopped(QString module, QString source) {
- oneItemStoppedOrCompleted(module, source, tr("Cancelled"));
+QString InstallProgress::getModuleName(int moduleIndex) {
+ BT_ASSERT(moduleIndex < m_modules.count());
+ CSwordModuleInfo * module = m_modules.at(moduleIndex);
+ return module->name();
}
-// TODO show failed status
-void InstallProgress::oneItemStoppedOrCompleted(QString module, QString source, QString statusMessage) {
- qDebug() << "\n**********************************\nBtInstallProgressDialog::oneItemStoppedOrCompleted" << module << statusMessage << "\n******************************************";
- qDebug() << "remove from threads maps" << source << m_threadsByModule.value(module);
- m_runningThreads.remove(source, m_threadsByModule.value(module));
- m_waitingThreads.remove(source, m_threadsByModule.value(module));
-
- //non-concurrent
- QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
- if (m_runningThreads.isEmpty() && threadIterator != m_waitingThreads.begin()) {
- --threadIterator; // the last item
- QString sourceName = threadIterator.key();
- BtInstallThread* t = threadIterator.value();
- m_runningThreads.insert(sourceName, t);
- threadIterator = m_waitingThreads.erase(threadIterator);
- t->start();
- }
-
- if (threadsDone()) {
- qDebug() << "close the dialog";
- close();
- }
+void InstallProgress::slotInstallStarted(int moduleIndex) {
+ BT_ASSERT(moduleIndex == m_nextInstallIndex);
+ m_nextInstallIndex++;
+ QString message = tr("Installing") + " " + getModuleName(moduleIndex);
+ m_progressObject->setProperty("text", message);
}
-void InstallProgress::slotStopInstall() {
- qDebug() << "BtInstallProgressDialog::slotStopInstall";
-
- // Clear the waiting threads map, stop all running threads.
- m_waitingThreads.clear();
- if (m_runningThreads.count() > 0) {
- foreach(BtInstallThread* thread, m_runningThreads) {
- thread->slotStopInstall();
- }
- }
- else {
- close();
- }
+void InstallProgress::slotDownloadStarted(int moduleIndex) {
+ m_progressObject->setProperty("value", 0);
+ QString message = tr("Downloading")+ " " + getModuleName(moduleIndex);
+ m_progressObject->setProperty("text", message);
}
-void InstallProgress::slotStatusUpdated(QString /* module */, int status) {
+void InstallProgress::slotStatusUpdated(int /*moduleIndex*/, int status) {
m_progressObject->setProperty("value", status);
}
-void InstallProgress::slotInstallStarted(QString /* module */, QString) {
-}
-
-void InstallProgress::slotDownloadStarted(QString module) {
- QString message = "Installing " + module;
- m_progressObject->setProperty("text", message);
- m_progressObject->setProperty("value", 0);
-}
-
-void InstallProgress::startThreads() {
- QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
- if (threadIterator != m_waitingThreads.begin()) {
- // go to the last item which is actually the first in the visible list
- // because the iterator is reversed compared to insert order
- --threadIterator;
- QString sourceName = threadIterator.key();
- BtInstallThread* t = threadIterator.value();
- m_runningThreads.insert(sourceName, t);
- threadIterator = m_waitingThreads.erase(threadIterator);
- t->start();
- }
+void InstallProgress::slotOneItemCompleted(int /* moduleIndex */, bool /* successful */) {
+ // TODO show failed status
}
-bool InstallProgress::threadsDone() {
- return (m_waitingThreads.isEmpty() && m_runningThreads.isEmpty());
+void InstallProgress::slotThreadFinished() {
+ close();
}
void InstallProgress::findProgressObject() {
QtQuick2ApplicationViewer* viewer = getViewManager()->getViewer();
- QQuickItem * rootObject = 0;
- if (viewer != 0)
+ QQuickItem * rootObject = nullptr;
+ if (viewer != nullptr)
rootObject = viewer->rootObject();
- if (rootObject != 0)
+ if (rootObject != nullptr)
m_progressObject = rootObject->findChild<QQuickItem*>("progress");
}