1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 09:45:21 +03:00

Profile date is now type safe. Semi working, not complete yet.

This commit is contained in:
Kjell Kernen 2014-02-17 01:16:24 +01:00
parent acbe17e4bc
commit fdc9873ab8
5 changed files with 396 additions and 264 deletions

View file

@ -10,11 +10,296 @@
#define COMPANY "OpenTX Companion" #define COMPANY "OpenTX Companion"
#define PRODUCT "OpenTX" #define PRODUCT "OpenTX"
#define MAX_PROFILES 15
class AppData class DataObj
{ {
public:
void store(const QByteArray newArray, QByteArray &array, const char *tag, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
settings.setValue(tag, newArray);
array = newArray;
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void store(const QStringList newSList, QStringList &stringList, const char *tag, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
settings.setValue(tag, newSList);
stringList = newSList;
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void store(const QString newString, QString &string, const char *tag, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
settings.setValue(tag, newString);
string = newString;
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void store(const bool newTruth, bool &truth, const char *tag, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
settings.setValue(tag, newTruth);
truth = newTruth;
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void store(const int newNumber, int &number, const char *tag, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
settings.setValue(tag, newNumber);
number = newNumber;
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
// Retrieval functions
void retrieve( QByteArray &array, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
array = settings.value(tag, def).toByteArray();
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void retrieve( QStringList &stringList, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
stringList = settings.value(tag, def).toStringList();
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void retrieve( QString &string, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
string = settings.value(tag, def).toString();
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void retrieve( bool &truth, const char *tag, const bool def, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
truth = settings.value(tag, def).toBool();
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
void retrieve( int &number, const char *tag, const int def, const QString group1="", const QString group2="" )
{
QSettings settings(PRODUCT, COMPANY);
if (!group1.isEmpty()) settings.beginGroup(group1);
if (!group2.isEmpty()) settings.beginGroup(group2);
number = settings.value(tag, def).toInt();
if (!group1.isEmpty()) settings.endGroup();
if (!group2.isEmpty()) settings.endGroup();
}
// Retrieve and Store functions
void getset( QByteArray &array, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
retrieve( array, tag, def, group1, group2);
store(array, array, tag, group1, group2);
}
void getset( QStringList &stringList, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
retrieve( stringList, tag, def, group1, group2);
store(stringList, stringList, tag, group1, group2);
}
void getset( QString &string, const char *tag, const char *def, const QString group1="", const QString group2="" )
{
retrieve( string, tag, def, group1, group2);
store(string, string, tag, group1, group2);
}
void getset( bool &truth, const char *tag, const bool def, const QString group1="", const QString group2="" )
{
retrieve( truth, tag, def, group1, group2);
store(truth, truth, tag, group1, group2);
}
void getset( int &number, const char *tag, const int def, const QString group1="", const QString group2="" )
{
retrieve( number, tag, def, group1, group2);
store(number, number, tag, group1, group2);
}
};
class Profile:DataObj
{
private: private:
// Class Internal Variable
int index;
// Application Variables
QString _firmware;
QString _Name;
QString _sdPath;
QString _SplashFileName;
bool _burnFirmware;
bool _rename_firmware_files;
int _default_channel_order;
int _default_mode;
// Firmware Variables
QString _Beeper;
QString _countryCode;
QString _currentCalib;
QString _Display;
QString _GSStickMode;
QString _Haptic;
QString _PPM_Multiplier;
QString _Speaker;
QString _StickPotCalib;
QString _TrainerCalib;
QString _VbatCalib;
QString _vBatWarn;
public:
// All the get declarations
QString firmware() { return _firmware; }
QString Name() { return _Name; }
QString sdPath() { return _sdPath; }
QString SplashFileName() { return _SplashFileName; }
bool burnFirmware() { return _burnFirmware; }
bool rename_firmware_files() { return _rename_firmware_files; }
int default_channel_order() { return _default_channel_order; }
int default_mode() { return _default_mode; }
QString Beeper() { return _Beeper; }
QString countryCode() { return _countryCode; }
QString currentCalib() { return _currentCalib; }
QString Display() { return _Display; }
QString GSStickMode() { return _GSStickMode; }
QString Haptic() { return _Haptic; }
QString PPM_Multiplier() { return _PPM_Multiplier; }
QString Speaker() { return _Speaker; }
QString StickPotCalib() { return _StickPotCalib; }
QString TrainerCalib() { return _TrainerCalib; }
QString VbatCalib() { return _VbatCalib; }
QString vBatWarn() { return _vBatWarn; }
// All the set declarations
void firmware (const QString str) { store(str, _firmware, "firmware" ,"Profiles", QString("profile%1").arg(index));}
void Name (const QString str) { store(str, _Name, "Name" ,"Profiles", QString("profile%1").arg(index));}
void sdPath (const QString str) { store(str, _sdPath, "sdPath" ,"Profiles", QString("profile%1").arg(index));}
void SplashFileName (const QString str) { store(str, _SplashFileName, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));}
void burnFirmware (const bool bl) { store(bl, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));}
void rename_firmware_files (const bool bl) { store(bl, _rename_firmware_files, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));}
void default_channel_order (const int it) { store(it, _default_channel_order, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));}
void default_mode (const int it) { store(it, _default_mode, "default_mode" ,"Profiles", QString("profile%1").arg(index));}
void Beeper (const QString str) { store(str, _Beeper, "Beeper" ,"Profiles", QString("profile%1").arg(index));}
void countryCode (const QString str) { store(str, _countryCode, "countryCode" ,"Profiles", QString("profile%1").arg(index));}
void currentCalib (const QString str) { store(str, _currentCalib, "currentCalib" ,"Profiles", QString("profile%1").arg(index));}
void Display (const QString str) { store(str, _Display, "Display" ,"Profiles", QString("profile%1").arg(index));}
void GSStickMode (const QString str) { store(str, _GSStickMode, "GSStickMode" ,"Profiles", QString("profile%1").arg(index));}
void Haptic (const QString str) { store(str, _Haptic, "Haptic" ,"Profiles", QString("profile%1").arg(index));}
void PPM_Multiplier (const QString str) { store(str, _PPM_Multiplier, "PPM_Multiplier" ,"Profiles", QString("profile%1").arg(index));}
void Speaker (const QString str) { store(str, _Speaker, "Speaker" ,"Profiles", QString("profile%1").arg(index));}
void StickPotCalib (const QString str) { store(str, _StickPotCalib, "StickPotCalib" ,"Profiles", QString("profile%1").arg(index));}
void TrainerCalib (const QString str) { store(str, _TrainerCalib, "TrainerCalib" ,"Profiles", QString("profile%1").arg(index));}
void VbatCalib (const QString str) { store(str, _VbatCalib, "VbatCalib" ,"Profiles", QString("profile%1").arg(index));}
void vBatWarn (const QString str) { store(str, _vBatWarn, "vBatWarn" ,"Profiles", QString("profile%1").arg(index));}
// Constructor
Profile()
{
index = -1;
}
void init(int newIndex)
{
index = newIndex;
QString pName;
retrieve( pName, "Name", "", "Profiles", QString("profile%1").arg(newIndex));
if ( newIndex > 1 && pName.isEmpty())
return;
// Load and store all variables. Use default values if setting values are missing
getset( _firmware, "firmware" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _Name, "Name" ,"----" ,"Profiles", QString("profile%1").arg(index));
getset( _sdPath, "sdPath" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _SplashFileName, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index));
getset( _rename_firmware_files, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index));
getset( _default_channel_order, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _default_mode, "default_mode" ,1 ,"Profiles", QString("profile%1").arg(index));
getset( _Beeper, "Beeper" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _countryCode, "countryCode" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _currentCalib, "currentCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _Display, "Display" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _GSStickMode, "GSStickMode" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _Haptic, "Haptic" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _PPM_Multiplier, "PPM_Multiplier" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _Speaker, "Speaker" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _StickPotCalib, "StickPotCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _TrainerCalib, "TrainerCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _VbatCalib, "VbatCalib" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _vBatWarn, "vBatWarn" ,"" ,"Profiles", QString("profile%1").arg(index));
}
};
class AppData:DataObj
{
// All the global variables // All the global variables
public:
Profile profile[MAX_PROFILES];
private:
QStringList _recentFileList; QStringList _recentFileList;
QByteArray _mainWindowGeometry; QByteArray _mainWindowGeometry;
QByteArray _mainWindowState; QByteArray _mainWindowState;
@ -65,101 +350,6 @@ class AppData
// Storage functions // Storage functions
void store(const QByteArray newArray, QByteArray &array, const char *tag)
{
QSettings settings(PRODUCT, COMPANY);
settings.setValue(tag, newArray);
array = newArray;
}
void store(const QStringList newSList, QStringList &stringList, const char *tag)
{
QSettings settings(PRODUCT, COMPANY);
settings.setValue(tag, newSList);
stringList = newSList;
}
void store(const QString newString, QString &string, const char *tag)
{
QSettings settings(PRODUCT, COMPANY);
settings.setValue(tag, newString);
string = newString;
}
void store(const bool newTruth, bool &truth, const char *tag)
{
QSettings settings(PRODUCT, COMPANY);
settings.setValue(tag, newTruth);
truth = newTruth;
}
void store(const int newNumber, int &number, const char *tag)
{
QSettings settings(PRODUCT, COMPANY);
settings.setValue(tag, newNumber);
number = newNumber;
}
// Retrieval functions
void retrieve( QByteArray &array, const char *tag, const char *def)
{
QSettings settings(PRODUCT, COMPANY);
array = settings.value(tag, def).toByteArray();
}
void retrieve( QStringList &stringList, const char *tag, const char *def)
{
QSettings settings(PRODUCT, COMPANY);
stringList = settings.value(tag, def).toStringList();
}
void retrieve( QString &string, const char *tag, const char *def)
{
QSettings settings(PRODUCT, COMPANY);
string = settings.value(tag, def).toString();
}
void retrieve( bool &truth, const char *tag, const bool def)
{
QSettings settings(PRODUCT, COMPANY);
truth = settings.value(tag, def).toBool();
}
void retrieve( int &number, const char *tag, const int def)
{
QSettings settings(PRODUCT, COMPANY);
number = settings.value(tag, def).toInt();
}
// Retrieve and Store functions
void getset( QByteArray &array, const char *tag, const char *def)
{
retrieve( array, tag, def);
store(array, array, tag);
}
void getset( QStringList &stringList, const char *tag, const char *def)
{
retrieve( stringList, tag, def);
store(stringList, stringList, tag);
}
void getset( QString &string, const char *tag, const char *def)
{
retrieve( string, tag, def);
store(string, string, tag);
}
void getset( bool &truth, const char *tag, const bool def)
{
retrieve( truth, tag, def);
store(truth, truth, tag);
}
void getset( int &number, const char *tag, const int def)
{
retrieve( number, tag, def);
store(number, number, tag);
}
public: public:
// All the get declarations // All the get declarations
@ -273,6 +463,12 @@ public:
settings.setValue(*i, c9x_settings.value(*i)); settings.setValue(*i, c9x_settings.value(*i));
} }
} }
//Initialize the index variables of the profiles
for (int i=0; i<MAX_PROFILES; i++)
profile[i].init( i+1 );
// Load and store all variables. Use default values if setting values are missing // Load and store all variables. Use default values if setting values are missing
@ -284,7 +480,7 @@ public:
getset( _locale, "locale" ,"" ); getset( _locale, "locale" ,"" );
getset( _cpu_id, "cpu_id" ,"" ); getset( _cpu_id, "cpu_id" ,"" );
getset( _SplashImage, "SplashImage" ,"" ); getset( _SplashImage, "SplashImage" ,"" );
getset( _Name, "Name" ,"" ); getset( _Name, "Name" ,"profile1" );
getset( _SplashFileName, "SplashFileName" ,"" ); getset( _SplashFileName, "SplashFileName" ,"" );
getset( _modelEditGeometry, "modelEditGeometry" ,"" ); getset( _modelEditGeometry, "modelEditGeometry" ,"" );
@ -310,19 +506,19 @@ public:
getset( _simuSW, "simuSW" ,false ); getset( _simuSW, "simuSW" ,false );
getset( _wizardEnable, "wizardEnable" ,true ); getset( _wizardEnable, "wizardEnable" ,true );
getset( _backLight, "backLight" ,0 ); getset( _backLight, "backLight" ,0 );
getset( _default_channel_order, "default_channel_order" ,0 ); getset( _default_channel_order, "default_channel_order" ,0 );
getset( _default_mode, "default_mode" ,1 ); getset( _default_mode, "default_mode" ,1 );
getset( _embedded_splashes, "embedded_splashes" ,0 ); getset( _embedded_splashes, "embedded_splashes" ,0 );
getset( _fwserver, "fwserver" ,0 ); getset( _fwserver, "fwserver" ,0 );
getset( _generalEditTab, "generalEditTab" ,0 ); getset( _generalEditTab, "generalEditTab" ,0 );
getset( _icon_size, "icon_size" ,2 ); getset( _icon_size, "icon_size" ,2 );
getset( _js_ctrl, "js_ctrl" ,0 ); getset( _js_ctrl, "js_ctrl" ,0 );
getset( _history_size, "history_size" ,6 ); getset( _history_size, "history_size" ,10 );
getset( _modelEditTab, "modelEditTab" ,0 ); getset( _modelEditTab, "modelEditTab" ,0 );
getset( _profileId, "profileId" ,0 ); getset( _profileId, "profileId" ,1 );
getset( _theme, "theme" ,1 ); getset( _theme, "theme" ,1 );
getset( _warningId, "warningId" ,0 ); getset( _warningId, "warningId" ,0 );
} }
}; };

View file

@ -160,7 +160,7 @@ void appPreferencesDialog::initSettings()
if (QDir(Path).exists()) { if (QDir(Path).exists()) {
ui->sdPath->setText(Path); ui->sdPath->setText(Path);
} }
ui->profileIndexLE->setText(QString(glob.profileId())); ui->profileIndexLE->setText(QString("%1").arg(glob.profileId()));
ui->profileNameLE->setText(glob.Name()); ui->profileNameLE->setText(glob.Name());
QString fileName=glob.SplashFileName(); QString fileName=glob.SplashFileName();
@ -260,54 +260,34 @@ void appPreferencesDialog::on_sdPathButton_clicked()
void appPreferencesDialog::saveProfile() void appPreferencesDialog::saveProfile()
{ {
QSettings settings; // The profile name may NEVER be empty
QString profile=QString("profile") + QString("%1").arg(glob.profileId());
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;
ui->profileNameLE->setText(name); ui->profileNameLE->setText(name);
} }
settings.beginGroup("Profiles"); glob.profile[glob.profileId()].Name( name );
settings.beginGroup(profile); glob.profile[glob.profileId()].default_channel_order( ui->channelorderCB->currentIndex());
settings.setValue("Name",name); glob.profile[glob.profileId()].default_mode( ui->stickmodeCB->currentIndex());
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex()); glob.profile[glob.profileId()].burnFirmware( ui->burnFirmware->isChecked());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex()); glob.profile[glob.profileId()].rename_firmware_files( ui->renameFirmware->isChecked());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked()); glob.profile[glob.profileId()].sdPath( ui->sdPath->text());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked()); glob.profile[glob.profileId()].SplashFileName( ui->SplashFileName->text());
settings.setValue("sdPath", ui->sdPath->text()); glob.profile[glob.profileId()].firmware( ui->firmwareLE->text());
settings.setValue("SplashFileName", ui->SplashFileName->text());
settings.setValue("firmware", ui->firmwareLE->text());
settings.endGroup();
settings.endGroup();
} }
void appPreferencesDialog::loadProfileString(QString profile, QString label) void appPreferencesDialog::loadFromProfile()
{ {
QSettings settings; int i = glob.profileId();
QString value; glob.Name( glob.profile[i].Name() );
glob.default_channel_order( glob.profile[i].default_channel_order());
settings.beginGroup("Profiles"); glob.default_mode( glob.profile[i].default_mode());
settings.beginGroup(profile); glob.burnFirmware( glob.profile[i].burnFirmware());
value = settings.value(label).toString(); glob.rename_firmware_files( glob.profile[i].rename_firmware_files());
settings.endGroup(); glob.sdPath( glob.profile[i].sdPath());
settings.endGroup(); glob.SplashFileName( glob.profile[i].SplashFileName());
glob.firmware( glob.profile[i].firmware());
settings.setValue( label, value );
}
void appPreferencesDialog::loadProfile()
{
QString profile=QString("profile") + glob.profileId();
loadProfileString( profile, "Name" );
loadProfileString( profile, "default_channel_order" );
loadProfileString( profile, "default_mode" );
loadProfileString( profile, "burnFirmware" );
loadProfileString( profile, "rename_firmware_files" );
loadProfileString( profile, "sdPath" );
loadProfileString( profile, "SplashFileName" );
loadProfileString( profile, "firmware" );
} }
void appPreferencesDialog::on_removeProfileButton_clicked() void appPreferencesDialog::on_removeProfileButton_clicked()
@ -317,13 +297,13 @@ void appPreferencesDialog::on_removeProfileButton_clicked()
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") + glob.profileId(); QString profile=QString("profile") + QString("%1").arg(glob.profileId());
settings.beginGroup("Profiles"); settings.beginGroup("Profiles");
settings.remove(profile); settings.remove(profile);
settings.endGroup(); settings.endGroup();
settings.setValue("profileId", "1"); glob.profileId( 1 );
loadProfile(); loadFromProfile();
initSettings(); initSettings();
} }
} }

View file

@ -26,7 +26,7 @@ private:
bool displayImage( QString fileName ); bool displayImage( QString fileName );
void saveProfile(); void saveProfile();
void loadProfileString(QString profile, QString label); void loadProfileString(QString profile, QString label);
void loadProfile(); void loadFromProfile();
private slots: private slots:
void writeValues(); void writeValues();

View file

@ -90,23 +90,23 @@ MainWindow::MainWindow():
mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setCentralWidget(mdiArea); setCentralWidget(mdiArea);
connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus()));
this, SLOT(updateMenus()));
windowMapper = new QSignalMapper(this); windowMapper = new QSignalMapper(this);
connect(windowMapper, SIGNAL(mapped(QWidget*)), connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
this, SLOT(setActiveSubWindow(QWidget*)));
MaxRecentFiles=MAX_RECENT;
QSettings settings;
restoreGeometry(settings.value("mainWindowGeometry").toByteArray());
createActions(); createActions();
createMenus(); createMenus();
createToolBars(); createToolBars();
createStatusBar(); createStatusBar();
updateMenus(); updateMenus();
readSettings();
restoreState(glob.mainWindowState());
if (glob.profileId() == 0)
{
createProfile();
glob.profileId( 1 );
}
setUnifiedTitleAndToolBarOnMac(true); setUnifiedTitleAndToolBarOnMac(true);
this->setWindowIcon(QIcon(":/icon.png")); this->setWindowIcon(QIcon(":/icon.png"));
@ -116,7 +116,7 @@ MainWindow::MainWindow():
// give time to the splash to disappear and main window to open before starting updates // give time to the splash to disappear and main window to open before starting updates
int updateDelay = 1000; int updateDelay = 1000;
bool showSplash = settings.value("show_splash", true).toBool(); bool showSplash = glob.show_splash();
if (showSplash) { if (showSplash) {
updateDelay += (SPLASH_TIME*1000); updateDelay += (SPLASH_TIME*1000);
} }
@ -169,8 +169,7 @@ MainWindow::MainWindow():
void MainWindow::displayWarnings() void MainWindow::displayWarnings()
{ {
QSettings settings; int warnId=glob.warningId();
int warnId=settings.value("warningId", 0 ).toInt();
if (warnId<WARNING_ID && warnId!=0) { if (warnId<WARNING_ID && warnId!=0) {
int res=0; int res=0;
if (WARNING_LEVEL>0) { if (WARNING_LEVEL>0) {
@ -181,10 +180,10 @@ void MainWindow::displayWarnings()
res = QMessageBox::question(this, "Companion",tr("Display previous message again at startup ?"),QMessageBox::Yes | QMessageBox::No); res = QMessageBox::question(this, "Companion",tr("Display previous message again at startup ?"),QMessageBox::Yes | QMessageBox::No);
} }
if (res == QMessageBox::No) { if (res == QMessageBox::No) {
settings.setValue("warningId", WARNING_ID); glob.warningId(WARNING_ID);
} }
} else if (warnId==0) { } else if (warnId==0) {
settings.setValue("warningId", WARNING_ID); glob.warningId(WARNING_ID);
} }
} }
@ -203,12 +202,11 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId)
showcheckForUpdatesResult = ignoreSettings; showcheckForUpdatesResult = ignoreSettings;
check1done = true; check1done = true;
check2done = true; check2done = true;
QSettings settings;
fwToUpdate = fwId; fwToUpdate = fwId;
QString stamp = GetFirmware(fwToUpdate)->stamp; QString stamp = GetFirmware(fwToUpdate)->stamp;
if (!stamp.isEmpty()) { if (!stamp.isEmpty()) {
if (checkFW || ignoreSettings) { if (glob.startup_check_fw() || ignoreSettings) {
check1done=false; check1done=false;
manager1 = new QNetworkAccessManager(this); manager1 = new QNetworkAccessManager(this);
connect(manager1, SIGNAL(finished(QNetworkReply*)), this, SLOT(reply1Finished(QNetworkReply*))); connect(manager1, SIGNAL(finished(QNetworkReply*)), this, SLOT(reply1Finished(QNetworkReply*)));
@ -219,7 +217,7 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId)
} }
} }
if (checkCompanion || ignoreSettings) { if (glob.startup_check_companion() || ignoreSettings) {
check2done = false; check2done = false;
manager2 = new QNetworkAccessManager(this); manager2 = new QNetworkAccessManager(this);
connect(manager2, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdateFinished(QNetworkReply*))); connect(manager2, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdateFinished(QNetworkReply*)));
@ -269,16 +267,14 @@ void MainWindow::checkForUpdateFinished(QNetworkReply * reply)
"Would you like to download it?").arg(version) , "Would you like to download it?").arg(version) ,
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
QSettings settings;
if (ret == QMessageBox::Yes) { if (ret == QMessageBox::Yes) {
#if defined __APPLE__ #if defined __APPLE__
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastUpdatesDir").toString() + QString(C9X_INSTALLER).arg(version)); QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version));
#else #else
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastUpdatesDir").toString() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)")); QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastUpdatesDir() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)"));
#endif #endif
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("lastUpdatesDir", QFileInfo(fileName).dir().absolutePath()); glob.lastUpdatesDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, QString(OPENTX_COMPANION_DOWNLOADS C9X_INSTALLER).arg(version), fileName); downloadDialog * dd = new downloadDialog(this, QString(OPENTX_COMPANION_DOWNLOADS C9X_INSTALLER).arg(version), fileName);
installer_fileName = fileName; installer_fileName = fileName;
connect(dd, SIGNAL(accepted()), this, SLOT(updateDownloaded())); connect(dd, SIGNAL(accepted()), this, SLOT(updateDownloaded()));
@ -311,11 +307,10 @@ void MainWindow::updateDownloaded()
void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmwareId) void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmwareId)
{ {
QString url, ext, cpuid; QString url, ext, cpuid;
QSettings settings;
url = firmware->getUrl(firmwareId); url = firmware->getUrl(firmwareId);
cpuid=settings.value("cpuid","").toString(); cpuid=glob.cpu_id();
ext = url.mid(url.lastIndexOf(".")); ext = url.mid(url.lastIndexOf("."));
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + firmwareId + ext); QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + firmwareId + ext);
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
downloadedFW = firmwareId; downloadedFW = firmwareId;
needRename=true; needRename=true;
@ -324,7 +319,7 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw
url.append("&cpuid="); url.append("&cpuid=");
url.append(cpuid); url.append(cpuid);
} }
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, url, fileName); downloadDialog * dd = new downloadDialog(this, url, fileName);
connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted()));
dd->exec(); dd->exec();
@ -457,7 +452,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
} }
QSettings settings; QSettings settings;
cpuid=settings.value("cpuid","").toString(); cpuid=glob.cpu_id();
QByteArray qba = reply->readAll(); QByteArray qba = reply->readAll();
int i = qba.indexOf("SVN_VERS"); int i = qba.indexOf("SVN_VERS");
int warning = qba.indexOf("WARNING"); int warning = qba.indexOf("WARNING");
@ -471,9 +466,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
if(!cres) { if(!cres) {
QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); QMessageBox::warning(this, "Companion", tr("Unable to check for updates."));
int server = settings.value("fwserver",0).toInt(); glob.fwserver(glob.fwserver()+1);
server++;
settings.setValue("fwserver",server);
return; return;
} }
@ -571,12 +564,12 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate); QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate);
QString ext = url.mid(url.lastIndexOf(".")); QString ext = url.mid(url.lastIndexOf("."));
needRename=false; needRename=false;
bool addversion=settings.value("rename_firmware_files", false).toBool(); bool addversion=glob.rename_firmware_files();
QString fileName; QString fileName;
if (addversion) { if (addversion) {
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + newrev + ext); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + newrev + ext);
} else { } else {
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + ext); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), glob.lastFlashDir() + "/" + fwToUpdate + ext);
} }
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
if (!cpuid.isEmpty()) { if (!cpuid.isEmpty()) {
@ -584,7 +577,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
url.append(cpuid); url.append(cpuid);
} }
downloadedFWFilename = fileName; downloadedFWFilename = fileName;
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, url, fileName); downloadDialog * dd = new downloadDialog(this, url, fileName);
currentFWrev_temp = NewFwRev; currentFWrev_temp = NewFwRev;
connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted())); connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted()));
@ -598,9 +591,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
} else { } else {
if(check1done && check2done) { if(check1done && check2done) {
QMessageBox::warning(this, "Companion", tr("Unable to check for updates.")); QMessageBox::warning(this, "Companion", tr("Unable to check for updates."));
int server = settings.value("fwserver",0).toInt(); glob.fwserver(glob.fwserver()+1);
server++;
settings.setValue("fwserver",server);
return; return;
} }
} }
@ -608,9 +599,8 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
QSettings settings; glob.mainWindowGeometry(saveGeometry());
settings.setValue("mainWindowGeometry", saveGeometry()); glob.mainWindowState(saveState());
settings.setValue("mainWindowState", saveState());
mdiArea->closeAllSubWindows(); mdiArea->closeAllSubWindows();
if (mdiArea->currentSubWindow()) { if (mdiArea->currentSubWindow()) {
event->ignore(); event->ignore();
@ -622,8 +612,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::setLanguage(QString langString) void MainWindow::setLanguage(QString langString)
{ {
QSettings settings; glob.locale( langString );
settings.setValue("locale", langString );
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("The selected language will be used the next time you start Companion.")); msgBox.setText(tr("The selected language will be used the next time you start Companion."));
@ -634,8 +623,7 @@ void MainWindow::setLanguage(QString langString)
void MainWindow::setTheme(int index) void MainWindow::setTheme(int index)
{ {
QSettings settings; glob.theme( index );
settings.setValue("theme", index );
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("The new theme will be loaded the next time you start Companion.")); msgBox.setText(tr("The new theme will be loaded the next time you start Companion."));
@ -646,8 +634,7 @@ void MainWindow::setTheme(int index)
void MainWindow::setIconThemeSize(int index) void MainWindow::setIconThemeSize(int index)
{ {
QSettings settings; glob.icon_size( index );
settings.setValue("icon_size", index );
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("The icon size will be used the next time you start Companion.")); msgBox.setText(tr("The icon size will be used the next time you start Companion."));
@ -671,10 +658,9 @@ void MainWindow::openDocURL()
void MainWindow::openFile() void MainWindow::openFile()
{ {
QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), glob.lastDir(), tr(EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); glob.lastDir(QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName); QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) { if (existing) {
@ -704,11 +690,9 @@ void MainWindow::saveAs()
void MainWindow::openRecentFile() void MainWindow::openRecentFile()
{ {
QSettings settings;
QAction *action = qobject_cast<QAction *>(sender()); QAction *action = qobject_cast<QAction *>(sender());
if (action) { if (action) {
QString fileName=action->data().toString(); QString fileName=action->data().toString();
// settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName); QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) { if (existing) {
@ -1113,14 +1097,14 @@ void MainWindow::writeFileToEeprom()
burnDialog *cd = new burnDialog(this, 1, &fileName, &backup); burnDialog *cd = new burnDialog(this, 1, &fileName, &backup);
cd->exec(); cd->exec();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); glob.lastDir(QFileInfo(fileName).dir().absolutePath());
int ret = QMessageBox::question(this, "Companion", tr("Write Models and settings from %1 to the Tx?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No); int ret = QMessageBox::question(this, "Companion", tr("Write Models and settings from %1 to the Tx?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) return; if (ret != QMessageBox::Yes) return;
if (!isValidEEPROM(fileName)) if (!isValidEEPROM(fileName))
ret = QMessageBox::question(this, "Companion", tr("The file %1\nhas not been recognized as a valid Models and Settings file\nWrite anyway ?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No); ret = QMessageBox::question(this, "Companion", tr("The file %1\nhas not been recognized as a valid Models and Settings file\nWrite anyway ?").arg(QFileInfo(fileName).fileName()), QMessageBox::Yes | QMessageBox::No);
if (ret != QMessageBox::Yes) return; if (ret != QMessageBox::Yes) return;
bool backupEnable = settings.value("backupEnable", true).toBool(); bool backupEnable = glob.backupEnable();
QString backupPath = settings.value("backupPath", "").toString(); QString backupPath = glob.backupPath();
if (!backupPath.isEmpty()) { if (!backupPath.isEmpty()) {
if (!QDir(backupPath).exists()) { if (!QDir(backupPath).exists()) {
if (backupEnable) { if (backupEnable) {
@ -1361,9 +1345,8 @@ bool MainWindow::convertEEPROM(QString backupFile, QString restoreFile, QString
void MainWindow::writeFlash(QString fileToFlash) void MainWindow::writeFlash(QString fileToFlash)
{ {
QSettings settings;
QString fileName; QString fileName;
bool backup = settings.value("backupOnFlash", false).toBool(); bool backup = glob.backupOnFlash();
if(!fileToFlash.isEmpty()) if(!fileToFlash.isEmpty())
fileName = fileToFlash; fileName = fileToFlash;
burnDialog *cd = new burnDialog(this, 2, &fileName, &backup); burnDialog *cd = new burnDialog(this, 2, &fileName, &backup);
@ -1371,12 +1354,12 @@ void MainWindow::writeFlash(QString fileToFlash)
if (IS_TARANIS(GetEepromInterface()->getBoard())) if (IS_TARANIS(GetEepromInterface()->getBoard()))
backup=false; backup=false;
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
settings.setValue("backupOnFlash", backup); glob.backupOnFlash(backup);
if (backup) { if (backup) {
QString tempDir = QDir::tempPath(); QString tempDir = QDir::tempPath();
QString backupFile = tempDir + "/backup.bin"; QString backupFile = tempDir + "/backup.bin";
bool backupEnable=settings.value("backupEnable", true).toBool(); bool backupEnable=glob.backupEnable();
QString backupPath=settings.value("backupPath", "").toString(); QString backupPath=glob.backupPath();
if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) { if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) {
if (!QDir(backupPath).exists()) { if (!QDir(backupPath).exists()) {
if (backupEnable) { if (backupEnable) {
@ -1430,8 +1413,8 @@ void MainWindow::writeFlash(QString fileToFlash)
} }
} }
else { else {
bool backupEnable=settings.value("backupEnable", true).toBool(); bool backupEnable=glob.backupEnable();
QString backupPath=settings.value("backupPath", "").toString(); QString backupPath=glob.backupPath();
if (!QDir(backupPath).exists()) { if (!QDir(backupPath).exists()) {
if (backupEnable) { if (backupEnable) {
QMessageBox::warning(this, tr("Backup is impossible"), tr("The backup dir set in preferences does not exist")); QMessageBox::warning(this, tr("Backup is impossible"), tr("The backup dir set in preferences does not exist"));
@ -1460,8 +1443,7 @@ void MainWindow::writeFlash(QString fileToFlash)
void MainWindow::readEepromToFile() void MainWindow::readEepromToFile()
{ {
QSettings settings; QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), glob.lastDir(), tr(EXTERNAL_EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) { if (IS_TARANIS(eepromInterface->getBoard())) {
@ -1480,7 +1462,7 @@ void MainWindow::readEepromToFile()
} }
} }
else { else {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath()); glob.lastDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveEEpromCommand(fileName); QStringList str = GetReceiveEEpromCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Tx")); avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Tx"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png")); ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
@ -1492,14 +1474,13 @@ void MainWindow::readEepromToFile()
void MainWindow::readFlash() void MainWindow::readFlash()
{ {
QSettings settings; QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), glob.lastFlashDir(),tr(FLASH_FILES_FILTER));
QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), settings.value("lastFlashDir").toString(),tr(FLASH_FILES_FILTER));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); QFile file(fileName);
if (file.exists()) { if (file.exists()) {
file.remove(); file.remove();
} }
settings.setValue("lastFlashDir",QFileInfo(fileName).dir().absolutePath()); glob.lastFlashDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveFlashCommand(fileName); QStringList str = GetReceiveFlashCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Tx"); avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Tx");
ad->setWindowIcon(CompanionIcon("read_flash.png")); ad->setWindowIcon(CompanionIcon("read_flash.png"));
@ -1578,8 +1559,7 @@ void MainWindow::updateMenus()
updateIconSizeActions(); updateIconSizeActions();
updateIconThemeActions(); updateIconThemeActions();
QSettings settings; setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( QString("%1").arg(glob.profileId()) ));
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg(settings.value("profileId").toString()));
} }
MdiChild *MainWindow::createMdiChild() MdiChild *MainWindow::createMdiChild()
@ -1630,7 +1610,7 @@ void MainWindow::createActions()
separatorAct = new QAction(this); separatorAct = new QAction(this);
separatorAct->setSeparator(true); separatorAct->setSeparator(true);
for (int i = 0; i < MaxRecentFiles; ++i) { for (int i = 0; i < MAX_RECENT; ++i) {
recentFileActs[i] = new QAction(this); recentFileActs[i] = new QAction(this);
recentFileActs[i]->setVisible(false); recentFileActs[i]->setVisible(false);
connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
@ -1728,7 +1708,7 @@ void MainWindow::createMenus()
fileMenu->addAction(saveAsAct); fileMenu->addAction(saveAsAct);
fileMenu->addMenu(recentFileMenu); fileMenu->addMenu(recentFileMenu);
recentFileMenu->setIcon(CompanionIcon("recentdocument.png")); recentFileMenu->setIcon(CompanionIcon("recentdocument.png"));
for (int i=0; i<MaxRecentFiles; ++i) for (int i=0; i<MAX_RECENT; ++i)
recentFileMenu->addAction(recentFileActs[i]); recentFileMenu->addAction(recentFileActs[i]);
fileMenu->addSeparator(); fileMenu->addSeparator();
fileMenu->addAction(logsAct); fileMenu->addAction(logsAct);
@ -1810,7 +1790,7 @@ void MainWindow::createMenus()
QMenu *MainWindow::createRecentFileMenu() QMenu *MainWindow::createRecentFileMenu()
{ {
QMenu *recentFileMenu = new QMenu(this); QMenu *recentFileMenu = new QMenu(this);
for ( int i = 0; i < MaxRecentFiles; ++i) for ( int i = 0; i < MAX_RECENT; ++i)
recentFileMenu->addAction(recentFileActs[i]); recentFileMenu->addAction(recentFileActs[i]);
return recentFileMenu; return recentFileMenu;
} }
@ -1831,10 +1811,8 @@ QMenu *MainWindow::createProfilesMenu()
void MainWindow::createToolBars() void MainWindow::createToolBars()
{ {
QSettings settings;
int icon_size=settings.value("icon_size",2 ).toInt();
QSize size; QSize size;
switch(icon_size) { switch(glob.icon_size()) {
case 0: case 0:
size=QSize(16,16); size=QSize(16,16);
break; break;
@ -1919,20 +1897,6 @@ void MainWindow::createStatusBar()
statusBar()->showMessage(tr("Ready")); statusBar()->showMessage(tr("Ready"));
} }
void MainWindow::readSettings()
{
QSettings settings;
restoreState(settings.value("mainWindowState").toByteArray());
checkCompanion = settings.value("startup_check_companion", true).toBool();
checkFW = settings.value("startup_check_fw", true).toBool();
MaxRecentFiles =settings.value("history_size",10).toInt();
if (settings.value("profileId",0).toInt() == 0)
{
createProfile();
settings.setValue("profileId", "1");
}
}
MdiChild *MainWindow::activeMdiChild() MdiChild *MainWindow::activeMdiChild()
{ {
if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow()) if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
@ -1965,7 +1929,7 @@ void MainWindow::updateRecentFileActions()
QSettings settings; QSettings settings;
QStringList files = settings.value("recentFileList").toStringList(); QStringList files = settings.value("recentFileList").toStringList();
numRecentFiles = qMin(files.size(), (int)MaxRecentFiles); numRecentFiles = qMin(files.size(), glob.history_size());
for ( i = 0; i < numRecentFiles; ++i) { for ( i = 0; i < numRecentFiles; ++i) {
QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
@ -1973,15 +1937,14 @@ void MainWindow::updateRecentFileActions()
recentFileActs[i]->setData(files[i]); recentFileActs[i]->setData(files[i]);
recentFileActs[i]->setVisible(true); recentFileActs[i]->setVisible(true);
} }
for ( j = numRecentFiles; j < MaxRecentFiles; ++j) for ( j = numRecentFiles; j < glob.history_size(); ++j)
recentFileActs[j]->setVisible(false); recentFileActs[j]->setVisible(false);
} }
void MainWindow::updateIconSizeActions() void MainWindow::updateIconSizeActions()
{ {
QSettings settings; switch (glob.icon_size())
int size = settings.value("icon_size","0").toInt(); {
switch (size){
case 0: smallIconAct->setChecked(true); break; case 0: smallIconAct->setChecked(true); break;
case 1: normalIconAct->setChecked(true); break; case 1: normalIconAct->setChecked(true); break;
case 2: bigIconAct->setChecked(true); break; case 2: bigIconAct->setChecked(true); break;
@ -1991,8 +1954,7 @@ void MainWindow::updateIconSizeActions()
void MainWindow::updateLanguageActions() void MainWindow::updateLanguageActions()
{ {
QSettings settings; QString langId = glob.locale();
QString langId = settings.value("locale","").toString();
if (langId=="") if (langId=="")
sysLangAct->setChecked(true); sysLangAct->setChecked(true);
@ -2022,9 +1984,8 @@ void MainWindow::updateLanguageActions()
void MainWindow::updateIconThemeActions() void MainWindow::updateIconThemeActions()
{ {
QSettings settings; switch (glob.theme())
int size = settings.value("theme","1").toInt(); {
switch (size){
case 0: classicThemeAct->setChecked(true); break; case 0: classicThemeAct->setChecked(true); break;
case 1: newThemeAct->setChecked(true); break; case 1: newThemeAct->setChecked(true); break;
case 2: monoWhiteAct->setChecked(true); break; case 2: monoWhiteAct->setChecked(true); break;
@ -2037,7 +1998,7 @@ void MainWindow::updateProfilesActions()
{ {
int i; int i;
QSettings settings; QSettings settings;
int activeProfile = settings.value("profileId").toInt(); int activeProfile = glob.profileId();
settings.beginGroup("Profiles"); settings.beginGroup("Profiles");
for (i=0; i<MAX_PROFILES; i++) { for (i=0; i<MAX_PROFILES; i++) {
@ -2182,8 +2143,7 @@ void MainWindow::dropEvent(QDropEvent *event)
QString fileName = urls.first().toLocalFile(); QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
QSettings settings; glob.lastDir(QFileInfo(fileName).dir().absolutePath());
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName); QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) { if (existing) {

View file

@ -49,9 +49,9 @@
#include "downloaddialog.h" #include "downloaddialog.h"
#include "eeprominterface.h" #include "eeprominterface.h"
#define MAX_RECENT 15
#define MAX_PROFILES 10
#define SPLASH_TIME 5 #define SPLASH_TIME 5
#define MAX_RECENT 10
#define MAX_PROFILES 15
class MdiChild; class MdiChild;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -166,7 +166,6 @@ private:
void createMenus(); void createMenus();
void createToolBars(); void createToolBars();
void createStatusBar(); void createStatusBar();
void readSettings();
void updateRecentFileActions(); void updateRecentFileActions();
void updateProfilesActions(); void updateProfilesActions();
void updateIconSizeActions(); void updateIconSizeActions();
@ -202,11 +201,8 @@ private:
QString downloadedFWFilename; QString downloadedFWFilename;
downloadDialog * downloadDialog_forWait; downloadDialog * downloadDialog_forWait;
bool checkCompanion;
bool checkFW;
bool needRename; bool needRename;
bool showcheckForUpdatesResult; bool showcheckForUpdatesResult;
int MaxRecentFiles;
int currentFWrev; int currentFWrev;
int currentFWrev_temp; int currentFWrev_temp;
int NewFwRev; int NewFwRev;