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
+3
View File
@@ -117,6 +117,7 @@ set(SQLB_MOC_HDR
src/PlotDock.h
src/RemoteDock.h
src/RemoteModel.h
src/RemotePushDialog.h
)
set(SQLB_SRC
@@ -154,6 +155,7 @@ set(SQLB_SRC
src/PlotDock.cpp
src/RemoteDock.cpp
src/RemoteModel.cpp
src/RemotePushDialog.cpp
)
set(SQLB_FORMS
@@ -172,6 +174,7 @@ set(SQLB_FORMS
src/ColumnDisplayFormatDialog.ui
src/PlotDock.ui
src/RemoteDock.ui
src/RemotePushDialog.ui
)
set(SQLB_RESOURCES
+26 -1
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)
+4 -1
View File
@@ -38,15 +38,18 @@ public:
RequestTypeDirectory,
RequestTypeNewVersionCheck,
RequestTypePush,
RequestTypeLicenceList,
};
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);
void push(const QString& filename, const QString& url, const QString& clientCert,
const QString& commitMessage = QString(), const QString& licence = QString(), bool isPublic = false);
signals:
void gotDirList(QString json, QVariant userdata);
void openFile(QString path);
void gotCurrentVersion(QString version, QString url);
void gotLicenceList(QMap<QString, QString> licences);
private:
void gotEncrypted(QNetworkReply* reply);
+11 -9
View File
@@ -8,6 +8,7 @@
#include "RemoteDatabase.h"
#include "RemoteModel.h"
#include "MainWindow.h"
#include "RemotePushDialog.h"
RemoteDock::RemoteDock(MainWindow* parent)
: QDialog(parent),
@@ -86,23 +87,24 @@ void RemoteDock::enableButtons()
void RemoteDock::pushDatabase()
{
// Ask for file name to save under. The default suggestion is the local file name. If it is a remote file (like when it initially was fetched using DB4S),
// The default suggestion for a database name is the local file name. If it is a remote file (like when it initially was fetched using DB4S),
// the extra bit of information at the end of the name gets removed first.
QString name = QFileInfo(mainWindow->getDb().currentFile()).fileName();
name = name.remove(QRegExp("_[0-9]+.remotedb$"));
name = QInputDialog::getText(this, qApp->applicationName(),
tr("Please enter the database name to push to."),
QLineEdit::Normal,
name);
if(name.isEmpty())
// Show the user a dialog for setting all the commit details
QString host = QString("https://%1:5550/").arg(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoServer));
RemotePushDialog pushDialog(this, remoteDatabase, host, remoteModel->currentClientCertificate(), name);
if(pushDialog.exec() != QDialog::Accepted)
return;
// Build push URL
QString url = QString("https://%1:5550/").arg(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoServer));
QString url = host;
url.append(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoUser));
url.append("/");
url.append(name);
url.append(pushDialog.name());
// Push database
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate());
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate(),
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic());
}
+75
View File
@@ -0,0 +1,75 @@
#include <QPushButton>
#include "RemotePushDialog.h"
#include "ui_RemotePushDialog.h"
#include "RemoteDatabase.h"
RemotePushDialog::RemotePushDialog(QWidget* parent, RemoteDatabase& remote, const QString& host, const QString& clientCert, const QString& name) :
QDialog(parent),
ui(new Ui::RemotePushDialog),
remoteDatabase(remote)
{
// Create UI
ui->setupUi(this);
// Set start values
ui->editName->setText(name);
// Enable/disable accept button
checkInput();
// Fetch list of available licences
connect(&remoteDatabase, &RemoteDatabase::gotLicenceList, this, &RemotePushDialog::fillInLicences);
remoteDatabase.fetch(host + "licence/list", RemoteDatabase::RequestTypeLicenceList, clientCert);
}
RemotePushDialog::~RemotePushDialog()
{
delete ui;
}
void RemotePushDialog::checkInput()
{
bool valid = true;
if(ui->editName->text().trimmed().isEmpty())
valid = false;
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
void RemotePushDialog::accept()
{
QDialog::accept();
}
QString RemotePushDialog::name() const
{
return ui->editName->text().trimmed();
}
QString RemotePushDialog::commitMessage() const
{
return ui->editCommitMessage->toPlainText().trimmed();
}
QString RemotePushDialog::licence() const
{
return ui->comboLicence->currentData(Qt::UserRole).toString();
}
bool RemotePushDialog::isPublic() const
{
return ui->checkPublic->isChecked();
}
void RemotePushDialog::fillInLicences(const QMap<QString, QString>& licences)
{
// Clear licence list and add default item for unspecified licence
ui->comboLicence->clear();
ui->comboLicence->addItem(tr("Unspecified"), QString());
// Parse licence list and fill combo box. Show the full name to the user and use the short name as user data.
for(auto it=licences.constBegin();it!=licences.constEnd();++it)
ui->comboLicence->addItem(it.value(), it.key());
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef REMOTEPUSHDIALOG_H
#define REMOTEPUSHDIALOG_H
#include <QDialog>
class RemoteDatabase;
namespace Ui {
class RemotePushDialog;
}
class RemotePushDialog : public QDialog
{
Q_OBJECT
public:
RemotePushDialog(QWidget* parent, RemoteDatabase& remote, const QString& host, const QString& clientCert, const QString& name = QString());
~RemotePushDialog();
QString name() const;
QString commitMessage() const;
QString licence() const;
bool isPublic() const;
private:
Ui::RemotePushDialog* ui;
// Reference to the remote database object which is stored somewhere in the main window
RemoteDatabase& remoteDatabase;
protected slots:
void checkInput();
virtual void accept();
void fillInLicences(const QMap<QString, QString>& licences);
};
#endif
+163
View File
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RemotePushDialog</class>
<widget class="QDialog" name="RemotePushDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>534</width>
<height>277</height>
</rect>
</property>
<property name="windowTitle">
<string>Push database</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Database na&amp;me to push to</string>
</property>
<property name="buddy">
<cstring>editName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Commit message</string>
</property>
<property name="buddy">
<cstring>editCommitMessage</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="editCommitMessage">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Oxygen-Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Database licence</string>
</property>
<property name="buddy">
<cstring>comboLicence</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboLicence">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Public</string>
</property>
<property name="buddy">
<cstring>checkPublic</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkPublic"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>editName</tabstop>
<tabstop>editCommitMessage</tabstop>
<tabstop>checkPublic</tabstop>
<tabstop>comboLicence</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RemotePushDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RemotePushDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>editName</sender>
<signal>textChanged(QString)</signal>
<receiver>RemotePushDialog</receiver>
<slot>checkInput()</slot>
<hints>
<hint type="sourcelabel">
<x>201</x>
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>217</x>
<y>3</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>checkInput()</slot>
</slots>
</ui>
+6 -3
View File
@@ -56,7 +56,8 @@ HEADERS += \
ForeignKeyEditorDelegate.h \
PlotDock.h \
RemoteDock.h \
RemoteModel.h
RemoteModel.h \
RemotePushDialog.h
SOURCES += \
sqlitedb.cpp \
@@ -91,7 +92,8 @@ SOURCES += \
ForeignKeyEditorDelegate.cpp \
PlotDock.cpp \
RemoteDock.cpp \
RemoteModel.cpp
RemoteModel.cpp \
RemotePushDialog.cpp
RESOURCES += icons/icons.qrc \
translations/flags/flags.qrc \
@@ -113,7 +115,8 @@ FORMS += \
ExportSqlDialog.ui \
ColumnDisplayFormatDialog.ui \
PlotDock.ui \
RemoteDock.ui
RemoteDock.ui \
RemotePushDialog.ui
TRANSLATIONS += \
translations/sqlb_ar_SA.ts \