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;
86 const QString &
error() const;
91 void restore(QSettings *settings);
92 void save(QSettings *settings);
94#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
95 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
109 void lastCheckNow()
const;
110 void setError(
const QString &context, QNetworkReply *reply);
111 void setError(
const QString &context,
const QJsonParseError &jsonError,
const QByteArray &response);
113 void queryRelease(
const QUrl &releaseUrl);
115 void processAssets(
const QJsonArray &assets,
bool forUpdate);
118 std::unique_ptr<UpdateNotifierPrivate> m_p;
141 explicit Updater(
const QString &executableName, QObject *parent =
nullptr);
142 explicit Updater(
const QString &executableName,
const QString &signatureExtension, QObject *parent =
nullptr);
147 const QString &
error()
const;
152#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
153 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
157 bool performUpdate(
const QString &downloadUrl,
const QString &signatureUrl);
168 void setError(
const QString &
error);
169 void startDownload(
const QString &downloadUrl,
const QString &signatureUrl);
170 void handleDownloadFinished();
171 void readSignature();
172 void storeExecutable();
173 void concludeUpdate();
176 std::unique_ptr<UpdaterPrivate> m_p;
197 explicit UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
199 const QString &executableName,
const QString &signatureExtension, QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
211#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
212 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
221 void handleUpdateCheckDone();
224#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
225 void scheduleNextUpdateCheck();
228 std::unique_ptr<UpdateHandlerPrivate> m_p;
234 return s_mainInstance;
248 : m_restartRequested(false)
253 return m_restartRequested;
255 void requestRestart();
258 m_restartRequested =
false;
260 void respawnIfRestartRequested();
267 std::atomic_bool m_restartRequested;
270#ifdef QT_UTILITIES_GUI_QTWIDGETS
276explicit UpdateOptionPage(UpdateHandler *updateHandler, QWidget *parentWidget =
nullptr);
278void setRestartHandler(std::function<
void()> &&handler);
282void updateLatestVersion(
bool inProgress =
false);
283std::unique_ptr<UpdateOptionPagePrivate> m_p;
293 explicit VerificationErrorMessageBox();
294 ~VerificationErrorMessageBox()
override;
297 int execForError(QString &errorMessage,
const QString &explanation = QString());
298 void openForError(
const QString &errorMessage,
const QString &explanation = QString());
308 explicit UpdateDialog(QWidget *parent =
nullptr);
309 ~UpdateDialog()
override;
310 UpdateOptionPage *page();
311 const UpdateOptionPage *page()
const;
314 std::unique_ptr<UpdateDialogPrivate> m_p;
323#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
bool isUpdateAvailable() const
void inProgressChanged(bool inProgress)
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)