-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cpp
2718 lines (2390 loc) · 104 KB
/
Configuration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Configuration.hpp"
//
// Read me!
//
// This file defines a configuration dialog with the user. The general
// strategy is to expose agreed configuration parameters via a custom
// interface (See Configuration.hpp). The state exposed through this
// public interface reflects stored or derived data in the
// Configuration::impl object. The Configuration::impl structure is
// an implementation of the PIMPL (a.k.a. Cheshire Cat or compilation
// firewall) implementation hiding idiom that allows internal state to
// be completely removed from the public interface.
//
// There is a secondary level of parameter storage which reflects
// current settings UI state, these parameters are not copied to the
// state store that the public interface exposes until the
// Configuration:impl::accept() operation is successful. The accept()
// operation is tied to the settings OK button. The normal and most
// convenient place to store this intermediate settings UI state is in
// the data models of the UI controls, if that is not convenient then
// separate member variables must be used to store that state. It is
// important for the user experience that no publicly visible settings
// are changed while the settings UI are changed i.e. all settings
// changes must be deferred until the "OK" button is
// clicked. Conversely, all changes must be discarded if the settings
// UI "Cancel" button is clicked.
//
// There is a complication related to the radio interface since the
// this module offers the facility to test the radio interface. This
// test means that the public visibility to the radio being tested
// must be changed. To maintain the illusion of deferring changes
// until they are accepted, the original radio related settings are
// stored upon showing the UI and restored if the UI is dismissed by
// canceling.
//
// It should be noted that the settings UI lives as long as the
// application client that uses it does. It is simply shown and hidden
// as it is needed rather than creating it on demand. This strategy
// saves a lot of expensive UI drawing at the expense of a little
// storage and gives a convenient place to deliver settings values
// from.
//
// Here is an overview of the high level flow of this module:
//
// 1) On construction the initial environment is initialized and
// initial values for settings are read from the QSettings
// database. At this point default values for any new settings are
// established by providing a default value to the QSettings value
// queries. This should be the only place where a hard coded value for
// a settings item is defined. Any remaining one-time UI
// initialization is also done. At the end of the constructor a method
// initialize_models() is called to load the UI with the current
// settings values.
//
// 2) When the settings UI is displayed by a client calling the exec()
// operation, only temporary state need be stored as the UI state will
// already mirror the publicly visible settings state.
//
// 3) As the user makes changes to the settings UI only validation
// need be carried out since the UI control data models are used as
// the temporary store of unconfirmed settings. As some settings will
// depend on each other a validate() operation is available, this
// operation implements a check of any complex multi-field values.
//
// 4) If the user discards the settings changes by dismissing the UI
// with the "Cancel" button; the reject() operation is called. The
// reject() operation calls initialize_models() which will revert all
// the UI visible state to the values as at the initial exec()
// operation. No changes are moved into the data fields in
// Configuration::impl that reflect the settings state published by
// the public interface (Configuration.hpp).
//
// 5) If the user accepts the settings changes by dismissing the UI
// with the "OK" button; the accept() operation is called which calls
// the validate() operation again and, if it passes, the fields that
// are used to deliver the settings state are updated from the UI
// control models or other temporary state variables. At the end of
// the accept() operation, just before hiding the UI and returning
// control to the caller; the new settings values are stored into the
// settings database by a call to the write_settings() operation, thus
// ensuring that settings changes are saved even if the application
// crashes or is subsequently killed.
//
// 6) On destruction, which only happens when the application
// terminates, the settings are saved to the settings database by
// calling the write_settings() operation. This is largely redundant
// but is still done to save the default values of any new settings on
// an initial run.
//
// To add a new setting:
//
// 1) Update the UI with the new widget to view and change the value.
//
// 2) Add a member to Configuration::impl to store the accepted
// setting state. If the setting state is dynamic; add a new signal to
// broadcast the setting value.
//
// 3) Add a query method to the public interface (Configuration.hpp)
// to access the new setting value. If the settings is dynamic; this
// step is optional since value changes will be broadcast via a
// signal.
//
// 4) Add a forwarding operation to implement the new query (3) above.
//
// 5) Add a settings read call to read_settings() with a sensible
// default value. If the setting value is dynamic, add a signal emit
// call to broadcast the setting value change.
//
// 6) Add code to initialize_models() to load the widget control's
// data model with the current value.
//
// 7) If there is no convenient data model field, add a data member to
// store the proposed new value. Ensure this member has a valid value
// on exit from read_settings().
//
// 8) Add any required inter-field validation to the validate()
// operation.
//
// 9) Add code to the accept() operation to extract the setting value
// from the widget control data model and load it into the
// Configuration::impl member that reflects the publicly visible
// setting state. If the setting value is dynamic; add a signal emit
// call to broadcast any changed state of the setting.
//
// 10) Add a settings write call to save the setting value to the
// settings database.
//
#include <stdexcept>
#include <iterator>
#include <algorithm>
#include <functional>
#include <limits>
#include <cmath>
#include <QApplication>
#include <QMetaType>
#include <QList>
#include <QSettings>
#include <QAudioDeviceInfo>
#include <QAudioInput>
#include <QDialog>
#include <QAction>
#include <QFileDialog>
#include <QDir>
#include <QTemporaryFile>
#include <QFormLayout>
#include <QString>
#include <QStringList>
#include <QStringListModel>
#include <QLineEdit>
#include <QRegExpValidator>
#include <QIntValidator>
#include <QThread>
#include <QTimer>
#include <QStandardPaths>
#include <QFont>
#include <QFontDialog>
#include <QColorDialog>
#include <QSerialPortInfo>
#include <QScopedPointer>
#include <QDebug>
#include <QProcess>
#include "pimpl_impl.hpp"
#include "qt_helpers.hpp"
#include "MetaDataRegistry.hpp"
#include "SettingsGroup.hpp"
#include "FrequencyLineEdit.hpp"
#include "CandidateKeyFilter.hpp"
#include "ForeignKeyDelegate.hpp"
#include "TransceiverFactory.hpp"
#include "Transceiver.hpp"
#include "Bands.hpp"
#include "IARURegions.hpp"
#include "Modes.hpp"
#include "FrequencyList.hpp"
#include "StationList.hpp"
#include "NetworkServerLookup.hpp"
#include "MessageBox.hpp"
#include "MaidenheadLocatorValidator.hpp"
#include "CallsignValidator.hpp"
#include "ui_Configuration.h"
#include "moc_Configuration.cpp"
namespace
{
// these undocumented flag values when stored in (Qt::UserRole - 1)
// of a ComboBox item model index allow the item to be enabled or
// disabled
int const combo_box_item_enabled (32 | 1);
int const combo_box_item_disabled (0);
// QRegExp message_alphabet {"[- A-Za-z0-9+./?]*"};
QRegExp message_alphabet {"[- @A-Za-z0-9+./?#<>]*"};
// Magic numbers for file validation
constexpr quint32 qrg_magic {0xadbccbdb};
constexpr quint32 qrg_version {100}; // M.mm
}
//
// Dialog to get a new Frequency item
//
class FrequencyDialog final
: public QDialog
{
public:
using Item = FrequencyList_v2::Item;
explicit FrequencyDialog (IARURegions * regions_model, Modes * modes_model, QWidget * parent = nullptr)
: QDialog {parent}
{
setWindowTitle (QApplication::applicationName () + " - " +
tr ("Add Frequency"));
region_combo_box_.setModel (regions_model);
mode_combo_box_.setModel (modes_model);
auto form_layout = new QFormLayout ();
form_layout->addRow (tr ("IARU &Region:"), ®ion_combo_box_);
form_layout->addRow (tr ("&Mode:"), &mode_combo_box_);
form_layout->addRow (tr ("&Frequency (MHz):"), &frequency_line_edit_);
auto main_layout = new QVBoxLayout (this);
main_layout->addLayout (form_layout);
auto button_box = new QDialogButtonBox {QDialogButtonBox::Ok | QDialogButtonBox::Cancel};
main_layout->addWidget (button_box);
connect (button_box, &QDialogButtonBox::accepted, this, &FrequencyDialog::accept);
connect (button_box, &QDialogButtonBox::rejected, this, &FrequencyDialog::reject);
}
Item item () const
{
return {frequency_line_edit_.frequency ()
, Modes::value (mode_combo_box_.currentText ())
, IARURegions::value (region_combo_box_.currentText ())};
}
private:
QComboBox region_combo_box_;
QComboBox mode_combo_box_;
FrequencyLineEdit frequency_line_edit_;
};
//
// Dialog to get a new Station item
//
class StationDialog final
: public QDialog
{
public:
explicit StationDialog (StationList const * stations, Bands * bands, QWidget * parent = nullptr)
: QDialog {parent}
, filtered_bands_ {new CandidateKeyFilter {bands, stations, 0, 0}}
{
setWindowTitle (QApplication::applicationName () + " - " + tr ("Add Station"));
band_.setModel (filtered_bands_.data ());
auto form_layout = new QFormLayout ();
form_layout->addRow (tr ("&Band:"), &band_);
form_layout->addRow (tr ("&Offset (MHz):"), &delta_);
form_layout->addRow (tr ("&Antenna:"), &description_);
auto main_layout = new QVBoxLayout (this);
main_layout->addLayout (form_layout);
auto button_box = new QDialogButtonBox {QDialogButtonBox::Ok | QDialogButtonBox::Cancel};
main_layout->addWidget (button_box);
connect (button_box, &QDialogButtonBox::accepted, this, &StationDialog::accept);
connect (button_box, &QDialogButtonBox::rejected, this, &StationDialog::reject);
if (delta_.text ().isEmpty ())
{
delta_.setText ("0");
}
}
StationList::Station station () const
{
return {band_.currentText (), delta_.frequency_delta (), description_.text ()};
}
int exec () override
{
filtered_bands_->set_active_key ();
return QDialog::exec ();
}
private:
QScopedPointer<CandidateKeyFilter> filtered_bands_;
QComboBox band_;
FrequencyDeltaLineEdit delta_;
QLineEdit description_;
};
class RearrangableMacrosModel
: public QStringListModel
{
public:
Qt::ItemFlags flags (QModelIndex const& index) const override
{
auto flags = QStringListModel::flags (index);
if (index.isValid ())
{
// disallow drop onto existing items
flags &= ~Qt::ItemIsDropEnabled;
}
return flags;
}
};
//
// Class MessageItemDelegate
//
// Item delegate for message entry such as free text message macros.
//
class MessageItemDelegate final
: public QStyledItemDelegate
{
public:
explicit MessageItemDelegate (QObject * parent = nullptr)
: QStyledItemDelegate {parent}
{
}
QWidget * createEditor (QWidget * parent
, QStyleOptionViewItem const& /* option*/
, QModelIndex const& /* index */
) const override
{
auto editor = new QLineEdit {parent};
editor->setFrame (false);
editor->setValidator (new QRegExpValidator {message_alphabet, editor});
return editor;
}
};
// Internal implementation of the Configuration class.
class Configuration::impl final
: public QDialog
{
Q_OBJECT;
public:
using FrequencyDelta = Radio::FrequencyDelta;
using port_type = Configuration::port_type;
explicit impl (Configuration * self, QDir const& temp_directory,
QSettings * settings, QWidget * parent);
~impl ();
bool have_rig ();
void transceiver_frequency (Frequency);
void transceiver_tx_frequency (Frequency);
void transceiver_mode (MODE);
void transceiver_ptt (bool);
void sync_transceiver (bool force_signal);
Q_SLOT int exec () override;
Q_SLOT void accept () override;
Q_SLOT void reject () override;
Q_SLOT void done (int) override;
private:
typedef QList<QAudioDeviceInfo> AudioDevices;
void read_settings ();
void write_settings ();
bool load_audio_devices (QAudio::Mode, QComboBox *, QAudioDeviceInfo *);
void update_audio_channels (QComboBox const *, int, QComboBox *, bool);
void initialize_models ();
bool split_mode () const
{
return
(WSJT_RIG_NONE_CAN_SPLIT || !rig_is_dummy_) &&
(rig_params_.split_mode != TransceiverFactory::split_mode_none);
}
void set_cached_mode ();
bool open_rig (bool force = false);
//bool set_mode ();
void close_rig ();
TransceiverFactory::ParameterPack gather_rig_data ();
void enumerate_rigs ();
void set_rig_invariants ();
bool validate ();
void fill_port_combo_box (QComboBox *);
Frequency apply_calibration (Frequency) const;
Frequency remove_calibration (Frequency) const;
void delete_frequencies ();
void load_frequencies ();
void merge_frequencies ();
void save_frequencies ();
void reset_frequencies ();
void insert_frequency ();
FrequencyList_v2::FrequencyItems read_frequencies_file (QString const&);
void delete_stations ();
void insert_station ();
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_CAT_serial_baud_combo_box_currentIndexChanged (int);
Q_SLOT void on_CAT_data_bits_button_group_buttonClicked (int);
Q_SLOT void on_CAT_stop_bits_button_group_buttonClicked (int);
Q_SLOT void on_CAT_handshake_button_group_buttonClicked (int);
Q_SLOT void on_CAT_poll_interval_spin_box_valueChanged (int);
Q_SLOT void on_split_mode_button_group_buttonClicked (int);
Q_SLOT void on_test_CAT_push_button_clicked ();
Q_SLOT void on_test_PTT_push_button_clicked (bool checked);
Q_SLOT void on_force_DTR_combo_box_currentIndexChanged (int);
Q_SLOT void on_force_RTS_combo_box_currentIndexChanged (int);
Q_SLOT void on_rig_combo_box_currentIndexChanged (int);
Q_SLOT void on_sound_input_combo_box_currentTextChanged (QString const&);
Q_SLOT void on_sound_output_combo_box_currentTextChanged (QString const&);
Q_SLOT void on_add_macro_push_button_clicked (bool = false);
Q_SLOT void on_delete_macro_push_button_clicked (bool = false);
Q_SLOT void on_PTT_method_button_group_buttonClicked (int);
Q_SLOT void on_add_macro_line_edit_editingFinished ();
Q_SLOT void delete_macro ();
void delete_selected_macros (QModelIndexList);
Q_SLOT void on_save_path_select_push_button_clicked (bool);
Q_SLOT void on_azel_path_select_push_button_clicked (bool);
Q_SLOT void on_calibration_intercept_spin_box_valueChanged (double);
Q_SLOT void on_calibration_slope_ppm_spin_box_valueChanged (double);
Q_SLOT void handle_transceiver_update (TransceiverState const&, unsigned sequence_number);
Q_SLOT void handle_transceiver_failure (QString const& reason);
Q_SLOT void on_pbCQmsg_clicked();
Q_SLOT void on_pbMyCall_clicked();
Q_SLOT void on_pbTxMsg_clicked();
Q_SLOT void on_pbNewDXCC_clicked();
Q_SLOT void on_pbNewCall_clicked();
//for RPI by KD8CEC
Q_SLOT void on_btnKeyboard1_clicked();
// typenames used as arguments must match registered type names :(
Q_SIGNAL void start_transceiver (unsigned seqeunce_number) const;
Q_SIGNAL void set_transceiver (Transceiver::TransceiverState const&,
unsigned sequence_number) const;
Q_SIGNAL void stop_transceiver () const;
Configuration * const self_; // back pointer to public interface
QThread * transceiver_thread_;
TransceiverFactory transceiver_factory_;
QList<QMetaObject::Connection> rig_connections_;
QScopedPointer<Ui::configuration_dialog> ui_;
QSettings * settings_;
QDir doc_dir_;
QDir data_dir_;
QDir temp_dir_;
QDir writeable_data_dir_;
QDir default_save_directory_;
QDir save_directory_;
QDir default_azel_directory_;
QDir azel_directory_;
QFont font_;
QFont next_font_;
QFont decoded_text_font_;
QFont next_decoded_text_font_;
bool restart_sound_input_device_;
bool restart_sound_output_device_;
Type2MsgGen type_2_msg_gen_;
QStringListModel macros_;
RearrangableMacrosModel next_macros_;
QAction * macro_delete_action_;
Bands bands_;
IARURegions regions_;
IARURegions::Region region_;
Modes modes_;
FrequencyList_v2 frequencies_;
FrequencyList_v2 next_frequencies_;
StationList stations_;
StationList next_stations_;
FrequencyDelta current_offset_;
FrequencyDelta current_tx_offset_;
QAction * frequency_delete_action_;
QAction * frequency_insert_action_;
QAction * load_frequencies_action_;
QAction * save_frequencies_action_;
QAction * merge_frequencies_action_;
QAction * reset_frequencies_action_;
FrequencyDialog * frequency_dialog_;
QAction * station_delete_action_;
QAction * station_insert_action_;
StationDialog * station_dialog_;
TransceiverFactory::ParameterPack rig_params_;
TransceiverFactory::ParameterPack saved_rig_params_;
TransceiverFactory::Capabilities::PortType last_port_type_;
bool rig_is_dummy_;
bool rig_active_;
bool have_rig_;
bool rig_changed_;
TransceiverState cached_rig_state_;
int rig_resolution_; // see Transceiver::resolution signal
CalibrationParams calibration_;
bool frequency_calibration_disabled_; // not persistent
unsigned transceiver_command_number_;
// configuration fields that we publish
QString my_callsign_;
QString my_grid_;
QColor color_CQ_;
QColor next_color_CQ_;
QColor color_MyCall_;
QColor next_color_MyCall_;
QColor color_TxMsg_;
QColor next_color_TxMsg_;
QColor color_DXCC_;
QColor next_color_DXCC_;
QColor color_NewCall_;
QColor next_color_NewCall_;
qint32 id_interval_;
qint32 ntrials_;
qint32 aggressive_;
qint32 RxBandwidth_;
double degrade_;
double txDelay_;
bool id_after_73_;
bool tx_QSY_allowed_;
bool spot_to_psk_reporter_;
bool monitor_off_at_startup_;
bool monitor_last_used_;
bool log_as_RTTY_;
bool report_in_comments_;
bool prompt_to_log_;
bool insert_blank_;
bool DXCC_;
bool clear_DX_;
bool miles_;
bool quick_call_;
bool disable_TX_on_73_;
int watchdog_;
bool TX_messages_;
bool enable_VHF_features_;
bool decode_at_52s_;
bool single_decode_;
bool twoPass_;
bool x2ToneSpacing_;
bool realTimeDecode_;
QString udp_server_name_;
port_type udp_server_port_;
bool accept_udp_requests_;
bool udpWindowToFront_;
bool udpWindowRestore_;
DataMode data_mode_;
bool pwrBandTxMemory_;
bool pwrBandTuneMemory_;
QAudioDeviceInfo audio_input_device_;
bool default_audio_input_device_selected_;
AudioDevice::Channel audio_input_channel_;
QAudioDeviceInfo audio_output_device_;
bool default_audio_output_device_selected_;
AudioDevice::Channel audio_output_channel_;
friend class Configuration;
};
#include "Configuration.moc"
// delegate to implementation class
Configuration::Configuration (QDir const& temp_directory,
QSettings * settings, QWidget * parent)
: m_ {this, temp_directory, settings, parent}
{
}
Configuration::~Configuration ()
{
}
QDir Configuration::doc_dir () const {return m_->doc_dir_;}
QDir Configuration::data_dir () const {return m_->data_dir_;}
QDir Configuration::writeable_data_dir () const {return m_->writeable_data_dir_;}
QDir Configuration::temp_dir () const {return m_->temp_dir_;}
void Configuration::select_tab (int index) {m_->ui_->configuration_tabs->setCurrentIndex (index);}
int Configuration::exec () {return m_->exec ();}
bool Configuration::is_active () const {return m_->isVisible ();}
QAudioDeviceInfo const& Configuration::audio_input_device () const {return m_->audio_input_device_;}
AudioDevice::Channel Configuration::audio_input_channel () const {return m_->audio_input_channel_;}
QAudioDeviceInfo const& Configuration::audio_output_device () const {return m_->audio_output_device_;}
AudioDevice::Channel Configuration::audio_output_channel () const {return m_->audio_output_channel_;}
bool Configuration::restart_audio_input () const {return m_->restart_sound_input_device_;}
bool Configuration::restart_audio_output () const {return m_->restart_sound_output_device_;}
auto Configuration::type_2_msg_gen () const -> Type2MsgGen {return m_->type_2_msg_gen_;}
QString Configuration::my_callsign () const {return m_->my_callsign_;}
QString Configuration::my_grid () const {return m_->my_grid_;}
QColor Configuration::color_CQ () const {return m_->color_CQ_;}
QColor Configuration::color_MyCall () const {return m_->color_MyCall_;}
QColor Configuration::color_TxMsg () const {return m_->color_TxMsg_;}
QColor Configuration::color_DXCC () const {return m_->color_DXCC_;}
QColor Configuration::color_NewCall () const {return m_->color_NewCall_;}
QFont Configuration::text_font () const {return m_->font_;}
QFont Configuration::decoded_text_font () const {return m_->decoded_text_font_;}
qint32 Configuration::id_interval () const {return m_->id_interval_;}
qint32 Configuration::ntrials() const {return m_->ntrials_;}
qint32 Configuration::aggressive() const {return m_->aggressive_;}
double Configuration::degrade() const {return m_->degrade_;}
double Configuration::txDelay() const {return m_->txDelay_;}
qint32 Configuration::RxBandwidth() const {return m_->RxBandwidth_;}
bool Configuration::id_after_73 () const {return m_->id_after_73_;}
bool Configuration::tx_QSY_allowed () const {return m_->tx_QSY_allowed_;}
bool Configuration::spot_to_psk_reporter () const
{
// rig must be open and working to spot externally
return is_transceiver_online () && m_->spot_to_psk_reporter_;
}
bool Configuration::monitor_off_at_startup () const {return m_->monitor_off_at_startup_;}
bool Configuration::monitor_last_used () const {return m_->rig_is_dummy_ || m_->monitor_last_used_;}
bool Configuration::log_as_RTTY () const {return m_->log_as_RTTY_;}
bool Configuration::report_in_comments () const {return m_->report_in_comments_;}
bool Configuration::prompt_to_log () const {return m_->prompt_to_log_;}
bool Configuration::insert_blank () const {return m_->insert_blank_;}
bool Configuration::DXCC () const {return m_->DXCC_;}
bool Configuration::clear_DX () const {return m_->clear_DX_;}
bool Configuration::miles () const {return m_->miles_;}
bool Configuration::quick_call () const {return m_->quick_call_;}
bool Configuration::disable_TX_on_73 () const {return m_->disable_TX_on_73_;}
int Configuration::watchdog () const {return m_->watchdog_;}
bool Configuration::TX_messages () const {return m_->TX_messages_;}
bool Configuration::enable_VHF_features () const {return m_->enable_VHF_features_;}
bool Configuration::decode_at_52s () const {return m_->decode_at_52s_;}
bool Configuration::single_decode () const {return m_->single_decode_;}
bool Configuration::twoPass() const {return m_->twoPass_;}
bool Configuration::x2ToneSpacing() const {return m_->x2ToneSpacing_;}
bool Configuration::realTimeDecode() const {return m_->realTimeDecode_;}
bool Configuration::split_mode () const {return m_->split_mode ();}
QString Configuration::udp_server_name () const {return m_->udp_server_name_;}
auto Configuration::udp_server_port () const -> port_type {return m_->udp_server_port_;}
bool Configuration::accept_udp_requests () const {return m_->accept_udp_requests_;}
bool Configuration::udpWindowToFront () const {return m_->udpWindowToFront_;}
bool Configuration::udpWindowRestore () const {return m_->udpWindowRestore_;}
Bands * Configuration::bands () {return &m_->bands_;}
Bands const * Configuration::bands () const {return &m_->bands_;}
StationList * Configuration::stations () {return &m_->stations_;}
StationList const * Configuration::stations () const {return &m_->stations_;}
IARURegions::Region Configuration::region () const {return m_->region_;}
FrequencyList_v2 * Configuration::frequencies () {return &m_->frequencies_;}
FrequencyList_v2 const * Configuration::frequencies () const {return &m_->frequencies_;}
QStringListModel * Configuration::macros () {return &m_->macros_;}
QStringListModel const * Configuration::macros () const {return &m_->macros_;}
QDir Configuration::save_directory () const {return m_->save_directory_;}
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_;}
void Configuration::set_calibration (CalibrationParams params)
{
m_->calibration_ = params;
}
void Configuration::enable_calibration (bool on)
{
auto target_frequency = m_->remove_calibration (m_->cached_rig_state_.frequency ()) - m_->current_offset_;
m_->frequency_calibration_disabled_ = !on;
transceiver_frequency (target_frequency);
}
bool Configuration::is_transceiver_online () const
{
return m_->rig_active_;
}
bool Configuration::is_dummy_rig () const
{
return m_->rig_is_dummy_;
}
bool Configuration::transceiver_online ()
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_online: " << m_->cached_rig_state_;
#endif
return m_->have_rig ();
}
int Configuration::transceiver_resolution () const
{
return m_->rig_resolution_;
}
void Configuration::transceiver_offline ()
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_offline:" << m_->cached_rig_state_;
#endif
m_->close_rig ();
}
void Configuration::transceiver_frequency (Frequency f)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_frequency:" << f << m_->cached_rig_state_;
#endif
m_->transceiver_frequency (f);
}
void Configuration::transceiver_tx_frequency (Frequency f)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_tx_frequency:" << f << m_->cached_rig_state_;
#endif
m_->transceiver_tx_frequency (f);
}
void Configuration::transceiver_mode (MODE mode)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_mode:" << mode << m_->cached_rig_state_;
#endif
m_->transceiver_mode (mode);
}
void Configuration::transceiver_ptt (bool on)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::transceiver_ptt:" << on << m_->cached_rig_state_;
#endif
m_->transceiver_ptt (on);
}
void Configuration::sync_transceiver (bool force_signal, bool enforce_mode_and_split)
{
#if WSJT_TRACE_CAT
qDebug () << "Configuration::sync_transceiver: force signal:" << force_signal << "enforce_mode_and_split:" << enforce_mode_and_split << m_->cached_rig_state_;
#endif
m_->sync_transceiver (force_signal);
if (!enforce_mode_and_split)
{
m_->transceiver_tx_frequency (0);
}
}
namespace
{
#if defined (Q_OS_MAC)
char const * app_root = "/../../../";
#else
char const * app_root = "/../";
#endif
QString doc_path ()
{
#if CMAKE_BUILD
if (QDir::isRelativePath (CMAKE_INSTALL_DOCDIR))
{
return QApplication::applicationDirPath () + app_root + CMAKE_INSTALL_DOCDIR;
}
return CMAKE_INSTALL_DOCDIR;
#else
return QApplication::applicationDirPath ();
#endif
}
QString data_path ()
{
#if CMAKE_BUILD
if (QDir::isRelativePath (CMAKE_INSTALL_DATADIR))
{
return QApplication::applicationDirPath () + app_root + CMAKE_INSTALL_DATADIR + QChar {'/'} + CMAKE_PROJECT_NAME;
}
return CMAKE_INSTALL_DATADIR;
#else
return QApplication::applicationDirPath ();
#endif
}
}
Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
QSettings * settings, QWidget * parent)
: QDialog {parent}
, self_ {self}
, transceiver_thread_ {nullptr}
, ui_ {new Ui::configuration_dialog}
, settings_ {settings}
, doc_dir_ {doc_path ()}
, data_dir_ {data_path ()}
, temp_dir_ {temp_directory}
, writeable_data_dir_ {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}
, restart_sound_input_device_ {false}
, restart_sound_output_device_ {false}
, frequencies_ {&bands_}
, next_frequencies_ {&bands_}
, stations_ {&bands_}
, next_stations_ {&bands_}
, current_offset_ {0}
, current_tx_offset_ {0}
, frequency_dialog_ {new FrequencyDialog {®ions_, &modes_, this}}
, station_dialog_ {new StationDialog {&next_stations_, &bands_, this}}
, last_port_type_ {TransceiverFactory::Capabilities::none}
, rig_is_dummy_ {false}
, rig_active_ {false}
, have_rig_ {false}
, rig_changed_ {false}
, rig_resolution_ {0}
, frequency_calibration_disabled_ {false}
, transceiver_command_number_ {0}
, degrade_ {0.} // initialize to zero each run, not
// saved in settings
, default_audio_input_device_selected_ {false}
, default_audio_output_device_selected_ {false}
{
ui_->setupUi (this);
// ui_->groupBox_6->setVisible(false); //### Temporary ??? ###
{
// Find a suitable data file location
if (!writeable_data_dir_.mkpath ("."))
{
MessageBox::critical_message (this, tr ("Failed to create data directory"),
tr ("path: \"%1\"").arg (writeable_data_dir_.absolutePath ()));
throw std::runtime_error {"Failed to create data directory"};
}
// Make sure the default save directory exists
QString save_dir {"save"};
default_save_directory_ = writeable_data_dir_;
default_azel_directory_ = writeable_data_dir_;
if (!default_save_directory_.mkpath (save_dir) || !default_save_directory_.cd (save_dir))
{
MessageBox::critical_message (this, tr ("Failed to create save directory"),
tr ("path: \"%1\%")
.arg (default_save_directory_.absoluteFilePath (save_dir)));
throw std::runtime_error {"Failed to create save directory"};
}
// we now have a deafult save path that exists
// make sure samples directory exists
QString samples_dir {"samples"};
if (!default_save_directory_.mkpath (samples_dir))
{
MessageBox::critical_message (this, tr ("Failed to create samples directory"),
tr ("path: \"%1\"")
.arg (default_save_directory_.absoluteFilePath (samples_dir)));
throw std::runtime_error {"Failed to create samples directory"};
}
// copy in any new sample files to the sample directory
QDir dest_dir {default_save_directory_};
dest_dir.cd (samples_dir);
QDir source_dir {":/" + samples_dir};
source_dir.cd (save_dir);
source_dir.cd (samples_dir);
auto list = source_dir.entryInfoList (QStringList {{"*.wav"}}, QDir::Files | QDir::Readable);
Q_FOREACH (auto const& item, list)
{
if (!dest_dir.exists (item.fileName ()))
{
QFile file {item.absoluteFilePath ()};
file.copy (dest_dir.absoluteFilePath (item.fileName ()));
}
}
}
// this must be done after the default paths above are set
read_settings ();
//
// validation
//
ui_->callsign_line_edit->setValidator (new CallsignValidator {this});
ui_->grid_line_edit->setValidator (new MaidenheadLocatorValidator {this});
ui_->add_macro_line_edit->setValidator (new QRegExpValidator {message_alphabet, this});
ui_->udp_server_port_spin_box->setMinimum (1);
ui_->udp_server_port_spin_box->setMaximum (std::numeric_limits<port_type>::max ());
//
// assign ids to radio buttons
//
ui_->CAT_data_bits_button_group->setId (ui_->CAT_7_bit_radio_button, TransceiverFactory::seven_data_bits);
ui_->CAT_data_bits_button_group->setId (ui_->CAT_8_bit_radio_button, TransceiverFactory::eight_data_bits);
ui_->CAT_stop_bits_button_group->setId (ui_->CAT_one_stop_bit_radio_button, TransceiverFactory::one_stop_bit);
ui_->CAT_stop_bits_button_group->setId (ui_->CAT_two_stop_bit_radio_button, TransceiverFactory::two_stop_bits);
ui_->CAT_handshake_button_group->setId (ui_->CAT_handshake_none_radio_button, TransceiverFactory::handshake_none);
ui_->CAT_handshake_button_group->setId (ui_->CAT_handshake_xon_radio_button, TransceiverFactory::handshake_XonXoff);
ui_->CAT_handshake_button_group->setId (ui_->CAT_handshake_hardware_radio_button, TransceiverFactory::handshake_hardware);
ui_->PTT_method_button_group->setId (ui_->PTT_VOX_radio_button, TransceiverFactory::PTT_method_VOX);
ui_->PTT_method_button_group->setId (ui_->PTT_CAT_radio_button, TransceiverFactory::PTT_method_CAT);
ui_->PTT_method_button_group->setId (ui_->PTT_DTR_radio_button, TransceiverFactory::PTT_method_DTR);
ui_->PTT_method_button_group->setId (ui_->PTT_RTS_radio_button, TransceiverFactory::PTT_method_RTS);
ui_->TX_audio_source_button_group->setId (ui_->TX_source_mic_radio_button, TransceiverFactory::TX_audio_source_front);
ui_->TX_audio_source_button_group->setId (ui_->TX_source_data_radio_button, TransceiverFactory::TX_audio_source_rear);
ui_->TX_mode_button_group->setId (ui_->mode_none_radio_button, data_mode_none);
ui_->TX_mode_button_group->setId (ui_->mode_USB_radio_button, data_mode_USB);
ui_->TX_mode_button_group->setId (ui_->mode_data_radio_button, data_mode_data);
ui_->split_mode_button_group->setId (ui_->split_none_radio_button, TransceiverFactory::split_mode_none);
ui_->split_mode_button_group->setId (ui_->split_rig_radio_button, TransceiverFactory::split_mode_rig);
ui_->split_mode_button_group->setId (ui_->split_emulate_radio_button, TransceiverFactory::split_mode_emulate);
//
// setup PTT port combo box drop down content
//
fill_port_combo_box (ui_->PTT_port_combo_box);
ui_->PTT_port_combo_box->addItem ("CAT");
//
// setup hooks to keep audio channels aligned with devices
//
{
using namespace std;
using namespace std::placeholders;
function<void (int)> cb (bind (&Configuration::impl::update_audio_channels, this, ui_->sound_input_combo_box, _1, ui_->sound_input_channel_combo_box, false));
connect (ui_->sound_input_combo_box, static_cast<void (QComboBox::*)(int)> (&QComboBox::currentIndexChanged), cb);
cb = bind (&Configuration::impl::update_audio_channels, this, ui_->sound_output_combo_box, _1, ui_->sound_output_channel_combo_box, true);
connect (ui_->sound_output_combo_box, static_cast<void (QComboBox::*)(int)> (&QComboBox::currentIndexChanged), cb);
}
//
// setup macros list view
//
ui_->macros_list_view->setModel (&next_macros_);
ui_->macros_list_view->setItemDelegate (new MessageItemDelegate {this});
macro_delete_action_ = new QAction {tr ("&Delete"), ui_->macros_list_view};
ui_->macros_list_view->insertAction (nullptr, macro_delete_action_);
connect (macro_delete_action_, &QAction::triggered, this, &Configuration::impl::delete_macro);
// setup IARU region combo box model
ui_->region_combo_box->setModel (®ions_);
//
// setup working frequencies table model & view
//
frequencies_.sort (FrequencyList_v2::frequency_column);
ui_->frequencies_table_view->setModel (&next_frequencies_);
ui_->frequencies_table_view->sortByColumn (FrequencyList_v2::frequency_column, Qt::AscendingOrder);
ui_->frequencies_table_view->setColumnHidden (FrequencyList_v2::frequency_mhz_column, true);
// delegates
auto frequencies_item_delegate = new QStyledItemDelegate {this};
frequencies_item_delegate->setItemEditorFactory (item_editor_factory ());
ui_->frequencies_table_view->setItemDelegate (frequencies_item_delegate);
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::region_column, new ForeignKeyDelegate {®ions_, 0, this});
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::mode_column, new ForeignKeyDelegate {&modes_, 0, this});
// actions
frequency_delete_action_ = new QAction {tr ("&Delete"), ui_->frequencies_table_view};
ui_->frequencies_table_view->insertAction (nullptr, frequency_delete_action_);
connect (frequency_delete_action_, &QAction::triggered, this, &Configuration::impl::delete_frequencies);
frequency_insert_action_ = new QAction {tr ("&Insert ..."), ui_->frequencies_table_view};
ui_->frequencies_table_view->insertAction (nullptr, frequency_insert_action_);
connect (frequency_insert_action_, &QAction::triggered, this, &Configuration::impl::insert_frequency);
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);
save_frequencies_action_ = new QAction {tr ("&Save as ..."), ui_->frequencies_table_view};
ui_->frequencies_table_view->insertAction (nullptr, save_frequencies_action_);
connect (save_frequencies_action_, &QAction::triggered, this, &Configuration::impl::save_frequencies);