1#ifndef QT_UTILITIES_SETUP_UPDATER_H
2#define QT_UTILITIES_SETUP_UPDATER_H
6#ifdef QT_UTILITIES_GUI_QTWIDGETS
11#include <c++utilities/chrono/datetime.h>
12#include <c++utilities/misc/flagenumclass.h>
17#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
18#include <QNetworkRequest>
20#ifdef QT_UTILITIES_GUI_QTWIDGETS
27QT_FORWARD_DECLARE_CLASS(QJsonParseError)
28QT_FORWARD_DECLARE_CLASS(QJsonArray)
29QT_FORWARD_DECLARE_CLASS(QNetworkAccessManager)
30QT_FORWARD_DECLARE_CLASS(QNetworkReply)
31QT_FORWARD_DECLARE_CLASS(QSettings)
39struct UpdateOptionPagePrivate;
40struct UpdateDialogPrivate;
88 const QString &
error() const;
95 void restore(QSettings *settings);
96 void save(QSettings *settings);
98#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
99 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
113 void lastCheckNow()
const;
114 void setError(
const QString &context, QNetworkReply *reply);
115 void setError(
const QString &context,
const QJsonParseError &jsonError,
const QByteArray &response);
117 void queryRelease(
const QUrl &releaseUrl,
bool forUpdate,
bool forPreviousVersion);
119 void processAssets(
const QJsonArray &assets,
bool forUpdate,
bool forPreviousVersion);
122 std::unique_ptr<UpdateNotifierPrivate> m_p;
145 explicit Updater(
const QString &executableName, QObject *parent =
nullptr);
146 explicit Updater(
const QString &executableName,
const QString &signatureExtension, QObject *parent =
nullptr);
151 const QString &
error()
const;
156#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
157 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
161 bool performUpdate(
const QString &downloadUrl,
const QString &signatureUrl);
172 void setError(
const QString &
error);
173 void startDownload(
const QString &downloadUrl,
const QString &signatureUrl);
174 void handleDownloadFinished();
175 void readSignature();
176 void storeExecutable();
177 void concludeUpdate();
180 std::unique_ptr<UpdaterPrivate> m_p;
201 explicit UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
203 const QString &executableName,
const QString &signatureExtension, QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
215#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
216 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
225 void handleUpdateCheckDone();
228#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
229 void scheduleNextUpdateCheck();
232 std::unique_ptr<UpdateHandlerPrivate> m_p;
238 return s_mainInstance;
252 : m_restartRequested(false)
257 return m_restartRequested;
259 void requestRestart();
262 m_restartRequested =
false;
264 void respawnIfRestartRequested();
271 std::atomic_bool m_restartRequested;
274#ifdef QT_UTILITIES_GUI_QTWIDGETS
280explicit UpdateOptionPage(UpdateHandler *updateHandler, QWidget *parentWidget =
nullptr);
282void setRestartHandler(std::function<
void()> &&handler);
286void updateLatestVersion(
bool inProgress =
false);
287std::unique_ptr<UpdateOptionPagePrivate> m_p;
297 explicit VerificationErrorMessageBox();
298 ~VerificationErrorMessageBox()
override;
301 int execForError(QString &errorMessage,
const QString &explanation = QString());
302 void openForError(
const QString &errorMessage,
const QString &explanation = QString());
312 explicit UpdateDialog(QWidget *parent =
nullptr);
313 ~UpdateDialog()
override;
314 UpdateOptionPage *page();
315 const UpdateOptionPage *page()
const;
318 std::unique_ptr<UpdateDialogPrivate> m_p;
327#if defined(QT_UTILITIES_GUI_QTWIDGETS)
std::function< void()> requester()
bool isRestartRequested()
The SettingsDialog class provides a framework for creating settings dialogs with different categories...
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 setFlags(UpdateCheckFlags flags)
void setNetworkAccessManager(QNetworkAccessManager *nm)
UpdateNotifier(QObject *parent=nullptr)
void updateAvailable(const QString &version, const QString &additionalInfo)
void save(QSettings *settings)
bool isInProgress() const
QUrl previousVersionSignatureUrl
bool isUpdateAvailable() const
void inProgressChanged(bool inProgress)
QUrl previousVersionDownloadUrl
void supplyNewReleaseData(const QByteArray &data)
UpdateCheckFlags flags() const
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
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(QtUtilities, QtUtilities::UpdateCheckFlags)