dbhub: Simplify code

This commit is contained in:
Martin Kleusberg
2020-07-17 21:18:16 +02:00
parent e2783b68ad
commit 0572b76fd7
4 changed files with 12 additions and 11 deletions
+6 -6
View File
@@ -476,7 +476,7 @@ bool RemoteDatabase::prepareSsl(QNetworkRequest* request, const QString& clientC
return true;
}
void RemoteDatabase::prepareProgressDialog(QNetworkReply* reply, bool upload, const QString& url)
void RemoteDatabase::prepareProgressDialog(QNetworkReply* reply, bool upload, const QUrl& url)
{
// Instantiate progress dialog and apply some basic settings
if(!m_progress)
@@ -486,7 +486,7 @@ void RemoteDatabase::prepareProgressDialog(QNetworkReply* reply, bool upload, co
m_progress->setCancelButtonText(tr("Cancel"));
// Set dialog text
QString url_for_display = QUrl(url).toString(QUrl::PrettyDecoded | QUrl::RemoveQuery);
QString url_for_display = url.toString(QUrl::PrettyDecoded | QUrl::RemoveQuery);
if(upload)
m_progress->setLabelText(tr("Uploading remote database to\n%1").arg(url_for_display));
else
@@ -502,7 +502,7 @@ void RemoteDatabase::prepareProgressDialog(QNetworkReply* reply, bool upload, co
connect(reply, &QNetworkReply::downloadProgress, this, &RemoteDatabase::updateProgress);
}
void RemoteDatabase::fetch(const QString& url, RequestType type, const QString& clientCert, QVariant userdata)
void RemoteDatabase::fetch(const QUrl& url, RequestType type, const QString& clientCert, QVariant userdata)
{
// Check if network is accessible. If not, abort right here
if(m_manager->networkAccessible() == QNetworkAccessManager::NotAccessible)
@@ -531,7 +531,7 @@ void RemoteDatabase::fetch(const QString& url, RequestType type, const QString&
// Set SSL configuration when trying to access a file via the HTTPS protocol.
// Skip this step when no client certificate was specified. In this case the default HTTPS configuration is used.
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;
bool https = url.scheme().compare("https", Qt::CaseInsensitive) == 0;
if(https && !clientCert.isNull())
{
// If configuring the SSL connection fails, abort the request here
@@ -554,7 +554,7 @@ void RemoteDatabase::fetch(const QString& url, RequestType type, const QString&
prepareProgressDialog(reply, false, url);
}
void RemoteDatabase::push(const QString& filename, const QString& url, const QString& clientCert, const QString& remotename,
void RemoteDatabase::push(const QString& filename, const QUrl& url, const QString& clientCert, const QString& remotename,
const QString& commitMessage, const QString& licence, bool isPublic, const QString& branch, bool forcePush)
{
// Check if network is accessible. If not, abort right here
@@ -596,7 +596,7 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
addPart(multipart, "commit", QString::fromStdString(localLastCommitId(clientCert, url, branch.toStdString())));
// Set SSL configuration when trying to access a file via the HTTPS protocol
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;
bool https = url.scheme().compare("https", Qt::CaseInsensitive) == 0;
if(https)
{
// If configuring the SSL connection fails, abort the request here
+3 -3
View File
@@ -92,8 +92,8 @@ public:
RequestTypeMetadata,
};
void fetch(const QString& url, RequestType type, const QString& clientCert = QString(), QVariant userdata = QVariant());
void push(const QString& filename, const QString& url, const QString& clientCert, const QString& remotename,
void fetch(const QUrl& url, RequestType type, const QString& clientCert = QString(), QVariant userdata = QVariant());
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);
@@ -166,7 +166,7 @@ private:
void gotError(QNetworkReply* reply, const QList<QSslError>& errors);
void updateProgress(qint64 bytesTransmitted, qint64 bytesTotal);
bool prepareSsl(QNetworkRequest* request, const QString& clientCert);
void prepareProgressDialog(QNetworkReply* reply, bool upload, const QString& url);
void prepareProgressDialog(QNetworkReply* reply, bool upload, const QUrl& url);
// Helper functions for managing the list of locally available databases
void localAssureOpened();
+1 -1
View File
@@ -307,7 +307,7 @@ void RemoteModel::fetchMore(const QModelIndex& parent)
// Fetch item URL
item->setFetchedDirectoryList(true);
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), RemoteDatabase::RequestTypeDirectory, currentClientCert, parent);
remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toUrl(), RemoteDatabase::RequestTypeDirectory, currentClientCert, parent);
}
const QString& RemoteModel::currentClientCertificate() const
+2 -1
View File
@@ -2,6 +2,7 @@
#define REMOTEMODEL_H
#include <QAbstractItemModel>
#include <QUrl>
#include <json.hpp>
@@ -109,7 +110,7 @@ private:
// This stores the currently used network identity so it can be used for further requests, e.g. for
// lazy population.
QString currentRootDirectory;
QUrl currentRootDirectory;
QString currentClientCert;
QString currentUserName;
};