1 #ifndef CONFIGURATION_HPP_ 2 #define CONFIGURATION_HPP_ 3 4 #include <QObject> 5 #include <QFont> 6 #include <QString> 7 8 #include "Radio.hpp" 9 #include "models/IARURegions.hpp" 10 #include "Audio/AudioDevice.hpp" 11 #include "Transceiver/Transceiver.hpp" 12 13 #include "pimpl_h.hpp" 14 15 class QSettings; 16 class QWidget; 17 class QAudioDeviceInfo; 18 class QDir; 19 class QNetworkAccessManager; 20 class Bands; 21 class FrequencyList_v2; 22 class StationList; 23 class QStringListModel; 24 class LotWUsers; 25 class DecodeHighlightingModel; 26 class LogBook; 27 28 // 29 // Class Configuration 30 // 31 // Encapsulates the control, access and, persistence of user defined 32 // settings for the wsjtx GUI. Setting values are accessed through a 33 // QDialog window containing concept orientated tab windows. 34 // 35 // Responsibilities 36 // 37 // Provides management of the CAT and PTT rig interfaces, providing 38 // control access via a minimal generic set of Qt slots and status 39 // updates via Qt signals. Internally the rig control capability is 40 // farmed out to a separate thread since many of the rig control 41 // functions are blocking. 42 // 43 // All user settings required by the wsjtx GUI are exposed through 44 // query methods. Settings only become visible once they have been 45 // accepted by the user which is done by clicking the "OK" button on 46 // the settings dialog. 47 // 48 // The QSettings instance passed to the constructor is used to read 49 // and write user settings. 50 // 51 // Pointers to three QAbstractItemModel objects are provided to give 52 // access to amateur band information, user working frequencies and, 53 // user operating band information. These porovide consistent data 54 // models that can be used in GUI lists or tables or simply queried 55 // for user defined bands, default operating frequencies and, station 56 // descriptions. 57 // 58 class Configuration final 59 : public QObject 60 { 61 Q_OBJECT 62 63 public: 64 using MODE = Transceiver::MODE; 65 using TransceiverState = Transceiver::TransceiverState; 66 using Frequency = Radio::Frequency; 67 using port_type = quint16; 68 69 enum DataMode {data_mode_none, data_mode_USB, data_mode_data}; 70 Q_ENUM (DataMode) 71 enum Type2MsgGen {type_2_msg_1_full, type_2_msg_3_full, type_2_msg_5_only}; 72 Q_ENUM (Type2MsgGen) 73 74 explicit Configuration (QNetworkAccessManager *, QDir const& temp_directory, QSettings * settings, 75 LogBook * logbook, QWidget * parent = nullptr); 76 ~Configuration (); 77 78 void select_tab (int); 79 int exec (); 80 bool is_active () const; 81 82 QDir temp_dir () const; 83 QDir doc_dir () const; 84 QDir data_dir () const; 85 QDir writeable_data_dir () const; 86 87 QAudioDeviceInfo const& audio_input_device () const; 88 AudioDevice::Channel audio_input_channel () const; 89 QAudioDeviceInfo const& audio_output_device () const; 90 AudioDevice::Channel audio_output_channel () const; 91 92 // These query methods should be used after a call to exec() to 93 // determine if either the audio input or audio output stream 94 // parameters have changed. The respective streams should be 95 // re-opened if they return true. 96 bool restart_audio_input () const; 97 bool restart_audio_output () const; 98 99 QString my_callsign () const; 100 QString my_grid () const; 101 QString Field_Day_Exchange() const; 102 QString RTTY_Exchange() const; 103 void setEU_VHF_Contest(); 104 QFont text_font () const; 105 QFont decoded_text_font () const; 106 qint32 id_interval () const; 107 qint32 ntrials() const; 108 qint32 aggressive() const; 109 qint32 RxBandwidth() const; 110 double degrade() const; 111 double txDelay() const; 112 bool id_after_73 () const; 113 bool tx_QSY_allowed () const; 114 bool spot_to_psk_reporter () const; 115 bool psk_reporter_tcpip () const; 116 bool monitor_off_at_startup () const; 117 bool monitor_last_used () const; 118 bool log_as_RTTY () const; 119 bool report_in_comments () const; 120 bool prompt_to_log () const; 121 bool autoLog() const; 122 bool decodes_from_top () const; 123 bool insert_blank () const; 124 bool DXCC () const; 125 bool ppfx() const; 126 bool clear_DX () const; 127 bool miles () const; 128 bool quick_call () const; 129 bool disable_TX_on_73 () const; 130 bool force_call_1st() const; 131 bool alternate_bindings() const; 132 int watchdog () const; 133 bool TX_messages () const; 134 bool split_mode () const; 135 bool enable_VHF_features () const; 136 bool decode_at_52s () const; 137 bool single_decode () const; 138 bool twoPass() const; 139 bool bFox() const; 140 bool bHound() const; 141 bool bLowSidelobes() const; 142 bool x2ToneSpacing() const; 143 bool x4ToneSpacing() const; 144 bool MyDx() const; 145 bool CQMyN() const; 146 bool NDxG() const; 147 bool NN() const; 148 bool EMEonly() const; 149 bool post_decodes () const; 150 QString opCall() const; 151 void opCall (QString const&); 152 QString udp_server_name () const; 153 port_type udp_server_port () const; 154 QStringList udp_interface_names () const; 155 int udp_TTL () const; 156 QString n1mm_server_name () const; 157 port_type n1mm_server_port () const; 158 bool valid_n1mm_info () const; 159 bool broadcast_to_n1mm() const; 160 bool lowSidelobes() const; 161 bool accept_udp_requests () const; 162 bool udpWindowToFront () const; 163 bool udpWindowRestore () const; 164 Bands * bands (); 165 Bands const * bands () const; 166 IARURegions::Region region () const; 167 FrequencyList_v2 * frequencies (); 168 FrequencyList_v2 const * frequencies () const; 169 StationList * stations (); 170 StationList const * stations () const; 171 QStringListModel * macros (); 172 QStringListModel const * macros () const; 173 QDir save_directory () const; 174 QDir azel_directory () const; 175 QString rig_name () const; 176 Type2MsgGen type_2_msg_gen () const; 177 bool pwrBandTxMemory () const; 178 bool pwrBandTuneMemory () const; 179 LotWUsers const& lotw_users () const; 180 DecodeHighlightingModel const& decode_highlighting () const; 181 bool highlight_by_mode () const; 182 bool highlight_only_fields () const; 183 bool include_WAE_entities () const; 184 // Z 185 QString qrzComUn () const; 186 QString qrzComPw () const; 187 bool disableWriteALL() const; 188 bool disableWriteFoxQSO() const; 189 bool colourAll() const; 190 bool autoCQfiltering() const; 191 bool rxTotxFreq() const; 192 bool udpFiltering() const; 193 bool highlightDX() const; 194 void setSpecial_Hound() ; 195 void setSpecial_Fox() ; 196 void setSpecial_None() ; 197 bool dbgScreen () const; 198 bool dbgFile () const; 199 bool dbgBoth () const; 200 bool wdResetAnywhere() const; 201 int wd_FT8() const ; 202 int wd_FT4() const; 203 bool wd_Timer() const; 204 bool processTailenders() const; 205 QString permIgnoreList() const; 206 bool showDistance() const ; 207 bool showBearing() const ; 208 bool autoTune() const; 209 bool showState() const; 210 bool rawViewDXCC() const; 211 bool clearRX() const; 212 int ignoreListReset() const; 213 QString separatorColor() const; 214 215 enum class SpecialOperatingActivity {NONE, NA_VHF, EU_VHF, FIELD_DAY, RTTY, WW_DIGI, FOX, HOUND}; 216 SpecialOperatingActivity special_op_id () const; 217 218 struct CalibrationParams 219 { CalibrationParamsConfiguration::CalibrationParams220 CalibrationParams () 221 : intercept {0.} 222 , slope_ppm {0.} 223 { 224 } 225 CalibrationParamsConfiguration::CalibrationParams226 CalibrationParams (double the_intercept, double the_slope_ppm) 227 : intercept {the_intercept} 228 , slope_ppm {the_slope_ppm} 229 { 230 } 231 232 double intercept; // Hertz 233 double slope_ppm; // Hertz 234 }; 235 236 // Temporarily enable or disable calibration adjustments. 237 void enable_calibration (bool = true); 238 239 // Set the calibration parameters and enable calibration corrections. 240 void set_calibration (CalibrationParams); 241 242 // Set the dynamic grid which is only used if configuration setting is enabled. 243 void set_location (QString const&); 244 245 // This method queries if a CAT and PTT connection is operational. 246 bool is_transceiver_online () const; 247 248 // Start the rig connection, safe and normal to call when rig is 249 // already open. 250 bool transceiver_online (); 251 252 // check if a real rig is configured 253 bool is_dummy_rig () const; 254 255 // Frequency resolution of the rig 256 // 257 // 0 - 1Hz 258 // 1 - 10Hz rounded 259 // -1 - 10Hz truncated 260 // 2 - 100Hz rounded 261 // -2 - 100Hz truncated 262 int transceiver_resolution () const; 263 264 // Close down connection to rig. 265 void transceiver_offline (); 266 267 // Set transceiver frequency in Hertz. 268 Q_SLOT void transceiver_frequency (Frequency); 269 270 // Setting a non zero TX frequency means split operation 271 // rationalise_mode means ensure TX uses same mode as RX. 272 Q_SLOT void transceiver_tx_frequency (Frequency = 0u); 273 274 // Set transceiver mode. 275 Q_SLOT void transceiver_mode (MODE); 276 277 // Set/unset PTT. 278 // 279 // Note that this must be called even if VOX PTT is selected since 280 // the "Emulate Split" mode requires PTT information to coordinate 281 // frequency changes. 282 Q_SLOT void transceiver_ptt (bool = true); 283 284 // Attempt to (re-)synchronise transceiver state. 285 // 286 // Force signal guarantees either a transceiver_update or a 287 // transceiver_failure signal. 288 // 289 // The enforce_mode_and_split parameter ensures that future 290 // transceiver updates have the correct mode and split setting 291 // i.e. the transceiver is ready for use. 292 Q_SLOT void sync_transceiver (bool force_signal = false, bool enforce_mode_and_split = false); 293 294 Q_SLOT void invalidate_audio_input_device (QString error); 295 Q_SLOT void invalidate_audio_output_device (QString error); 296 297 // 298 // These signals indicate a font has been selected and accepted for 299 // the application text and decoded text respectively. 300 // 301 Q_SIGNAL void text_font_changed (QFont) const; 302 Q_SIGNAL void decoded_text_font_changed (QFont) const; 303 304 // 305 // This signal is emitted when the UDP server changes 306 // 307 Q_SIGNAL void udp_server_changed (QString& udp_server_name, QStringList const& network_interfaces) const; 308 Q_SIGNAL void udp_server_port_changed (port_type server_port) const; 309 Q_SIGNAL void udp_TTL_changed (int TTL) const; 310 Q_SIGNAL void accept_udp_requests_changed (bool checked) const; 311 312 // signal updates to decode highlighting 313 Q_SIGNAL void decode_highlighting_changed (DecodeHighlightingModel const&) const; 314 315 // 316 // These signals are emitted and reflect transceiver state changes 317 // 318 319 // signals a change in one of the TransceiverState members 320 Q_SIGNAL void transceiver_update (Transceiver::TransceiverState const&) const; 321 322 // Signals a failure of a control rig CAT or PTT connection. 323 // 324 // A failed rig CAT or PTT connection is fatal and the underlying 325 // connections are closed automatically. The connections can be 326 // re-established with a call to transceiver_online(true) assuming 327 // the fault condition has been rectified or is transient. 328 Q_SIGNAL void transceiver_failure (QString const& reason) const; 329 330 // signal announces audio devices are being enumerated 331 // 332 // As this can take some time, particularly on Linux, consumers 333 // might like to notify the user. 334 Q_SIGNAL void enumerating_audio_devices (); 335 336 // Z 337 Q_SIGNAL void qrz_config_changed () const; 338 339 private: 340 class impl; 341 pimpl<impl> m_; 342 }; 343 344 ENUM_QDATASTREAM_OPS_DECL (Configuration, DataMode); 345 ENUM_QDATASTREAM_OPS_DECL (Configuration, Type2MsgGen); 346 347 ENUM_CONVERSION_OPS_DECL (Configuration, DataMode); 348 ENUM_CONVERSION_OPS_DECL (Configuration, Type2MsgGen); 349 350 #endif 351