Move LotW users file management to Configuration implementation

This commit is contained in:
Bill Somerville 2018-10-01 22:43:13 +01:00
parent 0032a00ffe
commit 617b845a85
6 changed files with 36 additions and 35 deletions

View File

@ -180,6 +180,7 @@
#include "MessageBox.hpp"
#include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp"
#include "LotWUsers.hpp"
#include "ui_Configuration.h"
#include "moc_Configuration.cpp"
@ -354,8 +355,11 @@ public:
using FrequencyDelta = Radio::FrequencyDelta;
using port_type = Configuration::port_type;
explicit impl (Configuration * self, QDir const& temp_directory,
QSettings * settings, QWidget * parent);
explicit impl (Configuration * self
, QNetworkAccessManager * network_manager
, QDir const& temp_directory
, QSettings * settings
, QWidget * parent);
~impl ();
bool have_rig ();
@ -471,6 +475,7 @@ private:
QScopedPointer<Ui::configuration_dialog> ui_;
QNetworkAccessManager * network_manager_;
QSettings * settings_;
QDir doc_dir_;
@ -488,6 +493,8 @@ private:
QFont decoded_text_font_;
QFont next_decoded_text_font_;
LotWUsers lotw_users_;
bool restart_sound_input_device_;
bool restart_sound_output_device_;
@ -602,13 +609,9 @@ private:
QString opCall_;
QString udp_server_name_;
port_type udp_server_port_;
// QString n1mm_server_name () const;
QString n1mm_server_name_;
port_type n1mm_server_port_;
bool broadcast_to_n1mm_;
// port_type n1mm_server_port () const;
// bool valid_n1mm_info () const;
// bool broadcast_to_n1mm() const;
bool accept_udp_requests_;
bool udpWindowToFront_;
bool udpWindowRestore_;
@ -630,9 +633,9 @@ private:
// delegate to implementation class
Configuration::Configuration (QDir const& temp_directory,
Configuration::Configuration (QNetworkAccessManager * network_manager, QDir const& temp_directory,
QSettings * settings, QWidget * parent)
: m_ {this, temp_directory, settings, parent}
: m_ {this, network_manager, temp_directory, settings, parent}
{
}
@ -735,6 +738,7 @@ QDir Configuration::azel_directory () const {return m_->azel_directory_;}
QString Configuration::rig_name () const {return m_->rig_params_.rig_name;}
bool Configuration::pwrBandTxMemory () const {return m_->pwrBandTxMemory_;}
bool Configuration::pwrBandTuneMemory () const {return m_->pwrBandTuneMemory_;}
LotWUsers const& Configuration::lotw_users () const {return m_->lotw_users_;}
void Configuration::set_calibration (CalibrationParams params)
{
@ -906,17 +910,19 @@ namespace
}
}
Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
QSettings * settings, QWidget * parent)
Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network_manager
, QDir const& temp_directory, QSettings * settings, QWidget * parent)
: QDialog {parent}
, self_ {self}
, transceiver_thread_ {nullptr}
, ui_ {new Ui::configuration_dialog}
, network_manager_ {network_manager}
, settings_ {settings}
, doc_dir_ {doc_path ()}
, data_dir_ {data_path ()}
, temp_dir_ {temp_directory}
, writeable_data_dir_ {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}
, lotw_users_ {network_manager_}
, restart_sound_input_device_ {false}
, restart_sound_output_device_ {false}
, frequencies_ {&bands_}
@ -997,6 +1003,9 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
// this must be done after the default paths above are set
read_settings ();
// load LotW users data
lotw_users_.load (writeable_data_dir_.absoluteFilePath ("lotw-user-activity.csv"));
//
// validation
//

View File

@ -16,11 +16,13 @@ class QWidget;
class QAudioDeviceInfo;
class QString;
class QDir;
class QNetworkAccessManager;
class Bands;
class FrequencyList_v2;
class StationList;
class QStringListModel;
class QHostAddress;
class LotWUsers;
//
// Class Configuration
@ -69,7 +71,7 @@ public:
enum Type2MsgGen {type_2_msg_1_full, type_2_msg_3_full, type_2_msg_5_only};
Q_ENUM (Type2MsgGen)
explicit Configuration (QDir const& temp_directory, QSettings * settings,
explicit Configuration (QNetworkAccessManager *, QDir const& temp_directory, QSettings * settings,
QWidget * parent = nullptr);
~Configuration ();
@ -181,6 +183,7 @@ public:
QColor color_LoTW() const;
bool pwrBandTxMemory () const;
bool pwrBandTuneMemory () const;
LotWUsers const& lotw_users () const;
struct CalibrationParams
{
@ -239,8 +242,6 @@ public:
Q_SLOT void transceiver_tx_frequency (Frequency = 0u);
// Set transceiver mode.
//
// Rationalise means ensure TX uses same mode as RX.
Q_SLOT void transceiver_mode (MODE);
// Set/unset PTT.

View File

@ -16,8 +16,6 @@
#include <QNetworkReply>
#include <QDebug>
#include "Configuration.hpp"
#include "pimpl_impl.hpp"
#include "moc_LotWUsers.cpp"
@ -34,10 +32,9 @@ class LotWUsers::impl final
Q_OBJECT
public:
impl (LotWUsers * self, QNetworkAccessManager * network_manager, QString const& lotw_csv_file)
impl (LotWUsers * self, QNetworkAccessManager * network_manager)
: self_ {self}
, network_manager_ {network_manager}
, csv_file_ {lotw_csv_file}
, url_valid_ {false}
, redirect_count_ {0}
{
@ -226,23 +223,20 @@ public:
#include "LotWUsers.moc"
LotWUsers::LotWUsers (Configuration const * configuration, QNetworkAccessManager * network_manager
, QObject * parent)
LotWUsers::LotWUsers (QNetworkAccessManager * network_manager, QObject * parent)
: QObject {parent}
, m_ {this
, network_manager
, configuration->writeable_data_dir ().absoluteFilePath ("lotw-user-activity.csv")}
, m_ {this, network_manager}
{
m_->load (false);
}
LotWUsers::~LotWUsers ()
{
}
void LotWUsers::download_new_file ()
void LotWUsers::load (QString const& lotw_csv_file, bool force_download)
{
m_->load (true);
m_->csv_file_.setFileName (lotw_csv_file);
m_->load (force_download);
}
bool LotWUsers::user (QString const& call, qint64 uploaded_since_days) const

View File

@ -7,7 +7,6 @@
class QString;
class QDate;
class Configuration;
class QNetworkAccessManager;
//
@ -19,10 +18,10 @@ class LotWUsers final
Q_OBJECT
public:
LotWUsers (Configuration const * configuration, QNetworkAccessManager *, QObject * parent = 0);
LotWUsers (QNetworkAccessManager *, QObject * parent = 0);
~LotWUsers ();
void download_new_file ();
void load (QString const& lotw_csv_file, bool force_download = false);
// returns true if the specified call sign 'call' has uploaded their
// log to LotW in the last 'uploaded_since_days' days

View File

@ -59,6 +59,7 @@
#include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp"
#include "EqualizationToolsDialog.hpp"
#include "LotWUsers.hpp"
#include "ui_mainwindow.h"
#include "moc_mainwindow.cpp"
@ -202,8 +203,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
m_configurations_button {0},
m_settings {multi_settings->settings ()},
ui(new Ui::MainWindow),
m_config {temp_directory, m_settings, this},
m_lotw_users {&m_config, &m_network_manager},
m_config {&m_network_manager, temp_directory, m_settings, this},
m_WSPR_band_hopping {m_settings, &m_config, this},
m_WSPR_tx_next {false},
m_rigErrorMessageBox {MessageBox::Critical, tr ("Rig Control Error")
@ -386,8 +386,8 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
ui->dxGridEntry->setValidator (new MaidenheadLocatorValidator {this});
ui->dxCallEntry->setValidator (new CallsignValidator {this});
ui->sbTR->values ({5, 10, 15, 30});
ui->decodedTextBrowser->setLotWUsers (&m_lotw_users);
ui->decodedTextBrowser2->setLotWUsers (&m_lotw_users);
ui->decodedTextBrowser->setLotWUsers (&m_config.lotw_users ());
ui->decodedTextBrowser2->setLotWUsers (&m_config.lotw_users ());
m_baseCall = Radio::base_callsign (m_config.my_callsign ());
m_opCall = m_config.opCall();
@ -557,7 +557,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
m_equalizationToolsDialog->show ();
});
connect (&m_lotw_users, &LotWUsers::LotW_users_error, this, [this] (QString const& reason) {
connect (&m_config.lotw_users (), &LotWUsers::LotW_users_error, this, [this] (QString const& reason) {
MessageBox::warning_message (this, tr ("Error Loading LotW Users Data"), reason);
}, Qt::QueuedConnection);

View File

@ -36,7 +36,6 @@
#include "astro.h"
#include "MessageBox.hpp"
#include "NetworkAccessManager.hpp"
#include "LotWUsers.hpp"
#define NUM_JT4_SYMBOLS 206 //(72+31)*2, embedded sync
#define NUM_JT65_SYMBOLS 126 //63 data + 63 sync
@ -343,7 +342,6 @@ private:
QScopedPointer<Ui::MainWindow> ui;
Configuration m_config;
LotWUsers m_lotw_users;
WSPRBandHopping m_WSPR_band_hopping;
bool m_WSPR_tx_next;
MessageBox m_rigErrorMessageBox;