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)
32QT_FORWARD_DECLARE_CLASS(QVersionNumber)
37struct VersionAndSuffix;
41struct UpdateOptionPagePrivate;
42struct UpdateDialogPrivate;
90 const QString &
error() const;
97 void restore(QSettings *settings);
98 void save(QSettings *settings);
100#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
101 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
102 static bool isVersionHigher(
const QString &lhs,
const QString &rhs);
116 void lastCheckNow()
const;
117 void setError(
const QString &context, QNetworkReply *reply);
118 void setError(
const QString &context,
const QJsonParseError &jsonError,
const QByteArray &response);
120 void queryRelease(
const QUrl &releaseUrl,
bool forUpdate,
bool forPreviousVersion);
122 void processAssets(
const QJsonArray &assets,
bool forUpdate,
bool forPreviousVersion);
125 std::unique_ptr<UpdateNotifierPrivate> m_p;
148 explicit Updater(
const QString &executableName, QObject *parent =
nullptr);
149 explicit Updater(
const QString &executableName,
const QString &signatureExtension, QObject *parent =
nullptr);
154 const QString &
error()
const;
159#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
160 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
164 bool performUpdate(
const QString &downloadUrl,
const QString &signatureUrl);
175 void setError(
const QString &
error);
176 void startDownload(
const QString &downloadUrl,
const QString &signatureUrl);
177 void handleDownloadFinished();
178 void readSignature();
179 void storeExecutable();
180 void concludeUpdate();
183 std::unique_ptr<UpdaterPrivate> m_p;
204 explicit UpdateHandler(QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
206 const QString &executableName,
const QString &signatureExtension, QSettings *settings, QNetworkAccessManager *nm, QObject *parent =
nullptr);
218#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
219 void setCacheLoadControl(QNetworkRequest::CacheLoadControl cacheLoadControl);
228 void handleUpdateCheckDone();
231#ifdef QT_UTILITIES_SETUP_TOOLS_ENABLED
232 void scheduleNextUpdateCheck();
235 std::unique_ptr<UpdateHandlerPrivate> m_p;
241 return s_mainInstance;
255 : m_restartRequested(false)
260 return m_restartRequested;
262 void requestRestart();
265 m_restartRequested =
false;
267 void respawnIfRestartRequested();
274 std::atomic_bool m_restartRequested;
277#ifdef QT_UTILITIES_GUI_QTWIDGETS
283explicit UpdateOptionPage(UpdateHandler *updateHandler, QWidget *parentWidget =
nullptr);
285void setRestartHandler(std::function<
void()> &&handler);
289void updateLatestVersion(
bool inProgress =
false);
290std::unique_ptr<UpdateOptionPagePrivate> m_p;
300 explicit VerificationErrorMessageBox();
301 ~VerificationErrorMessageBox()
override;
304 int execForError(QString &errorMessage,
const QString &explanation = QString());
305 void openForError(
const QString &errorMessage,
const QString &explanation = QString());
315 explicit UpdateDialog(QWidget *parent =
nullptr);
316 ~UpdateDialog()
override;
317 UpdateOptionPage *page();
318 const UpdateOptionPage *page()
const;
321 std::unique_ptr<UpdateDialogPrivate> m_p;
330#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)