From ffc62c792c9a5196cb4ce7a353287dfe20db6524 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Fri, 9 Oct 2026 14:12:35 +0200 Subject: New upstream version 3.3.0~beta1+dfsg --- Configuration.cpp | 848 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 716 insertions(+), 132 deletions(-) (limited to 'Configuration.cpp') diff --git a/Configuration.cpp b/Configuration.cpp index dd92ae11..d527606a 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -164,7 +164,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -173,6 +176,7 @@ #include #include #include +#include #include #include #include @@ -185,6 +189,11 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -209,11 +218,13 @@ #include "models/IARURegions.hpp" #include "models/Modes.hpp" #include "models/FrequencyList.hpp" +#include "models/FrequencySuggestions.hpp" #include "models/StationList.hpp" #include "Network/NetworkServerLookup.hpp" #include "Network/FoxVerifier.hpp" #include "widgets/MessageBox.hpp" #include "widgets/SettingsDialogLayout.hpp" +#include "widgets/SuggestedFrequenciesDialog.hpp" #include "validators/MaidenheadLocatorValidator.hpp" #include "validators/CallsignValidator.hpp" #include "Network/LotWUsers.hpp" @@ -228,6 +239,101 @@ namespace { + class LocationLineEditEnterFilter final : public QObject + { + public: + explicit LocationLineEditEnterFilter (QObject * parent) : QObject {parent} {} + + protected: + bool eventFilter (QObject * watched, QEvent * event) override + { + if (event->type () == QEvent::KeyPress) + { + auto key_event = static_cast (event); + if (key_event->key () == Qt::Key_Return || key_event->key () == Qt::Key_Enter) + { + if (auto edit = qobject_cast (watched)) + { + edit->clearFocus (); + return true; + } + } + } + return QObject::eventFilter (watched, event); + } + }; + + // Centre of a four- or six-character Maidenhead locator, with + // conventional east-positive longitude. Four-character locators are + // treated as their "mm" subsquare, as grid2deg() does. + bool grid_centre (QString grid, double& lat, double& lon) + { + grid = grid.trimmed (); + if (grid.size () < 4) return false; + grid = grid.left (6); + if (grid.size () < 6) grid += "mm"; + if (grid.size () != 6) return false; + grid[0] = grid[0].toUpper (); + grid[1] = grid[1].toUpper (); + grid[4] = grid[4].toLower (); + grid[5] = grid[5].toLower (); + if (grid[0] < 'A' || grid[0] > 'R' || grid[1] < 'A' || grid[1] > 'R' + || !grid[2].isDigit () || !grid[3].isDigit () + || grid[4] < 'a' || grid[4] > 'x' || grid[5] < 'a' || grid[5] > 'x') return false; + auto west = 180. - 20. * (grid[0].unicode () - 'A') + - 2. * (grid[2].unicode () - '0') + - 5. * ((grid[4].unicode () - 'a') + .5) / 60.; + lat = -90. + 10. * (grid[1].unicode () - 'A') + + (grid[3].unicode () - '0') + + 2.5 * ((grid[5].unicode () - 'a') + .5) / 60.; + lon = -west; + return true; + } + + // True when lat/lon are just the centre of the locator, i.e. they were + // derived from My Grid rather than entered as precise coordinates. + // Coordinates are displayed and stored to six decimal places, so allow + // for that rounding. + bool coordinates_are_grid_centre (QString const& grid, double lat, double lon) + { + double centre_lat, centre_lon; + return grid_centre (grid, centre_lat, centre_lon) + && std::abs (lat - centre_lat) < 1.e-6 && std::abs (lon - centre_lon) < 1.e-6; + } + + // Convert conventional signed decimal degrees to a six-character + // Maidenhead locator. Longitude is east-positive here, matching the UI. + bool coordinates_to_grid (double lat, double lon, QString& grid) + { + if (lat < -90. || lat > 90. || lon < -180. || lon > 180.) return false; + + auto east = lon; + auto lat_for_grid = lat; + if (east == 180.) east = std::nextafter (180., 0.); + if (lat_for_grid == 90.) lat_for_grid = std::nextafter (90., 0.); + auto x = east + 180.; + auto y = lat_for_grid + 90.; + int field_lon = static_cast (std::floor (x / 20.)); + int field_lat = static_cast (std::floor (y / 10.)); + x -= field_lon * 20.; + y -= field_lat * 10.; + int square_lon = static_cast (std::floor (x / 2.)); + int square_lat = static_cast (std::floor (y)); + x -= square_lon * 2.; + y -= square_lat; + int sub_lon = static_cast (std::floor (x * 12.)); + int sub_lat = static_cast (std::floor (y * 24.)); + + grid.clear (); + grid += QChar::fromLatin1 (static_cast ('A' + field_lon)); + grid += QChar::fromLatin1 (static_cast ('A' + field_lat)); + grid += QChar::fromLatin1 (static_cast ('0' + square_lon)); + grid += QChar::fromLatin1 (static_cast ('0' + square_lat)); + grid += QChar::fromLatin1 (static_cast ('a' + sub_lon)); + grid += QChar::fromLatin1 (static_cast ('a' + sub_lat)); + return true; + } + // these undocumented flag values when stored in (Qt::UserRole - 1) // of a ComboBox item model index allow the item to be enabled or // disabled @@ -527,6 +633,7 @@ public: class Configuration::impl final : public QDialog { + friend class TestConfigurationRadio; Q_OBJECT; public: @@ -621,7 +728,10 @@ private: void close_rig (bool failed = false); TransceiverFactory::ParameterPack gather_rig_data (); void enumerate_rigs (); + void normalize_rig_selections (bool restore = false); void set_rig_invariants (); + enum class RadioValidationError { none, invalid_ptt_method, invalid_ptt_port }; + RadioValidationError validate_radio_settings (); bool validate (); void fill_port_combo_box (QComboBox *); Frequency apply_calibration (Frequency) const; @@ -633,6 +743,10 @@ private: void save_frequencies (); void reset_frequencies (); void insert_frequency (); + void show_suggested_frequencies (); + void refresh_suggestion_notice (); + void dismiss_suggestions (); + void persist_seen_suggestions (); void size_frequency_table_columns(); FrequencyList_v2_101::FrequencyItems read_frequencies_file (QString const&); @@ -645,8 +759,8 @@ private: Q_SLOT void on_font_push_button_clicked (); Q_SLOT void on_decoded_text_font_push_button_clicked (); - Q_SLOT void on_PTT_port_combo_box_activated (int); - Q_SLOT void on_CAT_port_combo_box_activated (int); + Q_SLOT void on_PTT_port_combo_box_currentTextChanged (QString const&); + Q_SLOT void on_CAT_port_combo_box_currentTextChanged (QString const&); Q_SLOT void on_CAT_serial_baud_combo_box_currentIndexChanged (int); Q_SLOT void on_CAT_poll_interval_spin_box_valueChanged (int); Q_SLOT void on_test_CAT_push_button_clicked (); @@ -664,6 +778,10 @@ private: Q_SLOT void on_delete_macro_push_button_clicked (bool = false); Q_SLOT void on_move_macro_up_push_button_clicked (bool = false); Q_SLOT void on_move_macro_down_push_button_clicked (bool = false); + Q_SLOT void on_grid_line_edit_editingFinished (); + Q_SLOT void on_latitude_line_edit_editingFinished (); + Q_SLOT void on_longitude_line_edit_editingFinished (); + void update_home_coordinates_style (); Q_SLOT void on_add_macro_line_edit_editingFinished (); Q_SLOT void delete_macro (); void delete_selected_macros (QModelIndexList); @@ -690,8 +808,8 @@ private: void update_DXCC_control_availability (); Q_SLOT void on_PWR_and_SWR_check_box_toggled (bool); void update_PWR_and_SWR_control_availability (); - Q_SLOT void on_reset_highlighting_to_defaults_push_button_clicked (bool); - Q_SLOT void on_reset_highlighting_to_defaults2_push_button_clicked (bool); + void apply_color_preset (DecodeHighlightingModel::ColorPreset const& preset); + void reset_highlighting (QString const& confirmation, DecodeHighlightingModel::HighlightItems const& items); Q_SLOT void on_move_highlighting_up_push_button_clicked (bool = false); Q_SLOT void on_move_highlighting_down_push_button_clicked (bool = false); Q_SLOT void on_rescan_log_push_button_clicked (bool); @@ -772,6 +890,9 @@ private: Q_SIGNAL void stop_transceiver () const; Q_SIGNAL void enqueue_jtty_pcm (QByteArray const&, TxAudioQueueEpoch, qint64) const; Q_SIGNAL void clear_jtty_pcm (TxAudioQueueEpoch) const; + Q_SIGNAL void receive_discontinuity (JttyReceiveReason) const; + Q_SIGNAL void receive_stop_reason (JttyReceiveReason) const; + Q_SIGNAL void receive_drain (quint64 requestId) const; PerformanceTrace::Phase construction_trace_; Configuration * const self_; // back pointer to public interface @@ -833,7 +954,13 @@ private: QAction * save_frequencies_action_; QAction * merge_frequencies_action_; QAction * reset_frequencies_action_; + QAction * suggested_frequencies_action_; FrequencyDialog * frequency_dialog_; + QFrame * suggestions_notice_ {nullptr}; + QLabel * suggestions_notice_label_ {nullptr}; + QPushButton * suggestions_browse_button_ {nullptr}; + QPushButton * suggestions_dismiss_button_ {nullptr}; + FrequencySuggestions::NoticeState suggestion_notice_state_; QAction station_delete_action_; QAction station_insert_action_; @@ -875,6 +1002,9 @@ private: // configuration fields that we publish QString my_callsign_; QString my_grid_; + double home_latitude_ {0.}; + double home_longitude_ {0.}; + bool have_home_coordinates_ {false}; QString FD_exchange_; QString RTTY_exchange_; QString Contest_Name_; @@ -1352,6 +1482,40 @@ void Configuration::transceiver_period (double period) m_->transceiver_period (period); } +void Configuration::transceiver_receive_policy (ReceivePolicy policy) +{ + m_->cached_rig_state_.receive_policy (policy); + if (m_->cached_rig_state_.online () && m_->can_control_rig ("transceiver_receive_policy")) + Q_EMIT m_->set_transceiver (m_->cached_rig_state_, ++m_->transceiver_command_number_); +} + +void Configuration::transceiver_receive_discontinuity (JttyReceiveReason reason) +{ + Q_EMIT m_->receive_discontinuity (reason); +} + +void Configuration::transceiver_receive_context (quint64 context) +{ + m_->cached_rig_state_.receive_context (context); + if (m_->cached_rig_state_.online () && m_->can_control_rig ("transceiver_receive_context")) + Q_EMIT m_->set_transceiver (m_->cached_rig_state_, ++m_->transceiver_command_number_); +} + +void Configuration::transceiver_receive_stop_reason (JttyReceiveReason reason) +{ + Q_EMIT m_->receive_stop_reason (reason); +} + +void Configuration::requestContinuousReceiveDrain (quint64 requestId) +{ + if (!m_->rig_active_) + { + Q_EMIT continuousReceiveDrained (requestId, {}); + return; + } + Q_EMIT m_->receive_drain (requestId); +} + void Configuration::transceiver_blocksize (qint32 blocksize) { #if WSJT_TRACE_CAT @@ -1504,6 +1668,24 @@ QString Configuration::my_grid() const return the_grid; } +bool Configuration::has_precise_home_coordinates () const +{ + // Coordinates that are just the centre of My Grid add no precision, so + // leave the astronomical calculation on its original grid-based path. + return m_->have_home_coordinates_ && !(m_->use_dynamic_grid_ && m_->dynamic_grid_.size () >= 4) + && !coordinates_are_grid_centre (m_->my_grid_, m_->home_latitude_, m_->home_longitude_); +} + +double Configuration::home_latitude () const +{ + return m_->home_latitude_; +} + +double Configuration::home_longitude () const +{ + return m_->home_longitude_; +} + QString Configuration::Field_Day_Exchange() const { return m_->FD_exchange_; @@ -2209,15 +2391,36 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network ui_->calibration_slope_ppm_spin_box->setAccessibleName (tr ("Frequency calibration slope")); ui_->calibration_intercept_spin_box->setAccessibleName (tr ("Frequency calibration intercept")); ui_->frequencies_table_view->setAccessibleName (tr ("Working frequencies table")); + suggestions_notice_ = new QFrame {ui_->frequencies_tab}; + suggestions_notice_->setFrameShape (QFrame::StyledPanel); + auto * suggestions_notice_layout = new QHBoxLayout {suggestions_notice_}; + suggestions_notice_label_ = new QLabel {suggestions_notice_}; + suggestions_notice_label_->setWordWrap (true); + suggestions_browse_button_ = new QPushButton {tr ("Browse suggestions..."), suggestions_notice_}; + suggestions_dismiss_button_ = new QPushButton {tr ("Dismiss"), suggestions_notice_}; + suggestions_notice_layout->addWidget (suggestions_notice_label_, 1); + suggestions_notice_layout->addWidget (suggestions_browse_button_); + suggestions_notice_layout->addWidget (suggestions_dismiss_button_); + ui_->horizontalLayout->insertWidget (0, suggestions_notice_); + suggestions_notice_->hide (); + connect (suggestions_browse_button_, &QPushButton::clicked, + this, &Configuration::impl::show_suggested_frequencies); + connect (suggestions_dismiss_button_, &QPushButton::clicked, + this, &Configuration::impl::dismiss_suggestions); ui_->stations_table_view->setAccessibleName (tr ("Station information table")); ui_->highlighting_list_view->setAccessibleName (tr ("Decode highlighting rules")); ui_->highlighting_list_view->setAccessibleDescription (tr ("Highlighting rules and priorities for decoded messages.")); ui_->highlighting_actions_tool_button->setAccessibleName (tr ("Decode highlighting actions")); - ui_->highlighting_actions_tool_button->setAccessibleDescription (tr ("Change or reset colors for the selected highlighting rule.")); + ui_->highlighting_actions_tool_button->setAccessibleDescription ( + tr ("Change colors or restore Default 1 colors and enabled state for the selected highlighting rule.")); ui_->move_highlighting_up_push_button->setAccessibleName (tr ("Move selected highlighting rule up")); ui_->move_highlighting_up_push_button->setAccessibleDescription (tr ("Move the selected highlighting rule earlier in priority order.")); ui_->move_highlighting_down_push_button->setAccessibleName (tr ("Move selected highlighting rule down")); ui_->move_highlighting_down_push_button->setAccessibleDescription (tr ("Move the selected highlighting rule later in priority order.")); + ui_->color_presets_tool_button->setAccessibleName (tr ("Decode highlighting color presets")); + ui_->color_presets_tool_button->setAccessibleDescription (tr ("Apply colors to all decode highlighting rules without changing which rules are enabled or their priority.")); + ui_->reset_highlighting_tool_button->setAccessibleName (tr ("Reset decode highlighting")); + ui_->reset_highlighting_tool_button->setAccessibleDescription (tr ("Restore colors, enabled rules, and priority order to a complete default configuration.")); ui_->highlight_orange_callsigns->setAccessibleName (tr ("Orange highlight callsigns and grids")); ui_->highlight_blue_callsigns->setAccessibleName (tr ("Blue highlight callsigns and grids")); @@ -2367,6 +2570,8 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network register_settings_focus_page (ui_->frequencies_tab, { ui_->calibration_slope_ppm_spin_box, ui_->calibration_intercept_spin_box, + suggestions_browse_button_, + suggestions_dismiss_button_, ui_->frequencies_actions_tool_button, ui_->frequencies_table_view, ui_->stations_actions_tool_button, @@ -2378,8 +2583,8 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network ui_->highlighting_actions_tool_button, ui_->move_highlighting_up_push_button, ui_->move_highlighting_down_push_button, - ui_->reset_highlighting_to_defaults_push_button, - ui_->reset_highlighting_to_defaults2_push_button, + ui_->color_presets_tool_button, + ui_->reset_highlighting_tool_button, ui_->rescan_log_push_button, ui_->highlight_by_mode_check_box, ui_->highlight_orange_check_box, @@ -2575,6 +2780,12 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network PerformanceTrace::Phase settings_read {"configuration.settings_read"}; read_settings (); } + { + SettingsGroup g {settings_, "Configuration"}; + suggestion_notice_state_ = FrequencySuggestions::NoticeState { + settings_->value ("SeenSuggestedFrequencyKeys").toStringList (), + settings_->contains ("SeenSuggestedFrequencyKeys")}; + } // set up dynamic loading of audio devices connect (ui_->sound_input_combo_box, &LazyFillComboBox::about_to_show_popup, [this] () { @@ -2618,6 +2829,27 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network // ui_->callsign_line_edit->setValidator (new CallsignValidator {this}); ui_->grid_line_edit->setValidator (new MaidenheadLocatorValidator {this}); + auto latitude_validator = new QDoubleValidator {-90.0, 90.0, 8, this}; + latitude_validator->setNotation (QDoubleValidator::StandardNotation); + latitude_validator->setLocale (QLocale::c ()); + ui_->latitude_line_edit->setValidator (latitude_validator); + auto longitude_validator = new QDoubleValidator {-180.0, 180.0, 8, this}; + longitude_validator->setNotation (QDoubleValidator::StandardNotation); + longitude_validator->setLocale (QLocale::c ()); + ui_->longitude_line_edit->setValidator (longitude_validator); + + auto location_enter_filter = new LocationLineEditEnterFilter {this}; + ui_->grid_line_edit->installEventFilter (location_enter_filter); + ui_->latitude_line_edit->installEventFilter (location_enter_filter); + ui_->longitude_line_edit->installEventFilter (location_enter_filter); + // My Grid is only checked once editing is finished (see + // on_grid_line_edit_editingFinished), since a partly typed locator + // would briefly make grid-derived coordinates look user-entered. + for (auto edit : {ui_->latitude_line_edit, ui_->longitude_line_edit}) + { + connect (edit, &QLineEdit::textChanged, this, &Configuration::impl::update_home_coordinates_style); + } + ui_->add_macro_line_edit->setValidator (new QRegularExpressionValidator {message_alphabet, this}); ui_->Field_Day_Exchange->setValidator (new QRegularExpressionValidator {field_day_exchange_re, this}); ui_->RTTY_Exchange->setValidator (new QRegularExpressionValidator {RTTY_roundup_exchange_re, this}); @@ -2709,6 +2941,14 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network frequencies_.sort (FrequencyList_v2_101::frequency_column); ui_->frequencies_table_view->setModel (&next_frequencies_); + connect (&next_frequencies_, &QAbstractItemModel::dataChanged, + this, [this] { refresh_suggestion_notice (); }); + connect (&next_frequencies_, &QAbstractItemModel::rowsInserted, + this, [this] { refresh_suggestion_notice (); }); + connect (&next_frequencies_, &QAbstractItemModel::rowsRemoved, + this, [this] { refresh_suggestion_notice (); }); + connect (&next_frequencies_, &QAbstractItemModel::modelReset, + this, [this] { refresh_suggestion_notice (); }); ui_->frequencies_table_view->setTabKeyNavigation (false); ui_->frequencies_table_view->horizontalHeader ()->setSectionResizeMode (QHeaderView::ResizeToContents); @@ -2734,6 +2974,11 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network ui_->frequencies_table_view->insertAction (nullptr, frequency_insert_action_); connect (frequency_insert_action_, &QAction::triggered, this, &Configuration::impl::insert_frequency); + suggested_frequencies_action_ = new QAction {tr ("Add suggested frequencies ..."), ui_->frequencies_table_view}; + ui_->frequencies_table_view->insertAction (nullptr, suggested_frequencies_action_); + connect (suggested_frequencies_action_, &QAction::triggered, + this, &Configuration::impl::show_suggested_frequencies); + load_frequencies_action_ = new QAction {tr ("&Load ..."), ui_->frequencies_table_view}; ui_->frequencies_table_view->insertAction (nullptr, load_frequencies_action_); connect (load_frequencies_action_, &QAction::triggered, this, &Configuration::impl::load_frequencies); @@ -2754,6 +2999,7 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network frequencies_actions_menu->addAction (frequency_insert_action_); frequencies_actions_menu->addAction (frequency_delete_action_); frequencies_actions_menu->addSeparator (); + frequencies_actions_menu->addAction (suggested_frequencies_action_); frequencies_actions_menu->addAction (load_frequencies_action_); frequencies_actions_menu->addAction (save_frequencies_action_); frequencies_actions_menu->addAction (merge_frequencies_action_); @@ -2805,6 +3051,56 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network }); ui_->highlighting_actions_tool_button->setMenu (highlighting_actions_menu); + auto color_presets_menu = new QMenu {ui_->color_presets_tool_button}; + auto default_colors_action = color_presets_menu->addAction (tr ("Default 1 colors (original)")); + connect (default_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::default_color_preset ()); + }); + auto default2_colors_action = color_presets_menu->addAction (tr ("Default 2 colors (alternative)")); + connect (default2_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::default2_color_preset ()); + }); + color_presets_menu->addSeparator (); + auto red_green_colors_action = color_presets_menu->addAction (tr ("Red/green color-vision friendly")); + connect (red_green_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::red_green_color_vision_preset ()); + }); + auto blue_yellow_colors_action = color_presets_menu->addAction (tr ("Blue/yellow color-vision friendly")); + connect (blue_yellow_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::blue_yellow_color_vision_preset ()); + }); + auto high_contrast_colors_action = color_presets_menu->addAction (tr ("High contrast")); + connect (high_contrast_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::high_contrast_color_preset ()); + }); + color_presets_menu->addSeparator (); + auto dark_shack_colors_action = color_presets_menu->addAction (tr ("Dark shack")); + connect (dark_shack_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::dark_shack_color_preset ()); + }); + auto solarized_colors_action = color_presets_menu->addAction (tr ("Solarized")); + connect (solarized_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::solarized_color_preset ()); + }); + auto monochrome_colors_action = color_presets_menu->addAction (tr ("Monochrome")); + connect (monochrome_colors_action, &QAction::triggered, this, [this] { + apply_color_preset (DecodeHighlightingModel::monochrome_color_preset ()); + }); + ui_->color_presets_tool_button->setMenu (color_presets_menu); + + auto reset_highlighting_menu = new QMenu {ui_->reset_highlighting_tool_button}; + auto reset_default_action = reset_highlighting_menu->addAction (tr ("Default 1")); + connect (reset_default_action, &QAction::triggered, this, [this] { + reset_highlighting (tr ("Reset all decode highlighting and priorities to Default 1 values"), + DecodeHighlightingModel::default_items ()); + }); + auto reset_default2_action = reset_highlighting_menu->addAction (tr ("Default 2")); + connect (reset_default2_action, &QAction::triggered, this, [this] { + reset_highlighting (tr ("Reset all decode highlighting and priorities to Default 2 values"), + DecodeHighlightingModel::default_items2 ()); + }); + ui_->reset_highlighting_tool_button->setMenu (reset_highlighting_menu); + { PerformanceTrace::Phase rig_models {"configuration.rig_models"}; enumerate_rigs (); @@ -2884,6 +3180,10 @@ void Configuration::impl::initialize_models () ui_->grid_line_edit->setPalette (pal); ui_->callsign_line_edit->setText (my_callsign_); ui_->grid_line_edit->setText (my_grid_); + ui_->latitude_line_edit->setText (have_home_coordinates_ ? QString::number (home_latitude_, 'f', 6) : QString {}); + ui_->longitude_line_edit->setText (have_home_coordinates_ ? QString::number (home_longitude_, 'f', 6) : QString {}); + if (!have_home_coordinates_) on_grid_line_edit_editingFinished (); + update_home_coordinates_style (); ui_->use_dynamic_grid->setChecked(use_dynamic_grid_); ui_->CW_id_interval_spin_box->setValue (id_interval_); ui_->align_spin_box->setValue (align_steps_); @@ -3042,6 +3342,10 @@ void Configuration::impl::initialize_models () next_macros_.setStringList (macros_.stringList ()); next_frequencies_.frequency_list (frequencies_.frequency_list ()); + if (suggestion_notice_state_.acknowledge_present_catalog ( + FrequencyList_v2_101::default_items (), frequencies_.frequency_list ())) + persist_seen_suggestions (); + refresh_suggestion_notice (); next_stations_.station_list (stations_.station_list ()); next_decode_highlighing_model_.items (decode_highlighing_model_.items ()); @@ -3080,6 +3384,8 @@ void Configuration::impl::initialize_models () check_visibility (); + normalize_rig_selections (true); + initializing_models_ = false; set_rig_invariants (); } @@ -3107,6 +3413,14 @@ void Configuration::impl::read_settings () my_callsign_ = settings_->value ("MyCall", QString {}).toString (); my_grid_ = settings_->value ("MyGrid", QString {}).toString (); + have_home_coordinates_ = settings_->contains ("HomeLatitude") && settings_->contains ("HomeLongitude"); + if (have_home_coordinates_) + { + home_latitude_ = settings_->value ("HomeLatitude").toDouble (); + home_longitude_ = settings_->value ("HomeLongitude").toDouble (); + have_home_coordinates_ = home_latitude_ >= -90. && home_latitude_ <= 90. + && home_longitude_ >= -180. && home_longitude_ <= 180.; + } FD_exchange_ = settings_->value ("Field_Day_Exchange",QString {}).toString (); RTTY_exchange_ = settings_->value ("RTTY_Exchange",QString {}).toString (); Contest_Name_ = settings_->value ("Contest_Name",QString {}).toString (); @@ -3466,7 +3780,7 @@ void Configuration::impl::read_settings () if (rig_params_.ptt_type == TransceiverFactory::PTT_method_CAT) rig_params_.ptt_type = TransceiverFactory::PTT_method_VOX; } #ifdef WIN32 - QTimer::singleShot (2500, [=] {display_file_information ();}); + QTimer::singleShot (2500, this, &Configuration::impl::display_file_information); #else ui_->hamlib_groupBox->setTitle("Hamlib Version"); ui_->rbHamlib64->setVisible(false); @@ -3475,7 +3789,7 @@ void Configuration::impl::read_settings () ui_->revert_update_button->setVisible(false); ui_->backed_up_text->setVisible(false); ui_->backed_up->setVisible(false); - QTimer::singleShot (2500, [=] {display_file_information ();}); + QTimer::singleShot (2500, this, &Configuration::impl::display_file_information); #endif } @@ -3513,6 +3827,16 @@ void Configuration::impl::write_settings () settings_->setValue ("MyCall", my_callsign_); settings_->setValue ("MyGrid", my_grid_); + if (have_home_coordinates_) + { + settings_->setValue ("HomeLatitude", home_latitude_); + settings_->setValue ("HomeLongitude", home_longitude_); + } + else + { + settings_->remove ("HomeLatitude"); + settings_->remove ("HomeLongitude"); + } settings_->setValue ("Field_Day_Exchange", FD_exchange_); settings_->setValue ("RTTY_Exchange", RTTY_exchange_); settings_->setValue ("Contest_Name", Contest_Name_); @@ -3737,17 +4061,98 @@ void Configuration::impl::write_settings () settings_->sync (); } +void Configuration::impl::normalize_rig_selections (bool restore) +{ + QSignalBlocker cat_signals {ui_->CAT_port_combo_box}; + QSignalBlocker ptt_signals {ui_->PTT_port_combo_box}; + auto const rig = ui_->rig_combo_box->currentText (); + auto const port_type = transceiver_factory_.CAT_port_type (rig); + if (TransceiverFactory::basic_transceiver_name_ != rig + && (restore || port_type != last_port_type_)) + { + last_port_type_ = port_type; + switch (port_type) + { + case TransceiverFactory::Capabilities::serial: + fill_port_combo_box (ui_->CAT_port_combo_box); + ui_->CAT_port_combo_box->addItem ("USB"); + ui_->CAT_port_combo_box->setItemData (ui_->CAT_port_combo_box->count () - 1, "Custom USB device", Qt::ToolTipRole); + ui_->CAT_port_combo_box->setCurrentText (rig_params_.serial_port); + if (ui_->CAT_port_combo_box->currentText ().isEmpty () && ui_->CAT_port_combo_box->count ()) + { + ui_->CAT_port_combo_box->setCurrentText (ui_->CAT_port_combo_box->itemText (0)); + } + ui_->CAT_port_label->setText (tr ("Serial Port:")); + ui_->CAT_port_combo_box->setToolTip (tr ("Serial port used for CAT control")); + ui_->CAT_port_combo_box->setEnabled (true); + break; + + case TransceiverFactory::Capabilities::tci: + ui_->CAT_port_combo_box->clear (); + ui_->CAT_port_combo_box->setCurrentText (rig_params_.tci_port); + ui_->CAT_port_label->setText (tr ("TCI Server:")); + ui_->CAT_port_combo_box->setToolTip (tr ("Optional hostname and port of TCI service.\n" + "Leave blank for a sensible default on this machine.\n" + "Formats:\n" + "\thostname:port\n" + "\tIPv4-address:port\n" + "\t[IPv6-address]:port")); + ui_->CAT_port_combo_box->setEnabled (true); + break; + + case TransceiverFactory::Capabilities::network: + ui_->CAT_port_combo_box->clear (); + ui_->CAT_port_combo_box->setCurrentText (rig_params_.network_port); + ui_->CAT_port_label->setText (tr ("Network Server:")); + ui_->CAT_port_combo_box->setToolTip (tr ("Optional hostname and port of network service.\n" + "Leave blank for a sensible default on this machine.\n" + "Formats:\n" + "\thostname:port\n" + "\tIPv4-address:port\n" + "\t[IPv6-address]:port")); + ui_->CAT_port_combo_box->setEnabled (true); + break; + + case TransceiverFactory::Capabilities::usb: + ui_->CAT_port_combo_box->clear (); + ui_->CAT_port_combo_box->setCurrentText (rig_params_.usb_port); + ui_->CAT_port_label->setText (tr ("USB Device:")); + ui_->CAT_port_combo_box->setToolTip (tr ("Optional device identification.\n" + "Leave blank for a sensible default for the rig.\n" + "Format:\n" + "\t[VID[:PID[:VENDOR[:PRODUCT]]]]")); + ui_->CAT_port_combo_box->setEnabled (true); + break; + + default: + ui_->CAT_port_combo_box->clear (); + ui_->CAT_port_combo_box->setEnabled (false); + break; + } + } + auto const indirect_ptt = transceiver_factory_.has_CAT_indirect_serial_PTT (rig); + ui_->PTT_port_combo_box->setItemData (ui_->PTT_port_combo_box->findText ("CAT") + , indirect_ptt ? combo_box_item_enabled : combo_box_item_disabled + , Qt::UserRole - 1); + auto const ptt_port = ui_->PTT_port_combo_box->currentText (); + if (("CAT" == ptt_port && !indirect_ptt) || "USB" == ptt_port) + { + ui_->PTT_port_combo_box->setCurrentIndex (-1); + ui_->PTT_port_combo_box->clearEditText (); + } +} + void Configuration::impl::set_rig_invariants () { + if (initializing_models_) return; + + normalize_rig_selections (); auto const& rig = ui_->rig_combo_box->currentText (); auto const& ptt_port = ui_->PTT_port_combo_box->currentText (); auto ptt_method = static_cast (ui_->PTT_method_button_group->checkedId ()); auto CAT_PTT_enabled = transceiver_factory_.has_CAT_PTT (rig); - auto CAT_indirect_serial_PTT = transceiver_factory_.has_CAT_indirect_serial_PTT (rig); auto asynchronous_CAT = transceiver_factory_.has_asynchronous_CAT (rig); - auto is_hw_handshake = ui_->CAT_handshake_group_box->isEnabled () - && TransceiverFactory::handshake_hardware == static_cast (ui_->CAT_handshake_button_group->checkedId ()); is_tci_ = ui_->rig_combo_box->currentText().startsWith("TCI Cli"); ui_->tci_audio_check_box->setVisible(is_tci_); ui_->TCI_spin_box->setVisible(is_tci_); @@ -3764,6 +4169,8 @@ void Configuration::impl::set_rig_invariants () auto port_type = transceiver_factory_.CAT_port_type (rig); bool is_serial_CAT (TransceiverFactory::Capabilities::serial == port_type); + auto const is_hw_handshake = is_serial_CAT + && TransceiverFactory::handshake_hardware == static_cast (ui_->CAT_handshake_button_group->checkedId ()); auto const& cat_port = ui_->CAT_port_combo_box->currentText (); // only enable CAT option if transceiver has CAT PTT @@ -3775,20 +4182,6 @@ void Configuration::impl::set_rig_invariants () ui_->PTT_port_combo_box->setEnabled (enable_ptt_port); ui_->PTT_port_label->setEnabled (enable_ptt_port); - if (CAT_indirect_serial_PTT) - { - ui_->PTT_port_combo_box->setItemData (ui_->PTT_port_combo_box->findText ("CAT") - , combo_box_item_enabled, Qt::UserRole - 1); - } - else - { - ui_->PTT_port_combo_box->setItemData (ui_->PTT_port_combo_box->findText ("CAT") - , combo_box_item_disabled, Qt::UserRole - 1); - if ("CAT" == ui_->PTT_port_combo_box->currentText () && ui_->PTT_port_combo_box->currentIndex () > 0) - { - ui_->PTT_port_combo_box->setCurrentIndex (ui_->PTT_port_combo_box->currentIndex () - 1); - } - } ui_->PTT_RTS_radio_button->setEnabled (!((is_serial_CAT && ptt_port == cat_port && is_hw_handshake) || is_tci_)); if (TransceiverFactory::basic_transceiver_name_ == rig) @@ -3819,66 +4212,6 @@ void Configuration::impl::set_rig_invariants () ui_->test_CAT_push_button->setEnabled (true); ui_->test_PTT_push_button->setEnabled (false); ui_->TX_audio_source_group_box->setEnabled (transceiver_factory_.has_CAT_PTT_mic_data (rig) && TransceiverFactory::PTT_method_CAT == ptt_method); - if (port_type != last_port_type_) - { - last_port_type_ = port_type; - switch (port_type) - { - case TransceiverFactory::Capabilities::serial: - fill_port_combo_box (ui_->CAT_port_combo_box); - ui_->CAT_port_combo_box->setCurrentText (rig_params_.serial_port); - if (ui_->CAT_port_combo_box->currentText ().isEmpty () && ui_->CAT_port_combo_box->count ()) - { - ui_->CAT_port_combo_box->setCurrentText (ui_->CAT_port_combo_box->itemText (0)); - } - ui_->CAT_port_label->setText (tr ("Serial Port:")); - ui_->CAT_port_combo_box->setToolTip (tr ("Serial port used for CAT control")); - ui_->CAT_port_combo_box->setEnabled (true); - break; - - case TransceiverFactory::Capabilities::tci: - ui_->CAT_port_combo_box->clear (); - ui_->CAT_port_combo_box->setCurrentText (rig_params_.tci_port); - ui_->CAT_port_label->setText (tr ("TCI Server:")); - ui_->CAT_port_combo_box->setToolTip (tr ("Optional hostname and port of TCI service.\n" - "Leave blank for a sensible default on this machine.\n" - "Formats:\n" - "\thostname:port\n" - "\tIPv4-address:port\n" - "\t[IPv6-address]:port")); - ui_->CAT_port_combo_box->setEnabled (true); - break; - - case TransceiverFactory::Capabilities::network: - ui_->CAT_port_combo_box->clear (); - ui_->CAT_port_combo_box->setCurrentText (rig_params_.network_port); - ui_->CAT_port_label->setText (tr ("Network Server:")); - ui_->CAT_port_combo_box->setToolTip (tr ("Optional hostname and port of network service.\n" - "Leave blank for a sensible default on this machine.\n" - "Formats:\n" - "\thostname:port\n" - "\tIPv4-address:port\n" - "\t[IPv6-address]:port")); - ui_->CAT_port_combo_box->setEnabled (true); - break; - - case TransceiverFactory::Capabilities::usb: - ui_->CAT_port_combo_box->clear (); - ui_->CAT_port_combo_box->setCurrentText (rig_params_.usb_port); - ui_->CAT_port_label->setText (tr ("USB Device:")); - ui_->CAT_port_combo_box->setToolTip (tr ("Optional device identification.\n" - "Leave blank for a sensible default for the rig.\n" - "Format:\n" - "\t[VID[:PID[:VENDOR[:PRODUCT]]]]")); - ui_->CAT_port_combo_box->setEnabled (true); - break; - - default: - ui_->CAT_port_combo_box->clear (); - ui_->CAT_port_combo_box->setEnabled (false); - break; - } - } ui_->CAT_serial_port_parameters_group_box->setEnabled (is_serial_CAT); ui_->force_DTR_combo_box->setEnabled (is_serial_CAT && (cat_port != ptt_port @@ -3896,8 +4229,73 @@ void Configuration::impl::set_rig_invariants () || TransceiverFactory::basic_transceiver_name_ != rig); } +auto Configuration::impl::validate_radio_settings () -> RadioValidationError +{ + set_rig_invariants (); + + if (!ui_->PTT_method_button_group->checkedButton ()->isEnabled ()) + { + return RadioValidationError::invalid_ptt_method; + } + + auto ptt_method = static_cast (ui_->PTT_method_button_group->checkedId ()); + auto ptt_port = ui_->PTT_port_combo_box->currentText (); + auto const ptt_port_index = ui_->PTT_port_combo_box->findText (ptt_port); + if ((TransceiverFactory::PTT_method_DTR == ptt_method || TransceiverFactory::PTT_method_RTS == ptt_method) + && (ptt_port.trimmed ().isEmpty () + || (ptt_port_index >= 0 + && combo_box_item_disabled == ui_->PTT_port_combo_box->itemData (ptt_port_index, Qt::UserRole - 1)))) + { + return RadioValidationError::invalid_ptt_port; + } + + return RadioValidationError::none; +} + bool Configuration::impl::validate () { + auto const radio_error = validate_radio_settings (); + + // Latitude/longitude are conventional signed decimal degrees. Allow both + // fields to be empty (legacy/grid-only configuration), but if either is + // supplied require a complete, in-range pair before accepting Settings. + auto const latitude_text = ui_->latitude_line_edit->text ().trimmed (); + auto const longitude_text = ui_->longitude_line_edit->text ().trimmed (); + if (!latitude_text.isEmpty () || !longitude_text.isEmpty ()) + { + if (!ui_->latitude_line_edit->hasAcceptableInput () + || !ui_->longitude_line_edit->hasAcceptableInput ()) + { + find_tab (ui_->latitude_line_edit); + MessageBox::critical_message (this, tr ("Invalid station coordinates"), + tr ("Latitude must be between -90 and +90 degrees, " + "and longitude between -180 and +180 degrees.")); + return false; + } + } + + // Do not rely on editingFinished having synchronized My Grid with the + // coordinate fields before OK is clicked. A valid coordinate pair must + // lie inside the displayed six-character locator. + if (!latitude_text.isEmpty () && !longitude_text.isEmpty ()) + { + bool lat_ok {false}; + bool lon_ok {false}; + auto lat = latitude_text.toDouble (&lat_ok); + auto lon = longitude_text.toDouble (&lon_ok); + QString coordinate_grid; + auto grid = ui_->grid_line_edit->text ().trimmed ().left (6); + if (grid.size () < 6) grid += "mm"; + if (lat_ok && lon_ok && coordinates_to_grid (lat, lon, coordinate_grid) + && coordinate_grid.compare (grid, Qt::CaseInsensitive) != 0) + { + find_tab (ui_->grid_line_edit); + MessageBox::critical_message (this, tr ("Inconsistent station location"), + tr ("Latitude and longitude must lie within the My Grid locator.")); + return false; + } + } + if (ui_->sound_input_combo_box->currentIndex () < 0 && next_audio_input_device_.isNull ()) { @@ -3922,20 +4320,14 @@ bool Configuration::impl::validate () // don't reject as we can work without an audio output } - if (!ui_->PTT_method_button_group->checkedButton ()->isEnabled ()) + if (RadioValidationError::invalid_ptt_method == radio_error) { find_tab (ui_->PTT_method_button_group->checkedButton ()); MessageBox::critical_message (this, tr ("Invalid PTT method")); return false; } - auto ptt_method = static_cast (ui_->PTT_method_button_group->checkedId ()); - auto ptt_port = ui_->PTT_port_combo_box->currentText (); - auto const ptt_port_index = ui_->PTT_port_combo_box->findText (ptt_port); - if ((TransceiverFactory::PTT_method_DTR == ptt_method || TransceiverFactory::PTT_method_RTS == ptt_method) - && (ptt_port.isEmpty () - || (ptt_port_index >= 0 - && combo_box_item_disabled == ui_->PTT_port_combo_box->itemData (ptt_port_index, Qt::UserRole - 1)))) + if (RadioValidationError::invalid_ptt_port == radio_error) { find_tab (ui_->PTT_port_combo_box); MessageBox::critical_message (this, tr ("Invalid PTT port")); @@ -4156,6 +4548,16 @@ void Configuration::impl::accept () my_callsign_ = ui_->callsign_line_edit->text (); my_grid_ = ui_->grid_line_edit->text (); + bool lat_ok {false}; + bool lon_ok {false}; + auto lat = ui_->latitude_line_edit->text ().toDouble (&lat_ok); + auto lon = ui_->longitude_line_edit->text ().toDouble (&lon_ok); + have_home_coordinates_ = lat_ok && lon_ok && lat >= -90. && lat <= 90. && lon >= -180. && lon <= 180.; + if (have_home_coordinates_) + { + home_latitude_ = lat; + home_longitude_ = lon; + } FD_exchange_= ui_->Field_Day_Exchange->text ().toUpper (); RTTY_exchange_= ui_->RTTY_Exchange->text ().toUpper (); Contest_Name_= ui_->Contest_Name->text ().toUpper (); @@ -4408,10 +4810,14 @@ void Configuration::impl::accept () alert_Enabled_ = ui_->pbAlerts->isChecked(); write_settings (); // make visible to all + if (suggestion_notice_state_.commit (FrequencyList_v2_101::default_items (), + frequencies_.frequency_list ())) + persist_seen_suggestions (); } void Configuration::impl::reject () { + suggestion_notice_state_.cancel (); if (dns_lookup_id_ > -1) { QHostInfo::abortHostLookup (dns_lookup_id_); @@ -4451,23 +4857,25 @@ void Configuration::impl::on_font_push_button_clicked () next_font_ = QFontDialog::getFont (0, next_font_, this); } -void Configuration::impl::on_reset_highlighting_to_defaults_push_button_clicked (bool /*checked*/) +void Configuration::impl::apply_color_preset (DecodeHighlightingModel::ColorPreset const& preset) { - if (MessageBox::Yes == MessageBox::query_message (this - , tr ("Reset Decode Highlighting") - , tr ("Reset all decode highlighting and priorities to Default 1 values"))) + if (!next_decode_highlighing_model_.apply_color_preset (preset)) { - next_decode_highlighing_model_.items (DecodeHighlightingModel::default_items ()); + MessageBox::warning_message ( + this, + tr ("Color Preset Error"), + tr ("The selected color preset could not be applied. " + "Reset decode highlighting to a default configuration and try again.")); } } -void Configuration::impl::on_reset_highlighting_to_defaults2_push_button_clicked (bool /*checked*/) +void Configuration::impl::reset_highlighting (QString const& confirmation, DecodeHighlightingModel::HighlightItems const& items) { - if (MessageBox::Yes == MessageBox::query_message (this - , tr ("Reset Decode Highlighting") - , tr ("Reset all decode highlighting and priorities to Default 2 values"))) + if (MessageBox::Yes == MessageBox::query_message (this + , tr ("Reset Decode Highlighting") + , confirmation)) { - next_decode_highlighing_model_.items (DecodeHighlightingModel::default_items2 ()); + next_decode_highlighing_model_.items (items); } } @@ -4675,11 +5083,11 @@ void Configuration::impl::after_hamlib_downloaded () { QDir dataPath = QCoreApplication::applicationDirPath(); QFile::rename(dataPath.absolutePath() + "/" + "libhamlib-4.dll", dataPath.absolutePath() + "/" + "libhamlib-4_old.dll"); - QTimer::singleShot (1000, [=] { + QTimer::singleShot (1000, this, [=] { QFile::rename(dataPath.absolutePath() + "/" + "libhamlib-4_new.dll", dataPath.absolutePath() + "/" + "libhamlib-4.dll"); ui_->in_use->setText("Download completed. Restart the program."); }); - QTimer::singleShot (1500, [=] { + QTimer::singleShot (1500, this, [=] { MessageBox::information_message (this, tr ("Hamlib Update successful \n\nNew Hamlib will be used after restart")); ui_->revert_update_button->setEnabled (true); ui_->hamlib_download_button->setEnabled (true); @@ -4695,10 +5103,10 @@ void Configuration::impl::on_revert_update_button_clicked (bool /*clicked*/) ui_->revert_update_button->setEnabled (false); ui_->hamlib_download_button->setEnabled (false); QFile::rename(dataPath.absolutePath() + "/" + "libhamlib-4.dll", dataPath.absolutePath() + "/" + "libhamlib-4_new.dll"); - QTimer::singleShot (1000, [=] { + QTimer::singleShot (1000, this, [=] { QFile::copy(dataPath.absolutePath() + "/" + "libhamlib-4_old.dll", dataPath.absolutePath() + "/" + "libhamlib-4.dll"); }); - QTimer::singleShot (2000, [=] { + QTimer::singleShot (2000, this, [=] { MessageBox::information_message (this, tr ("Hamlib successfully reverted \n\nReverted Hamlib will be used after restart")); ui_->revert_update_button->setEnabled (true); ui_->hamlib_download_button->setEnabled (true); @@ -4749,12 +5157,12 @@ void Configuration::impl::update_DXCC_control_availability () ui_->show_country_names_check_box->setEnabled (enabled); } -void Configuration::impl::on_PTT_port_combo_box_activated (int /* index */) +void Configuration::impl::on_PTT_port_combo_box_currentTextChanged (QString const& /* text */) { set_rig_invariants (); } -void Configuration::impl::on_CAT_port_combo_box_activated (int /* index */) +void Configuration::impl::on_CAT_port_combo_box_currentTextChanged (QString const& /* text */) { set_rig_invariants (); } @@ -4986,6 +5394,95 @@ void Configuration::impl::on_TCI_spin_box_valueChanged(double a) } +void Configuration::impl::on_grid_line_edit_editingFinished () +{ + double centre_lat, centre_lon; + if (!grid_centre (ui_->grid_line_edit->text (), centre_lat, centre_lon)) + { + update_home_coordinates_style (); + return; + } + auto grid = ui_->grid_line_edit->text ().trimmed ().left (6); + if (grid.size () < 6) grid += "mm"; + + // If the currently displayed precise coordinates already lie in this + // six-character square, re-entering the same locator must not discard + // their extra precision. + bool lat_ok {false}; + bool lon_ok {false}; + auto current_lat = ui_->latitude_line_edit->text ().toDouble (&lat_ok); + auto current_lon = ui_->longitude_line_edit->text ().toDouble (&lon_ok); + if (lat_ok && lon_ok && current_lat >= -90. && current_lat <= 90. + && current_lon >= -180. && current_lon <= 180.) + { + QString coordinate_grid; + coordinates_to_grid (current_lat, current_lon, coordinate_grid); + if (coordinate_grid.compare (grid, Qt::CaseInsensitive) == 0) + { + update_home_coordinates_style (); + return; + } + } + + ui_->latitude_line_edit->setText (QString::number (centre_lat, 'f', 6)); + ui_->longitude_line_edit->setText (QString::number (centre_lon, 'f', 6)); + update_home_coordinates_style (); +} + +void Configuration::impl::update_home_coordinates_style () +{ + // Highlight coordinates entered by the user; those derived from the + // centre of My Grid keep the normal appearance. + bool lat_ok {false}; + bool lon_ok {false}; + auto lat = ui_->latitude_line_edit->text ().toDouble (&lat_ok); + auto lon = ui_->longitude_line_edit->text ().toDouble (&lon_ok); + bool user_entered = lat_ok && lon_ok + && !coordinates_are_grid_centre (ui_->grid_line_edit->text (), lat, lon); + for (auto edit : {ui_->latitude_line_edit, ui_->longitude_line_edit}) + { + QPalette pal; + if (user_entered) + { + pal = edit->palette (); + pal.setColor (QPalette::Base, "#ffffcc"); + pal.setColor (QPalette::Text, Qt::black); + } + edit->setPalette (pal); + } + auto tip = user_entered ? tr ("Precise coordinates entered by user; used for astronomical calculations.") + : tr ("Centre of the My Grid locator; enter precise coordinates for more accurate astronomical calculations."); + ui_->latitude_line_edit->setToolTip (tr ("Home-station latitude in decimal degrees. North is positive; south is negative.") + '\n' + tip); + ui_->longitude_line_edit->setToolTip (tr ("Home-station longitude in decimal degrees. East is positive; west is negative.") + '\n' + tip); +} + +void Configuration::impl::on_latitude_line_edit_editingFinished () +{ + on_longitude_line_edit_editingFinished (); +} + +void Configuration::impl::on_longitude_line_edit_editingFinished () +{ + // Clearing both fields reverts to the My Grid position, so show it. + if (ui_->latitude_line_edit->text ().trimmed ().isEmpty () + && ui_->longitude_line_edit->text ().trimmed ().isEmpty ()) + { + on_grid_line_edit_editingFinished (); + return; + } + + bool lat_ok {false}; + bool lon_ok {false}; + auto lat = ui_->latitude_line_edit->text ().toDouble (&lat_ok); + auto lon = ui_->longitude_line_edit->text ().toDouble (&lon_ok); + if (!lat_ok || !lon_ok || lat < -90. || lat > 90. || lon < -180. || lon > 180.) return; + + QString grid; + if (!coordinates_to_grid (lat, lon, grid)) return; + ui_->grid_line_edit->setText (grid); + update_home_coordinates_style (); +} + void Configuration::impl::on_add_macro_line_edit_editingFinished () { ui_->add_macro_line_edit->setText (ui_->add_macro_line_edit->text ().toUpper ()); @@ -5306,7 +5803,34 @@ FrequencyList_v2_101::FrequencyItems Configuration::impl::read_frequencies_file { try { - list = FrequencyList_v2_101::from_json_file(&frequencies_file); + FrequencyList_v2_101::ImportReport report; + list = FrequencyList_v2_101::from_json_file (&frequencies_file, &report); + if (report.skipped ()) + { + QStringList reasons; + if (report.invalid_frequency) + reasons << tr ("Invalid frequency: %1").arg (report.invalid_frequency); + if (report.invalid_region) + reasons << tr ("Unknown region: %1").arg (report.invalid_region); + if (!report.unknown_modes.isEmpty ()) + { + QStringList examples; + int unknown_count = 0; + for (auto it = report.unknown_modes.cbegin (); it != report.unknown_modes.cend (); ++it) + { + unknown_count += it.value (); + if (examples.size () < 3) + examples << tr ("%1 (%2)").arg (it.key ()).arg (it.value ()); + } + reasons << tr ("Unknown mode: %1 (%2)").arg (unknown_count).arg (examples.join (", ")); + } + if (report.invalid_item) + reasons << tr ("Invalid dates: %1").arg (report.invalid_item); + MessageBox::warning_message (this, tr ("Some working frequencies were skipped"), + tr ("Imported %1 of %2 entries. Skipped %3:\n%4") + .arg (report.imported).arg (report.entries).arg (report.skipped ()) + .arg (reasons.join ("\n"))); + } } catch (ReadFileException const &e) { @@ -5414,6 +5938,61 @@ void Configuration::impl::reset_frequencies () next_frequencies_.reset_to_defaults (); } size_frequency_table_columns (); + refresh_suggestion_notice (); +} + +void Configuration::impl::persist_seen_suggestions () +{ + SettingsGroup g {settings_, "Configuration"}; + settings_->setValue ("SeenSuggestedFrequencyKeys", suggestion_notice_state_.seen_keys ()); +} + +void Configuration::impl::dismiss_suggestions () +{ + suggestion_notice_state_.dismiss (FrequencyList_v2_101::default_items ()); + persist_seen_suggestions (); + suggestions_notice_->hide (); +} + +void Configuration::impl::refresh_suggestion_notice () +{ + auto const visibility = suggestion_notice_state_.visibility ( + FrequencyList_v2_101::default_items (), next_frequencies_.frequency_list ()); + suggestions_notice_label_->setText ( + visibility == FrequencySuggestions::NoticeState::Visibility::New + ? tr ("New suggested frequencies are available. Choose any you want to add without resetting your list.") + : tr ("Suggested frequencies are available. Choose any you want to add without resetting your list.")); + suggestions_notice_->setVisible (visibility != FrequencySuggestions::NoticeState::Visibility::Hidden); +} + +void Configuration::impl::show_suggested_frequencies () +{ + QSet new_keys; + { + SettingsGroup g {settings_, "Configuration"}; + if (settings_->contains ("SeenSuggestedFrequencyKeys")) + { + auto const seen = settings_->value ("SeenSuggestedFrequencyKeys").toStringList (); + for (auto const& item : FrequencyList_v2_101::default_items ()) + { + auto const key = FrequencySuggestions::key (item); + if (!seen.contains (key)) new_keys.insert (key); + } + } + } + + SuggestedFrequenciesDialog dialog {FrequencyList_v2_101::default_items (), + next_frequencies_.frequency_list (), bands_, + new_keys, this}; + if (dialog.exec () == QDialog::Accepted) + { + auto additions = FrequencySuggestions::prepare_additions ( + dialog.selected_items (), next_frequencies_.frequency_list (), bands_); + suggestion_notice_state_.selected_additions (additions); + next_frequencies_.frequency_list_merge (additions); + size_frequency_table_columns (); + } + refresh_suggestion_notice (); } void Configuration::impl::insert_frequency () @@ -6014,11 +6593,15 @@ bool Configuration::impl::open_rig (bool force) close_rig (); auto const txvolume = cached_rig_state_.txvolume (); + auto const receive_policy = cached_rig_state_.receive_policy (); + auto const receive_context = cached_rig_state_.receive_context (); // create a new Transceiver object auto rig = transceiver_factory_.create (rig_data, transceiver_thread_); cached_rig_state_ = Transceiver::TransceiverState {}; cached_rig_state_.txvolume (txvolume); + cached_rig_state_.receive_policy (receive_policy); + cached_rig_state_.receive_context (receive_context); // hook up Configuration transceiver control signals to Transceiver slots // @@ -6029,6 +6612,12 @@ bool Configuration::impl::open_rig (bool force) rig.get (), &Transceiver::enqueue_jtty_pcm); rig_connections_ << connect (this, &Configuration::impl::clear_jtty_pcm, rig.get (), &Transceiver::clear_jtty_pcm); + rig_connections_ << connect (this, &Configuration::impl::receive_discontinuity, + rig.get (), &Transceiver::receive_discontinuity); + rig_connections_ << connect (this, &Configuration::impl::receive_stop_reason, + rig.get (), &Transceiver::receive_stop_reason); + rig_connections_ << connect (this, &Configuration::impl::receive_drain, + rig.get (), &Transceiver::requestContinuousReceiveDrain); // hook up Transceiver signals to Configuration signals // @@ -6038,10 +6627,17 @@ bool Configuration::impl::open_rig (bool force) }); rig_connections_ << connect (rig.get (), &Transceiver::tciframeswritten, this, &Configuration::impl::handle_transceiver_tciframeswritten); rig_connections_ << connect (rig.get (), &Transceiver::receiveAudio, self_, &Configuration::transceiverReceiveAudio); + rig_connections_ << connect (rig.get (), &Transceiver::continuousAudioAvailable, + self_, &Configuration::continuousAudioAvailable); + rig_connections_ << connect (rig.get (), &Transceiver::continuousReceptionStopped, + self_, &Configuration::continuousReceptionStopped); + rig_connections_ << connect (rig.get (), &Transceiver::continuousReceiveDrained, + self_, &Configuration::continuousReceiveDrained); rig_connections_ << connect (rig.get (), &Transceiver::tci_mod_active, this, &Configuration::impl::handle_transceiver_tci_mod_active); rig_connections_ << connect (rig.get (), &Transceiver::txSourceCommitted, self_, &Configuration::txSourceCommitted); rig_connections_ << connect (rig.get (), &Transceiver::rawTxPlayoutSnapshot, self_, &Configuration::rawTxPlayoutSnapshot); rig_connections_ << connect (rig.get (), &Transceiver::jtty_drained, self_, &Configuration::transceiver_jtty_drained); + rig_connections_ << connect (rig.get (), &Transceiver::jtty_progress, self_, &Configuration::transceiver_jtty_progress); rig_connections_ << connect (rig.get (), &Transceiver::jtty_enqueue_accepted, self_, &Configuration::transceiver_jtty_enqueue_accepted); rig_connections_ << connect (rig.get (), &Transceiver::jtty_enqueue_failed, self_, &Configuration::transceiver_jtty_enqueue_failed); rig_connections_ << connect (rig.get (), &Transceiver::update, this, &Configuration::impl::handle_transceiver_update); @@ -6360,6 +6956,14 @@ void Configuration::impl::transceiver_enqueue_jtty_pcm (QByteArray const& sample TxAudioQueueEpoch epoch, qint64 enqueueId) { + if (!can_control_rig ("transceiver_enqueue_jtty_pcm")) + { + // Without an active transceiver nothing consumes the enqueue signal. + // Report the failure so the submission is rejected instead of hanging. + Q_EMIT self_->transceiver_jtty_enqueue_failed ( + epoch, enqueueId, TxAudioQueueEnqueueFailure::BackendUnavailable); + return; + } Q_EMIT enqueue_jtty_pcm (samples, epoch, enqueueId); } @@ -6791,26 +7395,8 @@ void Configuration::impl::fill_port_combo_box(QComboBox* cb) } } - // Sort ports by the numeric value of the port name, if possible std::sort(ports.begin(), ports.end(), [](const QSerialPortInfo& a, const QSerialPortInfo& b) { - bool isANumeric = a.portName().midRef(3).toInt(); - bool isBNumeric = b.portName().midRef(3).toInt(); - if (isANumeric && isBNumeric) - { - return a.portName().midRef(3).toInt() < b.portName().midRef(3).toInt(); - } - else if (isANumeric) - { - return true; // a comes before b - } - else if (isBNumeric) - { - return false; // b comes before a - } - else - { - return a.portName() < b.portName(); // Alphabetical order for non-numeric ports - } + return serial_port_name_less(a.portName(), b.portName()); }); // Add sorted ports to the combo box @@ -6826,8 +7412,6 @@ void Configuration::impl::fill_port_combo_box(QComboBox* cb) } } - cb->addItem("USB"); - cb->setItemData(cb->count() - 1, "Custom USB device", Qt::ToolTipRole); cb->setEditText(current_text); } -- cgit v1.2.3