From 9fd95c18bd08dd6d197c9e02a302dc97bd221f44 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Mon, 9 Dec 2019 13:24:08 +0100 Subject: [PATCH] desktop-widgets: divelogsDE: delay handling until user select upload Do not prepare zip file, just because user selected the divelogs.de radiobutton Move prepareDives to startUpload (slot handling user clicking on upload button). Signed-off-by: Jan Iversen --- desktop-widgets/subsurfacewebservices.cpp | 59 ++++++++++++++--------- desktop-widgets/subsurfacewebservices.h | 1 + 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index bca36b5e4..bc1311f5b 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -238,9 +238,8 @@ void DivelogsDeWebServices::prepareDivesForUpload(bool selected) { // this is called when the user selects the divelogs.de radiobutton - // Prepare zip file - if (!uploadDives(selected)) - return; + // Remember if all dives or selected dives are to be uploaded + useSelectedDives = selected; // Adjust UI hideDownload(); @@ -290,6 +289,32 @@ bool DivelogsDeWebServices::uploadDives(bool selected) } f.close(); f.remove(); + + { + QNetworkRequest request; + request.setUrl(QUrl("https://divelogs.de/DivelogsDirectImport.php")); + request.setRawHeader("Accept", "text/xml, application/xml"); + request.setRawHeader("User-Agent", userAgent.toUtf8()); + + QHttpPart part; + part.setRawHeader("Content-Disposition", "form-data; name=\"user\""); + part.setBody(ui.userID->text().toUtf8()); + multipart->append(part); + + part.setRawHeader("Content-Disposition", "form-data; name=\"pass\""); + part.setBody(ui.password->text().toUtf8()); + multipart->append(part); + + reply = manager()->post(request, multipart); + connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, + SLOT(uploadError(QNetworkReply::NetworkError))); + connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, + SLOT(updateProgress(qint64, qint64))); + + timeout.start(30000); // 30s + + } return true; } @@ -319,28 +344,14 @@ void DivelogsDeWebServices::startUpload() ui.userID->setEnabled(false); ui.password->setEnabled(false); - QNetworkRequest request; - request.setUrl(QUrl("https://divelogs.de/DivelogsDirectImport.php")); - request.setRawHeader("Accept", "text/xml, application/xml"); - request.setRawHeader("User-Agent", userAgent.toUtf8()); + // Prepare zip file + if (!uploadDives(useSelectedDives)) + return; - QHttpPart part; - part.setRawHeader("Content-Disposition", "form-data; name=\"user\""); - part.setBody(ui.userID->text().toUtf8()); - multipart->append(part); - - part.setRawHeader("Content-Disposition", "form-data; name=\"pass\""); - part.setBody(ui.password->text().toUtf8()); - multipart->append(part); - - reply = manager()->post(request, multipart); - connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished())); - connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, - SLOT(uploadError(QNetworkReply::NetworkError))); - connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, - SLOT(updateProgress(qint64, qint64))); - - timeout.start(30000); // 30s + // Remember for later + // connect(reply, SIGNAL(finished()), this, SLOT(listDownloadFinished())); + // connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), + // this, SLOT(downloadError(QNetworkReply::NetworkError))); } void DivelogsDeWebServices::startDownload() diff --git a/desktop-widgets/subsurfacewebservices.h b/desktop-widgets/subsurfacewebservices.h index 4da15c392..86454fd6c 100644 --- a/desktop-widgets/subsurfacewebservices.h +++ b/desktop-widgets/subsurfacewebservices.h @@ -74,6 +74,7 @@ private: QHttpMultiPart *multipart; QTemporaryFile zipFile; bool uploadMode; + bool useSelectedDives; }; class UserSurveyServices : public QDialog {