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-2025 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"
31#include "btbookshelftaskpage.h"
34
35
36namespace {
37auto const GeometryKey = QStringLiteral("GUI/BookshelfWizard/geometry");
38auto const SourcesKey = QStringLiteral("GUI/BookshelfWizard/sources");
39auto const LanguagesKey = QStringLiteral("GUI/BookshelfWizard/languages");
41} // anonymous namespace
42
43BtBookshelfWizard::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
75
76 // Load wizard geometry:
77 restoreGeometry(btConfig().value<QByteArray>(GeometryKey, QByteArray()));
78}
79
80static 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
110
113
115 if (currentPage() == m_installFinalPage) {
116 // Save settings:
117 btConfig().setValue(SourcesKey, selectedSources());
118 btConfig().setValue(LanguagesKey, selectedLanguages());
119 }
120
121 btConfig().setValue(GeometryKey, saveGeometry()); // Save wizard geometry
122 QDialog::accept();
123}
124
134
137
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
163void BtBookshelfWizard::keyPressEvent(QKeyEvent * event) {
164 if(event->key() == Qt::Key_Escape) {
166 m_closeRequested = true;
167 m_closeMessageBox->show();
168 stopDownload();
169 return;
170 }
171 }
172 QWizard::keyPressEvent(event);
173}
174
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)
@ removeFinalPage
@ removeWorksPage
@ 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.