From 93b5c0cd14fe33c80b801a0177e795462484f719 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 6 Dec 2013 17:10:32 -0800 Subject: Finish download from divelogs.de This is far from perfect. Avoid a weird warning when total = -1 is passed into the progress bar. Enable the Accept button once the download completes. Merge the downloaded dives into the existing dive list on Apply. Signed-off-by: Dirk Hohndel --- qt-ui/subsurfacewebservices.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 8699a23da..977e59fde 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -150,7 +150,9 @@ void WebServices::updateProgress(qint64 current, qint64 total) { if (!reply) return; - + if (total == -1) { + total = INT_MAX / 2 - 1; + } if (total >= INT_MAX / 2) { // over a gigabyte! if (total >= Q_INT64_C(1) << 47) { @@ -616,20 +618,8 @@ void DivelogsDeWebServices::downloadFinished() zipFile.close(); return; } - - quint64 entries = zip_get_num_entries(zip, 0); - for (quint64 i = 0; i < entries; ++i) { - struct zip_file *zip_file = zip_fopen_index(zip, i, 0); - if (!zip_file) { - QMessageBox::critical(this, tr("Corrupted download"), - tr("The archive contains corrupt data:\n%1").arg(QString::fromLocal8Bit(zip_strerror(zip)))); - goto close_zip; - } - - // ### FIXME: What do I do with this? - - zip_fclose(zip_file); - } + // now allow the user to cancel or accept + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true); close_zip: zip_close(zip); @@ -672,6 +662,22 @@ void DivelogsDeWebServices::uploadError(QNetworkReply::NetworkError error) void DivelogsDeWebServices::buttonClicked(QAbstractButton* button) { + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); + switch(ui.buttonBox->buttonRole(button)){ + case QDialogButtonBox::ApplyRole:{ + char *errorptr = NULL; + parse_file(zipFile.fileName().toUtf8().constData(), &errorptr); + // ### FIXME: do something useful with the error - but there shouldn't be one, right? + if (errorptr) + qDebug() << errorptr; + + hide(); + close(); + resetState(); + mark_divelist_changed(TRUE); + mainWindow()->refreshDisplay(); + } + } } -- cgit v1.2.3-70-g09d2