mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-02-09 21:28:30 -06:00
dbhub: Make network code less centralised
This adds the possibility to handle network replies individually instead of routing all of them through a central handler routine. The centralised approach made the code more complicated than necessary and would inevitably lead to confusion when sending similar requests simultaneously.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QtNetwork/QSslConfiguration>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
class QNetworkAccessManager;
|
||||
@@ -14,52 +15,6 @@ class QNetworkRequest;
|
||||
class QHttpMultiPart;
|
||||
class QFile;
|
||||
|
||||
class RemoteMetadataBranchInfo
|
||||
{
|
||||
public:
|
||||
RemoteMetadataBranchInfo(const std::string& _name, const std::string& _commit_id, const std::string& _description, unsigned int _commit_count) :
|
||||
name(_name),
|
||||
commit_id(_commit_id),
|
||||
description(_description),
|
||||
commit_count(_commit_count)
|
||||
{}
|
||||
RemoteMetadataBranchInfo() :
|
||||
commit_count(0)
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
std::string commit_id;
|
||||
std::string description;
|
||||
unsigned int commit_count;
|
||||
};
|
||||
|
||||
class RemoteMetadataReleaseInfo
|
||||
{
|
||||
public:
|
||||
RemoteMetadataReleaseInfo(const std::string& _name, const std::string& _commit_id, const std::string& _date,
|
||||
const std::string& _description, const std::string& _email,
|
||||
const std::string& _user_name, unsigned int _size) :
|
||||
name(_name),
|
||||
commit_id(_commit_id),
|
||||
date(_date),
|
||||
description(_description),
|
||||
email(_email),
|
||||
user_name(_user_name),
|
||||
size(_size)
|
||||
{}
|
||||
RemoteMetadataReleaseInfo() :
|
||||
size(0)
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
std::string commit_id;
|
||||
std::string date;
|
||||
std::string description;
|
||||
std::string email;
|
||||
std::string user_name;
|
||||
unsigned long size;
|
||||
};
|
||||
|
||||
class RemoteNetwork : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -85,17 +40,13 @@ public:
|
||||
|
||||
enum RequestType
|
||||
{
|
||||
RequestTypeCustom,
|
||||
RequestTypeDatabase,
|
||||
RequestTypeDirectory,
|
||||
RequestTypeNewVersionCheck,
|
||||
RequestTypePush,
|
||||
RequestTypeLicenceList,
|
||||
RequestTypeBranchList,
|
||||
RequestTypeMetadata,
|
||||
RequestTypeDownload,
|
||||
};
|
||||
|
||||
void fetch(const QUrl& url, RequestType type, const QString& clientCert = QString(), QVariant userdata = QVariant());
|
||||
void fetch(const QUrl& url, RequestType type, const QString& clientCert = QString(), std::function<void(QByteArray)> when_finished = {});
|
||||
void push(const QString& filename, const QUrl& url, const QString& clientCert, const QString& remotename,
|
||||
const QString& commitMessage = QString(), const QString& licence = QString(), bool isPublic = false,
|
||||
const QString& branch = QString("master"), bool forcePush = false, const QString& last_commit = QString());
|
||||
@@ -105,16 +56,6 @@ signals:
|
||||
// which might otherwise fail.
|
||||
void networkReady();
|
||||
|
||||
// These signals are emitted when the fetch() calls are finished that are not requesting a remote database but other data, like
|
||||
// a directory listing or the licence list.
|
||||
void gotDirList(QString json, QVariant userdata);
|
||||
void gotCurrentVersion(QString version, QString url);
|
||||
void gotLicenceList(std::vector<std::pair<std::string, std::string>> licences);
|
||||
void gotBranchList(std::vector<std::string> branches, std::string default_branch);
|
||||
void gotMetadata(std::vector<RemoteMetadataBranchInfo> branches, std::string commits,
|
||||
std::vector<RemoteMetadataReleaseInfo> releases, std::vector<RemoteMetadataReleaseInfo> tags,
|
||||
std::string default_branch, std::string web_page);
|
||||
|
||||
// The fetchFinished() signal is emitted when a fetch() call for a database is finished
|
||||
void fetchFinished(QString filename, QString identity, const QUrl& url, std::string new_commit_id, std::string branch,
|
||||
QDateTime last_modified, QIODevice* device);
|
||||
@@ -141,6 +82,10 @@ private:
|
||||
// object. Otherwise Qt might reuse the old certificate if the requested URL has been used before.
|
||||
void clearAccessCache(const QString& clientCert);
|
||||
|
||||
// This function is called for all network replies we get whether they are handled globally or individually.
|
||||
// It mainly does some error checking and returns true if the actual handler should be called.
|
||||
bool handleReply(QNetworkReply* reply);
|
||||
|
||||
QNetworkAccessManager* m_manager;
|
||||
QNetworkConfigurationManager* m_configurationManager;
|
||||
QProgressDialog* m_progress;
|
||||
|
||||
Reference in New Issue
Block a user