From d952333037d21dd5dcb46b5fd5533996ef8e018e Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Thu, 26 Jan 2023 14:53:13 +1100 Subject: [PATCH] feat(cpn): Status dialog when writing models and settings to radio (#3043) --- companion/src/helpers.cpp | 22 ++++++++++++++++++++++ companion/src/helpers.h | 15 +++++++++++++++ companion/src/mainwindow.cpp | 6 +++++- companion/src/mdichild.cpp | 11 +++++++---- companion/src/mdichild.h | 3 ++- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index bac0a2f23df..ccdda040c73 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -929,3 +929,25 @@ bool SemanticVersion::fromInt(const unsigned int val) version.preReleaseNumber = Helpers::getBitmappedValue(val, 0, 4); return isValid(); } + +StatusDialog::StatusDialog(QWidget * parent, const QString title, QString msgtext, const int width) : + QDialog(parent) +{ + setWindowTitle(title); + QVBoxLayout *layout = new QVBoxLayout(this); + msg = new QLabel(this); + msg->setFixedWidth(width); + msg->setContentsMargins(50, 50, 50, 50); + update(msgtext); + layout->addWidget(msg); + show(); +} + +StatusDialog::~StatusDialog() +{ +} + +void StatusDialog::update(QString text) +{ + msg->setText(text); +} diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 9719a2119ca..4b17581740e 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -29,6 +29,7 @@ #include #include #include +#include extern const QColor colors[CPN_MAX_CURVES]; @@ -311,3 +312,17 @@ class SemanticVersion inline int preReleaseTypeToInt(QString preRelType) const { return PreReleaseTypesStringList.indexOf(preRelType); } }; + +class StatusDialog: public QDialog +{ + Q_OBJECT + + public: + StatusDialog(QWidget * parent = nullptr, const QString title = "", QString msgtext = "", const int width = 200); + virtual ~StatusDialog(); + + void update(QString text); + + private: + QLabel *msg; +}; diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 422d4effcb0..36f2ffdfce4 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -530,8 +530,12 @@ void MainWindow::customizeSplash() void MainWindow::writeSettings() { + StatusDialog *status = new StatusDialog(this, tr("Writing models and settings to radio"), tr("In progress..."), 400); + if (activeMdiChild()) - activeMdiChild()->writeSettings(); + activeMdiChild()->writeSettings(status); + + delete status; } void MainWindow::readSettings() diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 62672287b50..b5b7b667e41 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1410,7 +1410,7 @@ int MdiChild::askQuestion(const QString & msg, QMessageBox::StandardButtons butt return QMessageBox::question(this, CPN_STR_APP_NAME, msg, buttons, defaultButton); } -void MdiChild::writeSettings() // write to Tx +void MdiChild::writeSettings(StatusDialog * status) // write to Tx { if (g.confirmWriteModelsAndSettings()) { QMessageBox msgbox; @@ -1420,7 +1420,7 @@ void MdiChild::writeSettings() // write to Tx msgbox.setStandardButtons(QMessageBox::Yes | QMessageBox::Abort); msgbox.setDefaultButton(QMessageBox::Abort); - QCheckBox *cb = new QCheckBox(tr("Don't show this message again")); + QCheckBox *cb = new QCheckBox(tr("Do not show this message again")); msgbox.setCheckBox(cb); connect(cb, &QCheckBox::stateChanged, [=](const int &state){ g.confirmWriteModelsAndSettings(!state); }); @@ -1438,12 +1438,15 @@ void MdiChild::writeSettings() // write to Tx QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find radio SD card!")); return; } + if (saveFile(radioPath, false)) { - QMessageBox::information(this, CPN_STR_TTL_INFO, tr("Saved models and settings to radio")); + status->hide(); + QMessageBox::information(this, CPN_STR_TTL_INFO, tr("Models and settings written to radio")); } else { qDebug() << "MdiChild::writeEeprom(): saveFile error"; - QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Error saving models and settings to radio!")); + status->hide(); + QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Error writing models and settings to radio!")); } } else { diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 4a5293b32f1..bfbbd863817 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -34,6 +34,7 @@ #include class QToolBar; +class StatusDialog; namespace Ui { class MdiChild; @@ -95,7 +96,7 @@ class MdiChild : public QWidget bool saveAs(bool isNew=false); bool saveFile(const QString & fileName, bool setCurrent=true); void closeFile(bool force = false); - void writeSettings(); + void writeSettings(StatusDialog * status); void print(int model=-1, const QString & filename=""); void onFirmwareChanged();