feat(cpn): Enhancements to update component runtime options (#2324)
* enh(cpn): Save update component asset options and manage in app settings * Add option to delete decompress folders independent of delete download folder * Fix sdsync to point to last update folder * Update options dlg to allow choosing release channel and saving settings as defaults * Rename params * Asset options dialog shared between settings and update run. Add to Save as defaults
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
#include "updateoptionsdialog.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QMap>
|
||||
#include <QFileDialog>
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
@@ -32,7 +31,8 @@
|
||||
UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::UpdatesDialog),
|
||||
factories(factories)
|
||||
factories(factories),
|
||||
sortedCompList(factories->sortedComponentsList(true))
|
||||
{
|
||||
// downloading the release meta data takes a few seconds for each component so display progress
|
||||
QDialog *status = new QDialog(parent);
|
||||
@@ -46,6 +46,8 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->chkDelDownloads->setChecked(g.updDelDownloads());
|
||||
ui->chkDelDecompress->setChecked(g.updDelDecompress());
|
||||
ui->leDownloadDir->setText(g.downloadDir());
|
||||
|
||||
connect(ui->chkDecompressDirUseDwnld, &QCheckBox::stateChanged, [=](const int checked) {
|
||||
@@ -53,15 +55,24 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
ui->leDecompressDir->setText(g.decompressDir());
|
||||
ui->leDecompressDir->setEnabled(true);
|
||||
ui->btnDecompressSelect->setEnabled(true);
|
||||
ui->chkDelDownloads->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui->leDecompressDir->setText(g.downloadDir());
|
||||
ui->leDecompressDir->setEnabled(false);
|
||||
ui->btnDecompressSelect->setEnabled(false);
|
||||
if (ui->chkDelDecompress->isChecked()) {
|
||||
ui->chkDelDownloads->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui->chkDelDownloads->setEnabled(false);
|
||||
ui->chkDelDownloads->setChecked(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ui->chkDecompressDirUseDwnld->setChecked(!g.decompressDirUseDwnld());
|
||||
// trigger toggled signal by changing design value and then setting to saved value
|
||||
ui->chkDecompressDirUseDwnld->setChecked(!ui->chkDecompressDirUseDwnld->isChecked());
|
||||
ui->chkDecompressDirUseDwnld->setChecked(g.decompressDirUseDwnld());
|
||||
|
||||
connect(ui->chkUpdateDirUseSD, &QCheckBox::stateChanged, [=](const int checked) {
|
||||
@@ -82,11 +93,6 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
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());
|
||||
@@ -116,6 +122,18 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->chkDelDecompress, &QCheckBox::stateChanged, [=](const int checked) {
|
||||
if (!checked) {
|
||||
if (ui->chkDecompressDirUseDwnld->isChecked()) {
|
||||
ui->chkDelDownloads->setEnabled(false);
|
||||
ui->chkDelDownloads->setChecked(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->chkDelDownloads->setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
@@ -130,18 +148,18 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
QLabel *h3 = new QLabel(tr("Channel"));
|
||||
grid->addWidget(h3, row, col++);
|
||||
|
||||
QLabel *h4 = new QLabel(tr("Current Release"));
|
||||
QLabel *h4 = new QLabel(tr("Current"));
|
||||
grid->addWidget(h4, row, col++);
|
||||
|
||||
QLabel *h5 = new QLabel(tr("Update Release"));
|
||||
QLabel *h5 = new QLabel(tr("Update to"));
|
||||
grid->addWidget(h5, row, col++);
|
||||
|
||||
col++; // options button
|
||||
col++; // options
|
||||
|
||||
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
|
||||
grid->addItem(spacer, row, col++);
|
||||
|
||||
QMapIterator<QString, int> it(factories->sortedComponentsList(true));
|
||||
QMapIterator<QString, int> it(sortedCompList);
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
@@ -162,23 +180,32 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
QLabel *lblName = new QLabel(name);
|
||||
grid->addWidget(lblName, row, col++);
|
||||
|
||||
QLabel *lblRC = new QLabel(ComponentData::releaseChannelsList().at(g.component[i].releaseChannel()));
|
||||
grid->addWidget(lblRC, row, col++);
|
||||
cboRelChannel[i] = new QComboBox();
|
||||
cboRelChannel[i]->addItems(ComponentData::releaseChannelsList());
|
||||
cboRelChannel[i]->setCurrentIndex(g.component[i].releaseChannel());
|
||||
grid->addWidget(cboRelChannel[i], row, col++);
|
||||
|
||||
lblCurrentRel[i] = new QLabel(factories->currentRelease(name));
|
||||
grid->addWidget(lblCurrentRel[i], row, col++);
|
||||
|
||||
lblUpdateRel[i] = new QLabel(factories->updateRelease(name));
|
||||
grid->addWidget(lblUpdateRel[i], row, col++);
|
||||
cboUpdateRel[i] = new QComboBox();
|
||||
cboUpdateRel[i]->addItems(factories->releases(name));
|
||||
grid->addWidget(cboUpdateRel[i], row, col++);
|
||||
|
||||
connect(cboRelChannel[i], QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (const int index) {
|
||||
factories->setReleaseChannel(name, index);
|
||||
cboUpdateRel[i]->clear();
|
||||
cboUpdateRel[i]->addItems(factories->releases(name));
|
||||
});
|
||||
|
||||
btnOptions[i] = new QPushButton(tr("Options"));
|
||||
connect(btnOptions[i], &QPushButton::clicked, [=]() {
|
||||
UpdateOptionsDialog *dlg = new UpdateOptionsDialog(this, factories, i);
|
||||
UpdateOptionsDialog *dlg = new UpdateOptionsDialog(this, factories, i, true);
|
||||
connect(dlg, &UpdateOptionsDialog::changed, [=](const int i) {
|
||||
QString name = g.component[i].name();
|
||||
chkUpdate[i]->setChecked(!factories->isLatestRelease(name));
|
||||
lblCurrentRel[i]->setText(factories->currentRelease(name));
|
||||
lblUpdateRel[i]->setText(factories->updateRelease(name));
|
||||
cboUpdateRel[i]->setCurrentText(factories->updateRelease(name));
|
||||
});
|
||||
dlg->exec();
|
||||
dlg->deleteLater();
|
||||
@@ -189,7 +216,11 @@ UpdatesDialog::UpdatesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
|
||||
ui->grpComponents->setLayout(grid);
|
||||
|
||||
ui->chkDelDownloads->setChecked(g.updDelDownloads());
|
||||
QPushButton *btnSaveAsDefaults = new QPushButton(tr("Save as Defaults"));
|
||||
ui->buttonBox->addButton(btnSaveAsDefaults, QDialogButtonBox::ActionRole);
|
||||
connect(btnSaveAsDefaults, &QPushButton::clicked, [=]() {
|
||||
saveAsDefaults();
|
||||
});
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, [=]() {
|
||||
QDialog::reject();
|
||||
@@ -227,30 +258,39 @@ void UpdatesDialog::accept()
|
||||
return;
|
||||
}
|
||||
|
||||
QMapIterator<QString, int> it(factories->sortedComponentsList());
|
||||
if (!ui->chkDecompressDirUseDwnld->isChecked() &&
|
||||
ui->leDecompressDir->text().trimmed() == ui->leDownloadDir->text().trimmed()) {
|
||||
QMessageBox::warning(this, CPN_STR_APP_NAME, tr("Decompress and download folders have the same path!"));
|
||||
return;
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
QMapIterator<QString, int> it(sortedCompList);
|
||||
|
||||
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 (chkUpdate[i]->isChecked()) {
|
||||
cnt++;
|
||||
const QString name = it.key();
|
||||
UpdateParameters *params = factories->getParams(name);
|
||||
params->updateRelease = cboUpdateRel[i]->currentText();
|
||||
params->flags |= UpdateInterface::UPDFLG_Update;
|
||||
params->downloadDir = ui->leDownloadDir->text();
|
||||
params->decompressDirUseDwnld = ui->chkDecompressDirUseDwnld->isChecked();
|
||||
params->decompressDir = ui->leDecompressDir->text();
|
||||
params->updateDirUseSD = ui->chkUpdateDirUseSD->isChecked();
|
||||
params->updateDir = ui->leUpdateDir->text();
|
||||
if (ui->chkDelDownloads->isChecked())
|
||||
params->flags |= UpdateInterface::UPDFLG_DelDownloads;
|
||||
else
|
||||
params->flags &= ~UpdateInterface::UPDFLG_DelDownloads;
|
||||
if (ui->chkDelDecompress->isChecked())
|
||||
params->flags |= UpdateInterface::UPDFLG_DelDecompress;
|
||||
else
|
||||
params->flags &= ~UpdateInterface::UPDFLG_DelDecompress;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,3 +301,23 @@ void UpdatesDialog::accept()
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void UpdatesDialog::saveAsDefaults()
|
||||
{
|
||||
g.downloadDir(ui->leDownloadDir->text());
|
||||
g.decompressDirUseDwnld(ui->chkDecompressDirUseDwnld->isChecked());
|
||||
g.decompressDir(ui->leDecompressDir->text());
|
||||
g.updateDirUseSD(ui->chkUpdateDirUseSD->isChecked());
|
||||
g.updateDir(ui->leUpdateDir->text());
|
||||
g.updDelDownloads(ui->chkDelDownloads->isChecked());
|
||||
g.updDelDecompress(ui->chkDelDecompress->isChecked());
|
||||
|
||||
QMapIterator<QString, int> it(sortedCompList);
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
int i = it.value();
|
||||
g.component[i].releaseChannel((ComponentData::ReleaseChannel)cboRelChannel[i]->currentIndex());
|
||||
factories->saveAssetSettings(it.key());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user