diff options
Diffstat (limited to 'src/frontend/bookshelfmanager/installpage')
18 files changed, 219 insertions, 591 deletions
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp index 01ca55b..a689c05 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h index 070df6f..49f1978 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp index 880ea6a..6f0fc9b 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -32,10 +32,6 @@ BtInstallModuleChooserDialogModel::BtInstallModuleChooserDialogModel( Qt::DirectConnection); } -BtInstallModuleChooserDialogModel::~BtInstallModuleChooserDialogModel() { - // Intentionally empty -} - QVariant BtInstallModuleChooserDialogModel::data(const QModelIndex &i, int role) const { switch (role) { case Qt::BackgroundRole: @@ -111,14 +107,11 @@ void BtInstallModuleChooserDialogModel::parentDataChanged(const QModelIndex &top m_dataChangedFired = false; } -bool BtInstallModuleChooserDialogModel::isMulti(CSwordModuleInfo *m1) const { - if (m1 != 0 && checkedModules().contains(m1)) { - Q_FOREACH(CSwordModuleInfo *m2, m_modules.keys()) { - if (m1 != m2 && checkedModules().contains(m2) && m1->name() == m2->name()) { +bool BtInstallModuleChooserDialogModel::isMulti(CSwordModuleInfo * m1) const { + if (m1 != 0 && checkedModules().contains(m1)) + Q_FOREACH (CSwordModuleInfo * m2, modules()) + if (m1 != m2 && checkedModules().contains(m2) && m1->name() == m2->name()) return true; - } - } - } return false; } diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h index 6120fa8..406b89c 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialogmodel.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -22,7 +22,6 @@ class BtInstallModuleChooserDialogModel: public BtBookshelfTreeModel { Q_OBJECT public: BtInstallModuleChooserDialogModel(const Grouping &grouping, QObject *parent = 0); - ~BtInstallModuleChooserDialogModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp index 9c7955a..5f8bfb8 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,12 +16,12 @@ #include <QHeaderView> #include <QLabel> #include <QPushButton> -#include <QSettings> #include <QSharedPointer> #include <QStackedLayout> #include <QToolButton> -#include "backend/config/cbtconfig.h" +#include "backend/config/btconfig.h" #include "backend/btinstallbackend.h" +#include "bibletimeapp.h" #include "frontend/bookshelfmanager/btmodulemanagerdialog.h" #include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h" #include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h" @@ -29,9 +29,10 @@ #include "frontend/bookshelfmanager/installpage/btinstallpathdialog.h" #include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h" #include "frontend/btbookshelfview.h" +#include "frontend/messagedialog.h" #include "util/cresmgr.h" -#include "util/dialogutil.h" #include "util/directory.h" +#include "util/geticon.h" #include "util/tool.h" @@ -39,6 +40,7 @@ namespace { const QString groupingOrderKey ("GUI/BookshelfManager/InstallPage/grouping"); const QString headerStateKey ("GUI/BookshelfManager/InstallPage/headerState"); const QString selectedModuleKey("GUI/BookshelfManager/InstallPage/selectedModule"); +const QString installPathKey ("GUI/BookshelfManager/InstallPage/installPathIndex"); } // anonymous namespace @@ -47,13 +49,13 @@ const QString selectedModuleKey("GUI/BookshelfManager/InstallPage/selectedModule // ********************************************************* BtInstallPage::BtInstallPage(BtModuleManagerDialog *parent) - : BtConfigDialog::Page(util::directory::getIcon(CResMgr::bookshelfmgr::installpage::icon), parent) + : BtConfigDialog::Page(util::getIcon(CResMgr::bookshelfmgr::installpage::icon), parent) , m_groupingOrder(groupingOrderKey) , m_modulesSelected(0) , m_modulesSelectedSources(0) { // Read settings: - m_headerState = CBTConfig::getConfig()->value(headerStateKey).toByteArray(); + m_headerState = btConfig().value<QByteArray>(headerStateKey, QByteArray()); // Initialize widgets: initView(); @@ -71,8 +73,6 @@ QString BtInstallPage::selectedInstallPath() { } void BtInstallPage::initView() { - namespace DU = util::directory; - // Warning label: m_warningLabel = new QLabel(this); @@ -85,10 +85,10 @@ void BtInstallPage::initView() { initSourcesCombo(); m_sourceAddButton = new QPushButton(this); - m_sourceAddButton ->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::add_icon)); + m_sourceAddButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::add_icon)); m_sourceDeleteButton = new QPushButton(this); - m_sourceDeleteButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon)); + m_sourceDeleteButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon)); QHBoxLayout *sourceChooserLayout = new QHBoxLayout(); sourceChooserLayout->setContentsMargins(0, 8, 0, 0); @@ -119,10 +119,10 @@ void BtInstallPage::initView() { initPathCombo(); m_configurePathButton = new QToolButton(this); - m_configurePathButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::path_icon)); + m_configurePathButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::path_icon)); m_installButton = new QPushButton(this); - m_installButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::install_icon)); + m_installButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::install_icon)); m_installButton->setEnabled(false); QHBoxLayout *pathLayout = new QHBoxLayout(); @@ -175,7 +175,7 @@ void BtInstallPage::initPathCombo() { } // choose the current value from config but check whether we have so many items - int configValue = CBTConfig::get(CBTConfig::installPathIndex); + int configValue = btConfig().value<int>(installPathKey, 0); int index = configValue > (m_pathCombo->count() - 1) ? m_pathCombo->count() - 1 : configValue; m_pathCombo->setCurrentIndex(index); } @@ -202,7 +202,7 @@ void BtInstallPage::initSourcesCombo() { } // Read selected module from config: - QString selected = CBTConfig::getConfig()->value(selectedModuleKey).toString(); + const QString selected = btConfig().value<QString>(selectedModuleKey, QString()); // Populate combo box bool selectionOk = false; @@ -219,7 +219,7 @@ void BtInstallPage::initSourcesCombo() { // Set selection, if it wasn't properly configured: if (!selectionOk) { m_sourceComboBox->setCurrentIndex(0); - CBTConfig::getConfig()->setValue(selectedModuleKey, sourceList.at(0)); + btConfig().setValue(selectedModuleKey, sourceList.at(0)); } } @@ -268,7 +268,7 @@ void BtInstallPage::retranslateUi() { m_sourceGroupBox->setTitle(tr("Select installation &source:")); m_sourceAddButton->setText(tr("&Add...")); - m_sourceAddButton ->setToolTip(tr("Add new source")); + m_sourceAddButton->setToolTip(tr("Add new source")); m_sourceDeleteButton->setText(tr("&Delete...")); m_sourceDeleteButton->setToolTip(tr("Delete this source")); @@ -293,7 +293,7 @@ void BtInstallPage::slotHeaderChanged() { Q_ASSERT(qobject_cast<IPWW*>(m_worksLayout->currentWidget()) != 0); IPWW *w = static_cast<IPWW*>(m_worksLayout->currentWidget()); m_headerState = w->treeView()->header()->saveState(); - CBTConfig::getConfig()->setValue(headerStateKey, m_headerState); + btConfig().setValue(headerStateKey, m_headerState); } void BtInstallPage::slotInstall() { @@ -310,7 +310,7 @@ void BtInstallPage::slotInstall() { canWrite = false; } if (!canWrite) { - const int result = util::showWarning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel); + const int result = message::showWarning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel); if (result != QMessageBox::Ignore) { return; } @@ -327,22 +327,17 @@ void BtInstallPage::slotInstall() { } if (dlg->exec() == QDialog::Accepted) { - QSet<const CSwordModuleInfo*> cm; - Q_FOREACH(const CSwordModuleInfo *m, dlg->checkedModules()) { - cm.insert(m); - } - - if (cm.empty()) + QList<CSwordModuleInfo *> modules(dlg->checkedModules().toList()); + if (modules.empty()) return; /// \todo first remove all modules which will be updated from the module list // but what modules? all with the same real name? (there may be _n modules...) // progressDialog is WA_DeleteOnClose - BtInstallProgressDialog *progressDialog = new BtInstallProgressDialog(cm, selectedInstallPath(), this); - + typedef BtInstallProgressDialog BIPD; + BIPD * const progressDialog = new BIPD(modules, selectedInstallPath(), this); m_installButton->setEnabled(false); - // the progress dialog is now modal, it can be made modeless later. progressDialog->exec(); @@ -351,7 +346,7 @@ void BtInstallPage::slotInstall() { } void BtInstallPage::slotPathChanged(const QString& /*pathText*/) { - CBTConfig::set(CBTConfig::installPathIndex, m_pathCombo->currentIndex( ) ); + btConfig().setValue(installPathKey, m_pathCombo->currentIndex()); } void BtInstallPage::slotEditPaths() { @@ -390,26 +385,35 @@ void BtInstallPage::slotSourceAdd() { void BtInstallPage::slotSourceDelete() { typedef BtInstallPageWorksWidget IPWW; - int ret = util::showWarning(this, tr("Delete Source?"), + int ret = message::showWarning(this, tr("Delete Source?"), tr("Do you really want to delete this source?"), QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { + qApp->setOverrideCursor(Qt::WaitCursor); + window()->setEnabled(false); Q_ASSERT(qobject_cast<IPWW*>(m_worksLayout->currentWidget())); IPWW *w = static_cast<IPWW*>(m_worksLayout->currentWidget()); + m_sourceMap.remove(QString(w->installSource().caption)); w->deleteSource(); initSourcesCombo(); slotSourceIndexChanged(m_sourceComboBox->currentIndex()); delete w; + window()->setEnabled(true); + qApp->restoreOverrideCursor(); } } void BtInstallPage::slotSourceIndexChanged(int index) { - if (index < 0) index = 0; + if (index < 0) { + if(!m_sourceComboBox->count()) + return; + index = 0; + } /// \todo use pointers instead of text QString moduleName = m_sourceComboBox->itemText(index); - CBTConfig::getConfig()->setValue(selectedModuleKey, moduleName); + btConfig().setValue(selectedModuleKey, moduleName); activateSource(BtInstallBackend::source(moduleName)); } @@ -431,9 +435,10 @@ void BtInstallPage::slotSelectedModulesChanged() { void BtInstallPage::slotSwordSetupChanged() { QString moduleName = m_sourceComboBox->currentText(); - initSourcesCombo(); + // clean m_sourceMap before initSourcesCombo() make too much work qDeleteAll(m_sourceMap.values()); m_sourceMap.clear(); + initSourcesCombo(); m_sourceComboBox->setCurrentIndex(m_sourceComboBox->findText(moduleName)); initPathCombo(); m_modulesSelected = 0; diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.h b/src/frontend/bookshelfmanager/installpage/btinstallpage.h index 0cb6724..fe791cf 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpage.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp index 9aa6743..06e97f8 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.cpp @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -27,10 +27,6 @@ BtInstallPageModel::BtInstallPageModel(const Grouping &grouping, QObject *parent setCheckable(true); } -BtInstallPageModel::~BtInstallPageModel() { - // Intentionally empty -} - QVariant BtInstallPageModel::data(const QModelIndex &i, int role) const { switch (role) { case Qt::DisplayRole: diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h index 8a02409..009aa15 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallpagemodel.h @@ -4,7 +4,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License * version 2.0. * @@ -22,7 +22,6 @@ class BtInstallPageModel: public BtBookshelfTreeModel { Q_OBJECT public: BtInstallPageModel(const Grouping &grouping, QObject *parent = 0); - ~BtInstallPageModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp index 0bb8829..629a69c 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,12 +16,13 @@ #include <QToolButton> #include "backend/btinstallbackend.h" #include "backend/managers/cswordbackend.h" +#include "bibletimeapp.h" #include "frontend/bookshelfmanager/installpage/btinstallpage.h" #include "frontend/bookshelfmanager/installpage/btinstallpagemodel.h" #include "frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h" #include "frontend/btbookshelfview.h" #include "util/cresmgr.h" -#include "util/directory.h" +#include "util/geticon.h" namespace { @@ -55,7 +56,6 @@ BtInstallPageWorksWidget::BtInstallPageWorksWidget( , m_backend(0) , m_myModel(0) { - namespace DU = util::directory; setTreeModel(new BtInstallPageModel(g, this)); @@ -65,15 +65,20 @@ BtInstallPageWorksWidget::BtInstallPageWorksWidget( m_sourceRefreshButton = new QToolButton(this); m_sourceRefreshButton->setAutoRaise(true); - m_sourceRefreshButton ->setToolTip(tr("Refresh the list of works from this source")); - m_sourceRefreshButton ->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon)); + m_sourceRefreshButton->setToolTip(tr("Refresh the list of works from this source")); + m_sourceRefreshButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon)); setRightCornerWidget(m_sourceRefreshButton); connect(m_sourceRefreshButton, SIGNAL(clicked()), this, SLOT(slotSourceRefresh())); - // Delayed init, part 1 - disable parent: - parent->setEnabled(false); + m_backend = BtInstallBackend::backend(m_source); + Q_ASSERT(m_backend != 0); + m_myModel = new BtBookshelfModel(this); + Q_FOREACH(CSwordModuleInfo *module, m_backend->moduleList()) { + if (filter(module)) m_myModel->addModule(module); + } + setSourceModel(m_myModel); } BtInstallPageWorksWidget::~BtInstallPageWorksWidget() { @@ -83,7 +88,6 @@ BtInstallPageWorksWidget::~BtInstallPageWorksWidget() { void BtInstallPageWorksWidget::deleteSource() { qDebug() << "Deleting source" << m_source.caption; - setEnabled(false); m_myModel->clear(); BtInstallBackend::deleteSource(QString(m_source.caption)); } @@ -103,28 +107,6 @@ void BtInstallPageWorksWidget::updateTree() { } } -void BtInstallPageWorksWidget::paintEvent(QPaintEvent *e) { - // Delayed init, part 2 - queue init when painted: - if (m_myModel == 0) { - QTimer::singleShot(0, this, SLOT(slotDelayedInit())); - } - BtBookshelfWidget::paintEvent(e); -} - -void BtInstallPageWorksWidget::slotDelayedInit() { - // Delayed init, part 3 - initialize + reenable parent - qApp->setOverrideCursor(Qt::WaitCursor); - m_backend = BtInstallBackend::backend(m_source); - Q_ASSERT(m_backend != 0); - m_myModel = new BtBookshelfModel(this); - Q_FOREACH(CSwordModuleInfo *module, m_backend->moduleList()) { - if (filter(module)) m_myModel->addModule(module); - } - setSourceModel(m_myModel); - m_parent->setEnabled(true); - qApp->restoreOverrideCursor(); -} - void BtInstallPageWorksWidget::slotSourceRefresh() { qDebug() << "Refreshing source" << m_source.caption; diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h index 1a9bd8f..d02e99e 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallpageworkswidget.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -39,12 +41,8 @@ class BtInstallPageWorksWidget: public BtBookshelfWidget { void updateTree(); - /** Reimplemented from QWidget. */ - virtual void paintEvent(QPaintEvent *e); - private slots: - void slotDelayedInit(); void slotSourceRefresh(); private: /* Fields: */ diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp index b4deb51..109bbd9 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -21,9 +21,11 @@ #include <QTreeWidget> #include <QTreeWidgetItem> #include "backend/btinstallbackend.h" -#include "util/dialogutil.h" +#include "bibletimeapp.h" +#include "frontend/messagedialog.h" #include "util/directory.h" #include "util/cresmgr.h" +#include "util/geticon.h" #include "util/tool.h" @@ -77,19 +79,19 @@ BtInstallPathDialog::BtInstallPathDialog() { m_addButton = new QPushButton(tr("&Add..."), this); m_addButton->setToolTip(tr("Add new folder")); - m_addButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::add_icon)); + m_addButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::add_icon)); connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddClicked())); buttonLayout->addWidget(m_addButton); m_editButton = new QPushButton(tr("&Edit..."), this); m_editButton->setToolTip(tr("Edit the selected folder")); - m_editButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::edit_icon)); + m_editButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::edit_icon)); connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditClicked())); buttonLayout->addWidget(m_editButton); m_removeButton = new QPushButton(tr("&Remove"), this); m_removeButton->setToolTip(tr("Remove the selected folder")); - m_removeButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::remove_icon)); + m_removeButton->setIcon(util::getIcon(CResMgr::bookshelfmgr::paths::remove_icon)); connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked())); buttonLayout->addWidget(m_removeButton); @@ -102,7 +104,7 @@ BtInstallPathDialog::BtInstallPathDialog() { QDialogButtonBox* buttonBox = new QDialogButtonBox(this); buttonBox->setOrientation(Qt::Horizontal); buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::NoButton | QDialogButtonBox::Ok); - util::prepareDialogBox(buttonBox); + message::prepareDialogBox(buttonBox); mainLayout->addWidget(buttonBox); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); @@ -177,7 +179,7 @@ void BtInstallPathDialog::slotEditClicked() { if (dir.isReadable()) { const QFileInfo fi( dir.canonicalPath() ); if (!fi.exists() || !fi.isWritable()) { - const int result = util::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you want to use this folder instead of the previous value?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + const int result = message::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you want to use this folder instead of the previous value?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (result != QMessageBox::Yes) return; } //i->setText(0, dir.absolutePath()); // absolute, not canonical @@ -197,7 +199,7 @@ void BtInstallPathDialog::slotAddClicked() { if (dir.isReadable()) { const QFileInfo fi( dir.canonicalPath() ); if (!fi.exists() || !fi.isWritable()) { - const int result = util::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf folders?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + const int result = message::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf folders?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (result != QMessageBox::Yes) { return; } diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h index 9adf6bc..de4c69a 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp index cc862fa..53fd274 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp +++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -21,21 +21,24 @@ #include <QTreeWidgetItem> #include <QVBoxLayout> #include "backend/managers/cswordbackend.h" -#include "frontend/bookshelfmanager/installpage/btinstallthread.h" +#include "backend/btinstallthread.h" -BtInstallProgressDialog::BtInstallProgressDialog( - const QSet<const CSwordModuleInfo*> &modules, - const QString &destination, QWidget *parent, Qt::WindowFlags flags) +BtInstallProgressDialog::BtInstallProgressDialog(const QList<CSwordModuleInfo *> & modules, + const QString & destination, + QWidget * parent, + Qt::WindowFlags flags) : QDialog(parent, flags) + , m_nextInstallIndex(0) { // we want this dialog to be deleted when user closes it or the downloads are completed setAttribute(Qt::WA_DeleteOnClose, true); + setWindowTitle(tr("Install Progress")); - //create the dialog which shows the status and lets the user stop installation + m_statusWidget = new QTreeWidget(); m_statusWidget->setRootIsDecorated(false); - m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress") << QString::null); + m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress")); m_statusWidget->header()->setStretchLastSection(false); #if QT_VERSION < 0x050000 m_statusWidget->header()->setResizeMode(1, QHeaderView::Stretch); @@ -44,190 +47,117 @@ BtInstallProgressDialog::BtInstallProgressDialog( m_statusWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch); m_statusWidget->header()->setSectionsMovable(false); #endif - //m_statusWidget->setColumnWidth(1, util::tool::mWidth(m_statusWidget, 2)); - - 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); - // progress widget/item - QPushButton* stopButton = new QPushButton(tr("Stop"), m_statusWidget); - stopButton->setFixedSize(stopButton->sizeHint()); - - // the item - QTreeWidgetItem* progressItem = new QTreeWidgetItem(m_statusWidget); - m_statusWidget->setColumnWidth(2, stopButton->sizeHint().width()); - progressItem->setSizeHint(2, stopButton->sizeHint()); + + Q_FOREACH(const CSwordModuleInfo * module, modules) { + QTreeWidgetItem * progressItem = new QTreeWidgetItem(m_statusWidget); progressItem->setText(0, module->name()); - progressItem->setFlags(Qt::ItemIsEnabled); - m_statusWidget->setItemWidget(progressItem, 2, stopButton); + progressItem->setIcon(0, module->moduleIcon()); progressItem->setText(1, tr("Waiting for turn...")); - - //connect the signals between the dialog, items and threads - QObject::connect(stopButton, SIGNAL(clicked()), thread, SLOT(slotStopInstall()), Qt::QueuedConnection); - QObject::connect(thread, SIGNAL(installStopped(QString, QString)), this, SLOT(slotOneItemStopped(QString, QString)), Qt::QueuedConnection); - //is this needed or is statusUpdated enough? - 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); + progressItem->setFlags(Qt::ItemIsEnabled); } m_statusWidget->setMinimumWidth(m_statusWidget->size().width()); - QPushButton* stopAllButton = new QPushButton(tr("Stop All"), this); + m_stopAllButton = new QPushButton(tr("Stop All"), this); - QVBoxLayout* layout = new QVBoxLayout(this); + QVBoxLayout * layout = new QVBoxLayout(this); layout->addWidget(m_statusWidget); - layout->addWidget(stopAllButton); - - connect(stopAllButton, SIGNAL(clicked()), SLOT(slotStopInstall()) ); - - qApp->processEvents(); - - startThreads(); - + layout->addWidget(m_stopAllButton); + + connect(m_stopAllButton, SIGNAL(clicked()), + this, SLOT(slotStopInstall())); + + m_thread = new BtInstallThread(modules, destination, this); + // Connect the signals between the dialog, items and threads + connect(m_thread, SIGNAL(preparingInstall(int)), + this, SLOT(slotInstallStarted(int)), + Qt::QueuedConnection); + connect(m_thread, SIGNAL(downloadStarted(int)), + this, SLOT(slotDownloadStarted(int)), + Qt::QueuedConnection); + connect(m_thread, SIGNAL(statusUpdated(int, int)), + this, SLOT(slotStatusUpdated(int, int)), + Qt::QueuedConnection); + connect(m_thread, SIGNAL(installCompleted(int, bool)), + this, SLOT(slotOneItemCompleted(int, bool)), + Qt::QueuedConnection); + connect(m_thread, SIGNAL(finished()), + this, SLOT(slotThreadFinished()), + Qt::QueuedConnection); + #if QT_VERSION < 0x050000 + connect(m_thread, SIGNAL(terminated()), + this, SLOT(slotThreadFinished()), + Qt::QueuedConnection); + #endif + m_thread->start(); } -void BtInstallProgressDialog::startThreads() { - // remove all the updated modules from the backend module list at once - //foreach (QString mName, m_threadsByModule.keys()) { - //} - //QList<CSwordModuleInfo*> CSwordBackend::instance()()->takeModulesFromList(m_threadsByModule.keys()); - //loop through the multimap of the waiting threads, start at most 3 threads for each source - QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end(); -// concurrency is disabled for now -// while (threadIterator != m_waitingThreads.end()) { -// QString sourceName = threadIterator.key(); -// if (m_runningThreads.values(sourceName).count() < 3) { -// BtInstallThread* t = threadIterator.value(); -// m_runningThreads.insert(sourceName, t); -// threadIterator = m_waitingThreads.erase(threadIterator); -// t->start(); -// } -// else ++threadIterator; -// } - //non-concurrent - 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(); - } +BtInstallProgressDialog::~BtInstallProgressDialog() { + m_thread->wait(); + delete m_thread; } -void BtInstallProgressDialog::slotOneItemCompleted(QString module, QString source, int status) { - QString message; - //status comes from the sword installer. - /// \todo Additionally we should check that there are files really installed. - if (status != 0) { - message = tr("Failed"); - } - else { - message = tr("Completed"); +void BtInstallProgressDialog::slotStopInstall() { + m_stopAllButton->setDisabled(true); + m_thread->stopInstall(); + for (int i = m_nextInstallIndex; i < m_statusWidget->topLevelItemCount(); i++) { + QTreeWidgetItem * const item = m_statusWidget->topLevelItem(i); + item->setText(1, QString::null); + item->setDisabled(true); } - oneItemStoppedOrCompleted(module, source, message); -} - -void BtInstallProgressDialog::slotOneItemStopped(QString module, QString source) { - oneItemStoppedOrCompleted(module, source, tr("Cancelled")); } -void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString source, QString statusMessage) { - qDebug() << "\n**********************************\nBtInstallProgressDialog::oneItemStoppedOrCompleted" << module << statusMessage << "\n******************************************"; - // update the list item - m_statusWidget->setItemWidget(getItem(module), 1, 0); - getItem(module)->setText(1, statusMessage); - m_statusWidget->itemWidget(getItem(module), 2)->setEnabled(false); - getItem(module)->setDisabled(true); - - 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)); - -//concurrency is disabled for now -// //start a waiting thread if there are any -// QList<BtInstallThread*> threadsForSource = m_waitingThreads.values(source); -// if (!threadsForSource.isEmpty()) { -// BtInstallThread* thread = threadsForSource.at(0); -// m_waitingThreads.remove(source, thread); -// m_runningThreads.insert(source, thread); -// thread->start(); -// } - - //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 BtInstallProgressDialog::slotInstallStarted(int moduleIndex) { + Q_ASSERT(moduleIndex == m_nextInstallIndex); + m_nextInstallIndex++; + QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex); + item->setText(1, tr("Preparing install...")); + m_statusWidget->scrollToItem(item); } -void BtInstallProgressDialog::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 BtInstallProgressDialog::slotDownloadStarted(int moduleIndex) { + QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex); + item->setText(1, QString::null); + getOrCreateProgressBar(item)->setValue(0); } -void BtInstallProgressDialog::slotStatusUpdated(QString module, int status) { +void BtInstallProgressDialog::slotStatusUpdated(int moduleIndex, int status) { // find the progress bar for this module and update the value - QWidget* itemWidget = m_statusWidget->itemWidget(getItem(module) , 1); - QProgressBar* bar = dynamic_cast<QProgressBar*>(itemWidget); - if (bar) bar->setValue(status); -} - -void BtInstallProgressDialog::slotInstallStarted(QString module, QString) { - getItem(module)->setText(1, tr("Preparing install...")); + getOrCreateProgressBar(moduleIndex)->setValue(status); } -void BtInstallProgressDialog::slotDownloadStarted(QString module) { - getItem(module)->setText(1, QString::null); - //m_statusWidget->itemWidget(getItem(module), 1)->setVisible(true); - - QProgressBar* bar = new QProgressBar(m_statusWidget); - bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - bar->setValue(0); - m_statusWidget->setItemWidget(getItem(module), 1, bar); +void BtInstallProgressDialog::slotOneItemCompleted(int moduleIndex, bool successful) { +QTreeWidgetItem * const item = m_statusWidget->topLevelItem(moduleIndex); + // update the list item + m_statusWidget->setItemWidget(item, 1, NULL); + item->setText(1, successful ? tr("Completed") : tr("Failed")); + item->setDisabled(true); } -QTreeWidgetItem* BtInstallProgressDialog::getItem(QString moduleName) { - return m_statusWidget->findItems(moduleName, Qt::MatchExactly).at(0); +void BtInstallProgressDialog::slotThreadFinished() { + close(); } -void BtInstallProgressDialog::closeEvent(QCloseEvent* event) { +void BtInstallProgressDialog::closeEvent(QCloseEvent * event) { if (event->spontaneous()) { event->ignore(); + slotStopInstall(); return; } // other parts of the UI/engine must be updated CSwordBackend::instance()->reloadModules(CSwordBackend::AddedModules); } -bool BtInstallProgressDialog::threadsDone() { - return (m_waitingThreads.isEmpty() && m_runningThreads.isEmpty()); +QProgressBar * BtInstallProgressDialog::getOrCreateProgressBar(int moduleIndex) { + return getOrCreateProgressBar(m_statusWidget->topLevelItem(moduleIndex)); +} + +QProgressBar * BtInstallProgressDialog::getOrCreateProgressBar(QTreeWidgetItem * item) { + QWidget * const itemWidget = m_statusWidget->itemWidget(item, 1); + QProgressBar * progressBar = dynamic_cast<QProgressBar *>(itemWidget); + if (!progressBar) { + progressBar = new QProgressBar(m_statusWidget); + progressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_statusWidget->setItemWidget(item, 1, progressBar); + } + return progressBar; } diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h index a72b280..e6add1c 100644 --- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h +++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -12,56 +14,56 @@ #include <QDialog> -#include <QMultiMap> #include <QString> class BtInstallThread; class CSwordModuleInfo; +class QProgressBar; class QTreeWidget; class QTreeWidgetItem; -class BtInstallProgressDialog : public QDialog { - Q_OBJECT - public: - BtInstallProgressDialog(const QSet<const CSwordModuleInfo*> &modules, - const QString &destination, QWidget *parent = 0, - Qt::WindowFlags flags = 0); - - public slots: - void slotOneItemCompleted(QString module, QString source, int status); - void slotOneItemStopped(QString module, QString source); - void slotStopInstall(); - void slotStatusUpdated(QString module, int status); - void slotDownloadStarted(QString module); - void slotInstallStarted(QString module, QString); - - protected: - /** - * Handles closing by the window close button, Cancel (Stop) All button, or completing - * the downloads. - */ - virtual void closeEvent(QCloseEvent* event); - -//signals: -// void swordSetupChanged(); - - private: - - /// \todo using maps is tedious and error prone. Find better solution for handling the modules - // and their states. - QMultiMap<QString, BtInstallThread*> m_waitingThreads; - QMultiMap<QString, BtInstallThread*> m_runningThreads; - QMap<QString, BtInstallThread*> m_threadsByModule; - //QList<BtInstallThread*> m_doneThreads; - - QTreeWidget* m_statusWidget; - - private: - QTreeWidgetItem* getItem(QString moduleName); - bool threadsDone(); - void startThreads(); - void oneItemStoppedOrCompleted(QString module, QString source, QString message); +class BtInstallProgressDialog: public QDialog { + + Q_OBJECT + +public: /* Methods: */ + + BtInstallProgressDialog(const QList<CSwordModuleInfo *> & modules, + const QString & destination, + QWidget * parent = 0, + Qt::WindowFlags flags = 0); + ~BtInstallProgressDialog(); + +public slots: + + void slotStopInstall(); + void slotInstallStarted(int moduleIndex); + void slotDownloadStarted(int moduleIndex); + void slotStatusUpdated(int moduleIndex, int status); + void slotOneItemCompleted(int moduleIndex, bool status); + void slotThreadFinished(); + +protected: /* Methods: */ + + /** + Handles closing by the window close button, Cancel (Stop) All button, or + completing the downloads. + */ + virtual void closeEvent(QCloseEvent * event); + +private: /* Methods: */ + + QProgressBar * getOrCreateProgressBar(int moduleIndex); + QProgressBar * getOrCreateProgressBar(QTreeWidgetItem * item); + +private: /* Fields: */ + + QTreeWidget * m_statusWidget; + QPushButton * m_stopAllButton; + BtInstallThread * m_thread; + int m_nextInstallIndex; + }; #endif diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp deleted file mode 100644 index 3b25f02..0000000 --- a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2011 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#include "frontend/bookshelfmanager/installpage/btinstallthread.h" - -#include <QApplication> -#include <QDebug> -#include <QDir> -#include <QString> -#include <QThread> -#include "backend/managers/cswordbackend.h" -#include "frontend/bookshelfmanager/btinstallmgr.h" -#include "backend/btinstallbackend.h" - -// Sword includes: -#include <filemgr.h> - - -BtInstallThread::BtInstallThread(const QString &moduleName, const QString &sourceName, - const QString &destinationName, QObject *parent) - : QThread(parent), - done(false), - m_module(moduleName), - m_destination(destinationName), - m_source(sourceName), - m_cancelled(false) { - m_iMgr = new BtInstallMgr(); -} - - -BtInstallThread::~BtInstallThread() { - delete m_iMgr; -} - -void BtInstallThread::run() { - qDebug() << "****************************************\nBtInstallThread::run, mod:" << m_module << "\n************************************"; - - - emit preparingInstall(m_module, m_source); - //This is 0 before set here - remember when using the value when cancelling - // the installation before this has been run - m_installSource = QSharedPointer<sword::InstallSource>(new sword::InstallSource(BtInstallBackend::source(m_source))); - m_backendForSource = QSharedPointer<CSwordBackend>(BtInstallBackend::backend(*m_installSource)); - - //make sure target/mods.d and target/modules exist - /// \todo move this to some common precondition - QDir dir(m_destination); - if (!dir.exists()) { - dir.mkdir(m_destination); - qDebug() << "made directory" << m_destination; - } - if (!dir.exists("modules")) { - dir.mkdir("modules"); - qDebug() << "made directory" << m_destination << "/modules"; - } - if (!dir.exists("mods.d")) { - dir.mkdir("mods.d"); - qDebug() << "made directory" << m_destination << "/mods.d"; - } - - QObject::connect(m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int)), Qt::QueuedConnection); - QObject::connect(m_iMgr, SIGNAL(downloadStarted()), this, SLOT(slotDownloadStarted()), Qt::QueuedConnection); - - //check whether it's an update. If yes, remove existing module first - /// \todo silently removing without undo if the user cancels the update is WRONG!!! - removeModule(); - - // manager for the destination path - sword::SWMgr lMgr( m_destination.toLatin1() ); - - if (BtInstallBackend::isRemote(*m_installSource)) { - int status = m_iMgr->installModule(&lMgr, 0, m_module.toLatin1(), m_installSource.data()); - if (status != 0) { - qWarning() << "Error with install: " << status << "module:" << m_module; - } - else { - done = true; - emit installCompleted(m_module, m_source, status); - } - } - else { //local source - emit statusUpdated(m_module, 0); - int status = m_iMgr->installModule(&lMgr, m_installSource->directory.c_str(), m_module.toLatin1()); - if (status > 0) { - qWarning() << "Error with install: " << status << "module:" << m_module; - } - else if (status == -1) { - // it was terminated, do nothing - } - else { - emit statusUpdated(m_module, 100); - done = true; - emit installCompleted(m_module, m_source, status); - } - } -} - -void BtInstallThread::slotStopInstall() { - qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************"; - if (!done) { - done = true; - qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************"; - m_iMgr->terminate(); - //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files - //qApp->processEvents(); - // wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze - int notRun = this->wait(25000); - if (notRun) { - this->terminate(); - this->wait(10000); - qDebug() << "installthread (" << m_module << ") terminated, delete m_iMgr"; - delete m_iMgr; // this makes sure the ftp library will be cleaned up in the destroyer - m_iMgr = 0; - } - // cleanup: remove the module, remove the temp files - // if installation has already started - if (m_installSource.data() != 0) { - // remove the installed module, just to be sure because mgr may - // have been terminated when copying files - removeModule(); - removeTempFiles(); - qDebug() << "BtInstallThread::slotStopInstall will emit installStopped..."; - } - emit installStopped(m_module, m_source); - } -} - -void BtInstallThread::slotManagerStatusUpdated(int totalProgress, int /*fileProgress*/) { - emit statusUpdated(m_module, totalProgress); -} - -void BtInstallThread::slotDownloadStarted() { - emit downloadStarted(m_module); -} - -void BtInstallThread::removeModule() { - CSwordModuleInfo* m; - m = CSwordBackend::instance()->findModuleByName(m_module); - if (!m) { - m = BtInstallBackend::backend(BtInstallBackend::source(m_destination.toLatin1()))->findModuleByName(m_module); - } - if (m) { //module found? - qDebug() << "BtInstallThread::removeModule, module" << m_module << "found"; - QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/"; - QString dataPath = m->config(CSwordModuleInfo::DataPath); - if (dataPath.left(2) == "./") { - dataPath = dataPath.mid(2); - } - - if (prefixPath.contains(dataPath)) { - prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() ); - } - else { - prefixPath = QString::fromLatin1(CSwordBackend::instance()->prefixPath); - } - - sword::SWMgr mgr(prefixPath.toLatin1()); - BtInstallMgr iMgr; - iMgr.removeModule(&mgr, m->name().toLatin1()); - } - else { - qDebug() << "BtInstallThread::removeModule, module" << m_module << "not found"; - } -} - -void BtInstallThread::removeTempFiles() { - // (take the remote conf file for this module, take DataPath, - // take the absolute path of the InstallMgr) - - //sword::InstallSource is = BtInstallBackend::source(m_source); - if (BtInstallBackend::isRemote(*m_installSource)) { - // get the path for the module temp files - CSwordModuleInfo* mInfo = m_backendForSource->findModuleByName(m_module); - QString dataPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath); - qDebug() << "Delete path:" << dataPath; - // it's easier to use sword than qt - sword::FileMgr::removeDir(dataPath.toLatin1().data()); - } -} diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.h b/src/frontend/bookshelfmanager/installpage/btinstallthread.h deleted file mode 100644 index 8bb660d..0000000 --- a/src/frontend/bookshelfmanager/installpage/btinstallthread.h +++ /dev/null @@ -1,99 +0,0 @@ -/********* -* -* This file is part of BibleTime's source code, http://www.bibletime.info/. -* -* Copyright 1999-2011 by the BibleTime developers. -* The BibleTime source code is licensed under the GNU General Public License version 2.0. -* -**********/ - -#ifndef BTINSTALLTHREAD_H -#define BTINSTALLTHREAD_H - -#include <QThread> - -#include <QSharedPointer> -#include "frontend/bookshelfmanager/btinstallmgr.h" - - -class BtInstallProgressDialog; -class CSwordBackend; - -/** -* Thread for installing a module. -* -* See the Qt thread documents. We have to be careful with signals and slots, -* with other things. - -The main thread creates and owns the BtInstallThread object. -When the install thread (the run() method) has been started -the install thread object receives status update signals -from the installmgr object. This works because these signals are sent -from the running install thread but received in the thread object which -lives in the main thread (note the difference between a thread object and a -running thread). The slot of the thread object is executed in the main thread -event loop, not in the install thread. - -The running thread sends update signals to the progress dialog. -(This works because the signals are queued, i.e. the dialog is running -in the main app event loop which queues the signals. ???) - -When the user cancels installing the main thread sends signal to a slot -in the thread object. The slot is then run in the main thread, not -in the install thread (note again the difference between a thread object and a -running thread). That slot terminates the running install thread immediately. -That is not the cleanest way to do it, but the Sword library has no good -support for threads. Terminating a Sword InstallMgr takes time and leads to -slow response. Therefore we stop installing by force and clean up the -temporary files manually. - -* Terminating a thread forcibly is "dangerous and discouraged" but we have to do it, -* I couldn't get cancelling work reliably otherwise. The Sword library is bad for threads. -* We use ftp connection and file resources; the connection can be ignored but the files -* have to be cleaned up after termination. -*/ -class BtInstallThread : public QThread { - Q_OBJECT - public: - BtInstallThread(const QString &moduleName, const QString &sourceName, - const QString &destinationName, QObject *parent = 0); - - ~BtInstallThread(); - - public slots: - void slotStopInstall(); - void slotManagerStatusUpdated(int totalProgress, int fileProgress); - void slotDownloadStarted(); - - public: // data member - bool done; - - protected: - virtual void run(); - void removeModule(); - void removeTempFiles(); - - QString m_module; - QString m_destination; - QString m_source; - bool m_cancelled; - BtInstallMgr* m_iMgr; - //BtInstallMgr m_iMgr; - QSharedPointer<sword::InstallSource> m_installSource; - /// \todo it would be best to get the backend from the bookshelf manager install page - // where it has already been created. Could fasten the progress dialog startup. - QSharedPointer<CSwordBackend> m_backendForSource; - - signals: - /** Emitted when the install progress status is updated. */ - void statusUpdated(QString module, int progressPercent); - /** Emitted when installing has been stopped/cancelled. */ - void installStopped(QString module, QString source); - /** Emitted when installing is complete. */ - void installCompleted(QString module, QString source, int errorStatus); - /** Emitted when the first file download has been started. */ - void downloadStarted(QString module); - void preparingInstall(QString module, QString source); -}; - -#endif diff --git a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp index 949c82e..856f58b 100644 --- a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp +++ b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.cpp @@ -2,7 +2,7 @@ #include <QApplication> #include "backend/btinstallbackend.h" -#include "util/dialogutil.h" +#include "frontend/messagedialog.h" BtRefreshProgressDialog::BtRefreshProgressDialog(sword::InstallSource &source, @@ -44,7 +44,7 @@ bool BtRefreshProgressDialog::runAndDelete() { setValue(100); qApp->processEvents(); } else { - util::showWarning(this, tr("Warning"), + message::showWarning(this, tr("Warning"), tr("Failed to refresh source %1") .arg(QString(m_source.caption))); } diff --git a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h index dfabcf6..03f82c9 100644 --- a/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h +++ b/src/frontend/bookshelfmanager/installpage/btrefreshprogressdialog.h @@ -1,8 +1,10 @@ /********* * +* In the name of the Father, and of the Son, and of the Holy Spirit. +* * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2011 by the BibleTime developers. +* Copyright 1999-2014 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -12,7 +14,7 @@ #include <QProgressDialog> -#include "frontend/bookshelfmanager/btinstallmgr.h" +#include "backend/btinstallmgr.h" class BtRefreshProgressDialog: public QProgressDialog { |