dbhub: Improve push database UI

This adds a new Push Database dialog which lets you specify the database
name, the licence, a commit message, and the visibility of the database.
This commit is contained in:
Martin Kleusberg
2017-08-12 14:58:30 +02:00
parent 5bdefad4fc
commit 1c7cc24b15
8 changed files with 326 additions and 14 deletions

View File

@@ -9,6 +9,8 @@
#include <QDir>
#include <QStandardPaths>
#include <QUrlQuery>
#include <QJsonDocument>
#include <QJsonObject>
#include "RemoteDatabase.h"
#include "version.h"
@@ -162,6 +164,23 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
emit gotCurrentVersion(version, url);
break;
}
case RequestTypeLicenceList:
{
// Read and check results
QJsonDocument json = QJsonDocument::fromJson(reply->readAll());
if(json.isNull() || !json.isObject())
break;
QJsonObject obj = json.object();
// Parse data and build licence map (short name -> long name)
QMap<QString, QString> licences;
for(auto it=obj.constBegin();it!=obj.constEnd();++it)
licences.insert(it.key(), it.value().toObject().value("full_name").toString());
// Send licence map to anyone who's interested
emit gotLicenceList(licences);
break;
}
default:
break;
}
@@ -370,7 +389,8 @@ void RemoteDatabase::fetch(const QString& url, RequestType type, const QString&
prepareProgressDialog(false, url);
}
void RemoteDatabase::push(const QString& filename, const QString& url, const QString& clientCert)
void RemoteDatabase::push(const QString& filename, const QString& url, const QString& clientCert,
const QString& commitMessage, const QString& licence, bool isPublic)
{
// Check if network is accessible. If not, abort right here
if(m_manager->networkAccessible() == QNetworkAccessManager::NotAccessible)
@@ -392,6 +412,11 @@ void RemoteDatabase::push(const QString& filename, const QString& url, const QSt
request.setUrl(url);
request.setRawHeader("User-Agent", QString("%1 %2").arg(qApp->organizationName()).arg(APP_VERSION).toUtf8());
// Set custom headers for extra information about the commit
request.setRawHeader("commitmsg", commitMessage.toUtf8());
request.setRawHeader("licence", licence.toUtf8());
request.setRawHeader("public", isPublic ? "true" : "false");
// Set SSL configuration when trying to access a file via the HTTPS protocol
bool https = QUrl(url).scheme().compare("https", Qt::CaseInsensitive) == 0;
if(https)