mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-17 01:09:36 -06:00
dbhub: Add "Upload Database" action to context menu of local file list
This adds a new action for uploading the selected database to the list of local databases in the Remote dock. See issue #2349.
This commit is contained in:
@@ -103,6 +103,7 @@ RemoteDock::RemoteDock(MainWindow* parent)
|
||||
bool enable = index.isValid() &&
|
||||
!index.sibling(index.row(), RemoteLocalFilesModel::ColumnFile).data().isNull();
|
||||
ui->actionOpenLocalDatabase->setEnabled(enable);
|
||||
ui->actionPushLocalDatabase->setEnabled(enable);
|
||||
ui->actionDeleteDatabase->setEnabled(enable);
|
||||
});
|
||||
ui->treeLocal->selectionModel()->currentChanged(QModelIndex(), QModelIndex()); // Enable/disable all action initially
|
||||
@@ -113,6 +114,7 @@ RemoteDock::RemoteDock(MainWindow* parent)
|
||||
deleteLocalDatabase(ui->treeLocal->currentIndex());
|
||||
});
|
||||
ui->treeLocal->addAction(ui->actionOpenLocalDatabase);
|
||||
ui->treeLocal->addAction(ui->actionPushLocalDatabase);
|
||||
ui->treeLocal->addAction(ui->actionDeleteDatabase);
|
||||
|
||||
// Prepare context menu for list of commits
|
||||
@@ -314,16 +316,8 @@ void RemoteDock::enableButtons()
|
||||
ui->actionFetchLatestCommit->setEnabled(db_opened && logged_in);
|
||||
}
|
||||
|
||||
void RemoteDock::pushDatabase()
|
||||
void RemoteDock::pushCurrentlyOpenedDatabase()
|
||||
{
|
||||
// If the currently active identity is the read-only public access to dbhub.io, don't show the Push Database dialog because it won't work anyway.
|
||||
// Instead switch to an explanation offering some advice to create and import a proper certificate.
|
||||
if(remoteModel->currentClientCertificate() == ":/user_certs/public.cert.pem")
|
||||
{
|
||||
ui->stack->setCurrentIndex(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Show a warning when trying to push a database with unsaved changes
|
||||
if(mainWindow->getDb().getDirty())
|
||||
{
|
||||
@@ -335,14 +329,44 @@ void RemoteDock::pushDatabase()
|
||||
return;
|
||||
}
|
||||
|
||||
// Push currently opened file
|
||||
pushDatabase(mainWindow->getDb().currentFile(), QString::fromStdString(currently_opened_file_info.branch));
|
||||
}
|
||||
|
||||
void RemoteDock::pushSelectedLocalDatabase()
|
||||
{
|
||||
// Return if no file is selected
|
||||
if(!ui->treeLocal->currentIndex().isValid())
|
||||
return;
|
||||
|
||||
const int row = ui->treeLocal->currentIndex().row();
|
||||
const QString filename = ui->treeLocal->currentIndex().sibling(row, RemoteLocalFilesModel::ColumnFile).data().toString();
|
||||
if(filename.isEmpty())
|
||||
return;
|
||||
|
||||
// Push selected file
|
||||
const QString branch = ui->treeLocal->currentIndex().sibling(row, RemoteLocalFilesModel::ColumnBranch).data().toString();
|
||||
pushDatabase(Settings::getValue("remote", "clonedirectory").toString() + "/" + filename, branch);
|
||||
}
|
||||
|
||||
void RemoteDock::pushDatabase(const QString& path, const QString& branch)
|
||||
{
|
||||
// If the currently active identity is the read-only public access to dbhub.io, don't show the Push Database dialog because it won't work anyway.
|
||||
// Instead switch to an explanation offering some advice to create and import a proper certificate.
|
||||
if(remoteModel->currentClientCertificate() == ":/user_certs/public.cert.pem")
|
||||
{
|
||||
ui->stack->setCurrentIndex(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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();
|
||||
QString name = QFileInfo(path).fileName();
|
||||
name = name.remove(QRegExp("_[0-9]+.remotedb$"));
|
||||
|
||||
// Show the user a dialog for setting all the commit details
|
||||
QString host = RemoteNetwork::get().getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteNetwork::CertInfoServer);
|
||||
RemotePushDialog pushDialog(this, host, remoteModel->currentClientCertificate(), name, QString::fromStdString(currently_opened_file_info.branch));
|
||||
RemotePushDialog pushDialog(this, host, remoteModel->currentClientCertificate(), name, branch);
|
||||
if(pushDialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
@@ -354,11 +378,11 @@ void RemoteDock::pushDatabase()
|
||||
|
||||
// Check if we are pushing a cloned database. Only in this case we provide the last known commit id
|
||||
QString commit_id;
|
||||
if(mainWindow->getDb().currentFile().startsWith(Settings::getValue("remote", "clonedirectory").toString()))
|
||||
if(path.startsWith(Settings::getValue("remote", "clonedirectory").toString()))
|
||||
commit_id = QString::fromStdString(remoteDatabase.localLastCommitId(remoteModel->currentClientCertificate(), url, pushDialog.branch().toStdString()));
|
||||
|
||||
// Push database
|
||||
RemoteNetwork::get().push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate(), pushDialog.name(),
|
||||
RemoteNetwork::get().push(path, url, remoteModel->currentClientCertificate(), pushDialog.name(),
|
||||
pushDialog.commitMessage(), pushDialog.licence(), pushDialog.isPublic(), pushDialog.branch(),
|
||||
pushDialog.forcePush(), commit_id);
|
||||
}
|
||||
@@ -553,7 +577,8 @@ void RemoteDock::pushFinished(const QString& filename, const QString& identity,
|
||||
QFile::copy(source_file, saveFileAs);
|
||||
|
||||
// Update info on currently opened file
|
||||
currently_opened_file_info = remoteDatabase.localGetLocalFileInfo(saveFileAs);
|
||||
if(currently_opened_file_info.file == QFileInfo(saveFileAs).fileName().toStdString())
|
||||
currently_opened_file_info = remoteDatabase.localGetLocalFileInfo(saveFileAs);
|
||||
|
||||
// Refresh view
|
||||
refresh();
|
||||
|
||||
@@ -40,7 +40,8 @@ private slots:
|
||||
void fetchDatabase(const QModelIndex& idx);
|
||||
void fetchDatabase(QString url = QString(), RemoteNetwork::RequestType request_type = RemoteNetwork::RequestTypeDatabase);
|
||||
void fetchCommit(const QModelIndex& idx, RemoteNetwork::RequestType request_type = RemoteNetwork::RequestTypeDatabase);
|
||||
void pushDatabase();
|
||||
void pushCurrentlyOpenedDatabase();
|
||||
void pushSelectedLocalDatabase();
|
||||
void newDirectoryNode(const QModelIndex& parent);
|
||||
void switchToMainView();
|
||||
void openLocalFile(const QModelIndex& idx);
|
||||
@@ -72,6 +73,8 @@ private:
|
||||
void refreshMetadata(const QString& username, const QString& dbname);
|
||||
|
||||
bool isLocalDatabaseModified(const QString& local_file, const QString& username, const QString& dbname, const QString& identity, const std::string& commit_id);
|
||||
|
||||
void pushDatabase(const QString& path, const QString& branch);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -523,6 +523,18 @@
|
||||
<string>Saves the selected revision of the database to another file</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPushLocalDatabase">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/push_database</normaloff>:/icons/push_database</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Upload Database</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Upload this database as a new commit</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>comboUser</tabstop>
|
||||
@@ -574,7 +586,7 @@
|
||||
<sender>buttonPushDatabase</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>RemoteDock</receiver>
|
||||
<slot>pushDatabase()</slot>
|
||||
<slot>pushCurrentlyOpenedDatabase()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>530</x>
|
||||
@@ -682,11 +694,28 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionPushLocalDatabase</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>RemoteDock</receiver>
|
||||
<slot>pushSelectedLocalDatabase()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>266</x>
|
||||
<y>193</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>setNewIdentity(QString)</slot>
|
||||
<slot>fetchDatabase(QModelIndex)</slot>
|
||||
<slot>pushDatabase()</slot>
|
||||
<slot>pushCurrentlyOpenedDatabase()</slot>
|
||||
<slot>pushSelectedLocalDatabase()</slot>
|
||||
<slot>switchToMainView()</slot>
|
||||
<slot>openLocalFile(QModelIndex)</slot>
|
||||
<slot>fetchDatabase()</slot>
|
||||
|
||||
Reference in New Issue
Block a user