| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef __KISSUPPORTERBUNDLESFETCHER_H_ |
| 5 |
#define __KISSUPPORTERBUNDLESFETCHER_H_ |
| 6 |
|
| 7 |
#include <QFileInfo> |
| 8 |
#include <QObject> |
| 9 |
#include <QUrl> |
| 10 |
#include <QVector> |
| 11 |
#include <functional> |
| 12 |
|
| 13 |
#include "KisSupporterBundle.h" |
| 14 |
|
| 15 |
class KisNetworkAccessManager; |
| 16 |
class QNetworkReply; |
| 17 |
class QSqlDatabase; |
| 18 |
|
| 19 |
class KisSupporterBundlesFetcher : public QObject |
| 20 |
{ |
| 21 |
Q_OBJECT |
| 22 |
public: |
| 23 |
explicit KisSupporterBundlesFetcher(QObject *parent = nullptr); |
| 24 |
|
| 25 |
bool isFetching() const |
| 26 |
{ |
| 27 |
return m_fetching; |
| 28 |
} |
| 29 |
|
| 30 |
const QVector<KisSupporterBundle> &bundles() const |
| 31 |
{ |
| 32 |
return m_bundles; |
| 33 |
} |
| 34 |
|
| 35 |
void fetchIndex(); |
| 36 |
|
| 37 |
QNetworkReply *fetchBundle(const KisSupporterBundle &bundle); |
| 38 |
|
| 39 |
static bool hasNetworkReplyError(QNetworkReply *reply, QString &outErrorMessage); |
| 40 |
|
| 41 |
Q_SIGNALS: |
| 42 |
void fetchIndexDone(bool success, const QString &errorMessage); |
| 43 |
|
| 44 |
private: |
| 45 |
static constexpr char BASE_URL[] = "https://cdn.kde.org/krita/.android-supporters-extra/supporterbundles/"; |
| 46 |
|
| 47 |
void handleCheckTxtFetched(QNetworkReply *reply); |
| 48 |
bool handleCheckTxtPredefinedFailure(const QString &content); |
| 49 |
|
| 50 |
bool checkExistingIndexDb(unsigned int expectedVersion, const QString &expectedHash); |
| 51 |
|
| 52 |
void fetchIndexDb(unsigned int expectedVersion, const QString &expectedHash); |
| 53 |
|
| 54 |
void handleIndexDbFetched(QNetworkReply *reply, unsigned int expectedVersion, const QString &expectedHash); |
| 55 |
|
| 56 |
void readIndexDbBundles(); |
| 57 |
|
| 58 |
QNetworkReply *fetch(const QString &path); |
| 59 |
|
| 60 |
void emitCheckTxtFetchFailed(const QString &errorMessage); |
| 61 |
void emitIndexDbFetchFailed(const QString &errorMessage); |
| 62 |
void emitFailure(const QString &errorMessage); |
| 63 |
|
| 64 |
bool doWithIndexDb(QString &outErrorMessage, const std::function<bool(QSqlDatabase &, QString &)> &block); |
| 65 |
|
| 66 |
static bool readSqliteUserVersion(const QByteArray &bytes, unsigned int &outVersion); |
| 67 |
|
| 68 |
KisNetworkAccessManager *m_nam = nullptr; |
| 69 |
QString m_indexDbPath; |
| 70 |
QVector<KisSupporterBundle> m_bundles; |
| 71 |
bool m_fetching = false; |
| 72 |
}; |
| 73 |
|
| 74 |
#endif |