From 9b4728c7a96edf48f7150bec943fb8484d9332cd Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 14 May 2018 20:17:08 +0200 Subject: [PATCH] Cloud-storage: consistently don't save empty file on desktop version Make the behavior consistent: Don't save an empty file to the cloud, neither on selection of "Save to cloud" nor on "Save". The latter was not the case. It was a bit hard to trigger: Open cloud, delete all dives, save. Fixes #1228 Reported-by: Jan Iversen Signed-off-by: Berthold Stoeger --- desktop-widgets/mainwindow.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index a4cddd264..9898fc72b 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -610,13 +610,21 @@ void MainWindow::on_actionCloudstorageopen_triggered() refreshDisplay(); } +// Return whether saving to cloud is OK. If it isn't, show an error return false. +static bool saveToCloudOK() +{ + if (!dive_table.nr) { + report_error(qPrintable(QObject::tr("Don't save an empty log to the cloud"))); + return false; + } + return true; +} + void MainWindow::on_actionCloudstoragesave_triggered() { QString filename; - if (!dive_table.nr) { - report_error(qPrintable(tr("Don't save an empty log to the cloud"))); + if (!saveToCloudOK()) return; - } if (getCloudURL(filename)) return; @@ -1725,6 +1733,8 @@ int MainWindow::file_save(void) return file_save_as(); is_cloud = (strncmp(existing_filename, "http", 4) == 0); + if (is_cloud && !saveToCloudOK()) + return -1; if (information()->isEditing()) information()->acceptChanges();