Skip to content

Commit

Permalink
Fixed foldynl#450 - Logbook: Added Callbook batch lookup ProgressBar
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Dec 25, 2024
1 parent 246af69 commit e74950c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
56 changes: 50 additions & 6 deletions ui/LogbookWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QShortcut>
#include <QEvent>
#include <QKeyEvent>
#include <QProgressDialog>

#include "logformat/AdiFormat.h"
#include "models/LogbookModel.h"
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}

Expand All @@ -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<QString, QString>& data)
{
FCT_IDENTIFICATION;
Expand Down Expand Up @@ -388,6 +423,9 @@ void LogbookWidget::callsignFound(const QMap<QString, QString> &data)

updateQSORecordFromCallbook(data);
currLookupIndex = QModelIndex();
if ( lookupDialog )
lookupDialog->setValue(lookupDialog->value() + 1);

queryNextQSOLookupBatch();
}

Expand All @@ -396,24 +434,25 @@ void LogbookWidget::callsignNotFound(const QString &call)
FCT_IDENTIFICATION;

qCDebug(runtime) << call << "not found";
if ( lookupDialog )
lookupDialog->setValue(lookupDialog->value() + 1);

queryNextQSOLookupBatch();
}

void LogbookWidget::callbookLoginFailed(const QString&callbookString)
{
FCT_IDENTIFICATION;

callbookLookupBatch.clear();
currLookupIndex = QModelIndex();
finishQSOLookupBatch();
QMessageBox::critical(this, tr("QLog Error"), callbookString + " " + tr("Callbook login failed"));
}

void LogbookWidget::callbookError(const QString &error)
{
FCT_IDENTIFICATION;

callbookLookupBatch.clear();
currLookupIndex = QModelIndex();
finishQSOLookupBatch();
QMessageBox::critical(this, tr("QLog Error"), tr("Callbook error: ") + error);
}

Expand Down Expand Up @@ -1117,5 +1156,10 @@ LogbookWidget::~LogbookWidget()
FCT_IDENTIFICATION;

saveTableHeaderState();
if ( lookupDialog )
{
callbookManager.abortQuery();
finishQSOLookupBatch();
}
delete ui;
}
3 changes: 3 additions & 0 deletions ui/LogbookWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LogbookWidget;

class ClubLog;
class LogbookModel;
class QProgressDialog;

class LogbookWidget : public QWidget {
Q_OBJECT
Expand Down Expand Up @@ -101,9 +102,11 @@ public slots:
void adjusteComboMinSize(QComboBox * combo);
void updateQSORecordFromCallbook(const QMap<QString, QString>& data);
void queryNextQSOLookupBatch();
void finishQSOLookupBatch();
QModelIndexList callbookLookupBatch;
QModelIndex currLookupIndex;
CallbookManager callbookManager;
QProgressDialog *lookupDialog;
};

/* https://forum.qt.io/topic/90403/show-tooltip-immediatly/7/ */
Expand Down
2 changes: 1 addition & 1 deletion ui/LogbookWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<normaloff>:/icons/cloud_download-24px.svg</normaloff>:/icons/cloud_download-24px.svg</iconset>
</property>
<property name="text">
<string>Add Missing Callbook Info</string>
<string>Update from Callbook</string>
</property>
<property name="toolTip">
<string>Add Missing Callbook Info</string>
Expand Down

0 comments on commit e74950c

Please sign in to comment.