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 00000000..3f10a3a9 Binary files /dev/null and b/src/icons/server_add.png differ