diff options
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 57 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.h | 2 |
2 files changed, 33 insertions, 26 deletions
diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 9d2d01aca..bca36b5e4 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -236,47 +236,51 @@ void DivelogsDeWebServices::downloadDives() void DivelogsDeWebServices::prepareDivesForUpload(bool selected) { + // this is called when the user selects the divelogs.de radiobutton + + // Prepare zip file + if (!uploadDives(selected)) + return; + + // Adjust UI + hideDownload(); + resetState(); + uploadMode = true; + ui.buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(true); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); + ui.buttonBox->button(QDialogButtonBox::Apply)->setText(tr("Done")); + exec(); +} + +bool DivelogsDeWebServices::uploadDives(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; + return false; } - if (uploadDiveLogsDE::instance()->prepareDives(filename, selected)) { - QFile f(filename); - if (f.open(QIODevice::ReadOnly)) { - uploadDives((QIODevice *)&f); - f.close(); - f.remove(); - return; - } else { - report_error("Failed to open upload file %s\n", qPrintable(filename)); - } - } else { + if (!uploadDiveLogsDE::instance()->prepareDives(filename, selected)) { report_error("Failed to create upload file %s\n", qPrintable(filename)); + return false; + } + + QFile f(filename); + if (!f.open(QIODevice::ReadOnly)) { + report_error("Failed to open upload file %s\n", qPrintable(filename)); + return false; } -} -void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) -{ QHttpMultiPart mp(QHttpMultiPart::FormDataType); QHttpPart part; - QFile *f = (QFile *)dldContent; - QFileInfo fi(*f); + QFileInfo fi(f); QString args("form-data; name=\"userfile\"; filename=\"" + fi.absoluteFilePath() + "\""); part.setRawHeader("Content-Disposition", args.toLatin1()); - part.setBodyDevice(dldContent); + part.setBodyDevice((QIODevice *)&f); mp.append(part); multipart = ∓ - hideDownload(); - resetState(); - uploadMode = true; - ui.buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(true); - ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); - ui.buttonBox->button(QDialogButtonBox::Apply)->setText(tr("Done")); - exec(); multipart = NULL; if (reply != NULL && reply->isOpen()) { @@ -284,6 +288,9 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent) delete reply; reply = NULL; } + f.close(); + f.remove(); + return true; } DivelogsDeWebServices::DivelogsDeWebServices(QWidget *parent, Qt::WindowFlags f) : WebServices(parent, f), diff --git a/desktop-widgets/subsurfacewebservices.h b/desktop-widgets/subsurfacewebservices.h index b67217684..4da15c392 100644 --- a/desktop-widgets/subsurfacewebservices.h +++ b/desktop-widgets/subsurfacewebservices.h @@ -65,7 +65,7 @@ slots: void startUpload(); private: - void uploadDives(QIODevice *dldContent); + bool uploadDives(bool selected); explicit DivelogsDeWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0); void setStatusText(int status); void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status); |