1#ifndef QT_UTILITIES_SETUP_UPDATER_H
2#define QT_UTILITIES_SETUP_UPDATER_H
6#ifdef QT_UTILITIES_GUI_QTWIDGETS
10#include <c++utilities/chrono/datetime.h>
15#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
16#include <QNetworkRequest>
21QT_FORWARD_DECLARE_CLASS(QJsonParseError)
22QT_FORWARD_DECLARE_CLASS(QJsonArray)
23QT_FORWARD_DECLARE_CLASS(QNetworkAccessManager)
24QT_FORWARD_DECLARE_CLASS(QNetworkReply)
25QT_FORWARD_DECLARE_CLASS(QSettings)
33struct UpdateOptionPagePrivate;
62 const QString &
error() const;
67 void restore(QSettings *settings);
68 void save(QSettings *settings);
70#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
71 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
84 void lastCheckNow()
const;
85 void setError(
const QString &context, QNetworkReply *reply);
86 void setError(
const QString &context,
const QJsonParseError &jsonError,
const QByteArray &response, QNetworkReply *reply);
88 void queryRelease(
const QUrl &releaseUrl);
90 void processAssets(
const QJsonArray &assets,
bool forUpdate);
93 std::unique_ptr<UpdateNotifierPrivate> m_p;
116 explicit Updater(
const QString &executableName, QObject *parent =
nullptr);
117 explicit Updater(
const QString &executableName,
const QString &signatureExtension, QObject *parent =
nullptr);
122 const QString &
error()
const;
127#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
128 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
132 bool performUpdate(
const QString &downloadUrl,
const QString &signatureUrl);
143 void setError(
const QString &
error);
144 void startDownload(
const QString &downloadUrl,
const QString &signatureUrl);
145 void handleDownloadFinished();
146 void readSignature();
147 void storeExecutable();
148 void concludeUpdate();
151 std::unique_ptr<UpdaterPrivate> m_p;
172 explicit UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
174 const QString &executableName,
const QString &signatureExtension, QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
185#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
186 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
194 void handleUpdateCheckDone();
197#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
198 void scheduleNextUpdateCheck();
201 std::unique_ptr<UpdateHandlerPrivate> m_p;
207 return s_mainInstance;
215#ifdef QT_UTILITIES_GUI_QTWIDGETS
221explicit UpdateOptionPage(
UpdateHandler *updateHandler, QWidget *parentWidget =
nullptr);
223void setRestartHandler(std::function<
void()> &&handler);
227void updateLatestVersion(
bool inProgress =
false);
228std::unique_ptr<UpdateOptionPagePrivate> m_p;
237#if defined(QT_UTILITIES_GUI_QTWIDGETS)
The UpdateHandler class manages the non-graphical aspects of checking for new updates and performing ...
bool isConsideringSeparateSignature() const
static UpdateHandler * mainInstance()
void setConsideringSeparateSignature(bool consideringSeparateSignature)
static void setMainInstance(UpdateHandler *mainInstance)
UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent=nullptr)
Handles checking for updates and performing an update of the application if available.
const CheckInterval & checkInterval() const
UpdateNotifier * notifier
void setCheckInterval(CheckInterval checkInterval)
UpdateNotifier * notifier()
The UpdateNotifier class allows checking for new updates.
void setNetworkAccessManager(QNetworkAccessManager *nm)
UpdateNotifier(QObject *parent=nullptr)
void updateAvailable(const QString &version, const QString &additionalInfo)
void save(QSettings *settings)
bool isInProgress() const
bool isUpdateAvailable() const
void inProgressChanged(bool inProgress)
const QString & latestVersion() const
void restore(QSettings *settings)
CppUtilities::DateTime lastCheck() const
The Updater class allows downloading and applying an update.
Updater(const QString &executableName, QObject *parent=nullptr)
void updatePercentageChanged(qint64 bytesReceived, qint64 bytesTotal)
void updateStatusChanged(const QString &statusMessage)
void updateFailed(const QString &error)
std::function< QString(const Update &)> VerifyFunction
bool performUpdate(const QString &downloadUrl, const QString &signatureUrl)
void setVerifier(VerifyFunction &&verifyFunction)
void inProgressChanged(bool inProgress)
void setNetworkAccessManager(QNetworkAccessManager *nm)
bool isInProgress() const
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
The CppUtilities namespace contains addons to the c++utilities library provided by the qtutilities li...
#define DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE(SomeClass)
Declares external instantiation of class declared with BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE in a c...
#define BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(SomeClass)
Declares a class inheriting from Dialogs::UiFileBasedOptionPage in a convenient way.
#define END_DECLARE_OPTION_PAGE
Must be used after BEGIN_DECLARE_OPTION_PAGE and BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE.
#define DECLARE_SETUP_WIDGETS
Declares the method setupWidget() in a convenient way.
The CheckInterval struct specifies whether automatic checks for updates are enabled and of often they...
bool enabled
Whether automatic checks for updates are enabled at all.
CppUtilities::TimeSpan duration
The duration of the interval. Only durations up to around 24 days are supported. Only full-second acc...
std::string_view executableName
std::string_view signatureName
std::string_view signature