#pragma once #include #include #include #include #include class QFile; class QNetworkReply; class LauncherUpdates : public QObject { Q_OBJECT QML_ELEMENT Q_PROPERTY(QString channel READ channel CONSTANT) Q_PROPERTY(QVariantMap catalogs READ catalogs NOTIFY catalogChanged) Q_PROPERTY(QVariantMap states READ states NOTIFY catalogChanged) Q_PROPERTY(QString latest READ latest NOTIFY catalogChanged) Q_PROPERTY(bool installing READ installing NOTIFY installationChanged) Q_PROPERTY(double downloadProgress READ downloadProgress NOTIFY downloadProgressChanged) public: explicit LauncherUpdates(QObject *parent = nullptr); ~LauncherUpdates() override; QString channel() const; QVariantMap catalogs() const { return m_catalogs; } QVariantMap states() const { return m_states; } QString latest() const { return m_latest; } bool installing() const { return bool(m_download); } double downloadProgress() const { return m_downloadProgress; } Q_INVOKABLE void refresh(const QString &channel); Q_INVOKABLE void install(const QString &channel, const QString &version); Q_INVOKABLE void cancelDownload(); signals: void catalogChanged(); void installationChanged(); void downloadProgressChanged(); void installationFailed(); private: void fetchPage(const QString &channel, int page, QVariantList entries); bool startInstallation(const QString &path); QNetworkAccessManager m_network; QVariantMap m_catalogs; QVariantMap m_states; QString m_latest; std::unique_ptr m_temp; std::unique_ptr m_download; QNetworkReply *m_downloadReply = nullptr; double m_downloadProgress = -1; bool m_cancelRequested = false; };