dbhub: Only show warning about losing unsaved changes when downloading

Make sure to only show a warning that local changes might be lost before
actually downloading a database and overriding the local copy. When we
just open the local copy, no warning needs to be shown.
This commit is contained in:
Martin Kleusberg
2020-07-22 14:55:39 +02:00
parent 5cf95f82be
commit 1af81359a9
2 changed files with 21 additions and 23 deletions

View File

@@ -524,6 +524,27 @@ void RemoteDatabase::fetch(const QUrl& url, RequestType type, const QString& cli
}
}
// Check if we already have a clone of this database branch. If so, show a warning because there might
// be unpushed changes. For this we don't care about the currently checked out commit id because for
// any commit local changes could be lost.
// TODO Detect local changes and don't warn when no changes were made
QUrl url_without_commit_id(url);
QUrlQuery url_without_commit_id_query(url_without_commit_id);
url_without_commit_id_query.removeQueryItem("commit");
url_without_commit_id.setQuery(url_without_commit_id_query);
if(!localExists(url_without_commit_id, clientCert, QUrlQuery(url).queryItemValue("branch").toStdString()).isEmpty())
{
if(QMessageBox::warning(nullptr,
QApplication::applicationName(),
tr("Fetching this commit might override local changes when you have not pushed them yet.\n"
"Are you sure you want to fetch it?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel) == QMessageBox::Cancel)
{
return;
}
}
// Build network request
QNetworkRequest request;
request.setUrl(url);

View File

@@ -192,29 +192,6 @@ void RemoteDock::fetchDatabase(QString url_string)
return;
}
// Check if we already have a clone of this database branch. In so, show a warning because there might
// be unpushed changes. For this we don't care about the currently checked out commit id because for
// any commit local changes could be lost.
// TODO Detect local changes and don't warn when no changes were made
QUrl url_without_commit_id(url);
QUrlQuery url_without_commit_id_query(url_without_commit_id);
url_without_commit_id_query.removeQueryItem("commit");
url_without_commit_id.setQuery(url_without_commit_id_query);
if(!remoteDatabase.localExists(url_without_commit_id, remoteModel->currentClientCertificate(), QUrlQuery(url).queryItemValue("branch").toStdString()).isEmpty())
{
if(QMessageBox::warning(this,
QApplication::applicationName(),
tr("Fetching this commit might override local changes when you have not pushed them yet.\n"
"Are you sure you want to fetch it?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel) == QMessageBox::Cancel)
{
return;
}
}
// Clone the database
remoteDatabase.fetch(url.toString(), RemoteDatabase::RequestTypeDatabase, remoteModel->currentClientCertificate());
}