-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathDxClusterDialog.cpp
More file actions
2761 lines (2488 loc) · 125 KB
/
Copy pathDxClusterDialog.cpp
File metadata and controls
2761 lines (2488 loc) · 125 KB
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 "DxClusterDialog.h"
#include "DxClusterStartupCommandsDialog.h"
#include "GuardedSlider.h"
#include "core/DxClusterClient.h"
#include "core/AppSettings.h"
#include "core/SpotCommandPolicy.h"
#include "core/SpotModeResolver.h"
#include "models/RadioModel.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QPushButton>
#include <QCheckBox>
#include <QGroupBox>
#include <QPlainTextEdit>
#include <QScrollBar>
#include <QTabWidget>
#include <QTableView>
#include <QHeaderView>
#include <QSortFilterProxyModel>
#include <QSlider>
#include <QColorDialog>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QRegularExpression>
#include <QSignalBlocker>
#include <QTimer>
#include "core/ThemeManager.h"
namespace AetherSDR {
// GuardedSlider variant that resets to a stored default on left
// double-click. Used for the Filter Match Window slider (#2609) so
// the operator can snap back to the 1 kHz default without dragging.
class ResetOnDoubleClickSlider : public GuardedSlider {
public:
using GuardedSlider::GuardedSlider;
void setResetValue(int v) { m_resetValue = v; }
protected:
void mouseDoubleClickEvent(QMouseEvent* ev) override {
if (ev->button() == Qt::LeftButton) {
setValue(m_resetValue);
ev->accept();
return;
}
GuardedSlider::mouseDoubleClickEvent(ev);
}
private:
int m_resetValue{0};
};
// Shared DSP-style toggle for every checkable button in SpotHub
// (matches kDspToggle in VfoWidget.cpp so the chrome reads the same as
// the NB / NR / ANF buttons in the VFO panel). Dark inset by default,
// green fill when checked, cyan hover-border accent.
static const QString kSpotHubToggle =
"QPushButton { background: #1a2a3a; border: 1px solid #304050;"
" border-radius: 2px; color: #c8d8e8; font-size: 13px;"
" font-weight: bold; padding: 2px 8px; }"
"QPushButton:checked { background: #1a6030; color: #ffffff;"
" border: 1px solid #20a040; }"
"QPushButton:hover { border: 1px solid #0090e0; }";
// Read the last N lines of a file without loading the entire thing.
static QStringList tailFile(const QString& path, int maxLines = 500)
{
QFile f(path);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
return {};
// For small files, just read everything
if (f.size() < 64 * 1024) {
QStringList lines;
while (!f.atEnd()) {
QString line = QString::fromUtf8(f.readLine()).trimmed();
if (!line.isEmpty())
lines.append(line);
}
if (lines.size() > maxLines)
lines = lines.mid(lines.size() - maxLines);
return lines;
}
// For large files, seek backwards to find enough newlines
constexpr qint64 CHUNK = 8192;
qint64 pos = f.size();
QByteArray tail;
int nlCount = 0;
while (pos > 0 && nlCount <= maxLines) {
qint64 readSize = qMin(CHUNK, pos);
pos -= readSize;
f.seek(pos);
QByteArray chunk = f.read(readSize);
tail.prepend(chunk);
nlCount += chunk.count('\n');
}
QStringList all = QString::fromUtf8(tail).split('\n', Qt::SkipEmptyParts);
for (auto& s : all) s = s.trimmed();
all.removeAll(QString());
if (all.size() > maxLines)
all = all.mid(all.size() - maxLines);
return all;
}
// ── SpotTableModel ──────────────────────────────────────────────────────────
QString SpotTableModel::extractMode(const QString& comment)
{
return SpotModeResolver::extractSpotModeFromComment(comment);
}
QVariant SpotTableModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || index.row() >= m_spots.size())
return {};
const auto& spot = m_spots[index.row()];
if (role == Qt::DisplayRole) {
switch (index.column()) {
case ColTime: return spot.utcTime.toString("HH:mm");
case ColFreq: return QString::number(spot.freqMhz * 1000.0, 'f', 1);
case ColDxCall: return spot.dxCall;
case ColMode: return extractMode(spot.comment);
case ColComment: return spot.comment;
case ColSpotter: return spot.spotterCall;
case ColBand: return bandForFreq(spot.freqMhz);
case ColSource: return spot.source;
}
}
if (role == Qt::TextAlignmentRole) {
if (index.column() == ColFreq)
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
if (index.column() == ColTime)
return QVariant(Qt::AlignCenter);
}
if (role == Qt::ForegroundRole) {
if (index.column() == ColDxCall)
return QColor(0x00, 0xb4, 0xd8); // accent
if (index.column() == ColFreq)
return QColor(0xe0, 0xd0, 0x60); // yellow-ish
}
// Store freq in UserRole for sorting
if (role == Qt::UserRole && index.column() == ColFreq)
return spot.freqMhz;
return {};
}
QVariant SpotTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
return {};
switch (section) {
case ColTime: return "Time";
case ColFreq: return "Freq (kHz)";
case ColDxCall: return "DX Call";
case ColMode: return "Mode";
case ColComment: return "Comment";
case ColSpotter: return "Spotter";
case ColBand: return "Band";
case ColSource: return "Source";
}
return {};
}
void SpotTableModel::addSpot(const DxSpot& spot)
{
beginInsertRows({}, 0, 0);
m_spots.prepend(spot);
endInsertRows();
if (m_spots.size() > m_maxSpots) {
beginRemoveRows({}, m_maxSpots, m_spots.size() - 1);
m_spots.resize(m_maxSpots);
endRemoveRows();
}
}
void SpotTableModel::addSpots(const QVector<DxSpot>& spots)
{
if (spots.isEmpty()) return;
int count = spots.size();
beginInsertRows({}, 0, count - 1);
// Prepend in reverse so newest is at index 0
for (int i = count - 1; i >= 0; --i)
m_spots.prepend(spots[i]);
endInsertRows();
if (m_spots.size() > m_maxSpots) {
beginRemoveRows({}, m_maxSpots, m_spots.size() - 1);
m_spots.resize(m_maxSpots);
endRemoveRows();
}
}
const DxSpot* SpotTableModel::spotAt(int row) const
{
if (row >= 0 && row < m_spots.size())
return &m_spots[row];
return nullptr;
}
void SpotTableModel::clear()
{
beginResetModel();
m_spots.clear();
endResetModel();
}
QString SpotTableModel::bandForFreq(double mhz)
{
if (mhz >= 1.8 && mhz <= 2.0) return "160m";
if (mhz >= 3.5 && mhz <= 4.0) return "80m";
if (mhz >= 5.0 && mhz <= 5.5) return "60m";
if (mhz >= 7.0 && mhz <= 7.3) return "40m";
if (mhz >= 10.1 && mhz <= 10.15) return "30m";
if (mhz >= 14.0 && mhz <= 14.35) return "20m";
if (mhz >= 18.068 && mhz <= 18.168) return "17m";
if (mhz >= 21.0 && mhz <= 21.45) return "15m";
if (mhz >= 24.89 && mhz <= 24.99) return "12m";
if (mhz >= 28.0 && mhz <= 29.7) return "10m";
if (mhz >= 50.0 && mhz <= 54.0) return "6m";
if (mhz >= 144.0 && mhz <= 148.0) return "2m";
return "";
}
// ── BandFilterProxy ─────────────────────────────────────────────────────────
void BandFilterProxy::setBandVisible(const QString& band, bool visible)
{
if (visible)
m_hiddenBands.remove(band);
else
m_hiddenBands.insert(band);
invalidateFilter();
}
bool BandFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if (m_hiddenBands.isEmpty())
return true;
auto idx = sourceModel()->index(sourceRow, SpotTableModel::ColBand, sourceParent);
QString band = sourceModel()->data(idx, Qt::DisplayRole).toString();
if (band.isEmpty())
return true; // unknown band — always show
return !m_hiddenBands.contains(band);
}
// ── DxClusterDialog ─────────────────────────────────────────────────────────
DxClusterDialog::DxClusterDialog(DxClusterClient* clusterClient, DxClusterClient* rbnClient,
WsjtxClient* wsjtxClient, SpotCollectorClient* spotCollectorClient,
PotaClient* potaClient,
#ifdef HAVE_WEBSOCKETS
FreeDvClient* freedvClient,
#endif
RadioModel* radioModel,
DxccColorProvider* dxccProvider,
QWidget* parent)
: PersistentDialog("SpotHub", "DxClusterDialogGeometry", parent),
m_client(clusterClient), m_rbnClient(rbnClient),
m_wsjtxClient(wsjtxClient), m_spotCollectorClient(spotCollectorClient),
m_potaClient(potaClient),
#ifdef HAVE_WEBSOCKETS
m_freedvClient(freedvClient),
#endif
m_radioModel(radioModel), m_dxccProvider(dxccProvider)
{
theme::setContainer(this, QStringLiteral("dialog/dxCluster"));
setMinimumSize(680, 560);
resize(760, 640);
// Capture source log paths up front so the per-tab Clear handlers (built
// below) can zero them on click. (#2022)
m_clusterLogPath = clusterClient->logFilePath();
m_rbnLogPath = rbnClient->logFilePath();
m_wsjtxLogPath = wsjtxClient->logFilePath();
m_potaLogPath = potaClient->logFilePath();
m_scLogPath = spotCollectorClient->logFilePath();
#ifdef HAVE_WEBSOCKETS
m_freedvLogPath = freedvClient->logFilePath();
#endif
auto* root = new QVBoxLayout(bodyWidget());
root->setSpacing(0);
root->setContentsMargins(4, 4, 4, 4);
auto* tabs = new QTabWidget;
AetherSDR::ThemeManager::instance().applyStyleSheet(tabs, "QTabWidget::pane { border: 1px solid {{color.background.1}}; }"
"QTabBar::tab { background: {{color.background.0}}; color: #808890; border: 1px solid {{color.background.1}}; "
" padding: 6px 16px; margin-right: 2px; }"
"QTabBar::tab:selected { background: {{color.background.0}}; color: {{color.accent}}; border-bottom: none; }");
buildClusterTab(tabs);
buildRbnTab(tabs);
buildWsjtxTab(tabs);
buildSpotCollectorTab(tabs);
buildPotaTab(tabs);
#ifdef HAVE_WEBSOCKETS
buildFreeDvTab(tabs);
#endif
buildSpotListTab(tabs);
buildDisplayTab(tabs);
root->addWidget(tabs);
// ── Spot batch timer (1/sec flush) ──────────────────────────────────
m_spotBatchTimer = new QTimer(this);
m_spotBatchTimer->start(1000);
connect(m_spotBatchTimer, &QTimer::timeout, this, &DxClusterDialog::flushSpotBatch);
// Auto-scroll helper: only scroll if user is already at the bottom
auto isAtBottom = [](QAbstractScrollArea* w) {
auto* sb = w->verticalScrollBar();
return sb->value() >= sb->maximum() - 2;
};
// ── Live updates from client ────────────────────────────────────────
connect(clusterClient, &DxClusterClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_console);
m_console->appendPlainText(line);
if (follow) {
auto* sb = m_console->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(clusterClient, &DxClusterClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "Cluster";
m_spotBatch.append(spot);
});
connect(clusterClient, &DxClusterClient::connected, this, [this] {
m_statusLabel->setText(QString("Connected to %1:%2").arg(m_client->host()).arg(m_client->port()));
AetherSDR::ThemeManager::instance().applyStyleSheet(m_statusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_connectBtn->setText("Disconnect");
m_cmdEdit->setEnabled(true);
m_sendBtn->setEnabled(true);
m_console->appendPlainText("--- Connected ---");
});
connect(clusterClient, &DxClusterClient::disconnected, this, [this] {
m_statusLabel->setText("Disconnected");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_statusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_connectBtn->setText("Connect");
m_cmdEdit->setEnabled(false);
m_sendBtn->setEnabled(false);
m_console->appendPlainText("--- Disconnected ---");
});
connect(clusterClient, &DxClusterClient::connectionError, this, [this](const QString& err) {
m_statusLabel->setText("Error: " + err);
AetherSDR::ThemeManager::instance().applyStyleSheet(m_statusLabel, "QLabel { color: {{color.accent.danger}}; font-size: 11px; }");
m_console->appendPlainText("--- Error: " + err + " ---");
});
// Defer log file loading until after the dialog is shown (#748).
// Reads only the last 500 lines per file to avoid blocking on large logs.
QTimer::singleShot(0, this, [this]() {
loadLogFiles(m_clusterLogPath, m_rbnLogPath, m_wsjtxLogPath,
m_potaLogPath, m_freedvLogPath);
});
// ── Live updates from RBN client ──────────────────────────────────
connect(rbnClient, &DxClusterClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_rbnConsole);
m_rbnConsole->appendPlainText(line);
if (follow) {
auto* sb = m_rbnConsole->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(rbnClient, &DxClusterClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "RBN";
m_spotBatch.append(spot);
});
connect(rbnClient, &DxClusterClient::connected, this, [this] {
m_rbnStatusLabel->setText(QString("Connected to %1:%2").arg(m_rbnClient->host()).arg(m_rbnClient->port()));
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnStatusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_rbnConnectBtn->setText("Disconnect");
m_rbnCmdEdit->setEnabled(true);
m_rbnSendBtn->setEnabled(true);
m_rbnConsole->appendPlainText("--- Connected ---");
});
connect(rbnClient, &DxClusterClient::disconnected, this, [this] {
m_rbnStatusLabel->setText("Disconnected");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_rbnConnectBtn->setText("Connect");
m_rbnCmdEdit->setEnabled(false);
m_rbnSendBtn->setEnabled(false);
m_rbnConsole->appendPlainText("--- Disconnected ---");
});
connect(rbnClient, &DxClusterClient::connectionError, this, [this](const QString& err) {
m_rbnStatusLabel->setText("Error: " + err);
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnStatusLabel, "QLabel { color: {{color.accent.danger}}; font-size: 11px; }");
m_rbnConsole->appendPlainText("--- Error: " + err + " ---");
});
// RBN log loaded in deferred loadLogFiles() (#748)
// ── Live updates from WSJT-X client ───────────────────────────────
connect(wsjtxClient, &WsjtxClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_wsjtxConsole);
m_wsjtxConsole->appendPlainText(line);
if (follow) {
auto* sb = m_wsjtxConsole->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(wsjtxClient, &WsjtxClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "WSJT-X";
// Apply spot filters:
// - Nothing checked: everything passes
// - CQ checked: only "CQ ..." messages
// - CQ POTA checked: only "CQ POTA ..." messages
// - Calling Me checked: only directed messages to my callsign
// CQ and CQ POTA are mutually exclusive; Calling Me can combine with either
const QString& msg = spot.comment;
auto& as = AppSettings::instance();
bool anyFilter = m_wsjtxFilterCQ->isChecked() || m_wsjtxFilterPOTA->isChecked()
|| m_wsjtxFilterCallingMe->isChecked();
// Determine which category matches and assign color
bool isCQ = msg.startsWith("CQ ");
bool isPOTA = msg.contains("CQ POTA");
bool isCallingMe = false;
{
QString myCall = as.value("DxClusterCallsign").toString();
if (!myCall.isEmpty()) {
QStringList parts = msg.split(' ', Qt::SkipEmptyParts);
if (parts.size() >= 2 && parts[0] == myCall)
isCallingMe = true;
}
}
// Apply color always: Calling Me > POTA > CQ > default
if (isCallingMe)
spot.color = as.value("WsjtxColorCallingMe", "#FF0000").toString();
else if (isPOTA)
spot.color = as.value("WsjtxColorPOTA", "#00FFFF").toString();
else if (isCQ)
spot.color = as.value("WsjtxColorCQ", "#00FF00").toString();
else
spot.color = as.value("WsjtxColorDefault", "#FFFFFF").toString();
// Filter: if any checkbox is checked, only matching spots pass
if (anyFilter) {
bool pass = false;
if (m_wsjtxFilterCQ->isChecked() && isCQ) pass = true;
if (m_wsjtxFilterPOTA->isChecked() && isPOTA) pass = true;
if (m_wsjtxFilterCallingMe->isChecked() && isCallingMe) pass = true;
if (!pass) return;
}
m_spotBatch.append(spot);
emit wsjtxSpotFiltered(spot);
});
connect(wsjtxClient, &WsjtxClient::listening, this, [this] {
m_wsjtxStatusLabel->setText(QString("Listening on port %1").arg(m_wsjtxPortSpin->value()));
AetherSDR::ThemeManager::instance().applyStyleSheet(m_wsjtxStatusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_wsjtxStartBtn->setText("Stop");
m_wsjtxConsole->appendPlainText("--- Listening ---");
});
connect(wsjtxClient, &WsjtxClient::stopped, this, [this] {
m_wsjtxStatusLabel->setText("Stopped");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_wsjtxStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_wsjtxStartBtn->setText("Start");
m_wsjtxConsole->appendPlainText("--- Stopped ---");
});
// WSJT-X log loaded in deferred loadLogFiles() (#748)
// ── Live updates from SpotCollector client ───────────────────────
connect(spotCollectorClient, &SpotCollectorClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_scConsole);
m_scConsole->appendPlainText(line);
if (follow) {
auto* sb = m_scConsole->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(spotCollectorClient, &SpotCollectorClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "SpotCollector";
m_spotBatch.append(spot);
});
connect(spotCollectorClient, &SpotCollectorClient::listening, this, [this] {
m_scStatusLabel->setText(QString("Listening on port %1").arg(m_scPortSpin->value()));
AetherSDR::ThemeManager::instance().applyStyleSheet(m_scStatusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_scStartBtn->setText("Stop");
m_scConsole->appendPlainText("--- Listening ---");
});
connect(spotCollectorClient, &SpotCollectorClient::stopped, this, [this] {
m_scStatusLabel->setText("Stopped");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_scStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_scStartBtn->setText("Start");
m_scConsole->appendPlainText("--- Stopped ---");
});
// ── Live updates from POTA client ─────────────────────────────────
connect(potaClient, &PotaClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_potaConsole);
m_potaConsole->appendPlainText(line);
if (follow) {
auto* sb = m_potaConsole->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(potaClient, &PotaClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "POTA";
m_spotBatch.append(spot);
});
connect(potaClient, &PotaClient::started, this, [this] {
m_potaStatusLabel->setText("Polling...");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_potaStatusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_potaStartBtn->setText("Stop");
m_potaConsole->appendPlainText("--- Polling started ---");
});
connect(potaClient, &PotaClient::stopped, this, [this] {
m_potaStatusLabel->setText("Stopped");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_potaStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_potaStartBtn->setText("Start");
m_potaConsole->appendPlainText("--- Stopped ---");
});
connect(potaClient, &PotaClient::pollError, this, [this](const QString& err) {
m_potaConsole->appendPlainText("--- Error: " + err + " ---");
});
connect(potaClient, &PotaClient::pollComplete, this, [this](int total, int newCount) {
m_potaStatusLabel->setText(QString("Polling... (%1 active, %2 new)").arg(total).arg(newCount));
});
// POTA log loaded in deferred loadLogFiles() (#748)
#ifdef HAVE_WEBSOCKETS
// ── Live updates from FreeDV client ───────────────────────────────
connect(freedvClient, &FreeDvClient::rawLineReceived, this, [this, isAtBottom](const QString& line) {
bool follow = isAtBottom(m_freedvConsole);
m_freedvConsole->appendPlainText(line);
if (follow) {
auto* sb = m_freedvConsole->verticalScrollBar();
sb->setValue(sb->maximum());
}
});
connect(freedvClient, &FreeDvClient::spotReceived, this, [this](DxSpot spot) {
spot.source = "FreeDV";
m_spotBatch.append(spot);
});
connect(freedvClient, &FreeDvClient::started, this, [this] {
m_freedvStatusLabel->setText("Connecting...");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_freedvStatusLabel, "QLabel { color: {{color.accent}}; font-size: 11px; }");
m_freedvStartBtn->setText("Stop");
m_freedvConsole->appendPlainText("--- Connecting ---");
});
connect(freedvClient, &FreeDvClient::stopped, this, [this] {
m_freedvStatusLabel->setText("Stopped");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_freedvStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
m_freedvStartBtn->setText("Start");
m_freedvConsole->appendPlainText("--- Stopped ---");
});
connect(freedvClient, &FreeDvClient::connectionError, this, [this](const QString& err) {
m_freedvConsole->appendPlainText("--- Error: " + err + " ---");
});
// Update status when FreeDV connects via Socket.IO
connect(freedvClient, &FreeDvClient::rawLineReceived, this, [this](const QString& line) {
if (line.startsWith("Connected to")) {
m_freedvStatusLabel->setText("Connected");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_freedvStatusLabel, "QLabel { color: {{color.accent.success}}; font-size: 11px; }");
}
});
// FreeDV log loaded in deferred loadLogFiles() (#748)
#endif
// Scroll spot table to show newest entries
m_spotTable->scrollToBottom();
// Disable autoDefault on all buttons so Enter in command inputs
// only fires returnPressed, not random button clicks (#459)
for (auto* btn : findChildren<QPushButton*>())
btn->setAutoDefault(false);
updateStatus();
}
void DxClusterDialog::truncateLogFile(const QString& path)
{
if (path.isEmpty())
return;
QFile f(path);
if (f.exists())
f.resize(0);
}
QPushButton* DxClusterDialog::makeConsoleClearButton(QPlainTextEdit* console,
const QString* logPath,
const QString& objectName)
{
auto* btn = new QPushButton("Clear");
btn->setObjectName(objectName);
btn->setFixedWidth(60);
btn->setToolTip("Clear this console and delete its stored log so it stays\n"
"empty after you reopen SpotHub.");
connect(btn, &QPushButton::clicked, this, [this, console, logPath] {
if (console)
console->clear();
if (logPath)
truncateLogFile(*logPath);
});
return btn;
}
void DxClusterDialog::loadLogFiles(const QString& clusterLog, const QString& rbnLog,
const QString& wsjtxLog, const QString& potaLog,
const QString& freedvLog)
{
static const QRegularExpression rx(
R"(^DX\s+de\s+(\S+?):\s+(\d+\.?\d*)\s+(\S+)\s+(.*?)\s+(\d{4})Z)",
QRegularExpression::CaseInsensitiveOption);
auto parseSpots = [&](const QStringList& lines, const QString& source) {
QVector<DxSpot> spots;
for (const auto& line : lines) {
auto match = rx.match(line);
if (match.hasMatch()) {
DxSpot spot;
spot.spotterCall = match.captured(1);
spot.freqMhz = match.captured(2).toDouble() / 1000.0;
spot.dxCall = match.captured(3);
spot.comment = match.captured(4).trimmed();
QString timeStr = match.captured(5);
spot.utcTime = QTime(timeStr.left(2).toInt(), timeStr.mid(2, 2).toInt());
if (spot.freqMhz > 0.0 && !spot.dxCall.isEmpty()) {
spot.source = source;
spots.append(spot);
}
}
}
return spots;
};
auto loadConsole = [](QPlainTextEdit* console, const QStringList& lines) {
if (!console || lines.isEmpty()) return;
console->setPlainText(lines.join('\n'));
auto* sb = console->verticalScrollBar();
sb->setValue(sb->maximum());
};
// Cluster log — parse spots + display in console
auto clusterLines = tailFile(clusterLog);
loadConsole(m_console, clusterLines);
auto clusterSpots = parseSpots(clusterLines, "Cluster");
// RBN log — parse spots + display in console
auto rbnLines = tailFile(rbnLog);
loadConsole(m_rbnConsole, rbnLines);
auto rbnSpots = parseSpots(rbnLines, "RBN");
// WSJT-X log — display only (no DX de format)
loadConsole(m_wsjtxConsole, tailFile(wsjtxLog));
// POTA log — display only
loadConsole(m_potaConsole, tailFile(potaLog));
// FreeDV log — display only
#ifdef HAVE_WEBSOCKETS
if (!freedvLog.isEmpty())
loadConsole(m_freedvConsole, tailFile(freedvLog));
#else
Q_UNUSED(freedvLog);
#endif
// Batch all spots into the model at once
QVector<DxSpot> allSpots;
allSpots.reserve(clusterSpots.size() + rbnSpots.size());
allSpots.append(clusterSpots);
allSpots.append(rbnSpots);
if (!allSpots.isEmpty())
m_spotModel->addSpots(allSpots);
m_spotTable->scrollToBottom();
}
void DxClusterDialog::buildClusterTab(QTabWidget* tabs)
{
auto* page = new QWidget;
auto* layout = new QVBoxLayout(page);
layout->setSpacing(8);
auto& s = AppSettings::instance();
// ── Connection settings ─────────────────────────────────────────────
auto* connGroup = new QGroupBox("Connection");
auto* connLayout = new QVBoxLayout(connGroup);
connLayout->setSpacing(4);
auto* grid = new QGridLayout;
grid->setColumnStretch(1, 1);
int row = 0;
grid->addWidget(new QLabel("Server:"), row, 0);
m_hostEdit = new QLineEdit(s.value("DxClusterHost", "dxc.nc7j.com").toString());
m_hostEdit->setPlaceholderText("dxc.nc7j.com");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_hostEdit, "QLineEdit { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_hostEdit, row, 1);
row++;
grid->addWidget(new QLabel("Port:"), row, 0);
m_portSpin = new QSpinBox;
m_portSpin->setRange(1, 65535);
m_portSpin->setValue(s.value("DxClusterPort", 7300).toInt());
AetherSDR::ThemeManager::instance().applyStyleSheet(m_portSpin, "QSpinBox { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_portSpin, row, 1);
row++;
grid->addWidget(new QLabel("Callsign:"), row, 0);
m_callEdit = new QLineEdit(s.value("DxClusterCallsign").toString());
m_callEdit->setPlaceholderText("your callsign");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_callEdit, "QLineEdit { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_callEdit, row, 1);
row++;
connLayout->addLayout(grid);
// Button row
auto* btnRow = new QHBoxLayout;
m_autoConnectBtn = new QPushButton(
s.value("DxClusterAutoConnect", "False").toString() == "True" ? "Auto-Connect: ON" : "Auto-Connect: OFF");
m_autoConnectBtn->setCheckable(true);
m_autoConnectBtn->setChecked(s.value("DxClusterAutoConnect", "False").toString() == "True");
m_autoConnectBtn->setStyleSheet(
kSpotHubToggle);
connect(m_autoConnectBtn, &QPushButton::toggled, this, [this](bool on) {
m_autoConnectBtn->setText(on ? "Auto-Connect: ON" : "Auto-Connect: OFF");
auto& s = AppSettings::instance();
s.setValue("DxClusterAutoConnect", on ? "True" : "False");
s.save();
});
btnRow->addWidget(m_autoConnectBtn);
// Startup-commands editor: writes "DxClusterStartupCommands" which
// DxClusterClient::sendStartupCommands() replays after every login
// (#2683).
auto* startupBtn = new QPushButton("Startup Commands…");
startupBtn->setToolTip(
"Edit cluster commands sent automatically after every login.\n"
"One command per line — e.g. SET/NAME, SET/QTH, ACCEPT/SPOT.");
startupBtn->setStyleSheet(kSpotHubToggle);
connect(startupBtn, &QPushButton::clicked, this, [this] {
DxClusterStartupCommandsDialog::edit(
"DX Cluster Startup Commands",
"DxClusterStartupCommands", this);
});
btnRow->addWidget(startupBtn);
btnRow->addStretch();
m_statusLabel = new QLabel("Disconnected");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_statusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
btnRow->addWidget(m_statusLabel);
btnRow->addStretch();
m_connectBtn = new QPushButton(m_client->isConnected() ? "Disconnect" : "Connect");
m_connectBtn->setFixedWidth(100);
AetherSDR::ThemeManager::instance().applyStyleSheet(m_connectBtn, "QPushButton { background: {{color.accent}}; color: {{color.background.0}}; font-weight: bold; "
"border: 1px solid {{color.accent.dim}}; padding: 4px; border-radius: 3px; }"
"QPushButton:hover { background: {{color.accent.bright}}; }"
"QPushButton:disabled { background: #404060; color: {{color.text.label}}; }");
connect(m_connectBtn, &QPushButton::clicked, this, [this] {
if (m_client->isConnected()) {
emit disconnectRequested();
return;
}
QString host = m_hostEdit->text().trimmed();
QString call = m_callEdit->text().trimmed().toUpper();
quint16 port = static_cast<quint16>(m_portSpin->value());
if (host.isEmpty() || call.isEmpty()) {
m_statusLabel->setText("Server and callsign are required");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_statusLabel, "QLabel { color: {{color.accent.danger}}; font-size: 11px; }");
return;
}
auto& s = AppSettings::instance();
s.setValue("DxClusterHost", host);
s.setValue("DxClusterPort", port);
s.setValue("DxClusterCallsign", call);
s.save();
emit connectRequested(host, port, call);
});
btnRow->addWidget(m_connectBtn);
connLayout->addLayout(btnRow);
layout->addWidget(connGroup);
// ── Console output ──────────────────────────────────────────────────
auto* consoleRow = new QHBoxLayout;
auto* consoleLabel = new QLabel("Cluster Console");
AetherSDR::ThemeManager::instance().applyStyleSheet(consoleLabel, "QLabel { color: {{color.accent}}; font-weight: bold; }");
consoleRow->addWidget(consoleLabel);
consoleRow->addStretch();
auto* dxcColorLabel = new QLabel("Spot Color:");
AetherSDR::ThemeManager::instance().applyStyleSheet(dxcColorLabel, "QLabel { color: {{color.text.label}}; font-size: 12px; }");
consoleRow->addWidget(dxcColorLabel);
QColor dxcColor(s.value("DxClusterSpotColor", "#D2B48C").toString());
auto* dxcColorBtn = new QPushButton;
dxcColorBtn->setFixedSize(18, 18);
dxcColorBtn->setStyleSheet(QString(
"QPushButton { background: %1; border: 2px solid #405060; border-radius: 3px; }"
"QPushButton:hover { border-color: #c8d8e8; }").arg(dxcColor.name()));
connect(dxcColorBtn, &QPushButton::clicked, this, [this, dxcColorBtn] {
QColor c = QColorDialog::getColor(
QColor(AppSettings::instance().value("DxClusterSpotColor", "#D2B48C").toString()),
this, "DX Cluster Spot Color");
if (c.isValid()) {
dxcColorBtn->setStyleSheet(QString(
"QPushButton { background: %1; border: 2px solid #405060; border-radius: 3px; }"
"QPushButton:hover { border-color: #c8d8e8; }").arg(c.name()));
AppSettings::instance().setValue("DxClusterSpotColor", c.name());
AppSettings::instance().save();
}
});
consoleRow->addWidget(dxcColorBtn);
layout->addLayout(consoleRow);
m_console = new QPlainTextEdit;
m_console->setReadOnly(true);
m_console->setMaximumBlockCount(2000);
AetherSDR::ThemeManager::instance().applyStyleSheet(m_console, "QPlainTextEdit {"
" background: {{color.background.0}};"
" color: {{color.text.secondary}};"
" font-family: monospace;"
" font-size: 11px;"
" border: 1px solid {{color.background.1}};"
" padding: 4px;"
"}");
layout->addWidget(m_console, 1);
// Command input row
auto* cmdRow = new QHBoxLayout;
m_cmdEdit = new QLineEdit;
m_cmdEdit->setPlaceholderText("Type a cluster command (e.g. sh/dx 20, set/filter, bye)");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_cmdEdit, "QLineEdit { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; font-family: monospace; }");
m_cmdEdit->setEnabled(m_client->isConnected());
connect(m_cmdEdit, &QLineEdit::returnPressed, this, [this] {
QString cmd = m_cmdEdit->text().trimmed();
if (cmd.isEmpty() || !m_client->isConnected()) return;
QMetaObject::invokeMethod(m_client, [client=m_client, cmd] { client->sendCommand(cmd); });
m_console->appendPlainText("> " + cmd);
m_cmdEdit->clear();
});
m_sendBtn = new QPushButton("Send");
m_sendBtn->setFixedWidth(60);
m_sendBtn->setEnabled(m_client->isConnected());
connect(m_sendBtn, &QPushButton::clicked, this, [this] {
m_cmdEdit->returnPressed();
});
cmdRow->addWidget(m_cmdEdit, 1);
cmdRow->addWidget(m_sendBtn);
cmdRow->addWidget(makeConsoleClearButton(m_console, &m_clusterLogPath, "clusterClearBtn"));
layout->addLayout(cmdRow);
tabs->addTab(page, "Cluster");
}
void DxClusterDialog::buildRbnTab(QTabWidget* tabs)
{
auto* page = new QWidget;
auto* layout = new QVBoxLayout(page);
layout->setSpacing(8);
auto& s = AppSettings::instance();
QString defaultCall = s.value("RbnCallsign").toString();
if (defaultCall.isEmpty())
defaultCall = s.value("DxClusterCallsign").toString();
// ── Connection settings ─────────────────────────────────────────────
auto* connGroup = new QGroupBox("RBN Connection");
auto* connLayout = new QVBoxLayout(connGroup);
connLayout->setSpacing(4);
auto* grid = new QGridLayout;
grid->setColumnStretch(1, 1);
int row = 0;
grid->addWidget(new QLabel("Server:"), row, 0);
m_rbnHostEdit = new QLineEdit(s.value("RbnHost", "telnet.reversebeacon.net").toString());
m_rbnHostEdit->setPlaceholderText("telnet.reversebeacon.net");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnHostEdit, "QLineEdit { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_rbnHostEdit, row, 1);
row++;
grid->addWidget(new QLabel("Port:"), row, 0);
m_rbnPortSpin = new QSpinBox;
m_rbnPortSpin->setRange(1, 65535);
m_rbnPortSpin->setValue(s.value("RbnPort", 7000).toInt());
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnPortSpin, "QSpinBox { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_rbnPortSpin, row, 1);
row++;
grid->addWidget(new QLabel("Callsign:"), row, 0);
m_rbnCallEdit = new QLineEdit(defaultCall);
m_rbnCallEdit->setPlaceholderText("your callsign");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnCallEdit, "QLineEdit { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
grid->addWidget(m_rbnCallEdit, row, 1);
row++;
// Rate limit
grid->addWidget(new QLabel("Rate Limit:"), row, 0);
auto* rateRow = new QHBoxLayout;
auto* rateSpin = new QSpinBox;
rateSpin->setRange(1, 100);
rateSpin->setValue(s.value("RbnRateLimit", 10).toInt());
rateSpin->setSuffix(" spots/sec");
AetherSDR::ThemeManager::instance().applyStyleSheet(rateSpin, "QSpinBox { background: {{color.background.0}}; color: {{color.text.primary}}; border: 1px solid {{color.background.1}}; padding: 3px; }");
connect(rateSpin, &QSpinBox::valueChanged, this, [](int v) {
auto& s = AppSettings::instance();
s.setValue("RbnRateLimit", v);
s.save();
});
rateRow->addWidget(rateSpin);
rateRow->addStretch();
grid->addLayout(rateRow, row, 1);
row++;
connLayout->addLayout(grid);
// Button row
auto* btnRow = new QHBoxLayout;
m_rbnAutoConnectBtn = new QPushButton(
s.value("RbnAutoConnect", "False").toString() == "True" ? "Auto-Connect: ON" : "Auto-Connect: OFF");
m_rbnAutoConnectBtn->setCheckable(true);
m_rbnAutoConnectBtn->setChecked(s.value("RbnAutoConnect", "False").toString() == "True");
m_rbnAutoConnectBtn->setStyleSheet(
kSpotHubToggle);
connect(m_rbnAutoConnectBtn, &QPushButton::toggled, this, [this](bool on) {
m_rbnAutoConnectBtn->setText(on ? "Auto-Connect: ON" : "Auto-Connect: OFF");
auto& s = AppSettings::instance();
s.setValue("RbnAutoConnect", on ? "True" : "False");
s.save();
});
btnRow->addWidget(m_rbnAutoConnectBtn);
// Startup-commands editor (RBN instance — independent AppSettings key
// from the DX-cluster tab, see MainWindow setStartupCommandsKey wiring
// for the corresponding backend hook).
auto* rbnStartupBtn = new QPushButton("Startup Commands…");
rbnStartupBtn->setToolTip(
"Edit RBN cluster commands sent automatically after every login.\n"
"One command per line — e.g. SET/NAME, SET/QTH, ACCEPT/SPOT.");
rbnStartupBtn->setStyleSheet(kSpotHubToggle);
connect(rbnStartupBtn, &QPushButton::clicked, this, [this] {
DxClusterStartupCommandsDialog::edit(
"RBN Startup Commands",
"RbnStartupCommands", this);
});
btnRow->addWidget(rbnStartupBtn);
btnRow->addStretch();
m_rbnStatusLabel = new QLabel("Disconnected");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnStatusLabel, "QLabel { color: {{color.text.label}}; font-size: 11px; }");
btnRow->addWidget(m_rbnStatusLabel);
btnRow->addStretch();
m_rbnConnectBtn = new QPushButton(m_rbnClient->isConnected() ? "Disconnect" : "Connect");
m_rbnConnectBtn->setFixedWidth(100);
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnConnectBtn, "QPushButton { background: {{color.accent}}; color: {{color.background.0}}; font-weight: bold; "
"border: 1px solid {{color.accent.dim}}; padding: 4px; border-radius: 3px; }"
"QPushButton:hover { background: {{color.accent.bright}}; }"
"QPushButton:disabled { background: #404060; color: {{color.text.label}}; }");
connect(m_rbnConnectBtn, &QPushButton::clicked, this, [this] {
if (m_rbnClient->isConnected()) {
emit rbnDisconnectRequested();
return;
}
QString host = m_rbnHostEdit->text().trimmed();
QString call = m_rbnCallEdit->text().trimmed().toUpper();
quint16 port = static_cast<quint16>(m_rbnPortSpin->value());
if (host.isEmpty() || call.isEmpty()) {
m_rbnStatusLabel->setText("Server and callsign are required");
AetherSDR::ThemeManager::instance().applyStyleSheet(m_rbnStatusLabel, "QLabel { color: {{color.accent.danger}}; font-size: 11px; }");
return;
}
auto& s = AppSettings::instance();
s.setValue("RbnHost", host);
s.setValue("RbnPort", port);
s.setValue("RbnCallsign", call);
s.save();
emit rbnConnectRequested(host, port, call);
});