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-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
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_progressBar->setMinimum(0);
64 m_progressBar->setMaximum(100);
65 m_verticalLayout->addWidget(m_progressBar,Qt::AlignCenter);
66
67 QHBoxLayout * const horizontalLayout = new QHBoxLayout();
68 m_stopButton = new QPushButton(this);
69 horizontalLayout->addSpacerItem(
70 new QSpacerItem(1, 1, QSizePolicy::Expanding));
71 horizontalLayout->addWidget(m_stopButton);
72 horizontalLayout->addSpacerItem(
73 new QSpacerItem(1, 1, QSizePolicy::Expanding));
74 m_verticalLayout->addLayout(horizontalLayout);
75
76 m_verticalLayout->addItem(new QSpacerItem(20,
77 40,
78 QSizePolicy::Minimum,
79 QSizePolicy::Expanding));
80
81 // Initialize connections:
82 BT_CONNECT(m_stopButton, &QPushButton::clicked,
84}
85
87 if (m_thread) {
89 while (!m_thread->wait()) /* join */;
90 delete m_thread;
91 m_thread = nullptr;
92 }
93}
94
96 m_stopButton->setText(tr("Stop"));
97
98 if (btWizard().taskType() == WizardTaskType::updateWorks) {
99 setTitle(QApplication::translate(
100 "BookshelfWizard", "Updating Works"));
101 setSubTitle(QApplication::translate(
102 "BookshelfWizard",
103 "The selected works are being updated."));
104 } else {
105 setTitle(QApplication::translate(
106 "BookshelfWizard", "Installing Works"));
107 setSubTitle(QApplication::translate(
108 "BookshelfWizard",
109 "The selected works are being installed."));
110 }
111}
112
113int BtBookshelfInstallFinalPage::nextId() const { return -1; }
114
118
119 // Install works:
120 auto & btWiz = btWizard();
121 m_modules = btWiz.selectedWorks().values();
122 m_thread = new BtInstallThread(m_modules, btWiz.installPath(), this);
125 Qt::QueuedConnection);
128 Qt::QueuedConnection);
131 Qt::QueuedConnection);
132 BT_CONNECT(m_thread, &BtInstallThread::finished,
134 Qt::QueuedConnection);
135 m_progressBar->setValue(0);
136 m_stopButton->setEnabled(true);
137 m_installFailed = false;
138 m_installCompleted = false;
139 m_thread->start();
140 btWiz.downloadStarted();
141}
142
145
147 m_stopButton->setDisabled(true);
149 m_installFailed = true;
150}
151
153 m_msgLabel->setText(
154 tr("Installing \"%1\"").arg(m_modules.at(moduleIndex)->name()));
155 m_msgLabel2->setText(m_modules.at(moduleIndex)->config(CSwordModuleInfo::Description));
156 m_lastStatus = -1;
157}
158
159void BtBookshelfInstallFinalPage::slotStatusUpdated(int moduleIndex, int status)
160{
161 // Skip initial high value sent by Sword:
162 if (m_lastStatus == -1 && status > 80)
163 return;
164
165 if (m_lastStatus == status)
166 return;
167
168 m_lastStatus = status;
169
170 int const perModuleIncrement = 100 / m_modules.count();
171 m_progressBar->setValue((moduleIndex * perModuleIncrement)
172 + (status * perModuleIncrement / 100));
173}
174
176 bool successful)
177{
178 m_progressBar->setValue((moduleIndex + 1) * (100 / m_modules.count()));
179 if (!successful)
180 m_installFailed = true;
181}
182
184 m_progressBar->setValue(100);
185 m_stopButton->setEnabled(false);
186 if (m_installFailed) {
187 m_msgLabel->setText(
188 tr("Some of the selected works were not installed."));
189 m_msgLabel->setStyleSheet("QLabel{color:red}");
190 } else {
191 m_msgLabel->setText(tr("The selected works have been installed."));
192 }
193 m_msgLabel2->setText("");
194
196
197 m_installCompleted = true;
198 Q_EMIT QWizardPage::completeChanged();
200}
#define BT_CONNECT(...)
Definition btconnect.h:20
BtBookshelfInstallFinalPage(QWidget *parent=nullptr)
QList< CSwordModuleInfo * > m_modules
void slotOneItemCompleted(int moduleIndex, bool status)
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