aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/subsurfacewebservices.cpp
diff options
context:
space:
mode:
authorGravatar John Plaxco <john@johnplaxco.com>2018-12-22 21:21:28 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-01-22 12:58:03 +1300
commit3865c1ec0a844af624507b66c8af13e498895e8c (patch)
tree64b7b129efd0c2454ed8326acbab3d97cd80bbaf /desktop-widgets/subsurfacewebservices.cpp
parentdb29fb4e68d20bc6207837bd9e85d897bb6cb8ee (diff)
downloadsubsurface-3865c1ec0a844af624507b66c8af13e498895e8c.tar.gz
Improve error reporting when exporting a selection of 0 dives.
If no dives are selected when trying to export a selection, a message is shown that no dives were selected, but it's immediately hidden behind a message saying that a temporary file could not be created. In fact, the creation of the temporary file wasn't never attempted, so the message that the user actually sees is misleading. The solution chosen here is to duplicate the check that at least some dives are selected, and abort early if that case is detected, rather than continuing on to show the additional misleading message. Not elegant, but it gets the job done. Better solutions to this include refactoring prepare_dives_for_divelogs to return something more descriptive than a bool, remove that check from prepare_dives_for_divelogs entirely since it doesn't seem to be a good fit there, or switch to exceptions for handling these problems rather than return values. I don't have sufficient familiarity with the codebase to attempt these more invasive changes, but they should be considered in the future. On a final note, some of the other error messages in this file start with a capital letter, but the one relevant to this particular PR does not. Again, I'm not familiar enough with the codebase (or translations) to know if that's safe to change, so I'll leave that for another time or another developer. Reported-by: John Plaxco Signed-off-by: John Plaxco <john@johnplaxco.com>
Diffstat (limited to 'desktop-widgets/subsurfacewebservices.cpp')
-rw-r--r--desktop-widgets/subsurfacewebservices.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp
index 2acc7451e..d62cd8552 100644
--- a/desktop-widgets/subsurfacewebservices.cpp
+++ b/desktop-widgets/subsurfacewebservices.cpp
@@ -484,6 +484,10 @@ void DivelogsDeWebServices::prepareDivesForUpload(bool selected)
{
/* generate a random filename and create/open that file with zip_open */
QString filename = QDir::tempPath() + "/import-" + QString::number(qrand() % 99999999) + ".dld";
+ if (!amount_selected) {
+ report_error(tr("no dives were selected").toUtf8());
+ return;
+ }
if (prepare_dives_for_divelogs(filename, selected)) {
QFile f(filename);
if (f.open(QIODevice::ReadOnly)) {