Skip to content

Commit

Permalink
feat(cpn): Status dialog when writing models and settings to radio (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Horne authored Jan 26, 2023
1 parent 57bf180 commit d952333
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
22 changes: 22 additions & 0 deletions companion/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
15 changes: 15 additions & 0 deletions companion/src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QTime>
#include <QElapsedTimer>
#include <QStandardItemModel>
#include <QDialog>

extern const QColor colors[CPN_MAX_CURVES];

Expand Down Expand Up @@ -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;
};
6 changes: 5 additions & 1 deletion companion/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions companion/src/mdichild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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); });

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion companion/src/mdichild.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QListWidget>

class QToolBar;
class StatusDialog;

namespace Ui {
class MdiChild;
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit d952333

Please sign in to comment.