BibleTime
btbookshelfinstallfinalpage.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-2026 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
14
15#include <QApplication>
16#include <QHBoxLayout>
17#include <QLabel>
18#include <QProgressBar>
19#include <QPushButton>
20#include <QSizePolicy>
21#include <QSpacerItem>
22#include <QStringLiteral>
23#include <Qt>
24#include <QVBoxLayout>
25#include <QWizardPage>
26#include "../../backend/btinstallthread.h"
27#include "../../backend/drivers/btmoduleset.h"
28#include "../../backend/drivers/cswordmoduleinfo.h"
29#include "../../backend/managers/cswordbackend.h"
30#include "../../util/btconnect.h"
31#include "btbookshelfwizard.h"
33
34
35namespace {
36QString const groupingOrderKey = "GUI/BookshelfWizard/InstallPage/grouping";
37QString const installPathKey =
38 "GUI/BookshelfWizard/InstallPage/installPathIndex";
39} // anonymous namespace
40
42 : BtBookshelfWizardPage(parent)
43{
44 // Setup UI:
45 m_verticalLayout = new QVBoxLayout(this);
46
47 m_verticalLayout->addItem(new QSpacerItem(20,
48 40,
49 QSizePolicy::Minimum,
50 QSizePolicy::Expanding));
51
52 m_msgLabel = new QLabel(this);
53 m_msgLabel->setAlignment(Qt::AlignCenter);
54 m_msgLabel->setWordWrap(true);
55 m_verticalLayout->addWidget(m_msgLabel);
56
57 m_msgLabel2 = new QLabel(this);
58 m_msgLabel2->setAlignment(Qt::AlignCenter);
59 m_msgLabel2->setWordWrap(true);
60 m_verticalLayout->addWidget(m_msgLabel2);
61
62 m_progressBar = new QProgressBar(this);
63 m_verticalLayout->addWidget(m_progressBar,Qt::AlignCenter);
64
65 QHBoxLayout * const horizontalLayout = new QHBoxLayout();
66 m_stopButton = new QPushButton(this);
67 horizontalLayout->addSpacerItem(
68 new QSpacerItem(1, 1, QSizePolicy::Expanding));
69 horizontalLayout->addWidget(m_stopButton);
70 horizontalLayout->addSpacerItem(
71 new QSpacerItem(1, 1, QSizePolicy::Expanding));
72 m_verticalLayout->addLayout(horizontalLayout);
73
74 m_verticalLayout->addItem(new QSpacerItem(20,
75 40,
76 QSizePolicy::Minimum,
77 QSizePolicy::Expanding));
78
79 // Initialize connections:
80 BT_CONNECT(m_stopButton, &QPushButton::clicked,
82}
83
85 if (m_thread) {
87 while (!m_thread->wait()) /* join */;
88 delete m_thread;
89 m_thread = nullptr;
90 }
91}
92
94 m_stopButton->setText(tr("Stop"));
95
96 if (btWizard().taskType() == WizardTaskType::updateWorks) {
97 setTitle(QApplication::translate(
98 "BookshelfWizard", "Updating Works"));
99 setSubTitle(QApplication::translate(
100 "BookshelfWizard",
101 "The selected works are being updated."));
102 } else {
103 setTitle(QApplication::translate(
104 "BookshelfWizard", "Installing Works"));
105 setSubTitle(QApplication::translate(
106 "BookshelfWizard",
107 "The selected works are being installed."));
108 }
109}
110
111int BtBookshelfInstallFinalPage::nextId() const { return -1; }
112
116
117 // Install works:
118 auto & btWiz = btWizard();
119
120 m_modules = btWiz.selectedWorks().values();
121 BT_ASSERT(!m_modules.empty());
122
123 m_thread = new BtInstallThread(m_modules, btWiz.installPath(), this);
126 Qt::QueuedConnection);
129 Qt::QueuedConnection);
132 Qt::QueuedConnection);
133 BT_CONNECT(m_thread, &BtInstallThread::finished,
135 Qt::QueuedConnection);
136
137 m_progressBar->setValue(0);
138 BT_ASSERT(m_modules.size() <= MAX_MODULES); // No int overflow
139 m_progressBar->setMaximum(m_modules.size() * 100);
140
141 m_stopButton->setEnabled(true);
142 m_installFailed = false;
143 m_installCompleted = false;
144 m_thread->start();
145 btWiz.downloadStarted();
146}
147
150
152 m_stopButton->setDisabled(true);
154 m_installFailed = true;
155}
156
158 m_msgLabel->setText(
159 tr("Installing \"%1\"").arg(m_modules.at(moduleIndex)->name()));
160 m_msgLabel2->setText(m_modules.at(moduleIndex)->config(CSwordModuleInfo::Description));
161 m_lastStatus = -1;
162}
163
165 int const status)
166{
167 BT_ASSERT(moduleIndex >= 0);
168 BT_ASSERT(moduleIndex < m_modules.size());
169 BT_ASSERT(status >= 0);
170 BT_ASSERT(status <= 100);
171
172 // Skip initial high value sent by Sword:
173 if (m_lastStatus == -1 && status > 80)
174 return;
175
176 if (m_lastStatus == status)
177 return;
178
179 m_lastStatus = status;
180
181 m_progressBar->setValue(moduleIndex * 100 + status);
182}
183
185 bool const successful)
186{
187 BT_ASSERT(moduleIndex >= 0);
188 BT_ASSERT(moduleIndex < m_modules.size());
189
190 m_progressBar->setValue((moduleIndex + 1) * 100);
191 if (!successful)
192 m_installFailed = true;
193}
194
196 m_progressBar->setValue(m_progressBar->maximum());
197 m_stopButton->setEnabled(false);
198 if (m_installFailed) {
199 m_msgLabel->setText(
200 tr("Some of the selected works were not installed."));
201 m_msgLabel->setStyleSheet("QLabel{color:red}");
202 } else {
203 m_msgLabel->setText(tr("The selected works have been installed."));
204 }
205 m_msgLabel2->setText("");
206
208
209 m_installCompleted = true;
210 Q_EMIT QWizardPage::completeChanged();
212}
#define BT_ASSERT(...)
Definition btassert.h:17
#define BT_CONNECT(...)
Definition btconnect.h:20
BtBookshelfInstallFinalPage(QWidget *parent=nullptr)
QList< CSwordModuleInfo * > m_modules
void slotOneItemCompleted(int moduleIndex, bool status)
static constexpr int const MAX_MODULES
void slotStatusUpdated(int moduleIndex, int status)
BtBookshelfWizard & btWizard() const noexcept
void downloadStarted(int moduleIndex)
void preparingInstall(int moduleIndex)
void installCompleted(int moduleIndex, bool success)
void statusUpdated(int moduleIndex, int progressPercent)
void reloadModules()
Reloads all Sword modules.
static CSwordBackend & instance() noexcept