From cc68bd2d84609c56932d7741c70d6292db08c911 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 23 Jul 2022 21:14:08 +1000 Subject: [PATCH] Handle no sd path set --- companion/src/apppreferencesdialog.cpp | 21 ++++- companion/src/updates/updatesdialog.cpp | 100 +++++++++++++++++------- companion/src/updates/updatesdialog.h | 3 +- 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index c01a55997..2a136d12d 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -429,9 +429,24 @@ void AppPreferencesDialog::loadUpdatesTab() // trigger toggled signal by changing design value and then setting to saved value ui->chkDecompressDirUseDwnld->setChecked(!ui->chkDecompressDirUseDwnld->isChecked()); ui->chkDecompressDirUseDwnld->setChecked(g.decompressDirUseDwnld()); - // trigger toggled signal by changing design value and then setting to saved value - ui->chkUpdateDirUseSD->setChecked(!ui->chkUpdateDirUseSD->isChecked()); - ui->chkUpdateDirUseSD->setChecked(g.updateDirUseSD()); + + if (g.currentProfile().sdPath().trimmed().isEmpty()) + ui->chkUpdateDirUseSD->setEnabled(false); + else + ui->chkUpdateDirUseSD->setEnabled(true); + + if (g.updateDirUseSD() && g.currentProfile().sdPath().trimmed().isEmpty()) { + g.updateDirUseSD(false); + g.updateDirReset(); + } + + if (g.updateDirUseSD()) { + // trigger toggled signal by changing design value and then setting to saved value + ui->chkUpdateDirUseSD->setChecked(!ui->chkUpdateDirUseSD->isChecked()); + ui->chkUpdateDirUseSD->setChecked(g.updateDirUseSD()); + } + else + ui->chkUpdateDirUseSD->setChecked(false); ui->chkDelDownloads->setChecked(g.updDelDownloads()); ui->cboLogLevel->setCurrentIndex(g.updLogLevel()); diff --git a/companion/src/updates/updatesdialog.cpp b/companion/src/updates/updatesdialog.cpp index 34944592c..77dc2eb21 100644 --- a/companion/src/updates/updatesdialog.cpp +++ b/companion/src/updates/updatesdialog.cpp @@ -27,6 +27,7 @@ #include #include #include +#include UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : QDialog(parent), @@ -76,8 +77,23 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : } }); - ui->chkUpdateDirUseSD->setChecked(!g.updateDirUseSD()); - ui->chkUpdateDirUseSD->setChecked(g.updateDirUseSD()); + if (g.currentProfile().sdPath().trimmed().isEmpty()) + ui->chkUpdateDirUseSD->setEnabled(false); + else + ui->chkUpdateDirUseSD->setEnabled(true); + + if (g.updateDirUseSD() && g.currentProfile().sdPath().trimmed().isEmpty()) { + g.updateDirUseSD(false); + g.updateDirReset(); + } + + if (g.updateDirUseSD()) { + // trigger toggled signal by changing design value and then setting to saved value + ui->chkUpdateDirUseSD->setChecked(!ui->chkUpdateDirUseSD->isChecked()); + ui->chkUpdateDirUseSD->setChecked(g.updateDirUseSD()); + } + else + ui->chkUpdateDirUseSD->setChecked(false); connect(ui->btnDownloadSelect, &QPushButton::clicked, [=]() { QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your download folder"), g.downloadDir()); @@ -176,34 +192,6 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) : ui->chkDelDownloads->setChecked(g.updDelDownloads()); - connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]() { - QMapIterator it(factories->sortedComponentsList()); - - while (it.hasNext()) { - it.next(); - int i = it.value(); - - if (g.component[i].checkForUpdate()) { - if (chkUpdate[i]->isChecked()) { - const QString name = it.key(); - UpdateParameters *runParams = factories->getRunParams(name); - runParams->data.flags |= UpdateInterface::UPDFLG_Update; - runParams->data.downloadDir = ui->leDownloadDir->text(); - runParams->data.decompressDirUseDwnld = ui->chkDecompressDirUseDwnld->isChecked(); - runParams->data.decompressDir = ui->leDecompressDir->text(); - runParams->data.updateDirUseSD = ui->chkUpdateDirUseSD->isChecked(); - runParams->data.updateDir = ui->leUpdateDir->text(); - if (ui->chkDelDownloads->isChecked()) - runParams->data.flags |= UpdateInterface::UPDFLG_DelDownloads; - else - runParams->data.flags &= ~UpdateInterface::UPDFLG_DelDownloads; - } - } - } - - QDialog::accept(); - }); - connect(ui->buttonBox, &QDialogButtonBox::rejected, [=]() { QDialog::reject(); }); @@ -222,3 +210,55 @@ UpdatesDialog::~UpdatesDialog() { delete ui; } + +void UpdatesDialog::accept() +{ + if (ui->leDownloadDir->text().isEmpty()) { + QMessageBox::warning(this, CPN_STR_APP_NAME, tr("Download folder path missing!")); + return; + } + + if (ui->leDecompressDir->text().isEmpty()) { + QMessageBox::warning(this, CPN_STR_APP_NAME, tr("Decompress folder path missing!")); + return; + } + + if (ui->leUpdateDir->text().isEmpty()) { + QMessageBox::warning(this, CPN_STR_APP_NAME, tr("Update folder path missing!")); + return; + } + + QMapIterator it(factories->sortedComponentsList()); + + int cnt = 0; + + while (it.hasNext()) { + it.next(); + int i = it.value(); + + if (g.component[i].checkForUpdate()) { + if (chkUpdate[i]->isChecked()) { + cnt++; + const QString name = it.key(); + UpdateParameters *runParams = factories->getRunParams(name); + runParams->data.flags |= UpdateInterface::UPDFLG_Update; + runParams->data.downloadDir = ui->leDownloadDir->text(); + runParams->data.decompressDirUseDwnld = ui->chkDecompressDirUseDwnld->isChecked(); + runParams->data.decompressDir = ui->leDecompressDir->text(); + runParams->data.updateDirUseSD = ui->chkUpdateDirUseSD->isChecked(); + runParams->data.updateDir = ui->leUpdateDir->text(); + if (ui->chkDelDownloads->isChecked()) + runParams->data.flags |= UpdateInterface::UPDFLG_DelDownloads; + else + runParams->data.flags &= ~UpdateInterface::UPDFLG_DelDownloads; + } + } + } + + if (cnt < 1) { + QMessageBox::warning(this, CPN_STR_APP_NAME, tr("No components selected for update!")); + return; + } + + QDialog::accept(); +} diff --git a/companion/src/updates/updatesdialog.h b/companion/src/updates/updatesdialog.h index 31f0e2702..4f70233ad 100644 --- a/companion/src/updates/updatesdialog.h +++ b/companion/src/updates/updatesdialog.h @@ -44,10 +44,11 @@ class UpdatesDialog : public QDialog signals: private slots: + virtual void accept(); private: Ui::UpdatesDialog *ui; - const UpdateFactories *factories; + UpdateFactories *factories; QCheckBox *chkUpdate[MAX_COMPONENTS]; QLabel *lblCurrentRel[MAX_COMPONENTS];