diff --git a/CMakeLists.txt b/CMakeLists.txt index 6389c3c..b1f7d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,7 @@ set (wsjtx_CXXSRCS messageaveraging.cpp WsprTxScheduler.cpp varicode.cpp + SelfDestructMessageBox.cpp mainwindow.cpp Configuration.cpp main.cpp diff --git a/SelfDestructMessageBox.cpp b/SelfDestructMessageBox.cpp new file mode 100644 index 0000000..5ec787b --- /dev/null +++ b/SelfDestructMessageBox.cpp @@ -0,0 +1,40 @@ +#include "SelfDestructMessageBox.h" + +SelfDestructMessageBox::SelfDestructMessageBox( + int timeout, + const QString& title, + const QString& text, + QMessageBox::Icon icon, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton, + QWidget* parent, + Qt::WindowFlags flags) + : QMessageBox(icon, title, text, buttons, parent, flags), + m_timeout(timeout), + m_text(text) +{ + connect(&m_timer, &QTimer::timeout, this, &SelfDestructMessageBox::tick); + m_timer.setInterval(1000); + + setDefaultButton(defaultButton); + connect(this->defaultButton(), &QPushButton::clicked, this, &SelfDestructMessageBox::accept); +} + +void SelfDestructMessageBox::showEvent(QShowEvent* event) +{ + tick(); + m_timer.start(); + QMessageBox::showEvent(event); +} + +void SelfDestructMessageBox::tick(){ + m_timeout--; + + if(m_timeout){ + setText(m_text.arg(m_timeout)); + return; + } + + m_timer.stop(); + accept(); +} diff --git a/SelfDestructMessageBox.h b/SelfDestructMessageBox.h new file mode 100644 index 0000000..7b3e5cd --- /dev/null +++ b/SelfDestructMessageBox.h @@ -0,0 +1,35 @@ +#ifndef SELFDESTRUCTMESSAGEBOX_H +#define SELFDESTRUCTMESSAGEBOX_H + +#include +#include +#include +#include +#include + +class SelfDestructMessageBox : public QMessageBox +{ + Q_OBJECT + +public: + SelfDestructMessageBox(int timeout, + const QString& title, + const QString& text, + QMessageBox::Icon icon, + QMessageBox::StandardButtons buttons = QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::StandardButton defaultButton = QMessageBox::Ok, + QWidget* parent = nullptr, + Qt::WindowFlags flags = 0); + + void showEvent(QShowEvent* event) override; + +private slots: + void tick(); + +private: + int m_timeout; + QString m_text; + QTimer m_timer; +}; + +#endif // SELFDESTRUCTMESSAGEBOX_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 2c53062..d6175eb 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -58,6 +58,7 @@ #include "MaidenheadLocatorValidator.hpp" #include "CallsignValidator.hpp" #include "EqualizationToolsDialog.hpp" +#include "SelfDestructMessageBox.h" #include "ui_mainwindow.h" #include "moc_mainwindow.cpp" @@ -1336,6 +1337,11 @@ void MainWindow::tryBandHop(){ return; } + // make sure we're not transmitting + if(isMessageQueuedForTransmit()){ + return; + } + // get the current band auto dialFreq = dialFrequency(); @@ -1382,21 +1388,43 @@ void MainWindow::tryBandHop(){ freqIsDifferent ); - //qDebug() << "Can switch to" << station.band_name_ << "=" << canSwitch << station.switch_at_.time().toString("hh:mm") << "<=" << d.time().toString("hh:mm") << "<=" << station.switch_until_.time().toString("hh:mm") << m_bandHopped << m_bandHoppedFreq; - // switch, if we can and the band is different than our current band if(canSwitch){ + Frequency frequency = station.frequency_; - qDebug() << "Automatic band hop from" << currentBand << "to" << station.band_name_ << "at" << Radio::frequency_MHz_string(station.frequency_); + m_bandHopped = false; + m_bandHoppedFreq = frequency; - // cache the frequency set by bandHop... - m_bandHopped = true; - m_bandHoppedFreq = station.frequency_; + SelfDestructMessageBox * m = new SelfDestructMessageBox(30, + "Scheduled Frequency Change", + QString("A scheduled frequency change has arrived. The rig frequency will be changed to %1 MHz in %2 second(s).").arg(Radio::frequency_MHz_string(station.frequency_)), + QMessageBox::Information, + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Ok, + this); - // TODO: jsherer - is this the right way to switch the rig freq? - setRig(station.frequency_); + connect(m, &SelfDestructMessageBox::accepted, this, [this, frequency](){ + m_bandHopped = true; + setRig(frequency); + }); - break; + m->show(); + +#if 0 + // TODO: jsherer - this is totally a hack because of the signal that gets emitted to clearActivity on band change... + QTimer *t = new QTimer(this); + t->setInterval(250); + t->setSingleShot(true); + connect(t, &QTimer::timeout, this, [this, station, dialFreq](){ + auto message = QString("Scheduled frequency switch from %1 MHz to %2 MHz"); + message = message.arg(Radio::frequency_MHz_string(dialFreq)); + message = message.arg(Radio::frequency_MHz_string(station.frequency_)); + writeNoticeTextToUI(QDateTime::currentDateTimeUtc(), message); + }); + t->start(); +#endif + + return; } } } @@ -5705,6 +5733,24 @@ void MainWindow::displayTextForFreq(QString text, int freq, QDateTime date, bool } } +void MainWindow::writeNoticeTextToUI(QDateTime date, QString text){ + auto c = ui->textEditRX->textCursor(); + c.movePosition(QTextCursor::End); + if(c.block().length() > 1){ + c.insertBlock(); + } + + text = text.toHtmlEscaped(); + c.insertBlock(); + c.insertHtml(QString("%1 - %2").arg(date.time().toString()).arg(text)); + + c.movePosition(QTextCursor::End); + + ui->textEditRX->ensureCursorVisible(); + ui->textEditRX->verticalScrollBar()->setValue(ui->textEditRX->verticalScrollBar()->maximum()); +} + + int MainWindow::writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block){ auto c = ui->textEditRX->textCursor(); diff --git a/mainwindow.h b/mainwindow.h index 16b5d01..21a279f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -134,6 +134,7 @@ public slots: QString lookupCallInCompoundCache(QString const &call); void clearActivity(); void displayTextForFreq(QString text, int freq, QDateTime date, bool isTx, bool isNewLine, bool isLast); + void writeNoticeTextToUI(QDateTime date, QString text); int writeMessageTextToUI(QDateTime date, QString text, int freq, bool bold, int block=-1); bool isMessageQueuedForTransmit(); void addMessageText(QString text, bool clear=false); diff --git a/wsjtx.pro b/wsjtx.pro index d5cfb15..0fc9aee 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -70,7 +70,8 @@ SOURCES += \ EqualizationToolsDialog.cpp \ varicode.cpp \ NetworkMessage.cpp \ - MessageClient.cpp + MessageClient.cpp \ + SelfDestructMessageBox.cpp HEADERS += qt_helpers.hpp \ pimpl_h.hpp pimpl_impl.hpp \ @@ -92,7 +93,8 @@ HEADERS += qt_helpers.hpp \ qpriorityqueue.h \ crc.h \ NetworkMessage.hpp \ - MessageClient.hpp + MessageClient.hpp \ + SelfDestructMessageBox.h INCLUDEPATH += qmake_only