From e2783b68ad700bde2fd083c41b53203246141b81 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 17 Jul 2020 21:13:48 +0200 Subject: [PATCH] dbhub: Add button for cloning databases from a link This adds a new button to clone databases using a direct link which is useful when you know which database you want to clone and do not want to browse through the list of all databases in the Remote dock. Generating this link still needs to be added to the DBHub.io web UI. --- src/RemoteDock.cpp | 42 ++++++++++++++++++++++++++++++++++++++- src/RemoteDock.h | 1 + src/RemoteDock.ui | 42 +++++++++++++++++++++++++++++++++++++++ src/icons/icons.qrc | 1 + src/icons/server_add.png | Bin 0 -> 676 bytes 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/icons/server_add.png diff --git a/src/RemoteDock.cpp b/src/RemoteDock.cpp index dab2b39e..8f2f643d 100644 --- a/src/RemoteDock.cpp +++ b/src/RemoteDock.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include #include #include #include @@ -145,7 +147,44 @@ void RemoteDock::fetchDatabase(const QModelIndex& idx) // Only open database file if(item->value(RemoteModelColumnType).toString() == "database") - remoteDatabase.fetch(item->value(RemoteModelColumnUrl).toString(), RemoteDatabase::RequestTypeDatabase, remoteModel->currentClientCertificate()); + fetchDatabase(item->value(RemoteModelColumnUrl).toString()); +} + +void RemoteDock::fetchDatabase(QString url_string) +{ + // If no URL was provided ask the user. Default to the current clipboard contents + if(url_string.isEmpty()) + { + url_string = QInputDialog::getText(this, + qApp->applicationName(), + tr("Please enter the URL to clone from."), + QLineEdit::Normal, + QApplication::clipboard()->text()); + } + + if(url_string.isEmpty()) + return; + + // Check the URL + QUrl url(url_string); + if(url.authority() != QUrl(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoServer)).authority()) + { + QMessageBox::warning(this, qApp->applicationName(), tr("Invalid URL: The host name does not match the host name of the current identity.")); + return; + } + if(!QUrlQuery(url).hasQueryItem("branch")) + { + QMessageBox::warning(this, qApp->applicationName(), tr("Invalid URL: No branch name specified.")); + return; + } + if(!QUrlQuery(url).hasQueryItem("commit")) + { + QMessageBox::warning(this, qApp->applicationName(), tr("Invalid URL: No commit ID specified.")); + return; + } + + // Clone the database + remoteDatabase.fetch(url.toString(), RemoteDatabase::RequestTypeDatabase, remoteModel->currentClientCertificate()); } void RemoteDock::enableButtons() @@ -153,6 +192,7 @@ void RemoteDock::enableButtons() bool db_opened = mainWindow->getDb().isOpen() && mainWindow->getDb().currentFile() != ":memory:"; bool logged_in = !remoteModel->currentClientCertificate().isEmpty(); + ui->buttonCloneDatabase->setEnabled(logged_in); ui->buttonPushDatabase->setEnabled(db_opened && logged_in); } diff --git a/src/RemoteDock.h b/src/RemoteDock.h index 764b8d08..9d5838bc 100644 --- a/src/RemoteDock.h +++ b/src/RemoteDock.h @@ -37,6 +37,7 @@ public slots: private slots: void setNewIdentity(const QString& identity); void fetchDatabase(const QModelIndex& idx); + void fetchDatabase(QString url = QString()); void pushDatabase(); void newDirectoryNode(const QModelIndex& parent); void switchToMainView(); diff --git a/src/RemoteDock.ui b/src/RemoteDock.ui index 63b4f14c..2d4a8948 100644 --- a/src/RemoteDock.ui +++ b/src/RemoteDock.ui @@ -77,6 +77,20 @@ + + + + Clone + + + + :/icons/clone_database:/icons/clone_database + + + Qt::ToolButtonTextBesideIcon + + + @@ -338,6 +352,17 @@ + + comboUser + buttonCloneDatabase + buttonPushDatabase + tabs + treeRemote + treeLocal + comboDatabaseBranch + treeDatabaseCommits + buttonNoCertBack + @@ -422,6 +447,22 @@ + + buttonCloneDatabase + clicked() + RemoteDock + fetchDatabase() + + + 412 + 15 + + + 266 + 178 + + + setNewIdentity(QString) @@ -429,5 +470,6 @@ pushDatabase() switchToMainView() openLocalFile(QModelIndex) + fetchDatabase() diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc index e7624f81..63c36fdc 100644 --- a/src/icons/icons.qrc +++ b/src/icons/icons.qrc @@ -102,5 +102,6 @@ document-link.png application_go.png monitor_link.png + server_add.png diff --git a/src/icons/server_add.png b/src/icons/server_add.png new file mode 100644 index 0000000000000000000000000000000000000000..3f10a3a9f4cfc0d3b23b1508c368a50523c1044e GIT binary patch literal 676 zcmV;V0$crwP)qA2Pi2L&&MfZ)$Tym*VCU=T$Q;z6Ze zJ$g#19)u*6U}?pjN9Q`P1faW_&ZrhEh`zTzI_Q+4udtc{7?20{`>0tzC%6 z<4$0NFD@aX1`EXFfryb1uLICn5nxWaVpGCkj6kwT4ni1iOhPYO8V+7ZA`uje zMd-SYjtzD?ftn&>m3S@d6_=&B-;Cz zF*bAv13UKN-Iq6*nUCUQI(Jw5*Xv9h7Nm56LZ>KDJd8b9y7n953x!Z9A}LY;0000< KMNUMnLSTZ#4=Y0e literal 0 HcmV?d00001