gpt4all/gpt4all-chat/download.h

95 lines
2.6 KiB
C
Raw Normal View History

2023-04-19 01:10:06 +00:00
#ifndef DOWNLOAD_H
#define DOWNLOAD_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QFile>
#include <QVariant>
#include <QTemporaryFile>
#include <QThread>
2023-04-19 01:10:06 +00:00
2023-04-28 14:54:05 +00:00
struct ReleaseInfo {
Q_GADGET
Q_PROPERTY(QString version MEMBER version)
Q_PROPERTY(QString notes MEMBER notes)
Q_PROPERTY(QString contributors MEMBER contributors)
public:
QString version;
QString notes;
QString contributors;
};
class HashAndSaveFile : public QObject
{
Q_OBJECT
public:
HashAndSaveFile();
public Q_SLOTS:
void hashAndSave(const QString &hash, const QString &saveFilePath,
QFile *tempFile, QNetworkReply *modelReply);
Q_SIGNALS:
2023-06-22 19:44:49 +00:00
void hashAndSaveFinished(bool success, const QString &error,
QFile *tempFile, QNetworkReply *modelReply);
private:
QThread m_hashAndSaveThread;
};
2023-04-19 01:10:06 +00:00
class Download : public QObject
{
Q_OBJECT
2023-04-28 14:54:05 +00:00
Q_PROPERTY(bool hasNewerRelease READ hasNewerRelease NOTIFY hasNewerReleaseChanged)
Q_PROPERTY(ReleaseInfo releaseInfo READ releaseInfo NOTIFY releaseInfoChanged)
2023-04-19 01:10:06 +00:00
public:
static Download *globalInstance();
2023-04-28 14:54:05 +00:00
ReleaseInfo releaseInfo() const;
bool hasNewerRelease() const;
2023-04-19 01:10:06 +00:00
Q_INVOKABLE void downloadModel(const QString &modelFile);
Q_INVOKABLE void cancelDownload(const QString &modelFile);
Q_INVOKABLE void installModel(const QString &modelFile, const QString &apiKey);
2023-05-16 13:32:01 +00:00
Q_INVOKABLE void removeModel(const QString &modelFile);
2023-04-28 14:54:05 +00:00
Q_INVOKABLE bool isFirstStart() const;
2023-04-19 01:10:06 +00:00
2023-06-22 19:44:49 +00:00
public Q_SLOTS:
void updateReleaseNotes();
2023-04-22 20:39:32 +00:00
private Q_SLOTS:
2023-04-24 21:52:19 +00:00
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
2023-04-28 14:54:05 +00:00
void handleReleaseJsonDownloadFinished();
void handleErrorOccurred(QNetworkReply::NetworkError code);
2023-04-19 01:10:06 +00:00
void handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void handleModelDownloadFinished();
2023-06-22 19:44:49 +00:00
void handleHashAndSaveFinished(bool success, const QString &error,
QFile *tempFile, QNetworkReply *modelReply);
void handleReadyRead();
2023-04-19 01:10:06 +00:00
Q_SIGNALS:
2023-04-28 14:54:05 +00:00
void releaseInfoChanged();
void hasNewerReleaseChanged();
void requestHashAndSave(const QString &hash, const QString &saveFilePath,
QFile *tempFile, QNetworkReply *modelReply);
2023-04-19 01:10:06 +00:00
private:
2023-04-28 14:54:05 +00:00
void parseReleaseJsonFile(const QByteArray &jsonData);
QString incompleteDownloadPath(const QString &modelFile);
2023-04-19 01:10:06 +00:00
HashAndSaveFile *m_hashAndSave;
2023-04-28 14:54:05 +00:00
QMap<QString, ReleaseInfo> m_releaseMap;
2023-04-19 01:10:06 +00:00
QNetworkAccessManager m_networkManager;
QMap<QNetworkReply*, QFile*> m_activeDownloads;
QDateTime m_startTime;
2023-04-19 01:10:06 +00:00
private:
explicit Download();
~Download() {}
friend class MyDownload;
};
#endif // DOWNLOAD_H