BibleTime
btbookshelfsourcesprogresspage.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 
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/btsourcesthread.h"
27 #include "../../util/btconnect.h"
28 #include "btbookshelfwizardenums.h"
29 #include "btbookshelfwizard.h"
30 
31 
33  : BtBookshelfWizardPage(parent)
34 {
35  // Setup UI:
36  QVBoxLayout * const vLayout = new QVBoxLayout(this);
37 
38  vLayout->addItem(new QSpacerItem(20,
39  40,
40  QSizePolicy::Minimum,
41  QSizePolicy::Expanding));
42 
43  m_msgLabel = new QLabel(this);
44  m_msgLabel->setAlignment(Qt::AlignCenter);
45  m_msgLabel->setWordWrap(true);
46  vLayout->addWidget(m_msgLabel);
47 
48  m_progressBar = new QProgressBar(this);
49  m_progressBar->setMinimum(0);
50  m_progressBar->setMaximum(100);
51  vLayout->addWidget(m_progressBar, Qt::AlignCenter);
52 
53  QHBoxLayout * const horizontalLayout = new QHBoxLayout();
54  m_stopButton = new QPushButton(this);
55  horizontalLayout->addSpacerItem(
56  new QSpacerItem(1, 1, QSizePolicy::Expanding));
57  horizontalLayout->addWidget(m_stopButton);
58  horizontalLayout->addSpacerItem(
59  new QSpacerItem(1, 1, QSizePolicy::Expanding));
60  vLayout->addLayout(horizontalLayout);
61 
62  vLayout->addItem(new QSpacerItem(20,
63  40,
64  QSizePolicy::Minimum,
65  QSizePolicy::Expanding));
66 
67  // Initialize connections:
68  BT_CONNECT(m_stopButton, &QPushButton::clicked,
70 }
71 
73  if (m_thread) {
74  m_thread->stop();
75  while (!m_thread->wait()) /* join */;
76  delete m_thread;
77  m_thread = nullptr;
78  }
79 }
80 
82  m_stopButton->setText(tr("Stop"));
83 
84  setTitle(QApplication::translate(
85  "BookshelfWizard", "Updating Remote Libraries"));
86  setSubTitle(QApplication::translate(
87  "BookshelfWizard",
88  "Updating information from remote libraries."));
89 }
90 
92  if (btWizard().taskType() == WizardTaskType::updateWorks)
95 }
96 
98  destroyThread();
99 
100  m_installCompleted = false;
101  m_thread = new BtSourcesThread(this);
103  m_progressBar, &QProgressBar::setValue,
104  Qt::QueuedConnection);
106  m_msgLabel, &QLabel::setText,
107  Qt::QueuedConnection);
108  BT_CONNECT(m_thread, &BtSourcesThread::finished,
110  Qt::QueuedConnection);
111  m_thread->start();
112  m_stopButton->setEnabled(true);
114  retranslateUi();
115 }
116 
118 { return m_installCompleted; }
119 
121  m_stopButton->setDisabled(true);
124  m_installCompleted = true;
125  Q_EMIT QWizardPage::completeChanged();
127 }
128 
130  m_stopButton->setDisabled(true);
131  m_thread->stop();
132 }
@ updateWorksPage
#define BT_CONNECT(...)
Definition: btconnect.h:20
BtBookshelfSourcesProgressPage(QWidget *parent=nullptr)
BtBookshelfWizard & btWizard() const noexcept
static void setAutoUpdateSources(bool value)
void stop() noexcept
void percentComplete(int percent)
void showMessage(QString const &msg)
bool finishedSuccessfully() const noexcept