Defer dwonloading LoTW users file until "Settings->Colors->Fetch" button pressed

This change also repairs a defect in showing potential LoTW users when
the  "Settings->General->Show DXCC,  grid, and  worked before  status"
option is not checked.
This commit is contained in:
Bill Somerville 2019-01-01 16:19:01 +00:00
parent 90617b29ab
commit 5b0f713cd4
3 changed files with 16 additions and 8 deletions

View File

@ -1004,13 +1004,11 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network
// this must be done after the default paths above are set // this must be done after the default paths above are set
read_settings (); read_settings ();
// conditionally load LotW users data // set up LoTW users CSV file fetching
ui_->LotW_CSV_fetch_push_button->setEnabled (false);
connect (&lotw_users_, &LotWUsers::load_finished, [this] () { connect (&lotw_users_, &LotWUsers::load_finished, [this] () {
ui_->LotW_CSV_fetch_push_button->setEnabled (true); ui_->LotW_CSV_fetch_push_button->setEnabled (true);
}); });
lotw_users_.set_local_file_path (writeable_data_dir_.absoluteFilePath ("lotw-user-activity.csv")); lotw_users_.set_local_file_path (writeable_data_dir_.absoluteFilePath ("lotw-user-activity.csv"));
lotw_users_.load (ui_->LotW_CSV_URL_line_edit->text ());
// //
// validation // validation

View File

@ -1,6 +1,7 @@
#include "LotWUsers.hpp" #include "LotWUsers.hpp"
#include <future> #include <future>
#include <chrono>
#include <QHash> #include <QHash>
#include <QString> #include <QString>
@ -265,7 +266,9 @@ void LotWUsers::set_age_constraint (qint64 uploaded_since_days)
bool LotWUsers::user (QString const& call) const bool LotWUsers::user (QString const& call) const
{ {
if (m_->future_load_.valid ()) // check if a pending asynchronous load is ready
if (m_->future_load_.valid ()
&& std::future_status::ready == m_->future_load_.wait_for (std::chrono::seconds {0}))
{ {
try try
{ {
@ -278,10 +281,13 @@ bool LotWUsers::user (QString const& call) const
} }
Q_EMIT load_finished (); Q_EMIT load_finished ();
} }
if (m_->last_uploaded_.size ())
{
auto p = m_->last_uploaded_.constFind (call); auto p = m_->last_uploaded_.constFind (call);
if (p != m_->last_uploaded_.end ()) if (p != m_->last_uploaded_.end ())
{ {
return p.value ().daysTo (QDate::currentDate ()) <= m_->age_constraint_; return p.value ().daysTo (QDate::currentDate ()) <= m_->age_constraint_;
} }
}
return false; return false;
} }

View File

@ -400,7 +400,11 @@ void DisplayText::displayDecodedText(DecodedText const& decodedText, QString con
} }
else else
{ {
highlight_types types {Highlight::CQ, Highlight::LotW}; highlight_types types {Highlight::CQ};
if (m_config && m_config->lotw_users ().user (decodedText.CQersCall()))
{
types.push_back (Highlight::LotW);
}
set_colours (m_config, &bg, &fg, types); set_colours (m_config, &bg, &fg, types);
} }
} }