BibleTime
btbookshelfwizard.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btbookshelfwizard.h"
14 
15 #include <QAbstractButton>
16 #include <QApplication>
17 #include <QByteArray>
18 #include <QDialog>
19 #include <QKeyEvent>
20 #include <QMessageBox>
21 #include <QPushButton>
22 #include <QRect>
23 #include "../../backend/config/btconfig.h"
24 #include "../../backend/drivers/btmoduleset.h"
25 #include "../../util/btassert.h"
29 #include "btbookshelfsourcespage.h"
31 #include "btbookshelftaskpage.h"
32 #include "btbookshelfwizardenums.h"
33 #include "btbookshelfworkspage.h"
34 
35 
36 namespace {
37 auto const GeometryKey = QStringLiteral("GUI/BookshelfWizard/geometry");
38 auto const SourcesKey = QStringLiteral("GUI/BookshelfWizard/sources");
39 auto const LanguagesKey = QStringLiteral("GUI/BookshelfWizard/languages");
40 bool autoSourcesUpdate = true;
41 } // anonymous namespace
42 
43 BtBookshelfWizard::BtBookshelfWizard(QWidget * parent, Qt::WindowFlags flags)
44  : QWizard(parent, flags)
45  , m_downloadInProgress(false)
46  , m_closeRequested(false)
47  , m_closeMessageBox(new QMessageBox(this))
48  , m_taskPage(new BtBookshelfTaskPage(this))
49  , m_sourcesPage(new BtBookshelfSourcesPage(this))
50  , m_sourcesProgressPage(new BtBookshelfSourcesProgressPage(this))
51  , m_languagesPage(new BtBookshelfLanguagesPage(this))
52  , m_installWorksPage(new BtBookshelfWorksPage(WizardTaskType::installWorks, this))
53  , m_updateWorksPage(new BtBookshelfWorksPage(WizardTaskType::updateWorks, this))
54  , m_removeWorksPage(new BtBookshelfWorksPage(WizardTaskType::removeWorks, this))
55  , m_installFinalPage(new BtBookshelfInstallFinalPage(this)) // For install and update
56 {
66  setStartId(WizardPage::taskPage);
67 
68  QRect rect = geometry();
69  rect.setWidth(780);
70  rect.setHeight(600);
71  setGeometry(rect);
72  setOption(QWizard::NoBackButtonOnLastPage);
73 
74  retranslateUi();
75 
76  // Load wizard geometry:
77  restoreGeometry(btConfig().value<QByteArray>(GeometryKey, QByteArray()));
78 }
79 
80 static void replaceButtonText(QWizard * wizard, QWizard::WizardButton which, const QString& text) {
81  QAbstractButton * button = wizard->button(which);
82  if (button != nullptr)
83  button->setText(text);
84 }
85 
86 // This function can be used by other QWizard's in the future
88  replaceButtonText(wizard, QWizard::BackButton, QPushButton::tr("Back" ,"Dialog Button"));
89  replaceButtonText(wizard, QWizard::NextButton, QPushButton::tr("Next" ,"Dialog Button"));
90  replaceButtonText(wizard, QWizard::CommitButton, QPushButton::tr("Commit","Dialog Button"));
91  replaceButtonText(wizard, QWizard::FinishButton, QPushButton::tr("Finish","Dialog Button"));
92  replaceButtonText(wizard, QWizard::CancelButton, QPushButton::tr("Cancel","Dialog Button"));
93  replaceButtonText(wizard, QWizard::HelpButton, QPushButton::tr("Help" ,"Dialog Button"));
94 }
95 
98  setWindowTitle(QApplication::translate("BookshelfWizard",
99  "Bookshelf Manager"));
100  m_closeMessageBox->setWindowTitle(QApplication::translate(
101  "BookshelfWizard",
102  "Canceling Downloads"));
103  m_closeMessageBox->setText(QApplication::translate(
104  "BookshelfWizard",
105  "The Bookshelf Manager will close when the current download finishes."));
106 }
107 
109 { return m_sourcesPage->selectedSources(); }
110 
112 { return m_languagesPage->selectedLanguages(); }
113 
115  if (currentPage() == m_installFinalPage) {
116  // Save settings:
119  }
120 
121  btConfig().setValue(GeometryKey, saveGeometry()); // Save wizard geometry
122  QDialog::accept();
123 }
124 
126  WizardTaskType const iType = m_taskPage->taskType();
127  if (iType == WizardTaskType::installWorks)
129  if (iType == WizardTaskType::updateWorks)
133 }
134 
136 { return m_taskPage->taskType(); }
137 
139  WizardTaskType const iType = m_taskPage->taskType();
140  if (iType == WizardTaskType::installWorks)
143  return m_updateWorksPage->installPath();
144 }
145 
147  autoSourcesUpdate = value;
148 }
149 
151  return autoSourcesUpdate;
152 }
153 
155  if (currentPage() == m_installFinalPage) {
157  }
158  if (currentPage() == m_sourcesProgressPage) {
160  }
161 }
162 
163 void BtBookshelfWizard::keyPressEvent(QKeyEvent * event) {
164  if(event->key() == Qt::Key_Escape) {
165  if (m_downloadInProgress) {
166  m_closeRequested = true;
167  m_closeMessageBox->show();
168  stopDownload();
169  return;
170  }
171  }
172  QWizard::keyPressEvent(event);
173 }
174 
176  m_downloadInProgress = true;
177 }
178 
180  m_downloadInProgress = false;
181  if (m_closeRequested) {
182  m_closeMessageBox->hide();
183  accept();
184  }
185 }
#define BT_ASSERT(...)
Definition: btassert.h:17
void translateQWizardStandardButtons(QWizard *wizard)
static void replaceButtonText(QWizard *wizard, QWizard::WizardButton which, const QString &text)
@ installWorks
@ removeFinalPage
@ removeWorksPage
@ languagesPage
@ updateWorksPage
@ installFinalPage
@ installWorksPage
@ sourcesProgressPage
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
Definition: btconfig.h:305
QStringList selectedSources() const
WizardTaskType taskType() const
QMessageBox * m_closeMessageBox
QStringList selectedSources() const
BtBookshelfWizard(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
virtual void keyPressEvent(QKeyEvent *event) override
BtBookshelfSourcesPage *const m_sourcesPage
QStringList selectedLanguages() const
void accept() final override
static bool autoUpdateSources()
static void setAutoUpdateSources(bool value)
BtBookshelfSourcesProgressPage *const m_sourcesProgressPage
BtBookshelfLanguagesPage *const m_languagesPage
BtBookshelfInstallFinalPage *const m_installFinalPage
QString installPath() const
WizardTaskType taskType() const
BtBookshelfWorksPage *const m_removeWorksPage
BtModuleSet selectedWorks() const
BtBookshelfWorksPage *const m_updateWorksPage
BtBookshelfWorksPage *const m_installWorksPage
BtBookshelfTaskPage *const m_taskPage
BtModuleSet const & checkedModules() const
void setValue(QString const &key, T const &value)
Sets a value for a key.
Definition: btconfigcore.h:73