mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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 <dirk@hohndel.org>
This commit is contained in:
parent
3a0f138023
commit
93b5c0cd14
1 changed files with 21 additions and 15 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue