From e74950cc385aa8c5527ffcd516e06ea2374ace62 Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Wed, 25 Dec 2024 18:45:36 +0100 Subject: [PATCH] Fixed #450 - Logbook: Added Callbook batch lookup ProgressBar --- ui/LogbookWidget.cpp | 56 +++++++++++++++++++++++++++++++++++++++----- ui/LogbookWidget.h | 3 +++ ui/LogbookWidget.ui | 2 +- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/ui/LogbookWidget.cpp b/ui/LogbookWidget.cpp index 78798b83..f9882c6f 100644 --- a/ui/LogbookWidget.cpp +++ b/ui/LogbookWidget.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "logformat/AdiFormat.h" #include "models/LogbookModel.h" @@ -34,7 +35,8 @@ MODULE_IDENTIFICATION("qlog.ui.logbookwidget"); LogbookWidget::LogbookWidget(QWidget *parent) : QWidget(parent), ui(new Ui::LogbookWidget), - blockClublogSignals(false) + blockClublogSignals(false), + lookupDialog(nullptr) { FCT_IDENTIFICATION; @@ -293,10 +295,26 @@ void LogbookWidget::actionCallbookLookup() if ( callbookLookupBatch.count() > 100 ) { callbookLookupBatch.clear(); - QMessageBox::warning(this, tr("QLog Warning"), tr("Up to 100 QSOs are supported per batch.")); + QMessageBox::warning(this, tr("QLog Warning"), tr("Each batch supports up to 100 QSOs.")); return; } + lookupDialog = new QProgressDialog(tr("QSOs Update Progress"), + tr("Cancel"), + 0, callbookLookupBatch.count(), + this); + + connect(lookupDialog, &QProgressDialog::canceled, this, [this]() + { + qCDebug(runtime)<< "Operation canceled"; + callbookManager.abortQuery(); + finishQSOLookupBatch(); + }); + + lookupDialog->setValue(0); + lookupDialog->setWindowModality(Qt::WindowModal); + lookupDialog->show(); + queryNextQSOLookupBatch(); } @@ -305,12 +323,29 @@ void LogbookWidget::queryNextQSOLookupBatch() FCT_IDENTIFICATION; if ( callbookLookupBatch.isEmpty() ) + { + finishQSOLookupBatch(); return; + } currLookupIndex = callbookLookupBatch.takeFirst(); callbookManager.queryCallsign(model->data(model->index(currLookupIndex.row(), LogbookModel::COLUMN_CALL), Qt::DisplayRole).toString()); } +void LogbookWidget::finishQSOLookupBatch() +{ + FCT_IDENTIFICATION; + + callbookLookupBatch.clear(); + currLookupIndex = QModelIndex(); + if ( lookupDialog ) + { + lookupDialog->done(QDialog::Accepted); + lookupDialog->deleteLater(); + lookupDialog = nullptr; + } +} + void LogbookWidget::updateQSORecordFromCallbook(const QMap& data) { FCT_IDENTIFICATION; @@ -388,6 +423,9 @@ void LogbookWidget::callsignFound(const QMap &data) updateQSORecordFromCallbook(data); currLookupIndex = QModelIndex(); + if ( lookupDialog ) + lookupDialog->setValue(lookupDialog->value() + 1); + queryNextQSOLookupBatch(); } @@ -396,6 +434,9 @@ void LogbookWidget::callsignNotFound(const QString &call) FCT_IDENTIFICATION; qCDebug(runtime) << call << "not found"; + if ( lookupDialog ) + lookupDialog->setValue(lookupDialog->value() + 1); + queryNextQSOLookupBatch(); } @@ -403,8 +444,7 @@ void LogbookWidget::callbookLoginFailed(const QString&callbookString) { FCT_IDENTIFICATION; - callbookLookupBatch.clear(); - currLookupIndex = QModelIndex(); + finishQSOLookupBatch(); QMessageBox::critical(this, tr("QLog Error"), callbookString + " " + tr("Callbook login failed")); } @@ -412,8 +452,7 @@ void LogbookWidget::callbookError(const QString &error) { FCT_IDENTIFICATION; - callbookLookupBatch.clear(); - currLookupIndex = QModelIndex(); + finishQSOLookupBatch(); QMessageBox::critical(this, tr("QLog Error"), tr("Callbook error: ") + error); } @@ -1117,5 +1156,10 @@ LogbookWidget::~LogbookWidget() FCT_IDENTIFICATION; saveTableHeaderState(); + if ( lookupDialog ) + { + callbookManager.abortQuery(); + finishQSOLookupBatch(); + } delete ui; } diff --git a/ui/LogbookWidget.h b/ui/LogbookWidget.h index 77524c21..58d723c6 100644 --- a/ui/LogbookWidget.h +++ b/ui/LogbookWidget.h @@ -14,6 +14,7 @@ class LogbookWidget; class ClubLog; class LogbookModel; +class QProgressDialog; class LogbookWidget : public QWidget { Q_OBJECT @@ -101,9 +102,11 @@ public slots: void adjusteComboMinSize(QComboBox * combo); void updateQSORecordFromCallbook(const QMap& data); void queryNextQSOLookupBatch(); + void finishQSOLookupBatch(); QModelIndexList callbookLookupBatch; QModelIndex currLookupIndex; CallbookManager callbookManager; + QProgressDialog *lookupDialog; }; /* https://forum.qt.io/topic/90403/show-tooltip-immediatly/7/ */ diff --git a/ui/LogbookWidget.ui b/ui/LogbookWidget.ui index 4561a805..7854e54a 100644 --- a/ui/LogbookWidget.ui +++ b/ui/LogbookWidget.ui @@ -276,7 +276,7 @@ :/icons/cloud_download-24px.svg:/icons/cloud_download-24px.svg - Add Missing Callbook Info + Update from Callbook Add Missing Callbook Info