mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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 <jan@casacondor.com>
This commit is contained in:
parent
8becc29ca8
commit
9fd95c18bd
2 changed files with 36 additions and 24 deletions
|
@ -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()
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
QHttpMultiPart *multipart;
|
||||
QTemporaryFile zipFile;
|
||||
bool uploadMode;
|
||||
bool useSelectedDives;
|
||||
};
|
||||
|
||||
class UserSurveyServices : public QDialog {
|
||||
|
|
Loading…
Reference in a new issue