mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
desktop-widgets: split UI and network in DivelogsDeWebServices (prepare)
Clean prepareDivesForUpload() and uploadDives() so that uploadDives() only contain network handling no UI. Signed-off-by: Jan Iversen <jan@casacondor.com>
This commit is contained in:
parent
10ab833d7d
commit
8becc29ca8
2 changed files with 40 additions and 33 deletions
|
@ -236,40 +236,13 @@ void DivelogsDeWebServices::downloadDives()
|
|||
|
||||
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());
|
||||
// this is called when the user selects the divelogs.de radiobutton
|
||||
|
||||
// Prepare zip file
|
||||
if (!uploadDives(selected))
|
||||
return;
|
||||
}
|
||||
|
||||
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 {
|
||||
report_error("Failed to create upload file %s\n", qPrintable(filename));
|
||||
}
|
||||
}
|
||||
|
||||
void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
|
||||
{
|
||||
QHttpMultiPart mp(QHttpMultiPart::FormDataType);
|
||||
QHttpPart part;
|
||||
QFile *f = (QFile *)dldContent;
|
||||
QFileInfo fi(*f);
|
||||
QString args("form-data; name=\"userfile\"; filename=\"" + fi.absoluteFilePath() + "\"");
|
||||
part.setRawHeader("Content-Disposition", args.toLatin1());
|
||||
part.setBodyDevice(dldContent);
|
||||
mp.append(part);
|
||||
|
||||
multipart = ∓
|
||||
// Adjust UI
|
||||
hideDownload();
|
||||
resetState();
|
||||
uploadMode = true;
|
||||
|
@ -277,6 +250,37 @@ void DivelogsDeWebServices::uploadDives(QIODevice *dldContent)
|
|||
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 false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
QHttpMultiPart mp(QHttpMultiPart::FormDataType);
|
||||
QHttpPart part;
|
||||
QFileInfo fi(f);
|
||||
QString args("form-data; name=\"userfile\"; filename=\"" + fi.absoluteFilePath() + "\"");
|
||||
part.setRawHeader("Content-Disposition", args.toLatin1());
|
||||
part.setBodyDevice((QIODevice *)&f);
|
||||
mp.append(part);
|
||||
|
||||
multipart = ∓
|
||||
|
||||
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),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue