Main and the preferences dialog are done.

At least as far as the simple values. I have not made support for complex values like profiles yet.
This commit is contained in:
Kjell Kernen
2014-02-16 18:17:10 +01:00
parent ea3f47c7f2
commit acbe17e4bc
4 changed files with 84 additions and 108 deletions
+1 -1
View File
@@ -205,7 +205,7 @@ public:
int generalEditTab() { return _generalEditTab; } int generalEditTab() { return _generalEditTab; }
int icon_size() { return _icon_size; } int icon_size() { return _icon_size; }
int history_size() { return _history_size; } int history_size() { return _history_size; }
int js_ctr() { return _js_ctrl; } int js_ctrl() { return _js_ctrl; }
int modelEditTab() { return _modelEditTab; } int modelEditTab() { return _modelEditTab; }
int profileId() { return _profileId; } int profileId() { return _profileId; }
int theme() { return _theme; } int theme() { return _theme; }
+68 -81
View File
@@ -35,61 +35,58 @@ appPreferencesDialog::~appPreferencesDialog()
void appPreferencesDialog::writeValues() void appPreferencesDialog::writeValues()
{ {
QSettings settings; glob.startup_check_companion(ui->startupCheck_companion9x->isChecked());
settings.setValue("startup_check_companion", ui->startupCheck_companion9x->isChecked()); glob.startup_check_fw(ui->startupCheck_fw->isChecked());
settings.setValue("startup_check_fw", ui->startupCheck_fw->isChecked()); glob.wizardEnable(ui->wizardEnable_ChkB->isChecked());
settings.setValue("wizardEnable", ui->wizardEnable_ChkB->isChecked()); glob.show_splash(ui->showSplash->isChecked());
settings.setValue("show_splash", ui->showSplash->isChecked()); glob.simuSW(ui->simuSW->isChecked());
settings.setValue("simuSW", ui->simuSW->isChecked()); glob.history_size(ui->historySize->value());
settings.setValue("history_size", ui->historySize->value()); glob.backLight(ui->backLightColor->currentIndex());
settings.setValue("backLight", ui->backLightColor->currentIndex()); glob.libraryPath(ui->libraryPath->text());
settings.setValue("libraryPath", ui->libraryPath->text()); glob.gePath(ui->ge_lineedit->text());
settings.setValue("gePath", ui->ge_lineedit->text()); glob.embedded_splashes(ui->splashincludeCB->currentIndex());
settings.setValue("embedded_splashes", ui->splashincludeCB->currentIndex()); glob.backupEnable(ui->backupEnable->isChecked());
settings.setValue("backupEnable", ui->backupEnable->isChecked());
if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) { if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) {
settings.setValue("js_support", ui->joystickChkB ->isChecked()); glob.js_support(ui->joystickChkB ->isChecked());
settings.setValue("js_ctrl", ui->joystickCB ->currentIndex()); glob.js_ctrl(ui->joystickCB ->currentIndex());
} }
else { else {
settings.remove("js_support"); glob.js_support(false);
settings.remove("js_ctrl"); glob.js_ctrl(0);
} }
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex()); glob.default_channel_order(ui->channelorderCB->currentIndex());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex()); glob.default_mode(ui->stickmodeCB->currentIndex());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked()); glob.rename_firmware_files(ui->renameFirmware->isChecked());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked()); glob.burnFirmware(ui->burnFirmware->isChecked());
settings.setValue("profileId", ui->profileIndexLE->text()); glob.profileId(ui->profileIndexLE->text().toInt());
settings.setValue("Name", ui->profileNameLE->text()); glob.Name(ui->profileNameLE->text());
settings.setValue("sdPath", ui->sdPath->text()); glob.sdPath(ui->sdPath->text());
settings.setValue("SplashFileName", ui->SplashFileName->text()); glob.SplashFileName(ui->SplashFileName->text());
if (!ui->SplashFileName->text().isEmpty()) if (!ui->SplashFileName->text().isEmpty())
settings.setValue("SplashImage", ""); glob.SplashImage("");
settings.setValue("firmware", ui->firmwareLE->text()); glob.firmware(ui->firmwareLE->text());
saveProfile(); saveProfile();
} }
void appPreferencesDialog::on_snapshotPathButton_clicked() void appPreferencesDialog::on_snapshotPathButton_clicked()
{ {
QSettings settings; QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), glob.snapshotpath());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), settings.value("snapshotPath").toString());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("snapshotpath", fileName); glob.snapshotpath(fileName);
settings.setValue("snapshot_to_clipboard", false); glob.snapshot_to_clipboard(false);
ui->snapshotPath->setText(fileName); ui->snapshotPath->setText(fileName);
} }
} }
void appPreferencesDialog::initSettings() void appPreferencesDialog::initSettings()
{ {
QSettings settings; ui->snapshotClipboardCKB->setChecked(glob.snapshot_to_clipboard());
ui->snapshotClipboardCKB->setChecked(settings.value("snapshot_to_clipboard", false).toBool()); ui->burnFirmware->setChecked(glob.burnFirmware());
ui->burnFirmware->setChecked(settings.value("burnFirmware", true).toBool());
QString Path=settings.value("snapshotPath", "").toString(); QString Path=glob.snapshotpath();
if (QDir(Path).exists()) { if (QDir(Path).exists()) {
ui->snapshotPath->setText(Path); ui->snapshotPath->setText(Path);
ui->snapshotPath->setReadOnly(true); ui->snapshotPath->setReadOnly(true);
@@ -98,38 +95,38 @@ void appPreferencesDialog::initSettings()
ui->snapshotPath->setDisabled(true); ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true); ui->snapshotPathButton->setDisabled(true);
} }
ui->startupCheck_companion9x->setChecked(settings.value("startup_check_companion", true).toBool()); ui->startupCheck_companion9x->setChecked(glob.startup_check_companion());
ui->startupCheck_fw->setChecked(settings.value("startup_check_fw", true).toBool()); ui->startupCheck_fw->setChecked(glob.startup_check_fw());
ui->wizardEnable_ChkB->setChecked(settings.value("wizardEnable", true).toBool()); ui->wizardEnable_ChkB->setChecked(glob.wizardEnable());
ui->showSplash->setChecked(settings.value("show_splash", true).toBool()); ui->showSplash->setChecked(glob.show_splash());
ui->historySize->setValue(settings.value("history_size", 10).toInt()); ui->historySize->setValue(glob.history_size());
ui->backLightColor->setCurrentIndex(settings.value("backLight", 0).toInt()); ui->backLightColor->setCurrentIndex(glob.backLight());
ui->simuSW->setChecked(settings.value("simuSW", false).toBool()); ui->simuSW->setChecked(glob.simuSW());
Path=settings.value("libraryPath", "").toString(); Path=glob.libraryPath();
if (QDir(Path).exists()) { if (QDir(Path).exists()) {
ui->libraryPath->setText(Path); ui->libraryPath->setText(Path);
} }
Path=settings.value("gePath", "").toString(); Path=glob.gePath();
if (QFile(Path).exists()) { if (QFile(Path).exists()) {
ui->ge_lineedit->setText(Path); ui->ge_lineedit->setText(Path);
} }
Path=settings.value("backupPath", "").toString(); Path=glob.backupPath();
if (!Path.isEmpty()) { if (!Path.isEmpty()) {
if (QDir(Path).exists()) { if (QDir(Path).exists()) {
ui->backupPath->setText(Path); ui->backupPath->setText(Path);
ui->backupEnable->setEnabled(true); ui->backupEnable->setEnabled(true);
ui->backupEnable->setChecked(settings.value("backupEnable", true).toBool()); ui->backupEnable->setChecked(glob.backupEnable());
} else { } else {
ui->backupEnable->setDisabled(true); ui->backupEnable->setDisabled(true);
} }
} else { } else {
ui->backupEnable->setDisabled(true); ui->backupEnable->setDisabled(true);
} }
ui->splashincludeCB->setCurrentIndex(settings.value("embedded_splashes", 0).toInt()); ui->splashincludeCB->setCurrentIndex(glob.embedded_splashes());
#ifdef JOYSTICKS #ifdef JOYSTICKS
ui->joystickChkB->setChecked(settings.value("js_support", false).toBool()); ui->joystickChkB->setChecked(glob.js_support());
if (ui->joystickChkB->isChecked()) { if (ui->joystickChkB->isChecked()) {
QStringList joystickNames; QStringList joystickNames;
joystickNames << tr("No joysticks found"); joystickNames << tr("No joysticks found");
@@ -147,7 +144,7 @@ void appPreferencesDialog::initSettings()
} }
ui->joystickCB->clear(); ui->joystickCB->clear();
ui->joystickCB->insertItems(0, joystickNames); ui->joystickCB->insertItems(0, joystickNames);
ui->joystickCB->setCurrentIndex(settings.value("js_ctrl", 0).toInt()); ui->joystickCB->setCurrentIndex(glob.js_ctrl());
} }
else { else {
ui->joystickCB->clear(); ui->joystickCB->clear();
@@ -156,17 +153,17 @@ void appPreferencesDialog::initSettings()
} }
#endif #endif
// Profile Tab Inits // Profile Tab Inits
ui->channelorderCB->setCurrentIndex(settings.value("default_channel_order", 0).toInt()); ui->channelorderCB->setCurrentIndex(glob.default_channel_order());
ui->stickmodeCB->setCurrentIndex(settings.value("default_mode", 1).toInt()); ui->stickmodeCB->setCurrentIndex(glob.default_mode());
ui->renameFirmware->setChecked(settings.value("rename_firmware_files", false).toBool()); ui->renameFirmware->setChecked(glob.rename_firmware_files());
Path=settings.value("sdPath", "").toString(); Path=glob.sdPath();
if (QDir(Path).exists()) { if (QDir(Path).exists()) {
ui->sdPath->setText(Path); ui->sdPath->setText(Path);
} }
ui->profileIndexLE->setText(settings.value("profileId", "").toString()); ui->profileIndexLE->setText(QString(glob.profileId()));
ui->profileNameLE->setText(settings.value("Name", "").toString()); ui->profileNameLE->setText(glob.Name());
QString fileName=settings.value("SplashFileName","").toString(); QString fileName=glob.SplashFileName();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); QFile file(fileName);
if (file.exists()){ if (file.exists()){
@@ -174,40 +171,37 @@ void appPreferencesDialog::initSettings()
displayImage( fileName ); displayImage( fileName );
} }
} }
ui->firmwareLE->setText(settings.value("firmware","").toString()); ui->firmwareLE->setText(glob.firmware());
} }
void appPreferencesDialog::on_libraryPathButton_clicked() void appPreferencesDialog::on_libraryPathButton_clicked()
{ {
QSettings settings; QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), glob.libraryPath());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), settings.value("libraryPath").toString());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("libraryPath", fileName); glob.libraryPath(fileName);
ui->libraryPath->setText(fileName); ui->libraryPath->setText(fileName);
} }
} }
void appPreferencesDialog::on_snapshotClipboardCKB_clicked() void appPreferencesDialog::on_snapshotClipboardCKB_clicked()
{ {
QSettings settings;
if (ui->snapshotClipboardCKB->isChecked()) { if (ui->snapshotClipboardCKB->isChecked()) {
ui->snapshotPath->setDisabled(true); ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true); ui->snapshotPathButton->setDisabled(true);
settings.setValue("snapshot_to_clipboard", true); glob.snapshot_to_clipboard(true);
} else { } else {
ui->snapshotPath->setEnabled(true); ui->snapshotPath->setEnabled(true);
ui->snapshotPath->setReadOnly(true); ui->snapshotPath->setReadOnly(true);
ui->snapshotPathButton->setEnabled(true); ui->snapshotPathButton->setEnabled(true);
settings.setValue("snapshot_to_clipboard", false); glob.snapshot_to_clipboard(false);
} }
} }
void appPreferencesDialog::on_backupPathButton_clicked() void appPreferencesDialog::on_backupPathButton_clicked()
{ {
QSettings settings; QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), glob.backupPath());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), settings.value("backupPath").toString());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("backupPath", fileName); glob.backupPath(fileName);
ui->backupPath->setText(fileName); ui->backupPath->setText(fileName);
} }
ui->backupEnable->setEnabled(true); ui->backupEnable->setEnabled(true);
@@ -215,7 +209,6 @@ void appPreferencesDialog::on_backupPathButton_clicked()
void appPreferencesDialog::on_ge_pathButton_clicked() void appPreferencesDialog::on_ge_pathButton_clicked()
{ {
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text()); QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->ge_lineedit->setText(fileName); ui->ge_lineedit->setText(fileName);
@@ -259,8 +252,7 @@ void appPreferencesDialog::on_joystickcalButton_clicked() {
void appPreferencesDialog::on_sdPathButton_clicked() void appPreferencesDialog::on_sdPathButton_clicked()
{ {
QSettings settings; QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), glob.sdPath());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), settings.value("sdPath").toString());
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
ui->sdPath->setText(fileName); ui->sdPath->setText(fileName);
} }
@@ -270,7 +262,7 @@ void appPreferencesDialog::saveProfile()
{ {
QSettings settings; QSettings settings;
QString profile=QString("profile") + settings.value("profileId").toString(); QString profile=QString("profile") + glob.profileId();
QString name=ui->profileNameLE->text(); QString name=ui->profileNameLE->text();
if (name.isEmpty()) { if (name.isEmpty()) {
name = profile; name = profile;
@@ -306,8 +298,7 @@ void appPreferencesDialog::loadProfileString(QString profile, QString label)
void appPreferencesDialog::loadProfile() void appPreferencesDialog::loadProfile()
{ {
QSettings settings; QString profile=QString("profile") + glob.profileId();
QString profile=QString("profile") + settings.value("profileId").toString();
loadProfileString( profile, "Name" ); loadProfileString( profile, "Name" );
loadProfileString( profile, "default_channel_order" ); loadProfileString( profile, "default_channel_order" );
@@ -322,12 +313,11 @@ void appPreferencesDialog::loadProfile()
void appPreferencesDialog::on_removeProfileButton_clicked() void appPreferencesDialog::on_removeProfileButton_clicked()
{ {
QSettings settings; QSettings settings;
QString profileId = settings.value("profileId").toString(); if ( glob.profileId() == 1 )
if ( profileId == "1" )
QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed.")); QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed."));
else else
{ {
QString profile=QString("profile") + profileId; QString profile=QString("profile") + glob.profileId();
settings.beginGroup("Profiles"); settings.beginGroup("Profiles");
settings.remove(profile); settings.remove(profile);
settings.endGroup(); settings.endGroup();
@@ -340,15 +330,13 @@ void appPreferencesDialog::on_removeProfileButton_clicked()
bool appPreferencesDialog::displayImage( QString fileName ) bool appPreferencesDialog::displayImage( QString fileName )
{ {
QSettings settings;
QImage image(fileName); QImage image(fileName);
if (image.isNull()) if (image.isNull())
return false; return false;
// This code below just figures out if the width of the latest firmware is 128 or 212. It works , but... // This code below just figures out if the width of the latest firmware is 128 or 212. It works , but...
QString filePath1 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".bin"; QString filePath1 = glob.lastFlashDir() + "/" + glob.firmware() + ".bin";
QString filePath2 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".hex"; QString filePath2 = glob.lastFlashDir() + "/" + glob.firmware() + ".hex";
QFile file(filePath1); QFile file(filePath1);
if (!file.exists()) if (!file.exists())
filePath1 = filePath2; filePath1 = filePath2;
@@ -390,12 +378,11 @@ void appPreferencesDialog::on_SplashSelect_clicked()
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
} }
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); tr("Open Image to load"), glob.lastImagesDir(), tr("Images (%1)").arg(supportedImageFormats));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); glob.lastImagesDir(QFileInfo(fileName).dir().absolutePath());
if (displayImage(fileName)) if (displayImage(fileName))
ui->SplashFileName->setText(fileName); ui->SplashFileName->setText(fileName);
+14 -26
View File
@@ -74,6 +74,9 @@ class MyProxyStyle : public QProxyStyle
}; };
#endif #endif
// Global data and storge object
AppData glob;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Q_INIT_RESOURCE(companion); Q_INIT_RESOURCE(companion);
@@ -86,46 +89,31 @@ int main(int argc, char *argv[])
app.setStyle(new MyProxyStyle); app.setStyle(new MyProxyStyle);
#endif #endif
// Start by borrowing any left over settings from companion9x
QSettings c9x_settings("companion9x", "companion9x");
QSettings settings;
if (!settings.contains("pos")) {
QStringList keys = c9x_settings.allKeys();
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++) {
settings.setValue(*i, c9x_settings.value(*i));
}
}
QString dir;
if (argc) dir = QFileInfo(argv[0]).canonicalPath() + "/lang";
QString locale = settings.value("locale",QLocale::system().name()).toString();
bool showSplash = settings.value("show_splash", true).toBool();
QTranslator companionTranslator; QTranslator companionTranslator;
companionTranslator.load(":/companion_" + locale); companionTranslator.load(":/companion_" + glob.locale());
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load((QString)"qt_" + locale.left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load((QString)"qt_" + glob.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&companionTranslator); app.installTranslator(&companionTranslator);
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString(); if (glob.firmware().isEmpty())
firmware_id.replace("open9x", "opentx"); glob.firmware(default_firmware_variant.id);
firmware_id.replace("x9da", "taranis"); QString tmp_id = glob.firmware();
tmp_id.replace("open9x", "opentx");
tmp_id.replace("x9da", "taranis");
glob.firmware(tmp_id);
QPixmap pixmap = QPixmap(firmware_id.contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png"); QPixmap pixmap = QPixmap(glob.firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap); QSplashScreen *splash = new QSplashScreen(pixmap);
RegisterFirmwares(); RegisterFirmwares();
settings.setValue("firmware", firmware_id); current_firmware_variant = GetFirmwareVariant(glob.firmware());
current_firmware_variant = GetFirmwareVariant(firmware_id);
MainWindow *mainWin = new MainWindow(); MainWindow *mainWin = new MainWindow();
if (showSplash) { if (glob.show_splash()) {
splash->show(); splash->show();
QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close())); QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close()));
QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show())); QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show()));
+1
View File
@@ -45,6 +45,7 @@
#include <QtGui> #include <QtGui>
#include <QMainWindow> #include <QMainWindow>
#include <QDateTime> #include <QDateTime>
#include "appdata.h"
#include "downloaddialog.h" #include "downloaddialog.h"
#include "eeprominterface.h" #include "eeprominterface.h"