BibleTime
btinstallthread.h
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 #pragma once
14 
15 #include <QThread>
16 
17 #include <atomic>
18 #include <QList>
19 #include <QObject>
20 #include <QString>
21 #include <Qt>
22 #include "btinstallmgr.h"
23 #include "../util/btconnect.h"
24 
25 
26 class CSwordModuleInfo;
27 
28 class BtInstallThread: public QThread {
29 
30  Q_OBJECT
31 
32  public:
33 
35  const QString & destination,
36  QObject * const parent = nullptr)
37  : QThread(parent)
38  , m_modules(modules)
39  , m_destination(destination)
40  , m_stopRequested(false)
41  {
44  Qt::QueuedConnection);
47  Qt::QueuedConnection);
48  }
49 
50  void stopInstall()
51  { m_stopRequested.store(true, std::memory_order_relaxed); }
52 
53  Q_SIGNALS:
54 
55  /** Emitted when starting the installation. */
56  void preparingInstall(int moduleIndex);
57 
58  /** Emitted when the first file download has been started. */
59  void downloadStarted(int moduleIndex);
60 
61  /** Emitted when the install progress status is updated. */
62  void statusUpdated(int moduleIndex, int progressPercent);
63 
64  /** Emitted when installing is complete. */
65  void installCompleted(int moduleIndex, bool success);
66 
67  protected: // methods:
68 
69  void run() override;
70 
71  private: // methods:
72 
73  void installModule();
74  bool removeModule();
75 
76  private Q_SLOTS:
77 
78  void slotDownloadStarted();
79  void slotManagerStatusUpdated(int totalProgress, int fileProgress);
80 
81  private: // fields:
82 
84  const QString m_destination;
87  std::atomic<bool> m_stopRequested;
88 
89 };
#define BT_CONNECT(...)
Definition: btconnect.h:20
void percentCompleted(const int total, const int file)
void downloadStarted()
void downloadStarted(int moduleIndex)
void preparingInstall(int moduleIndex)
BtInstallThread(const QList< CSwordModuleInfo * > &modules, const QString &destination, QObject *const parent=nullptr)
void installCompleted(int moduleIndex, bool success)
std::atomic< bool > m_stopRequested
void statusUpdated(int moduleIndex, int progressPercent)
void slotManagerStatusUpdated(int totalProgress, int fileProgress)
void run() override
const QString m_destination
const QList< CSwordModuleInfo * > & m_modules
BtInstallMgr m_iMgr