QtAutoUpdater  3.0.0
A Qt library to automatically check for updates and install them
updaterbackend.h
1 #ifndef QTAUTOUPDATER_UPDATERBACKEND_H
2 #define QTAUTOUPDATER_UPDATERBACKEND_H
3 
4 #include <optional>
5 
6 #include <QtCore/qobject.h>
7 #include <QtCore/qshareddata.h>
8 #include <QtCore/qversionnumber.h>
9 #include <QtCore/qvariant.h>
10 #include <QtCore/qscopedpointer.h>
11 #include <QtCore/qloggingcategory.h>
12 
13 #include "QtAutoUpdaterCore/qtautoupdatercore_global.h"
14 #include "QtAutoUpdaterCore/updateinfo.h"
15 
16 namespace QtAutoUpdater {
17 
18 class UpdateInstaller;
19 
20 class UpdaterBackendPrivate;
22 class Q_AUTOUPDATERCORE_EXPORT UpdaterBackend : public QObject
23 {
24  Q_OBJECT
25 
26 public:
28  enum class Feature {
29  CheckUpdates = 0x00,
30  CheckProgress = 0x01,
31  TriggerInstall = 0x02,
32  ParallelTrigger = (TriggerInstall | 0x04),
33  PerformInstall = 0x08
34  };
35  Q_DECLARE_FLAGS(Features, Feature)
36  Q_FLAG(Features)
37 
38 
39  class Q_AUTOUPDATERCORE_EXPORT IConfigReader
40  {
41  Q_DISABLE_COPY(IConfigReader)
42  public:
43  IConfigReader() = default;
44  virtual ~IConfigReader() = default;
45 
47  virtual QString backend() const = 0;
49  virtual std::optional<QVariant> value(const QString &key) const = 0;
51  virtual QVariant value(const QString &key, const QVariant &defaultValue) const = 0;
52  };
53 
55  using SecondaryInfo = std::optional<std::pair<QString, QString>>; // (key, display-name)
56 
58  Q_INVOKABLE QString key() const;
60  virtual Features features() const = 0;
62  virtual SecondaryInfo secondaryInfo() const;
64  bool initialize(QScopedPointer<IConfigReader> &&config);
65 
67  virtual void checkForUpdates() = 0;
69  virtual void abort(bool force) = 0;
70 
72  virtual bool triggerUpdates(const QList<UpdateInfo> &infos, bool track) = 0;
74  virtual UpdateInstaller *createInstaller() = 0;
75 
77  static QStringList readStringList(const QVariant &value, QChar listSeperator = QLatin1Char(','));
78 
79 Q_SIGNALS:
81  void checkProgress(double percent, const QString &status);
83  void checkDone(bool success, const QList<QtAutoUpdater::UpdateInfo> &updates = {});
85  void triggerInstallDone(bool success);
86 
87 protected:
89  explicit UpdaterBackend(QString &&key, QObject *parent = nullptr);
91  explicit UpdaterBackend(UpdaterBackendPrivate &dd, QObject *parent = nullptr);
92 
94  IConfigReader *config() const;
95 
97  virtual bool initialize() = 0;
98 
99 private:
100  friend class Updater;
101  Q_DECLARE_PRIVATE(UpdaterBackend)
102 };
103 
104 }
105 
106 Q_DECLARE_OPERATORS_FOR_FLAGS(QtAutoUpdater::UpdaterBackend::Features)
107 
108 #endif // QTAUTOUPDATER_UPDATERBACKEND_H
QtAutoUpdater::Updater
The main updater. Can check for updates and trigger update installations.
Definition: updater.h:26
QList
QString
QChar
QtAutoUpdater::UpdaterBackend::SecondaryInfo
std::optional< std::pair< QString, QString > > SecondaryInfo
Holds the variant map key and display name of the secondary update information.
Definition: updaterbackend.h:55
QScopedPointer
QtAutoUpdater::UpdaterBackend::IConfigReader
A helper interface to allow backend generic access to a backends configuration.
Definition: updaterbackend.h:39
QLatin1Char
QtAutoUpdater::UpdateInstaller
An interface to implement and consume custom in-process installer.
Definition: updateinstaller.h:17
QVariant
QObject
QtAutoUpdater::UpdaterBackend::Feature
Feature
Various features a backend may or may not support.
Definition: updaterbackend.h:28
QtAutoUpdater
The QtAutoUpdater namespace holds all classes that are related with the updater.
Definition: adminauthoriser.h:9
QStringList
QtAutoUpdater::UpdaterBackend
An interface to be implemented by updater plugins to provide the updater functionalities.
Definition: updaterbackend.h:22