Refactor firmware and companion updates plus add extra supporting components
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
#include "apppreferencesdialog.h"
|
||||
#include "ui_apppreferencesdialog.h"
|
||||
#include "mainwindow.h"
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
#include "storage.h"
|
||||
#if defined(JOYSTICKS)
|
||||
@@ -30,14 +29,16 @@
|
||||
#endif
|
||||
#include "moduledata.h"
|
||||
#include "compounditemmodels.h"
|
||||
#include "updates/updateinterface.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
AppPreferencesDialog::AppPreferencesDialog(QWidget * parent) :
|
||||
AppPreferencesDialog::AppPreferencesDialog(QWidget * parent, UpdateFactories * factories) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AppPreferencesDialog),
|
||||
updateLock(false),
|
||||
mainWinHasDirtyChild(false)
|
||||
mainWinHasDirtyChild(false),
|
||||
factories(factories)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(CompanionIcon("apppreferences.png"));
|
||||
@@ -73,9 +74,6 @@ void AppPreferencesDialog::accept()
|
||||
{
|
||||
Profile & profile = g.currentProfile();
|
||||
|
||||
g.autoCheckApp(ui->autoCheckCompanion->isChecked());
|
||||
g.OpenTxBranch(AppData::DownloadBranchType(ui->OpenTxBranch->currentIndex()));
|
||||
g.autoCheckFw(ui->autoCheckFirmware->isChecked());
|
||||
g.showSplash(ui->showSplash->isChecked());
|
||||
g.promptProfile(ui->chkPromptProfile->isChecked());
|
||||
g.simuSW(ui->simuSW->isChecked());
|
||||
@@ -101,6 +99,28 @@ void AppPreferencesDialog::accept()
|
||||
g.jsSupport(false);
|
||||
g.jsCtrl(0);
|
||||
}
|
||||
|
||||
// Updates tab
|
||||
|
||||
g.updateCheckFreq(AppData::UpdateCheckFreq(ui->cboUpdateCheckFreq->currentIndex()));
|
||||
g.downloadDir(ui->leDownloadDir->text());
|
||||
|
||||
g.decompressUseDwnld(ui->chkDecompressUseDwnld->isChecked());
|
||||
g.decompressDir(ui->leDecompressDir->text());
|
||||
|
||||
g.updateUseSD(ui->chkUpdateUseSD->isChecked());
|
||||
g.updateDir(ui->leUpdateDir->text());
|
||||
|
||||
QMapIterator<QString, int> it(factories->sortedComponentsList());
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
int i = it.value();
|
||||
|
||||
g.component[i].checkForUpdate(chkCheckForUpdate[i]->isChecked());
|
||||
g.component[i].releaseChannel((ComponentData::ReleaseChannel)cboReleaseChannel[i]->currentIndex());
|
||||
}
|
||||
|
||||
profile.defaultInternalModule(ui->defaultInternalModuleCB->currentData().toInt());
|
||||
profile.channelOrder(ui->channelorderCB->currentIndex());
|
||||
profile.defaultMode(ui->stickmodeCB->currentIndex());
|
||||
@@ -169,11 +189,6 @@ void AppPreferencesDialog::initSettings()
|
||||
{
|
||||
const Profile & profile = g.currentProfile();
|
||||
|
||||
// Disable these for now, until online elements are implemented
|
||||
ui->autoCheckFirmware->setDisabled(true);
|
||||
ui->autoCheckCompanion->setDisabled(true);
|
||||
ui->OpenTxBranch->setDisabled(true);
|
||||
|
||||
ui->snapshotClipboardCKB->setChecked(g.snapToClpbrd());
|
||||
ui->burnFirmware->setChecked(profile.burnFirmware());
|
||||
ui->snapshotPath->setText(g.snapshotDir());
|
||||
@@ -183,18 +198,6 @@ void AppPreferencesDialog::initSettings()
|
||||
ui->snapshotPathButton->setDisabled(true);
|
||||
}
|
||||
|
||||
#if !defined(ALLOW_NIGHTLY_BUILDS)
|
||||
// remove nightly version option entirely unless it's the current one (because user might have nightly version also installed)
|
||||
if (g.OpenTxBranch() != AppData::BRANCH_NIGHTLY_UNSTABLE)
|
||||
ui->OpenTxBranch->removeItem(2);
|
||||
// if it's already selected, add a warning message
|
||||
else
|
||||
ui->updatesLayout->addWidget(new QLabel("<font color='red'>" % tr("Note: Nightly builds are not available in this version, Release/RC update channel will be used.") % "</font>", this));
|
||||
#endif
|
||||
ui->OpenTxBranch->setCurrentIndex(g.OpenTxBranch());
|
||||
|
||||
ui->autoCheckCompanion->setChecked(g.autoCheckApp());
|
||||
ui->autoCheckFirmware->setChecked(g.autoCheckFw());
|
||||
ui->showSplash->setChecked(g.showSplash());
|
||||
ui->chkPromptProfile->setChecked(g.promptProfile());
|
||||
ui->historySize->setValue(g.historySize());
|
||||
@@ -303,6 +306,134 @@ void AppPreferencesDialog::initSettings()
|
||||
}
|
||||
|
||||
populateFirmwareOptions(getBaseFirmware());
|
||||
|
||||
// Updates tab
|
||||
|
||||
ui->cboUpdateCheckFreq->addItems(AppData::updateCheckFreqsList());
|
||||
|
||||
connect(ui->btnResetUpdatesToDefaults, &QPushButton::clicked, [=]() {
|
||||
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Reset all update settings to defaults. Are you sure?"),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
|
||||
for (int i = 0; i < MAX_COMPONENTS; i++) {
|
||||
if (g.component[i].existsOnDisk())
|
||||
g.getComponent(i).resetAll();
|
||||
}
|
||||
g.resetUpdatesSettings();
|
||||
QMessageBox::warning(this, CPN_STR_APP_NAME,
|
||||
tr("Update settings have been reset. You must restart Companion to avoid unexpected behaviour!"));
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->chkDecompressUseDwnld, &QCheckBox::toggled, [=](const bool checked) {
|
||||
if (!checked) {
|
||||
ui->leDecompressDir->setText(g.decompressDir());
|
||||
ui->leDecompressDir->setEnabled(true);
|
||||
ui->btnDecompressSelect->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui->leDecompressDir->setText(g.downloadDir());
|
||||
ui->leDecompressDir->setEnabled(false);
|
||||
ui->btnDecompressSelect->setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->chkUpdateUseSD, &QCheckBox::toggled, [=](const bool checked) {
|
||||
if (!checked) {
|
||||
ui->leUpdateDir->setText(g.updateDir());
|
||||
ui->leUpdateDir->setEnabled(true);
|
||||
ui->btnUpdateSelect->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
ui->leUpdateDir->setText(g.currentProfile().sdPath());
|
||||
ui->leUpdateDir->setEnabled(false);
|
||||
ui->btnUpdateSelect->setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btnDownloadSelect, &QPushButton::clicked, [=]() {
|
||||
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your download folder"), g.downloadDir());
|
||||
if (!dirPath.isEmpty()) {
|
||||
ui->leDownloadDir->setText(dirPath);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btnDecompressSelect, &QPushButton::clicked, [=]() {
|
||||
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your decompress folder"), g.decompressDir());
|
||||
if (!dirPath.isEmpty()) {
|
||||
ui->leDecompressDir->setText(dirPath);
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->btnUpdateSelect, &QPushButton::clicked, [=]() {
|
||||
QString dirPath = QFileDialog::getExistingDirectory(this,tr("Select your update destination folder"), g.updateDir());
|
||||
if (!dirPath.isEmpty()) {
|
||||
ui->leUpdateDir->setText(dirPath);
|
||||
}
|
||||
});
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
QGridLayout *grid = new QGridLayout();
|
||||
|
||||
col++; // leave col 0 blank
|
||||
|
||||
QLabel *h1 = new QLabel(tr("Check"));
|
||||
grid->addWidget(h1, row, col++);
|
||||
|
||||
QLabel *h2 = new QLabel(tr("Release channel"));
|
||||
grid->addWidget(h2, row, col++);
|
||||
|
||||
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
|
||||
grid->addItem(spacer, row, col++);
|
||||
|
||||
QMapIterator<QString, int> it(factories->sortedComponentsList());
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
int i = it.value();
|
||||
|
||||
row++;
|
||||
col = 0;
|
||||
|
||||
lblName[i] = new QLabel();
|
||||
grid->addWidget(lblName[i], row, col++);
|
||||
|
||||
chkCheckForUpdate[i] = new QCheckBox();
|
||||
grid->addWidget(chkCheckForUpdate[i], row, col++);
|
||||
grid->setAlignment(chkCheckForUpdate[i], Qt::AlignHCenter);
|
||||
|
||||
cboReleaseChannel[i] = new QComboBox();
|
||||
cboReleaseChannel[i]->addItems(ComponentData::releaseChannelsList());
|
||||
grid->addWidget(cboReleaseChannel[i], row, col++);
|
||||
}
|
||||
|
||||
ui->grpComponents->setLayout(grid);
|
||||
|
||||
loadUpdatesTab();
|
||||
}
|
||||
|
||||
void AppPreferencesDialog::loadUpdatesTab()
|
||||
{
|
||||
ui->cboUpdateCheckFreq->setCurrentIndex(g.updateCheckFreq());
|
||||
ui->leDownloadDir->setText(g.downloadDir());
|
||||
// trigger toggled signal by changing design value and then setting to saved value
|
||||
ui->chkDecompressUseDwnld->setChecked(!ui->chkDecompressUseDwnld->isChecked());
|
||||
ui->chkDecompressUseDwnld->setChecked(g.decompressUseDwnld());
|
||||
// trigger toggled signal by changing design value and then setting to saved value
|
||||
ui->chkUpdateUseSD->setChecked(!ui->chkUpdateUseSD->isChecked());
|
||||
ui->chkUpdateUseSD->setChecked(g.updateUseSD());
|
||||
|
||||
QMapIterator<QString, int> it(factories->sortedComponentsList());
|
||||
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
int i = it.value();
|
||||
|
||||
lblName[i]->setText(it.key());
|
||||
chkCheckForUpdate[i]->setChecked(g.component[i].checkForUpdate());
|
||||
cboReleaseChannel[i]->setCurrentIndex(g.component[i].releaseChannel());
|
||||
}
|
||||
}
|
||||
|
||||
void AppPreferencesDialog::on_libraryPathButton_clicked()
|
||||
|
||||
Reference in New Issue
Block a user