Merge pull request #728 from opentx/dvogonen/making_settings_type_safe

Merging this one myself since both Bertrand and I have been throug it over and over. Better merge it fast before something else changes and forces new changes.
This commit is contained in:
Kjell Kernen
2014-02-21 10:14:09 +01:00
34 changed files with 1570 additions and 1739 deletions
+93 -91
View File
@@ -96,102 +96,103 @@ include_directories(
add_subdirectory(modeledit)
add_subdirectory(simulation)
SET( companion_SRCS
eeprominterface.cpp
hexinterface.cpp
flashinterface.cpp
file.cpp
xmlinterface.cpp
${PROJECT_BINARY_DIR}/radio.cxx
firmwares/th9x/th9xeeprom.cpp
firmwares/th9x/th9xinterface.cpp
firmwares/er9x/er9xeeprom.cpp
firmwares/er9x/er9xinterface.cpp
firmwares/gruvin9x/gruvin9xeeprom.cpp
firmwares/gruvin9x/gruvin9xinterface.cpp
firmwares/opentx/opentxeeprom.cpp
firmwares/opentx/open9xStockeeprom.cpp
firmwares/opentx/open9xGruvin9xeeprom.cpp
firmwares/opentx/open9xSky9xeeprom.cpp
firmwares/opentx/opentxinterface.cpp
firmwares/opentx/opentxTaranisSimulator.cpp
firmwares/opentx/opentxSky9xsimulator.cpp
firmwares/opentx/opentxGruvin9xsimulator.cpp
firmwares/opentx/opentxM128simulator.cpp
firmwares/opentx/opentxsimulator.cpp
firmwares/ersky9x/ersky9xeeprom.cpp
firmwares/ersky9x/ersky9xinterface.cpp
${RADIO_SRC_DIRECTORY}/bitmaps/sticks.lbm
helpers.cpp
mdichild.cpp
generaledit.cpp
modelslist.cpp
mountlist.cpp
avroutputdialog.cpp
apppreferencesdialog.cpp
fwpreferencesdialog.cpp
burnconfigdialog.cpp
comparedialog.cpp
contributorsdialog.cpp
customizesplashdialog.cpp
burndialog.cpp
printdialog.cpp
fusesdialog.cpp
logsdialog.cpp
downloaddialog.cpp
splashlibrary.cpp
mainwindow.cpp
main.cpp
modelconfigdialog.cpp
qcustomplot.cpp
set(companion_SRCS
eeprominterface.cpp
hexinterface.cpp
flashinterface.cpp
file.cpp
xmlinterface.cpp
${PROJECT_BINARY_DIR}/radio.cxx
firmwares/th9x/th9xeeprom.cpp
firmwares/th9x/th9xinterface.cpp
firmwares/er9x/er9xeeprom.cpp
firmwares/er9x/er9xinterface.cpp
firmwares/gruvin9x/gruvin9xeeprom.cpp
firmwares/gruvin9x/gruvin9xinterface.cpp
firmwares/opentx/opentxeeprom.cpp
firmwares/opentx/open9xStockeeprom.cpp
firmwares/opentx/open9xGruvin9xeeprom.cpp
firmwares/opentx/open9xSky9xeeprom.cpp
firmwares/opentx/opentxinterface.cpp
firmwares/opentx/opentxTaranisSimulator.cpp
firmwares/opentx/opentxSky9xsimulator.cpp
firmwares/opentx/opentxGruvin9xsimulator.cpp
firmwares/opentx/opentxM128simulator.cpp
firmwares/opentx/opentxsimulator.cpp
firmwares/ersky9x/ersky9xeeprom.cpp
firmwares/ersky9x/ersky9xinterface.cpp
${RADIO_SRC_DIRECTORY}/bitmaps/sticks.lbm
appdata.cpp
helpers.cpp
mdichild.cpp
generaledit.cpp
modelslist.cpp
mountlist.cpp
avroutputdialog.cpp
apppreferencesdialog.cpp
fwpreferencesdialog.cpp
burnconfigdialog.cpp
comparedialog.cpp
contributorsdialog.cpp
customizesplashdialog.cpp
burndialog.cpp
printdialog.cpp
fusesdialog.cpp
logsdialog.cpp
downloaddialog.cpp
splashlibrary.cpp
mainwindow.cpp
companion.cpp
modelconfigdialog.cpp
qcustomplot.cpp
)
SET( companion_MOC_HDRS
avroutputdialog.h
apppreferencesdialog.h
fwpreferencesdialog.h
burnconfigdialog.h
comparedialog.h
printdialog.h
fusesdialog.h
logsdialog.h
contributorsdialog.h
customizesplashdialog.h
splashlibrary.h
splashlabel.h
burndialog.h
downloaddialog.h
generaledit.h
modelslist.h
mdichild.h
mainwindow.h
modelconfigdialog.h
qcustomplot.h
helpers.h
set(companion_MOC_HDRS
avroutputdialog.h
apppreferencesdialog.h
fwpreferencesdialog.h
burnconfigdialog.h
comparedialog.h
printdialog.h
fusesdialog.h
logsdialog.h
contributorsdialog.h
customizesplashdialog.h
splashlibrary.h
splashlabel.h
burndialog.h
downloaddialog.h
generaledit.h
modelslist.h
mdichild.h
mainwindow.h
modelconfigdialog.h
qcustomplot.h
helpers.h
)
SET( companion_UIS
mdichild.ui
avroutputdialog.ui
comparedialog.ui
fusesdialog.ui
logsdialog.ui
apppreferencesdialog.ui
fwpreferencesdialog.ui
burnconfigdialog.ui
downloaddialog.ui
generaledit.ui
printdialog.ui
contributorsdialog.ui
customizesplashdialog.ui
splashlibrary.ui
burndialog.ui
modelconfigdialog.ui
set(companion_UIS
mdichild.ui
avroutputdialog.ui
comparedialog.ui
fusesdialog.ui
logsdialog.ui
apppreferencesdialog.ui
fwpreferencesdialog.ui
burnconfigdialog.ui
downloaddialog.ui
generaledit.ui
printdialog.ui
contributorsdialog.ui
customizesplashdialog.ui
splashlibrary.ui
burndialog.ui
modelconfigdialog.ui
)
SET( companion_RCS
companion.qrc
${CMAKE_CURRENT_BINARY_DIR}/translations.qrc
set(companion_RCS
companion.qrc
${CMAKE_CURRENT_BINARY_DIR}/translations.qrc
)
MACRO (TODAY RESULT)
@@ -315,7 +316,8 @@ set(simu_SRCS
file.cpp # TODO not needed
modeledit/node.cpp
modeledit/edge.cpp # TODO not needed
simulation/main.cpp
appdata.cpp
simulator.cpp
)
set(simu_HDRS
+643
View File
@@ -0,0 +1,643 @@
// Companion Application Data Class Definition.
// Author Kjell Kernen
#include "appdata.h"
// Global data and storage object
AppData g;
// ** CompStoreObj class********************
void CompStoreObj::clear (const QString tag1, const QString tag2, const QString tag3)
{
QSettings settings(PRODUCT, COMPANY);
if (tag2.isEmpty())
{
settings.remove(tag1);
}
else if (tag3.isEmpty())
{
settings.beginGroup(tag1);
settings.remove(tag2);
settings.endGroup();
}
else
{
settings.beginGroup(tag1);
settings.beginGroup(tag2);
settings.remove(tag3);
settings.endGroup();
settings.endGroup();
}
}
void CompStoreObj::store(const QByteArray newArray, QByteArray &array, const QString 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 CompStoreObj::store(const QStringList newSList, QStringList &stringList, const QString 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 CompStoreObj::store(const QString newString, QString &string, const QString 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 CompStoreObj::store(const bool newTruth, bool &truth, const QString 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 CompStoreObj::store(const int newNumber, int &number, const QString 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 CompStoreObj::retrieve( QByteArray &array, const QString tag, const QString 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 CompStoreObj::retrieve( QStringList &stringList, const QString tag, const QString 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 CompStoreObj::retrieve( QString &string, const QString tag, const QString 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 CompStoreObj::retrieve( bool &truth, const QString 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 CompStoreObj::retrieve( int &number, const QString 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 CompStoreObj::getset( QByteArray &array, const QString tag, const QString def, const QString group1, const QString group2 )
{
retrieve( array, tag, def, group1, group2);
store(array, array, tag, group1, group2);
}
void CompStoreObj::getset( QStringList &stringList, const QString tag, const QString def, const QString group1, const QString group2 )
{
retrieve( stringList, tag, def, group1, group2);
store(stringList, stringList, tag, group1, group2);
}
void CompStoreObj::getset( QString &string, const QString tag, const QString def, const QString group1, const QString group2 )
{
retrieve( string, tag, def, group1, group2);
store(string, string, tag, group1, group2);
}
void CompStoreObj::getset( bool &truth, const QString tag, const bool def, const QString group1, const QString group2 )
{
retrieve( truth, tag, def, group1, group2);
store(truth, truth, tag, group1, group2);
}
void CompStoreObj::getset( int &number, const QString tag, const int def, const QString group1, const QString group2 )
{
retrieve( number, tag, def, group1, group2);
store(number, number, tag, group1, group2);
}
// ** FwRevision class********************
int FwRevision::get( const QString fwName )
{
QString result;
retrieve( result, fwName, "", "FwRevisions" );
return result.toInt();
}
void FwRevision::set( const QString fwName, const int fwRevision )
{
QString tempString= QString("%1").arg(fwRevision);
store( tempString, tempString, fwName, "FwRevisions" );
}
void FwRevision::remove( const QString tag )
{
clear( "FwRevisions", tag );
}
// ** JStickData class********************
// Get declarations
int JStickData::stick_axe() { return _stickAxe; }
int JStickData::stick_min() { return _stickMin; }
int JStickData::stick_med() { return _stickMed; }
int JStickData::stick_max() { return _stickMax; }
int JStickData::stick_inv() { return _stickInv; }
// Set declarations
void JStickData::stick_axe(const int it) { store( it, _stickAxe, QString("stick%1_axe").arg(index), "JsCalibration" );}
void JStickData::stick_min(const int it) { store( it, _stickMin, QString("stick%1_min").arg(index), "JsCalibration" );}
void JStickData::stick_med(const int it) { store( it, _stickMed, QString("stick%1_med").arg(index), "JsCalibration" );}
void JStickData::stick_max(const int it) { store( it, _stickMax, QString("stick%1_max").arg(index), "JsCalibration" );}
void JStickData::stick_inv(const int it) { store( it, _stickInv, QString("stick%1_inv").arg(index), "JsCalibration" );}
// Constructor
JStickData::JStickData()
{
index = -1;
}
void JStickData::remove()
{
// Remove all JStickData values from settings file
QSettings settings(PRODUCT, COMPANY);
settings.beginGroup( "JsCalibration" );
settings.remove( QString( "stick%1_axe").arg(index) );
settings.remove( QString( "stick%1_min").arg(index) );
settings.remove( QString( "stick%1_med").arg(index) );
settings.remove( QString( "stick%1_max").arg(index) );
settings.remove( QString( "stick%1_inv").arg(index) );
settings.endGroup();
// Reset all JStickData variables to initial values
init(index);
}
bool JStickData::existsOnDisk()
{
QSettings settings(PRODUCT, COMPANY);
settings.beginGroup("JsCalibration");
int axe = settings.value( QString("stick%1_axe").arg(index), -1 ).toInt();
settings.endGroup();
return (axe > -1);
}
void JStickData::init(int newIndex)
{
index = newIndex;
_stickAxe = -1;
_stickMin = -32767;
_stickMed = 0;
_stickMax = 0;
_stickInv = 0;
// Do not write empty joystick calibrations to disk.
if ( !existsOnDisk() )
return;
flush();
}
void JStickData::flush()
{
getset( _stickAxe, QString("stick%1_axe").arg(index), -1, "JsCalibration" );
getset( _stickMin, QString("stick%1_min").arg(index), -32767, "JsCalibration" );
getset( _stickMed, QString("stick%1_med").arg(index), 0, "JsCalibration" );
getset( _stickMax, QString("stick%1_max").arg(index), 0, "JsCalibration" );
getset( _stickInv, QString("stick%1_inv").arg(index), 0, "JsCalibration" );
}
// ** Profile class********************
// Get declarations
QString Profile::firmware() { return _firmware; }
QString Profile::name() { return _name; }
QString Profile::sdPath() { return _sdPath; }
QString Profile::splashFile() { return _splashFile; }
bool Profile::burnFirmware() { return _burnFirmware; }
bool Profile::renameFwFiles() { return _renameFwFiles; }
bool Profile::patchImage() { return _patchImage; }
int Profile::channelOrder() { return _channelOrder; }
int Profile::defaultMode() { return _defaultMode; }
QString Profile::beeper() { return _beeper; }
QString Profile::countryCode() { return _countryCode; }
QString Profile::display() { return _display; }
QString Profile::haptic() { return _haptic; }
QString Profile::speaker() { return _speaker; }
QString Profile::stickPotCalib() { return _stickPotCalib; }
QString Profile::trainerCalib() { return _trainerCalib; }
int Profile::currentCalib() { return _currentCalib; }
int Profile::gsStickMode() { return _gsStickMode; }
int Profile::ppmMultiplier() { return _ppmMultiplier; }
int Profile::vBatCalib() { return _vBatCalib; }
int Profile::vBatWarn() { return _vBatWarn; }
// Set declarations
void Profile::name (const QString x) { if (x.isEmpty()) // Name may never be empty!
store("----", _name, "Name", "Profiles", QString("profile%1").arg(index));
else
store(x, _name, "Name", "Profiles", QString("profile%1").arg(index));}
void Profile::firmware (const QString x) { store(x, _firmware, "firmware" ,"Profiles", QString("profile%1").arg(index));}
void Profile::sdPath (const QString x) { store(x, _sdPath, "sdPath" ,"Profiles", QString("profile%1").arg(index));}
void Profile::splashFile (const QString x) { store(x, _splashFile, "SplashFileName" ,"Profiles", QString("profile%1").arg(index));}
void Profile::burnFirmware (const bool x) { store(x, _burnFirmware, "burnFirmware" ,"Profiles", QString("profile%1").arg(index));}
void Profile::renameFwFiles (const bool x) { store(x, _renameFwFiles, "rename_firmware_files" ,"Profiles", QString("profile%1").arg(index));}
void Profile::patchImage (const bool x) { store(x, _patchImage, "patchImage" ,"Profiles", QString("profile%1").arg(index));}
void Profile::channelOrder (const int x) { store(x, _channelOrder, "default_channel_order" ,"Profiles", QString("profile%1").arg(index));}
void Profile::defaultMode (const int x) { store(x, _defaultMode, "default_mode" ,"Profiles", QString("profile%1").arg(index));}
void Profile::beeper (const QString x) { store(x, _beeper, "Beeper" ,"Profiles", QString("profile%1").arg(index));}
void Profile::countryCode (const QString x) { store(x, _countryCode, "countryCode" ,"Profiles", QString("profile%1").arg(index));}
void Profile::display (const QString x) { store(x, _display, "Display" ,"Profiles", QString("profile%1").arg(index));}
void Profile::haptic (const QString x) { store(x, _haptic, "Haptic" ,"Profiles", QString("profile%1").arg(index));}
void Profile::speaker (const QString x) { store(x, _speaker, "Speaker" ,"Profiles", QString("profile%1").arg(index));}
void Profile::stickPotCalib (const QString x) { store(x, _stickPotCalib, "StickPotCalib" ,"Profiles", QString("profile%1").arg(index));}
void Profile::trainerCalib (const QString x) { store(x, _trainerCalib, "TrainerCalib" ,"Profiles", QString("profile%1").arg(index));}
void Profile::currentCalib (const int x) { store(x, _currentCalib, "currentCalib" ,"Profiles", QString("profile%1").arg(index));}
void Profile::gsStickMode (const int x) { store(x, _gsStickMode, "GSStickMode" ,"Profiles", QString("profile%1").arg(index));}
void Profile::ppmMultiplier (const int x) { store(x, _ppmMultiplier, "PPM_Multiplier" ,"Profiles", QString("profile%1").arg(index));}
void Profile::vBatCalib (const int x) { store(x, _vBatCalib, "VbatCalib" ,"Profiles", QString("profile%1").arg(index));}
void Profile::vBatWarn (const int x) { store(x, _vBatWarn, "vBatWarn" ,"Profiles", QString("profile%1").arg(index));}
// Constructor
Profile::Profile()
{
index = -1;
}
void Profile::remove()
{
// Remove all profile values from settings file
QSettings settings(PRODUCT, COMPANY);
settings.beginGroup("Profiles");
settings.remove(QString("profile%1").arg(index));
settings.endGroup();
// Reset all profile variables to initial values
init(index);
}
bool Profile::existsOnDisk()
{
QSettings settings(PRODUCT, COMPANY);
settings.beginGroup("Profiles");
settings.beginGroup(QString("profile%1").arg(index));
QStringList keyList = settings.allKeys();
settings.endGroup();
settings.endGroup();
return (keyList.length() > 0);
}
void Profile::init(int newIndex)
{
index = newIndex;
_firmware = "";
_name = "";
_sdPath = "";
_splashFile = "";
_burnFirmware = false;
_renameFwFiles = false;
_patchImage = false;
_channelOrder = 0;
_defaultMode = 1;
_beeper = "";
_countryCode = "";
_display = "";
_haptic = "";
_speaker = "";
_stickPotCalib = "";
_trainerCalib = "";
_currentCalib = 0;
_gsStickMode = 0;
_ppmMultiplier = 0;
_vBatCalib = 0;
_vBatWarn = 0;
// Do not write empty profiles to disk except the default (0) profile.
if ( index > 0 && !existsOnDisk())
return;
flush();
}
void Profile::flush()
{
// 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( _splashFile, "SplashFileName" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _burnFirmware, "burnFirmware" ,false ,"Profiles", QString("profile%1").arg(index));
getset( _renameFwFiles, "rename_firmware_files" ,false ,"Profiles", QString("profile%1").arg(index));
getset( _patchImage, "patchImage" ,false ,"Profiles", QString("profile%1").arg(index));
getset( _channelOrder, "default_channel_order" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _defaultMode, "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( _display, "Display" ,"" ,"Profiles", QString("profile%1").arg(index));
getset( _haptic, "Haptic" ,"" ,"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( _currentCalib, "currentCalib" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _gsStickMode, "GSStickMode" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _ppmMultiplier, "PPM_Multiplier" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _vBatCalib, "VbatCalib" ,0 ,"Profiles", QString("profile%1").arg(index));
getset( _vBatWarn, "vBatWarn" ,0 ,"Profiles", QString("profile%1").arg(index));
}
// ** AppData class********************
// Get declarations
QStringList AppData::recentFiles() { return _recentFiles; }
QByteArray AppData::mainWinGeo() { return _mainWinGeo; }
QByteArray AppData::mainWinState() { return _mainWinState; }
QByteArray AppData::modelEditGeo() { return _modelEditGeo; }
QString AppData::armMcu() { return _armMcu; }
QString AppData::avrArguments() { return _avrArguments; }
QString AppData::avrPort() { return _avrPort; }
QString AppData::avrdudeLocation() { return _avrdudeLocation; }
QString AppData::compileServer() { return _compileServer; }
QString AppData::cpuId() { return _cpuId; }
QString AppData::dfuArguments() { return _dfuArguments; }
QString AppData::dfuLocation() { return _dfuLocation; }
QString AppData::lastFw() { return _lastFw; }
QString AppData::locale() { return _locale; }
QString AppData::mcu() { return _mcu; }
QString AppData::programmer() { return _programmer; }
QString AppData::sambaLocation() { return _sambaLocation; }
QString AppData::sambaPort() { return _sambaPort; }
QString AppData::backupDir() { return _backupDir; }
QString AppData::gePath() { return _gePath; }
QString AppData::eepromDir() { return _eepromDir; }
QString AppData::flashDir() { return _flashDir; }
QString AppData::imagesDir() { return _imagesDir; }
QString AppData::logDir() { return _logDir; }
QString AppData::libDir() { return _libDir; }
QString AppData::snapshotDir() { return _snapshotDir; }
QString AppData::updatesDir() { return _updatesDir; }
bool AppData::enableBackup() { return _enableBackup; }
bool AppData::backupOnFlash() { return _backupOnFlash; }
bool AppData::jsSupport() { return _jsSupport; }
bool AppData::rev4aSupport() { return _rev4aSupport; }
bool AppData::maximized() { return _maximized; }
bool AppData::showSplash() { return _showSplash; }
bool AppData::snapToClpbrd() { return _snapToClpbrd; }
bool AppData::autoCheckApp() { return _autoCheckApp; }
bool AppData::autoCheckFw() { return _autoCheckFw; }
bool AppData::simuSW() { return _simuSW; }
bool AppData::enableWizard() { return _enableWizard; }
int AppData::backLight() { return _backLight; }
int AppData::embedSplashes() { return _embedSplashes; }
int AppData::fwServerFails() { return _fwServerFails; }
int AppData::generalEditTab() { return _generalEditTab; }
int AppData::iconSize() { return _iconSize; }
int AppData::historySize() { return _historySize; }
int AppData::jsCtrl() { return _jsCtrl; }
int AppData::modelEditTab() { return _modelEditTab; }
int AppData::id() { return _id; }
int AppData::theme() { return _theme; }
int AppData::warningId() { return _warningId; }
// Set declarations
void AppData::recentFiles (const QStringList x) { store(x, _recentFiles, "recentFileList" );}
void AppData::mainWinGeo (const QByteArray x) { store(x, _mainWinGeo, "mainWindowGeometry" );}
void AppData::mainWinState (const QByteArray x) { store(x, _mainWinState, "mainWindowState" );}
void AppData::modelEditGeo (const QByteArray x) { store(x, _modelEditGeo, "modelEditGeometry" );}
void AppData::armMcu (const QString x) { store(x, _armMcu, "arm_mcu" );}
void AppData::avrArguments (const QString x) { store(x, _avrArguments, "avr_arguments" );}
void AppData::avrPort (const QString x) { store(x, _avrPort, "avr_port" );}
void AppData::avrdudeLocation (const QString x) { store(x, _avrdudeLocation, "avrdudeLocation" );}
void AppData::compileServer (const QString x) { store(x, _compileServer, "compilation-server" );}
void AppData::cpuId (const QString x) { store(x, _cpuId, "cpu_id" );}
void AppData::dfuArguments (const QString x) { store(x, _dfuArguments, "dfu_arguments" );}
void AppData::dfuLocation (const QString x) { store(x, _dfuLocation, "dfu_location" );}
void AppData::lastFw (const QString x) { store(x, _lastFw, "lastFw" );}
void AppData::locale (const QString x) { store(x, _locale, "locale" );}
void AppData::mcu (const QString x) { store(x, _mcu, "mcu" );}
void AppData::programmer (const QString x) { store(x, _programmer, "programmer" );}
void AppData::sambaLocation (const QString x) { store(x, _sambaLocation, "samba_location" );}
void AppData::sambaPort (const QString x) { store(x, _sambaPort, "samba_port" );}
void AppData::backupDir (const QString x) { store(x, _backupDir, "backupPath" );}
void AppData::gePath (const QString x) { store(x, _gePath, "gePath" );}
void AppData::eepromDir (const QString x) { store(x, _eepromDir, "lastDir" );}
void AppData::flashDir (const QString x) { store(x, _flashDir, "lastFlashDir" );}
void AppData::imagesDir (const QString x) { store(x, _imagesDir, "lastImagesDir" );}
void AppData::logDir (const QString x) { store(x, _logDir, "lastLogDir" );}
void AppData::libDir (const QString x) { store(x, _libDir, "libraryPath" );}
void AppData::snapshotDir (const QString x) { store(x, _snapshotDir, "snapshotpath" );}
void AppData::updatesDir (const QString x) { store(x, _updatesDir, "lastUpdatesDir" );}
void AppData::enableBackup (const bool x) { store(x, _enableBackup, "backupEnable" );}
void AppData::backupOnFlash (const bool x) { store(x, _backupOnFlash, "backupOnFlash" );}
void AppData::maximized (const bool x) { store(x, _maximized, "maximized" );}
void AppData::jsSupport (const bool x) { store(x, _jsSupport, "js_support" );}
void AppData::rev4aSupport (const bool x) { store(x, _rev4aSupport, "rev4asupport" );}
void AppData::showSplash (const bool x) { store(x, _showSplash, "show_splash" );}
void AppData::snapToClpbrd (const bool x) { store(x, _snapToClpbrd, "snapshot_to_clipboard" );}
void AppData::autoCheckApp (const bool x) { store(x, _autoCheckApp, "startup_check_companion" );}
void AppData::autoCheckFw (const bool x) { store(x, _autoCheckFw, "startup_check_fw" );}
void AppData::simuSW (const bool x) { store(x, _simuSW, "simuSW" );}
void AppData::enableWizard (const bool x) { store(x, _enableWizard, "wizardEnable" );}
void AppData::backLight (const int x) { store(x, _backLight, "backLight" );}
void AppData::embedSplashes (const int x) { store(x, _embedSplashes, "embedded_splashes" );}
void AppData::fwServerFails (const int x) { store(x, _fwServerFails, "fwserver" );}
void AppData::generalEditTab (const int x) { store(x, _generalEditTab, "generalEditTab" );}
void AppData::iconSize (const int x) { store(x, _iconSize, "icon_size" );}
void AppData::historySize (const int x) { store(x, _historySize, "history_size" );}
void AppData::jsCtrl (const int x) { store(x, _jsCtrl, "js_ctrl" );}
void AppData::modelEditTab (const int x) { store(x, _modelEditTab, "modelEditTab" );}
void AppData::id (const int x) { store(x, _id, "profileId" );}
void AppData::theme (const int x) { store(x, _theme, "theme" );}
void AppData::warningId (const int x) { store(x, _warningId, "warningId" );}
// Constructor
AppData::AppData()
{
//Initialize the profiles
for (int i=0; i<MAX_PROFILES; i++)
profile[i].init( i );
//Initialize the joysticks
for (int i=0; i<MAX_JOYSTICKS; i++)
joystick[i].init( i );
// Import settings from companion9x, but only do it one time.
// Use "location" tag as an indicator that the settings are missing
QSettings c9x_settings("companion9x", "companion9x");
QSettings settings(PRODUCT, COMPANY);
if (!settings.contains("locale"))
{
QStringList keys = c9x_settings.allKeys();
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
{
settings.setValue(*i, c9x_settings.value(*i));
}
// Convert firmware name
QString firmware = settings.value("firmware", "").toString();
firmware.replace("open9x","opentx");
firmware.replace("x9da","taranis");
// Move Companion9x settings to profile0, the new default profile
profile[0].firmware( firmware );
profile[0].name( settings.value( "Name", "" ).toString());
profile[0].sdPath( settings.value( "sdPath", "" ).toString());
profile[0].splashFile( settings.value( "SplashFileName", "" ).toString());
profile[0].burnFirmware( settings.value( "burnFirmware", false ).toBool());
profile[0].renameFwFiles( settings.value( "rename_firmware_files", false ).toBool());
profile[0].patchImage( settings.value( "patchImage", false ).toBool());
profile[0].channelOrder( settings.value( "default_channel_order", "0" ).toInt());
profile[0].defaultMode( settings.value( "default_mode", "1" ).toInt());
// Delete unused settings
settings.remove("firmware");
settings.remove("Name");
settings.remove("sdPath");
settings.remove("SplashFileName");
settings.remove("burnFirmware");
settings.remove("rename_firmware_files");
settings.remove("patchImage");
settings.remove("default_channel_order");
settings.remove("default_mode");
}
// Load and store all variables. Use default values if setting values are missing
getset( _recentFiles, "recentFileList" ,"" );
getset( _mainWinGeo, "mainWindowGeometry" ,"" );
getset( _mainWinState, "mainWindowState" ,"" );
getset( _modelEditGeo, "modelEditGeometry" ,"" );
getset( _armMcu, "arm_mcu" ,"at91sam3s4-9x" );
getset( _avrArguments, "avr_arguments" ,"" );
getset( _avrPort, "avr_port" ,"" );
getset( _avrdudeLocation, "avrdudeLocation" ,"" );
getset( _compileServer, "compilation-server" ,"" );
getset( _cpuId, "cpu_id" ,"" );
getset( _dfuArguments, "dfu_arguments" ,"-a 0" );
getset( _dfuLocation, "dfu_location" ,"" );
getset( _lastFw, "lastFw" ,"" );
getset( _locale, "locale" ,"" );
getset( _mcu, "mcu" ,"m64" );
getset( _programmer, "programmer" ,"usbasp" );
getset( _sambaLocation, "samba_location" ,"" );
getset( _sambaPort, "samba_port" ,"\\USBserial\\COM23" );
getset( _backupDir, "backupPath" ,"" );
getset( _gePath, "gePath" ,"" );
getset( _eepromDir, "lastDir" ,"" );
getset( _flashDir, "lastFlashDir" ,"" );
getset( _imagesDir, "lastImagesDir" ,"" );
getset( _logDir, "lastLogDir" ,"" );
getset( _libDir, "libraryPath" ,"" );
getset( _snapshotDir, "snapshotpath" ,"" );
getset( _updatesDir, "lastUpdatesDir" ,"" );
getset( _enableBackup, "backupEnable" ,false );
getset( _backupOnFlash, "backupOnFlash" ,true );
getset( _jsSupport, "js_support" ,false );
getset( _rev4aSupport, "rev4asupport" ,false );
getset( _maximized, "maximized" ,false );
getset( _showSplash, "show_splash" ,true );
getset( _snapToClpbrd, "snapshot_to_clipboard" ,false );
getset( _autoCheckApp, "startup_check_companion" ,true );
getset( _autoCheckFw, "startup_check_fw" ,true );
getset( _simuSW, "simuSW" ,false );
getset( _enableWizard, "wizardEnable" ,true );
getset( _backLight, "backLight" ,0 );
getset( _embedSplashes, "embedded_splashes" ,0 );
getset( _fwServerFails, "fwserver" ,0 );
getset( _generalEditTab, "generalEditTab" ,0 );
getset( _iconSize, "icon_size" ,2 );
getset( _jsCtrl, "js_ctrl" ,0 );
getset( _historySize, "history_size" ,10 );
getset( _modelEditTab, "modelEditTab" ,0 );
getset( _id, "profileId" ,0 );
getset( _theme, "theme" ,1 );
getset( _warningId, "warningId" ,0 );
}
+355
View File
@@ -0,0 +1,355 @@
// Companion Application Data Class Definition.
// Author Kjell Kernen
// All temporary and permanent global variables are defined here to make
// initialization and storage safe and visible.
// Do not access variables in QSettings directly, it is not type safe!
#ifndef COMPANION_APPDATA_H
#define COMPANION_APPDATA_H
#include <QByteArray>
#include <QStringList>
#include <QString>
#include <QSettings>
#define COMPANY "OpenTX Companion"
#define PRODUCT "OpenTX"
#define MAX_PROFILES 15
#define MAX_JOYSTICKS 8
class CompStoreObj
{
public:
void clear (const QString tag1="", const QString tag2="", const QString tag3="");
void store(const QByteArray newArray, QByteArray &array, const QString tag, const QString group1="", const QString group2="" );
void store(const QStringList newSList, QStringList &stringList, const QString tag, const QString group1="", const QString group2="" );
void store(const QString newString, QString &string, const QString tag, const QString group1="", const QString group2="" );
void store(const bool newTruth, bool &truth, const QString tag, const QString group1="", const QString group2="" );
void store(const int newNumber, int &number, const QString tag, const QString group1="", const QString group2="" );
// Retrieval functions
void retrieve( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" );
void retrieve( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" );
void retrieve( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" );
void retrieve( bool &truth, const QString tag, const bool def, const QString group1="", const QString group2="" );
void retrieve( int &number, const QString tag, const int def, const QString group1="", const QString group2="" );
// Retrieve and Store functions
void getset( QByteArray &array, const QString tag, const QString def, const QString group1="", const QString group2="" );
void getset( QStringList &stringList, const QString tag, const QString def, const QString group1="", const QString group2="" );
void getset( QString &string, const QString tag, const QString def, const QString group1="", const QString group2="" );
void getset( bool &truth, const QString tag, const bool def, const QString group1="", const QString group2="" );
void getset( int &number, const QString tag, const int def, const QString group1="", const QString group2="" );
};
class FwRevision: protected CompStoreObj
{
public:
int get( const QString);
void set( const QString, const int );
void remove( const QString );
};
class JStickData: protected CompStoreObj
{
private:
int index;
int _stickAxe;
int _stickMin;
int _stickMed;
int _stickMax;
int _stickInv;
public:
// All the get definitions
int stick_axe();
int stick_min();
int stick_med();
int stick_max();
int stick_inv();
// All the set definitions
void stick_axe(const int);
void stick_min(const int);
void stick_med(const int);
void stick_max(const int);
void stick_inv(const int);
JStickData();
void remove();
bool existsOnDisk();
void init(int index);
void flush();
};
class Profile: protected CompStoreObj
{
private:
// Class Internal Variable
int index;
// Application Variables
QString _firmware;
QString _name;
QString _sdPath;
QString _splashFile;
bool _burnFirmware;
bool _renameFwFiles;
bool _patchImage;
int _channelOrder;
int _defaultMode;
// Firmware Variables
QString _beeper;
QString _countryCode;
QString _display;
QString _haptic;
QString _speaker;
QString _stickPotCalib;
QString _trainerCalib;
int _currentCalib;
int _gsStickMode;
int _ppmMultiplier;
int _vBatCalib;
int _vBatWarn;
public:
// All the get definitions
QString firmware();
QString name();
QString sdPath();
QString splashFile();
bool burnFirmware();
bool renameFwFiles();
bool patchImage();
int channelOrder();
int defaultMode();
QString beeper();
QString countryCode();
QString display();
QString haptic();
QString speaker();
QString stickPotCalib();
QString trainerCalib();
int currentCalib();
int gsStickMode();
int ppmMultiplier();
int vBatCalib();
int vBatWarn();
// All the set definitions
void name (const QString);
void firmware (const QString);
void sdPath (const QString);
void splashFile (const QString);
void burnFirmware (const bool);
void renameFwFiles (const bool);
void patchImage (const bool);
void channelOrder (const int);
void defaultMode (const int);
void beeper (const QString);
void countryCode (const QString);
void display (const QString);
void haptic (const QString);
void speaker (const QString);
void stickPotCalib (const QString);
void trainerCalib (const QString);
void currentCalib (const int);
void gsStickMode (const int);
void ppmMultiplier (const int);
void vBatCalib (const int);
void vBatWarn (const int);
Profile();
void remove();
bool existsOnDisk();
void init(int newIndex);
void flush();
};
class AppData: protected CompStoreObj
{
// All the global variables
public:
Profile profile[MAX_PROFILES];
JStickData joystick[MAX_JOYSTICKS];
FwRevision fwRev;
private:
QStringList _recentFiles;
QByteArray _mainWinGeo;
QByteArray _mainWinState;
QByteArray _modelEditGeo;
QString _armMcu;
QString _avrArguments;
QString _avrPort;
QString _avrdudeLocation;
QString _compileServer;
QString _cpuId;
QString _dfuArguments;
QString _dfuLocation;
QString _lastFw;
QString _locale;
QString _mcu;
QString _programmer;
QString _sambaLocation;
QString _sambaPort;
QString _backupDir;
QString _gePath;
QString _eepromDir;
QString _flashDir;
QString _imagesDir;
QString _logDir;
QString _libDir;
QString _snapshotDir;
QString _updatesDir;
bool _enableBackup;
bool _backupOnFlash;
bool _maximized;
bool _jsSupport;
bool _rev4aSupport;
bool _showSplash;
bool _snapToClpbrd;
bool _autoCheckApp;
bool _autoCheckFw;
bool _simuSW;
bool _enableWizard;
int _backLight;
int _embedSplashes;
int _fwServerFails;
int _generalEditTab;
int _iconSize;
int _jsCtrl;
int _historySize;
int _modelEditTab;
int _id;
int _theme;
int _warningId;
public:
// All the get definitions
QStringList recentFiles();
QByteArray mainWinGeo();
QByteArray mainWinState();
QByteArray modelEditGeo();
QString armMcu();
QString avrArguments();
QString avrPort();
QString avrdudeLocation();
QString compileServer();
QString cpuId();
QString dfuArguments();
QString dfuLocation();
QString lastFw();
QString locale();
QString mcu();
QString programmer();
QString sambaLocation();
QString sambaPort();
QString backupDir();
QString gePath();
QString eepromDir();
QString flashDir();
QString imagesDir();
QString logDir();
QString libDir();
QString snapshotDir();
QString updatesDir();
bool enableBackup();
bool backupOnFlash();
bool jsSupport();
bool rev4aSupport();
bool maximized();
bool showSplash();
bool snapToClpbrd();
bool autoCheckApp();
bool autoCheckFw();
bool simuSW();
bool enableWizard();
int backLight();
int embedSplashes();
int fwServerFails();
int generalEditTab();
int iconSize();
int historySize();
int jsCtrl();
int modelEditTab();
int id();
int theme();
int warningId();
// All the set definitions
void recentFiles (const QStringList x);
void mainWinGeo (const QByteArray);
void mainWinState (const QByteArray);
void modelEditGeo (const QByteArray);
void armMcu (const QString);
void avrArguments (const QString);
void avrPort (const QString);
void avrdudeLocation (const QString);
void compileServer (const QString);
void cpuId (const QString);
void dfuArguments (const QString);
void dfuLocation (const QString);
void lastFw (const QString);
void locale (const QString);
void mcu (const QString);
void programmer (const QString);
void sambaLocation (const QString);
void sambaPort (const QString);
void backupDir (const QString);
void gePath (const QString);
void eepromDir (const QString);
void flashDir (const QString);
void imagesDir (const QString);
void logDir (const QString);
void libDir (const QString);
void snapshotDir (const QString);
void updatesDir (const QString);
void enableBackup (const bool);
void backupOnFlash (const bool);
void maximized (const bool);
void jsSupport (const bool);
void rev4aSupport (const bool);
void showSplash (const bool);
void snapToClpbrd (const bool);
void autoCheckApp (const bool);
void autoCheckFw (const bool);
void simuSW (const bool);
void enableWizard (const bool);
void backLight (const int);
void embedSplashes (const int);
void fwServerFails (const int);
void generalEditTab (const int);
void iconSize (const int);
void historySize (const int);
void jsCtrl (const int);
void modelEditTab (const int);
void id (const int);
void theme (const int);
void warningId (const int);
// Constructor
AppData();
};
extern AppData g;
#endif // COMPANION_APPDATA_H
+92 -170
View File
@@ -1,6 +1,7 @@
#include "apppreferencesdialog.h"
#include "ui_apppreferencesdialog.h"
#include "mainwindow.h"
#include "appdata.h"
#include "helpers.h"
#include "flashinterface.h"
#ifdef JOYSTICKS
@@ -35,101 +36,87 @@ appPreferencesDialog::~appPreferencesDialog()
void appPreferencesDialog::writeValues()
{
QSettings settings;
settings.setValue("startup_check_companion", ui->startupCheck_companion9x->isChecked());
settings.setValue("startup_check_fw", ui->startupCheck_fw->isChecked());
settings.setValue("wizardEnable", ui->wizardEnable_ChkB->isChecked());
settings.setValue("show_splash", ui->showSplash->isChecked());
settings.setValue("simuSW", ui->simuSW->isChecked());
settings.setValue("history_size", ui->historySize->value());
settings.setValue("backLight", ui->backLightColor->currentIndex());
settings.setValue("libraryPath", ui->libraryPath->text());
settings.setValue("gePath", ui->ge_lineedit->text());
settings.setValue("embedded_splashes", ui->splashincludeCB->currentIndex());
settings.setValue("backupEnable", ui->backupEnable->isChecked());
g.autoCheckApp(ui->startupCheck_companion9x->isChecked());
g.autoCheckFw(ui->startupCheck_fw->isChecked());
g.enableWizard(ui->wizardEnable_ChkB->isChecked());
g.showSplash(ui->showSplash->isChecked());
g.simuSW(ui->simuSW->isChecked());
g.historySize(ui->historySize->value());
g.backLight(ui->backLightColor->currentIndex());
g.libDir(ui->libraryPath->text());
g.gePath(ui->ge_lineedit->text());
g.embedSplashes(ui->splashincludeCB->currentIndex());
g.enableBackup(ui->backupEnable->isChecked());
if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) {
settings.setValue("js_support", ui->joystickChkB ->isChecked());
settings.setValue("js_ctrl", ui->joystickCB ->currentIndex());
g.jsSupport(ui->joystickChkB ->isChecked());
g.jsCtrl(ui->joystickCB ->currentIndex());
}
else {
settings.remove("js_support");
settings.remove("js_ctrl");
g.jsSupport(false);
g.jsCtrl(0);
}
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked());
settings.setValue("profileId", ui->profileIndexLE->text());
settings.setValue("Name", ui->profileNameLE->text());
settings.setValue("sdPath", ui->sdPath->text());
settings.setValue("SplashFileName", ui->SplashFileName->text());
if (!ui->SplashFileName->text().isEmpty())
settings.setValue("SplashImage", "");
settings.setValue("firmware", ui->firmwareLE->text());
g.id(ui->profileIndexLE->text().toInt());
g.profile[g.id()].channelOrder(ui->channelorderCB->currentIndex());
g.profile[g.id()].defaultMode(ui->stickmodeCB->currentIndex());
g.profile[g.id()].renameFwFiles(ui->renameFirmware->isChecked());
g.profile[g.id()].burnFirmware(ui->burnFirmware->isChecked());
g.profile[g.id()].name(ui->profileNameLE->text());
g.profile[g.id()].sdPath(ui->sdPath->text());
g.profile[g.id()].splashFile(ui->SplashFileName->text());
g.profile[g.id()].firmware(ui->firmwareLE->text());
saveProfile();
}
void appPreferencesDialog::on_snapshotPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), settings.value("snapshotPath").toString());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), g.snapshotDir());
if (!fileName.isEmpty()) {
settings.setValue("snapshotpath", fileName);
settings.setValue("snapshot_to_clipboard", false);
g.snapshotDir(fileName);
g.snapToClpbrd(false);
ui->snapshotPath->setText(fileName);
}
}
void appPreferencesDialog::initSettings()
{
QSettings settings;
ui->snapshotClipboardCKB->setChecked(settings.value("snapshot_to_clipboard", false).toBool());
ui->burnFirmware->setChecked(settings.value("burnFirmware", true).toBool());
QString Path=settings.value("snapshotPath", "").toString();
if (QDir(Path).exists()) {
ui->snapshotPath->setText(Path);
ui->snapshotPath->setReadOnly(true);
}
if (ui->snapshotClipboardCKB->isChecked()) {
ui->snapshotClipboardCKB->setChecked(g.snapToClpbrd());
ui->burnFirmware->setChecked(g.profile[g.id()].burnFirmware());
ui->snapshotPath->setText(g.snapshotDir());
ui->snapshotPath->setReadOnly(true);
if (ui->snapshotClipboardCKB->isChecked())
{
ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true);
}
ui->startupCheck_companion9x->setChecked(settings.value("startup_check_companion", true).toBool());
ui->startupCheck_fw->setChecked(settings.value("startup_check_fw", true).toBool());
ui->wizardEnable_ChkB->setChecked(settings.value("wizardEnable", true).toBool());
ui->showSplash->setChecked(settings.value("show_splash", true).toBool());
ui->historySize->setValue(settings.value("history_size", 10).toInt());
ui->backLightColor->setCurrentIndex(settings.value("backLight", 0).toInt());
ui->simuSW->setChecked(settings.value("simuSW", false).toBool());
ui->startupCheck_companion9x->setChecked(g.autoCheckApp());
ui->startupCheck_fw->setChecked(g.autoCheckFw());
ui->wizardEnable_ChkB->setChecked(g.enableWizard());
ui->showSplash->setChecked(g.showSplash());
ui->historySize->setValue(g.historySize());
ui->backLightColor->setCurrentIndex(g.backLight());
ui->simuSW->setChecked(g.simuSW());
ui->libraryPath->setText(g.libDir());
ui->ge_lineedit->setText(g.gePath());
Path=settings.value("libraryPath", "").toString();
if (QDir(Path).exists()) {
ui->libraryPath->setText(Path);
}
Path=settings.value("gePath", "").toString();
if (QFile(Path).exists()) {
ui->ge_lineedit->setText(Path);
}
Path=settings.value("backupPath", "").toString();
if (!Path.isEmpty()) {
if (QDir(Path).exists()) {
ui->backupPath->setText(Path);
if (!g.backupDir().isEmpty()) {
if (QDir(g.backupDir()).exists()) {
ui->backupPath->setText(g.backupDir());
ui->backupEnable->setEnabled(true);
ui->backupEnable->setChecked(settings.value("backupEnable", true).toBool());
ui->backupEnable->setChecked(g.enableBackup());
} else {
ui->backupEnable->setDisabled(true);
}
} else {
ui->backupEnable->setDisabled(true);
}
ui->splashincludeCB->setCurrentIndex(settings.value("embedded_splashes", 0).toInt());
ui->splashincludeCB->setCurrentIndex(g.embedSplashes());
#ifdef JOYSTICKS
ui->joystickChkB->setChecked(settings.value("js_support", false).toBool());
ui->joystickChkB->setChecked(g.jsSupport());
if (ui->joystickChkB->isChecked()) {
QStringList joystickNames;
joystickNames << tr("No joysticks found");
@@ -147,7 +134,7 @@ void appPreferencesDialog::initSettings()
}
ui->joystickCB->clear();
ui->joystickCB->insertItems(0, joystickNames);
ui->joystickCB->setCurrentIndex(settings.value("js_ctrl", 0).toInt());
ui->joystickCB->setCurrentIndex(g.jsCtrl());
}
else {
ui->joystickCB->clear();
@@ -156,58 +143,46 @@ void appPreferencesDialog::initSettings()
}
#endif
// Profile Tab Inits
ui->channelorderCB->setCurrentIndex(settings.value("default_channel_order", 0).toInt());
ui->stickmodeCB->setCurrentIndex(settings.value("default_mode", 1).toInt());
ui->renameFirmware->setChecked(settings.value("rename_firmware_files", false).toBool());
Path=settings.value("sdPath", "").toString();
if (QDir(Path).exists()) {
ui->sdPath->setText(Path);
}
ui->profileIndexLE->setText(settings.value("profileId", "").toString());
ui->profileNameLE->setText(settings.value("Name", "").toString());
ui->channelorderCB->setCurrentIndex(g.profile[g.id()].channelOrder());
ui->stickmodeCB->setCurrentIndex(g.profile[g.id()].defaultMode());
ui->renameFirmware->setChecked(g.profile[g.id()].renameFwFiles());
ui->sdPath->setText(g.profile[g.id()].sdPath());
ui->profileIndexLE->setText(QString("%1").arg(g.id()));
ui->profileNameLE->setText(g.profile[g.id()].name());
ui->firmwareLE->setText(g.profile[g.id()].firmware());
ui->SplashFileName->setText(g.profile[g.id()].splashFile());
QString fileName=settings.value("SplashFileName","").toString();
if (!fileName.isEmpty()) {
QFile file(fileName);
if (file.exists()){
ui->SplashFileName->setText(fileName);
displayImage( fileName );
}
}
ui->firmwareLE->setText(settings.value("firmware","").toString());
displayImage( g.profile[g.id()].splashFile() );
}
void appPreferencesDialog::on_libraryPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), settings.value("libraryPath").toString());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), g.libDir());
if (!fileName.isEmpty()) {
settings.setValue("libraryPath", fileName);
g.libDir(fileName);
ui->libraryPath->setText(fileName);
}
}
void appPreferencesDialog::on_snapshotClipboardCKB_clicked()
{
QSettings settings;
if (ui->snapshotClipboardCKB->isChecked()) {
ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true);
settings.setValue("snapshot_to_clipboard", true);
g.snapToClpbrd(true);
} else {
ui->snapshotPath->setEnabled(true);
ui->snapshotPath->setReadOnly(true);
ui->snapshotPathButton->setEnabled(true);
settings.setValue("snapshot_to_clipboard", false);
g.snapToClpbrd(false);
}
}
void appPreferencesDialog::on_backupPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), settings.value("backupPath").toString());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), g.backupDir());
if (!fileName.isEmpty()) {
settings.setValue("backupPath", fileName);
g.backupDir(fileName);
ui->backupPath->setText(fileName);
}
ui->backupEnable->setEnabled(true);
@@ -215,7 +190,6 @@ void appPreferencesDialog::on_backupPathButton_clicked()
void appPreferencesDialog::on_ge_pathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text());
if (!fileName.isEmpty()) {
ui->ge_lineedit->setText(fileName);
@@ -259,8 +233,7 @@ void appPreferencesDialog::on_joystickcalButton_clicked() {
void appPreferencesDialog::on_sdPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), settings.value("sdPath").toString());
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), g.profile[g.id()].sdPath());
if (!fileName.isEmpty()) {
ui->sdPath->setText(fileName);
}
@@ -268,95 +241,45 @@ void appPreferencesDialog::on_sdPathButton_clicked()
void appPreferencesDialog::saveProfile()
{
QSettings settings;
// The profile name may NEVER be empty
if (ui->profileNameLE->text().isEmpty())
ui->profileNameLE->setText("----");
QString profile=QString("profile") + settings.value("profileId").toString();
QString name=ui->profileNameLE->text();
if (name.isEmpty()) {
name = profile;
ui->profileNameLE->setText(name);
}
settings.beginGroup("Profiles");
settings.beginGroup(profile);
settings.setValue("Name",name);
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked());
settings.setValue("sdPath", ui->sdPath->text());
settings.setValue("SplashFileName", ui->SplashFileName->text());
settings.setValue("firmware", ui->firmwareLE->text());
settings.endGroup();
settings.endGroup();
}
void appPreferencesDialog::loadProfileString(QString profile, QString label)
{
QSettings settings;
QString value;
settings.beginGroup("Profiles");
settings.beginGroup(profile);
value = settings.value(label).toString();
settings.endGroup();
settings.endGroup();
settings.setValue( label, value );
}
void appPreferencesDialog::loadProfile()
{
QSettings settings;
QString profile=QString("profile") + settings.value("profileId").toString();
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" );
g.profile[g.id()].name( ui->profileNameLE->text() );
g.profile[g.id()].channelOrder( ui->channelorderCB->currentIndex());
g.profile[g.id()].defaultMode( ui->stickmodeCB->currentIndex());
g.profile[g.id()].burnFirmware( ui->burnFirmware->isChecked());
g.profile[g.id()].renameFwFiles( ui->renameFirmware->isChecked());
g.profile[g.id()].sdPath( ui->sdPath->text());
g.profile[g.id()].splashFile( ui->SplashFileName->text());
g.profile[g.id()].firmware( ui->firmwareLE->text());
}
void appPreferencesDialog::on_removeProfileButton_clicked()
{
QSettings settings;
QString profileId = settings.value("profileId").toString();
if ( profileId == "1" )
if ( g.id() == 0 )
QMessageBox::information(this, tr("Not possible to remove profile"), tr("The default profile can not be removed."));
else
{
QString profile=QString("profile") + profileId;
settings.beginGroup("Profiles");
settings.remove(profile);
settings.endGroup();
settings.setValue("profileId", "1");
loadProfile();
g.profile[g.id()].remove();
g.id( 0 );
initSettings();
}
}
bool appPreferencesDialog::displayImage( QString fileName )
{
QSettings settings;
// Start by clearing the pixmap
ui->imageLabel->setPixmap(QPixmap());
QImage image(fileName);
if (image.isNull())
return false;
// 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 filePath2 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".hex";
QFile file(filePath1);
if (!file.exists())
filePath1 = filePath2;
// Use the firmware name to determine splash width
int width = SPLASH_WIDTH;
FlashInterface flash(filePath1);
if (flash.hasSplash())
width = flash.getSplashWidth(); // Returns SPLASHX9D_HEIGHT if filePath1 does not exist!
// There must be a cleaner way of finding out the width of the firmware splash!
if (g.profile[g.id()].firmware().contains("taranis"))
width = SPLASHX9D_WIDTH;
ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, SPLASH_HEIGHT)));
if (width==SPLASHX9D_WIDTH) {
@@ -390,15 +313,14 @@ void appPreferencesDialog::on_SplashSelect_clicked()
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
}
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats));
tr("Open Image to load"), g.imagesDir(), tr("Images (%1)").arg(supportedImageFormats));
if (!fileName.isEmpty()) {
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
if (displayImage(fileName))
ui->SplashFileName->setText(fileName);
if (!fileName.isEmpty()){
g.imagesDir(QFileInfo(fileName).dir().absolutePath());
displayImage(fileName);
ui->SplashFileName->setText(fileName);
}
}
+1 -1
View File
@@ -26,7 +26,7 @@ private:
bool displayImage( QString fileName );
void saveProfile();
void loadProfileString(QString profile, QString label);
void loadProfile();
void loadFromProfile();
private slots:
void writeValues();
+37 -37
View File
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>685</width>
<height>462</height>
<height>446</height>
</rect>
</property>
<property name="sizePolicy">
@@ -839,16 +839,6 @@ This is used by the templated to determine which channel goes to what number out
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="profileNameLE">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="9" column="1" colspan="6">
<widget class="Line" name="line_6">
<property name="orientation">
@@ -872,7 +862,35 @@ This is used by the templated to determine which channel goes to what number out
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Firmware</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="firmwareLE">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="6">
<widget class="QPushButton" name="SplashSelect">
<property name="text">
<string>Select Image</string>
</property>
</widget>
</item>
<item row="7" column="6">
<widget class="QPushButton" name="clearImageButton">
<property name="text">
<string>Clear Image</string>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLineEdit" name="profileIndexLE">
<property name="enabled">
<bool>false</bool>
@@ -885,17 +903,13 @@ This is used by the templated to determine which channel goes to what number out
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Firmware</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="firmwareLE">
<property name="enabled">
<bool>false</bool>
<item row="0" column="1">
<widget class="QLineEdit" name="profileNameLE">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
@@ -933,20 +947,6 @@ This is used by the templated to determine which channel goes to what number out
</property>
</widget>
</item>
<item row="4" column="6">
<widget class="QPushButton" name="SplashSelect">
<property name="text">
<string>Select Image</string>
</property>
</widget>
</item>
<item row="7" column="6">
<widget class="QPushButton" name="clearImageButton">
<property name="text">
<string>Clear Image</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
+40 -31
View File
@@ -3,6 +3,7 @@
#include "avroutputdialog.h"
#include "eeprominterface.h"
#include "helpers.h"
#include "appdata.h"
#include <QtGui>
#if !defined WIN32 && defined __GNUC__
@@ -83,33 +84,42 @@ burnConfigDialog::~burnConfigDialog()
void burnConfigDialog::getSettings()
{
QSettings settings;
avrLoc = g.avrdudeLocation();
sambaLoc = g.sambaLocation();
dfuLoc = g.dfuLocation();
#if defined WIN32 || !defined __GNUC__
avrLoc = settings.value("avrdude_location", QFileInfo("avrdude.exe").absoluteFilePath()).toString();
sambaLoc = settings.value("samba_location", QFileInfo("sam-ba.exe").absoluteFilePath()).toString();
dfuLoc = settings.value("dfu_location", QFileInfo("dfu-util.exe").absoluteFilePath()).toString();
if ( avrLoc.isEmpty())
avrLoc = QFileInfo("avrdude.exe").absoluteFilePath();
if ( sambaLoc.isEmpty())
sambaLoc = QFileInfo("sam-ba.exe").absoluteFilePath();
if ( dfuLoc.isEmpty())
dfuLoc = QFileInfo("dfu-util.exe").absoluteFilePath();
#elif defined __APPLE__
avrLoc = settings.value("avrdude_location", "/usr/local/bin/avrdude").toString();
sambaLoc = settings.value("samba_location", "/usr/local/bin/sam-ba").toString();
dfuLoc = settings.value("dfu_location", QFileInfo("/opt/local/bin/dfu-util").absoluteFilePath()).toString();
if ( avrLoc.isEmpty())
avrLoc = "/usr/local/bin/avrdude";
if ( sambaLoc.isEmpty())
sambaLoc = "/usr/local/bin/sam-ba";
if ( dfuLoc.isEmpty())
dfuLoc = QFileInfo("/opt/local/bin/dfu-util").absoluteFilePath();
#else
avrLoc = settings.value("avrdude_location", "/usr/bin/avrdude").toString();
sambaLoc = settings.value("samba_location", "/usr/bin/sam-ba").toString();
dfuLoc = settings.value("dfu_location", QFileInfo("/usr/bin/dfu-util").absoluteFilePath()).toString();
if ( avrLoc.isEmpty())
avrLoc = "/usr/bin/avrdude";
if ( sambaLoc.isEmpty())
sambaLoc = "/usr/bin/sam-ba";
if ( dfuLoc.isEmpty())
dfuLoc = QFileInfo("/usr/bin/dfu-util").absoluteFilePath();
#endif
QString str = settings.value("avr_arguments").toString();
avrArgs = str.split(" ", QString::SkipEmptyParts);
avrProgrammer = settings.value("programmer", QString("usbasp")).toString();
avrMCU = settings.value("mcu", QString("m64")).toString();
armMCU = settings.value("arm_mcu", QString("at91sam3s4-9x")).toString();
dfuArgs = g.dfuArguments().split(" ", QString::SkipEmptyParts);
avrArgs = g.avrArguments().split(" ", QString::SkipEmptyParts);
avrProgrammer = g.programmer();
avrPort = g.avrPort();
avrMCU = g.mcu();
armMCU = g.armMcu();
sambaPort = g.sambaPort();
avrPort = settings.value("avr_port", "").toString();
sambaPort = settings.value("samba_port", "\\USBserial\\COM23").toString();
str = settings.value("dfu_arguments", "-a 0").toString();
dfuArgs = str.split(" ", QString::SkipEmptyParts);
ui->avrdude_location->setText(getAVRDUDE());
ui->avrArgs->setText(getAVRArgs().join(" "));
@@ -137,17 +147,16 @@ void burnConfigDialog::getSettings()
void burnConfigDialog::putSettings()
{
QSettings settings;
settings.setValue("avrdude_location", avrLoc);
settings.setValue("programmer", avrProgrammer);
settings.setValue("mcu", avrMCU);
settings.setValue("avr_port", avrPort);
settings.setValue("avr_arguments", avrArgs.join(" "));
settings.setValue("samba_location", sambaLoc);
settings.setValue("samba_port", sambaPort);
settings.setValue("arm_mcu", armMCU);
settings.setValue("dfu_location", dfuLoc);
settings.setValue("dfu_arguments", dfuArgs.join(" "));
g.avrdudeLocation( avrLoc );
g.programmer( avrProgrammer);
g.mcu( avrMCU );
g.avrPort( avrPort );
g.avrArguments( avrArgs.join(" ") );
g.sambaLocation( sambaLoc );
g.sambaPort( sambaPort );
g.armMcu( armMCU );
g.dfuLocation( dfuLoc );
g.dfuArguments( dfuArgs.join(" ") );
}
void burnConfigDialog::populateProgrammers()
+34 -60
View File
@@ -7,6 +7,7 @@
#include "splashlibrary.h"
#include "flashinterface.h"
#include "hexinterface.h"
#include "appdata.h"
burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * backupEE, QString DocName):
QDialog(parent),
@@ -58,15 +59,7 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac
else {
setWindowTitle(tr("Write Models and Settings in %1 to TX").arg(DocName));
}
QSettings settings;
int profileid=settings.value("profileId", 1).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profileid);
settings.beginGroup(profile);
QString Name=settings.value("Name","").toString();
settings.endGroup();
settings.endGroup();
ui->profile_label->setText(tr("Current profile")+QString(": ")+Name);
ui->profile_label->setText(tr("Current profile")+QString(": ")+g.profile[g.id()].name());
}
if (!hexfileName->isEmpty()) {
ui->FWFileName->setText(*hexfileName);
@@ -76,20 +69,13 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac
else {
burnraw=false;
if (checkeEprom(*hexfileName)) {
QSettings settings;
int profileid=settings.value("profileId", 1).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profileid);
settings.beginGroup(profile);
QString Name=settings.value("Name","").toString();
QString calib=settings.value("StickPotCalib","").toString();
QString trainercalib=settings.value("TrainerCalib","").toString();
QString DisplaySet=settings.value("Display","").toString();
QString BeeperSet=settings.value("Beeper","").toString();
QString HapticSet=settings.value("Haptic","").toString();
QString SpeakerSet=settings.value("Speaker","").toString();
settings.endGroup();
settings.endGroup();
QString Name = g.profile[g.id()].name();
QString calib = g.profile[g.id()].stickPotCalib();
QString trainercalib = g.profile[g.id()].trainerCalib();
QString DisplaySet = g.profile[g.id()].display();
QString BeeperSet = g.profile[g.id()].beeper();
QString HapticSet = g.profile[g.id()].haptic();
QString SpeakerSet = g.profile[g.id()].speaker();
if (!Name.isEmpty()) {
ui->profile_label->show();
ui->patchcalib_CB->show();
@@ -119,9 +105,8 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac
hexfileName->clear();
}
else if (Type==2) {
QSettings settings;
QString FileName;
FileName = settings.value("lastFw").toString();
FileName = g.lastFw();
QFile file(FileName);
if (file.exists()) {
checkFw(FileName);
@@ -138,7 +123,7 @@ burnDialog::~burnDialog()
void burnDialog::on_FlashLoadButton_clicked()
{
QString fileName;
QSettings settings;
ui->ImageLoadButton->setDisabled(true);
ui->libraryButton->setDisabled(true);
ui->InvertColorButton->setDisabled(true);
@@ -155,11 +140,11 @@ void burnDialog::on_FlashLoadButton_clicked()
ui->EEbackupCB->hide();
QTimer::singleShot(0, this, SLOT(shrink()));
if (hexType==2) {
fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER);
fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.flashDir(), FLASH_FILES_FILTER);
checkFw(fileName);
}
else {
QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getOpenFileName(this,tr("Choose file to load Models and Settings from"), g.eepromDir(), tr(EXTERNAL_EEPROM_FILES_FILTER));
if (checkeEprom(fileName)) {
if (burnraw==false) {
ui->BurnFlashButton->setEnabled(true);
@@ -191,7 +176,6 @@ void burnDialog::checkFw(QString fileName)
if (fileName.isEmpty()) {
return;
}
QSettings settings;
if (!IS_TARANIS(GetEepromInterface()->getBoard())) {
ui->EEbackupCB->show();
}
@@ -216,8 +200,8 @@ void burnDialog::checkFw(QString fileName)
ui->imageLabel->setFixedSize(flash.getSplashWidth(), flash.getSplashHeight());
ui->FwImage->show();
ui->FwImage->setPixmap(QPixmap::fromImage(flash.getSplash()));
QString ImageStr = settings.value("SplashImage", "").toString();
bool PatchFwCB = settings.value("patchImage", false).toBool();
QString ImageStr = g.profile[g.id()].splashFile();
bool PatchFwCB = g.profile[g.id()].patchImage();
if (!ImageStr.isEmpty()) {
QImage Image = qstring2image(ImageStr);
ui->imageLabel->setPixmap(QPixmap::fromImage(Image.convertToFormat(flash.getSplashFormat())));
@@ -260,7 +244,7 @@ void burnDialog::checkFw(QString fileName)
ui->BurnFlashButton->setEnabled(true);
}
QTimer::singleShot(0, this, SLOT(shrink()));
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
g.flashDir( QFileInfo(fileName).dir().absolutePath() );
}
bool burnDialog::checkeEprom(QString fileName)
@@ -360,12 +344,11 @@ void burnDialog::on_ImageLoadButton_clicked()
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
}
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats));
tr("Open Image to load"), g.imagesDir(), tr("Images (%1)").arg(supportedImageFormats));
if (!fileName.isEmpty()) {
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
g.imagesDir( QFileInfo(fileName).dir().absolutePath() );
QImage image(fileName);
if (image.isNull()) {
QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName));
@@ -442,11 +425,10 @@ void burnDialog::on_BurnFlashButton_clicked()
if (hexType==2) {
QString fileName=ui->FWFileName->text();
if (!fileName.isEmpty()) {
QSettings settings;
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
settings.setValue("lastFw", fileName);
g.flashDir( QFileInfo(fileName).dir().absolutePath() );
g.lastFw( fileName );
if (ui->PatchFWCB->isChecked()) {
settings.setValue("patchImage", true);
g.profile[g.id()].patchImage( true );
QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width(), ui->imageLabel->height());
if (!image.isNull()) {
QString tempDir = QDir::tempPath();
@@ -469,7 +451,7 @@ void burnDialog::on_BurnFlashButton_clicked()
QMessageBox::critical(this, tr("Warning"), tr("Custom image not found"));
}
} else {
settings.setValue("patchImage", false);
g.profile[g.id()].patchImage( false );
hexfileName->clear();
hexfileName->append(fileName);
}
@@ -479,26 +461,19 @@ void burnDialog::on_BurnFlashButton_clicked()
}
}
if (hexType==1) {
QSettings settings;
int profileid=settings.value("profileId", 1).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profileid);
settings.beginGroup(profile);
QString calib=settings.value("StickPotCalib","").toString();
QString trainercalib=settings.value("TrainerCalib","").toString();
QString calib = g.profile[g.id()].stickPotCalib();
QString trainercalib = g.profile[g.id()].trainerCalib();
int potsnum=GetEepromInterface()->getCapability(Pots);
int8_t vBatCalib=(int8_t)settings.value("VbatCalib", radioData.generalSettings.vBatCalib).toInt();
int8_t currentCalib=(int8_t)settings.value("currentCalib", radioData.generalSettings.currentCalib).toInt();
int8_t PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", radioData.generalSettings.PPM_Multiplier).toInt();
uint8_t GSStickMode=(uint8_t)settings.value("GSStickMode", radioData.generalSettings.stickMode).toUInt();
uint8_t vBatWarn=(uint8_t)settings.value("vBatWarn",radioData.generalSettings.vBatWarn).toUInt();
int8_t vBatCalib=(int8_t) g.profile[g.id()].vBatCalib();
int8_t currentCalib=(int8_t) g.profile[g.id()].currentCalib();
int8_t PPM_Multiplier=(int8_t) g.profile[g.id()].ppmMultiplier();
uint8_t GSStickMode=(uint8_t) g.profile[g.id()].gsStickMode();
uint8_t vBatWarn=(uint8_t) g.profile[g.id()].vBatWarn();
QString DisplaySet=settings.value("Display","").toString();
QString BeeperSet=settings.value("Beeper","").toString();
QString HapticSet=settings.value("Haptic","").toString();
QString SpeakerSet=settings.value("Speaker","").toString();
settings.endGroup();
settings.endGroup();
QString DisplaySet= g.profile[g.id()].display();
QString BeeperSet= g.profile[g.id()].beeper();
QString HapticSet= g.profile[g.id()].haptic();
QString SpeakerSet= g.profile[g.id()].speaker();
bool patch=false;
if (ui->patchcalib_CB->isChecked()) {
if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) {
@@ -656,8 +631,7 @@ void burnDialog::on_PreferredImageCB_toggled(bool checked)
{
QString tmpFileName;
if (checked) {
QSettings settings;
QString ImageStr = settings.value("SplashImage", "").toString();
QString ImageStr = g.profile[g.id()].splashFile();
if (!ImageStr.isEmpty()) {
QImage Image = qstring2image(ImageStr);
if (ui->imageLabel->width()!=128) {
@@ -45,12 +45,12 @@
#include <QString>
#include <QDir>
#include <QFileInfo>
#include <QSettings>
#include <QSplashScreen>
#include <QThread>
#include <iostream>
#include "mainwindow.h"
#include "eeprominterface.h"
#include "appdata.h"
#if defined WIN32 || !defined __GNUC__
#include <windows.h>
@@ -86,46 +86,27 @@ int main(int argc, char *argv[])
app.setStyle(new MyProxyStyle);
#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;
companionTranslator.load(":/companion_" + locale);
companionTranslator.load(":/companion_" + g.locale());
QTranslator qtTranslator;
qtTranslator.load((QString)"qt_" + locale.left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qtTranslator.load((QString)"qt_" + g.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&companionTranslator);
app.installTranslator(&qtTranslator);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString();
firmware_id.replace("open9x", "opentx");
firmware_id.replace("x9da", "taranis");
if (g.profile[g.id()].firmware().isEmpty())
g.profile[g.id()].firmware(default_firmware_variant.id);
QPixmap pixmap = QPixmap(firmware_id.contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png");
QPixmap pixmap = QPixmap(g.profile[g.id()].firmware().contains("taranis") ? ":/images/splasht.png" : ":/images/splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
RegisterFirmwares();
settings.setValue("firmware", firmware_id);
current_firmware_variant = GetFirmwareVariant(firmware_id);
current_firmware_variant = GetFirmwareVariant(g.profile[g.id()].firmware());
MainWindow *mainWin = new MainWindow();
if (showSplash) {
if (g.showSplash()) {
splash->show();
QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close()));
QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show()));
+17 -17
View File
@@ -2,6 +2,7 @@
#include "ui_customizesplashdialog.h"
#include <QtGui>
#include "appdata.h"
#include "helpers.h"
#include "burndialog.h"
#include "splashlibrary.h"
@@ -28,9 +29,10 @@ bool Side::displayImage( QString fileName, Source pictSource )
{
QImage image;
if (fileName.isEmpty()) {
if (fileName.isEmpty())
return false;
}
// Determine which picture format to use
if (pictSource == FW ){
FlashInterface flash(fileName);
if (!flash.hasSplash())
@@ -40,13 +42,16 @@ bool Side::displayImage( QString fileName, Source pictSource )
*format = (flash.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X);
}
else {
image.load(fileName);
if (pictSource== PICT)
*format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X;
image.load(fileName);
if (pictSource== PICT)
*format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X;
else if (pictSource == PROFILE)
*format = (g.profile[g.id()].firmware().contains("taranis")) ? LCDTARANIS : LCD9X;
}
if (image.isNull()) {
return false;
}
// Prepare and display image
if (*format==LCDTARANIS) {
image=image.convertToFormat(QImage::Format_RGB32);
QRgb col;
@@ -102,8 +107,6 @@ bool Side::refreshImage()
bool Side::saveImage()
{
QSettings settings;
if (*source == FW )
{
FlashInterface flash(*saveToFileName);
@@ -112,7 +115,7 @@ bool Side::saveImage()
}
QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight());
if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) {
settings.setValue("lastFlashDir", QFileInfo(*saveToFileName).dir().absolutePath());
g.flashDir( QFileInfo(*saveToFileName).dir().absolutePath() );
}
else {
return false;
@@ -121,7 +124,7 @@ bool Side::saveImage()
else if (*source == PICT) {
QImage image = imageLabel->pixmap()->toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
if (image.save(*saveToFileName)) {
settings.setValue("lastImagesDir", QFileInfo(*saveToFileName).dir().absolutePath());
g.imagesDir( QFileInfo(*saveToFileName).dir().absolutePath() );
}
else {
return false;
@@ -179,13 +182,12 @@ void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left);}
void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right);}
void customizeSplashDialog::loadFirmware(Side side)
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER);
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.flashDir(), FLASH_FILES_FILTER);
if (!fileName.isEmpty()) {
if (!side.displayImage( fileName, FW ))
QMessageBox::critical(this, tr("Error"), tr("Cannot load embedded FW image from %1.").arg(fileName));
else
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
g.flashDir( QFileInfo(fileName).dir().absolutePath() );
}
}
@@ -197,15 +199,14 @@ void customizeSplashDialog::loadPicture(Side side)
for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) {
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
}
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats));
tr("Open Image to load"), g.imagesDir(), tr("Images (%1)").arg(supportedImageFormats));
if (!fileName.isEmpty()) {
if (!side.displayImage( fileName, PICT ))
QMessageBox::critical(this, tr("Error"), tr("Cannot load the image file %1.").arg(fileName));
else
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
g.imagesDir( QFileInfo(fileName).dir().absolutePath() );
}
}
@@ -213,8 +214,7 @@ void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left
void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);}
void customizeSplashDialog::loadProfile(Side side)
{
QSettings settings;
QString fileName=settings.value("SplashFileName","").toString();
QString fileName=g.profile[g.id()].splashFile();
if (!fileName.isEmpty()) {
if (!side.displayImage( fileName, PROFILE ))
+18 -29
View File
@@ -6,7 +6,7 @@
#include "firmwares/gruvin9x/gruvin9xinterface.h"
#include "firmwares/opentx/opentxinterface.h"
#include "firmwares/ersky9x/ersky9xinterface.h"
#include "qsettings.h"
#include "appdata.h"
#include "helpers.h"
QString EEPROMWarnings;
@@ -772,34 +772,25 @@ GeneralSettings::GeneralSettings()
calibSpanNeg[i] = 0x180;
calibSpanPos[i] = 0x180;
}
QSettings settings;
templateSetup = settings.value("default_channel_order", 0).toInt();
stickMode = settings.value("default_mode", 1).toInt();
int profile_id = settings.value("profileId", 0).toInt();
if (profile_id>0) {
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profile_id);
settings.beginGroup(profile);
QString t_calib=settings.value("StickPotCalib","").toString();
templateSetup = g.profile[g.id()].channelOrder();
stickMode = g.profile[g.id()].defaultMode();
QString t_calib=g.profile[g.id()].stickPotCalib();
int potsnum=GetEepromInterface()->getCapability(Pots);
if (t_calib.isEmpty()) {
settings.endGroup();
settings.endGroup();
return;
} else {
QString t_trainercalib=settings.value("TrainerCalib","").toString();
int8_t t_vBatCalib=(int8_t)settings.value("VbatCalib", vBatCalib).toInt();
int8_t t_currentCalib=(int8_t)settings.value("currentCalib", currentCalib).toInt();
int8_t t_PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", PPM_Multiplier).toInt();
uint8_t t_stickMode=(uint8_t)settings.value("GSStickMode", stickMode).toUInt();
uint8_t t_vBatWarn=(uint8_t)settings.value("vBatWarn",vBatWarn).toUInt();
QString t_DisplaySet=settings.value("Display","").toString();
QString t_BeeperSet=settings.value("Beeper","").toString();
QString t_HapticSet=settings.value("Haptic","").toString();
QString t_SpeakerSet=settings.value("Speaker","").toString();
QString t_CountrySet=settings.value("countryCode","").toString();
settings.endGroup();
settings.endGroup();
QString t_trainercalib=g.profile[g.id()].trainerCalib();
int8_t t_vBatCalib=(int8_t)g.profile[g.id()].vBatCalib();
int8_t t_currentCalib=(int8_t)g.profile[g.id()].currentCalib();
int8_t t_PPM_Multiplier=(int8_t)g.profile[g.id()].ppmMultiplier();
uint8_t t_stickMode=(uint8_t)g.profile[g.id()].gsStickMode();
uint8_t t_vBatWarn=(uint8_t)g.profile[g.id()].vBatWarn();
QString t_DisplaySet=g.profile[g.id()].display();
QString t_BeeperSet=g.profile[g.id()].beeper();
QString t_HapticSet=g.profile[g.id()].haptic();
QString t_SpeakerSet=g.profile[g.id()].speaker();
QString t_CountrySet=g.profile[g.id()].countryCode();
if ((t_calib.length()==(NUM_STICKS+potsnum)*12) && (t_trainercalib.length()==16)) {
QString Byte;
@@ -881,7 +872,7 @@ GeneralSettings::GeneralSettings()
}
}
}
}
}
ModelData::ModelData()
@@ -1031,14 +1022,12 @@ ModelData ModelData::removeGlobalVars()
QList<EEPROMInterface *> eepromInterfaces;
void RegisterEepromInterfaces()
{
QSettings settings;
int rev4a = settings.value("rev4asupport",0).toInt();
eepromInterfaces.push_back(new OpenTxInterface(BOARD_STOCK));
eepromInterfaces.push_back(new OpenTxInterface(BOARD_M128));
eepromInterfaces.push_back(new OpenTxInterface(BOARD_GRUVIN9X));
eepromInterfaces.push_back(new OpenTxInterface(BOARD_SKY9X));
eepromInterfaces.push_back(new OpenTxInterface(BOARD_TARANIS));
if (rev4a)
if (g.rev4aSupport())
eepromInterfaces.push_back(new OpenTxInterface(BOARD_TARANIS_REV4a));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X));
@@ -19,6 +19,7 @@
#include "er9xeeprom.h"
#include "er9xsimulator.h"
#include "file.h"
#include "appdata.h"
#define FILE_TYP_GENERAL 1
#define FILE_TYP_MODEL 2
@@ -44,8 +45,7 @@ const char * Er9xInterface::getName()
const int Er9xInterface::getEEpromSize()
{
QSettings settings;
QString avrMCU = settings.value("mcu", QString("m64")).toString();
QString avrMCU = g.mcu();
if (avrMCU==QString("m128")) {
return 2*EESIZE_STOCK;
}
@@ -18,6 +18,7 @@
#include "gruvin9xinterface.h"
#include "gruvin9xeeprom.h"
#include "file.h"
#include "appdata.h"
#define FILE_TYP_GENERAL 1
#define FILE_TYP_MODEL 2
@@ -47,8 +48,7 @@ const char * Gruvin9xInterface::getName()
const int Gruvin9xInterface::getEEpromSize()
{
if (board == BOARD_STOCK) {
QSettings settings;
QString avrMCU = settings.value("mcu", QString("m64")).toString();
QString avrMCU = g.mcu();
if (avrMCU==QString("m128")) {
return EESIZE_STOCK*2;
}
@@ -16,6 +16,7 @@
#include "opentxSky9xsimulator.h"
#include "opentxinterface.h"
#include "appdata.h"
#define SIMU
#define SIMU_EXCEPTIONS
@@ -135,8 +136,7 @@ using namespace Open9xSky9x;
Open9xSky9xSimulator::Open9xSky9xSimulator(OpenTxInterface * open9xInterface):
open9xInterface(open9xInterface)
{
QSettings settings;
QString path=settings.value("sdPath", ".").toString()+"/";
QString path=g.profile[g.id()].sdPath()+"/";
int i=0;
for (i=0; i< std::min(path.length(),1022); i++) {
simuSdDirectory[i]=path.at(i).toAscii();
@@ -16,6 +16,7 @@
#include "opentxTaranisSimulator.h"
#include "opentxinterface.h"
#include "appdata.h"
#define SIMU
#define SIMU_EXCEPTIONS
@@ -181,8 +182,7 @@ OpentxTaranisSimulator::OpentxTaranisSimulator(OpenTxInterface * open9xInterface
open9xInterface(open9xInterface)
{
taranisSimulatorBoard = GetEepromInterface()->getBoard();
QSettings settings;
QString path=settings.value("sdPath", ".").toString()+"/";
QString path=g.profile[g.id()].sdPath()+"/";
int i=0;
for (i=0; i< std::min(path.length(),1022); i++) {
simuSdDirectory[i]=path.at(i).toAscii();
@@ -26,6 +26,7 @@
#include "opentxSky9xsimulator.h"
#include "opentxTaranisSimulator.h"
#include "file.h"
#include "appdata.h"
#define FILE_TYP_GENERAL 1
#define FILE_TYP_MODEL 2
@@ -934,9 +935,11 @@ bool OpenTxInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esiz
QString geturl( int board)
{
QSettings settings;
QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString();
QString url = g.compileServer();
if (url.isEmpty()){
url= OPENTX_FIRMWARE_DOWNLOADS;
g.compileServer(url);
}
switch(board) {
case BOARD_STOCK:
case BOARD_M128:
@@ -957,8 +960,11 @@ QString geturl( int board)
QString getstamp( int board)
{
QSettings settings;
QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString();
QString url = g.compileServer();
if (url.isEmpty()){
url= OPENTX_FIRMWARE_DOWNLOADS;
g.compileServer(url);
}
url.append("/stamp-opentx-");
switch(board) {
case BOARD_STOCK:
@@ -986,8 +992,11 @@ QString getstamp( int board)
QString getrnurl( int board)
{
QSettings settings;
QString url = settings.value("compilation-server", OPENTX_FIRMWARE_DOWNLOADS).toString();
QString url = g.compileServer();
if (url.isEmpty()){
url= OPENTX_FIRMWARE_DOWNLOADS;
g.compileServer(url);
}
url.append("/releasenotes-");
switch(board) {
case BOARD_STOCK:
@@ -1213,9 +1222,7 @@ void RegisterOpen9xFirmwares()
open9x->addOptions(fai_options);
firmwares.push_back(open9x);
QSettings settings;
int rev4a = settings.value("rev4asupport",0).toInt();
if (rev4a) {
if (g.rev4aSupport()) {
open9x = new Open9xFirmware("opentx-taranisrev4a", QObject::tr("OpenTX for FrSky Taranis Rev4a"), new OpenTxInterface(BOARD_TARANIS_REV4a), geturl(BOARD_TARANIS_REV4a), getstamp(BOARD_TARANIS_REV4a),getrnurl(BOARD_TARANIS), true);
open9x->addOption("noheli", QObject::tr("Disable HELI menu and cyclic mix support"));
open9x->addOption("notemplates", QObject::tr("Disable TEMPLATES menu"));
@@ -19,6 +19,7 @@
#include "th9xeeprom.h"
#include "th9xsimulator.h"
#include "file.h"
#include "appdata.h"
#define FILE_TYP_GENERAL 1
#define FILE_TYP_MODEL 2
@@ -44,8 +45,7 @@ const char * Th9xInterface::getName()
const int Th9xInterface::getEEpromSize()
{
QSettings settings;
QString avrMCU = settings.value("mcu", QString("m64")).toString();
QString avrMCU = g.mcu();
if (avrMCU==QString("m128")) {
return 2*EESIZE_STOCK;
}
+10 -19
View File
@@ -3,6 +3,7 @@
#include "mainwindow.h"
#include "eeprominterface.h"
#include "helpers.h"
#include "appdata.h"
#include <QDesktopServices>
#include <QtGui>
@@ -187,11 +188,8 @@ void fwPreferencesDialog::firmwareChanged()
ui->CPU_ID_LE->hide();
ui->CPU_ID_LABEL->hide();
}
QSettings settings;
settings.beginGroup("FwRevisions");
int fwrev = settings.value(variant.id, -1).toInt();
settings.endGroup();
if (fwrev != -1) {
int fwrev = g.fwRev.get(variant.id);
if (fwrev != 0) {
ui->FwInfo->setText(tr("Last downloaded release: %1").arg(fwrev));
if (!stamp.isEmpty()) {
ui->checkFWUpdates->show();
@@ -213,11 +211,9 @@ void fwPreferencesDialog::firmwareChanged()
void fwPreferencesDialog::writeValues()
{
QSettings settings;
settings.setValue("cpu_id", ui->CPU_ID_LE->text());
g.cpuId( ui->CPU_ID_LE->text() );
current_firmware_variant = getFirmwareVariant();
settings.setValue("firmware", current_firmware_variant.id);
g.profile[g.id()].firmware( current_firmware_variant.id );
}
void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware)
@@ -275,9 +271,7 @@ void fwPreferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware)
void fwPreferencesDialog::initSettings()
{
QSettings settings;
ui->CPU_ID_LE->setText(settings.value("cpu_id", "").toString());
ui->CPU_ID_LE->setText(g.cpuId());
FirmwareInfo * current_firmware = GetCurrentFirmware();
foreach(FirmwareInfo * firmware, firmwares) {
@@ -293,12 +287,10 @@ void fwPreferencesDialog::initSettings()
void fwPreferencesDialog::on_checkFWUpdates_clicked()
{
QSettings settings;
FirmwareVariant variant = getFirmwareVariant();
if (settings.value("burnFirmware", true).toBool()) {
if (g.profile[g.id()].burnFirmware()) {
current_firmware_variant = variant;
settings.setValue("firmware", variant.id);
g.profile[g.id()].firmware( variant.id );
}
MainWindow * mw = (MainWindow *)this->parent();
mw->checkForUpdates(true, variant.id);
@@ -307,14 +299,13 @@ void fwPreferencesDialog::on_checkFWUpdates_clicked()
void fwPreferencesDialog::on_fw_dnld_clicked()
{
QSettings settings;
MainWindow * mw = (MainWindow *)this->parent();
FirmwareVariant variant = getFirmwareVariant();
writeValues();
if (!variant.firmware->getUrl(variant.id).isNull()) {
if (settings.value("burnFirmware", true).toBool()) {
if (g.profile[g.id()].burnFirmware()) {
current_firmware_variant = getFirmwareVariant();
settings.setValue("firmware", current_firmware_variant.id);
g.profile[g.id()].firmware( current_firmware_variant.id );
}
mw->downloadLatestFW(current_firmware_variant.firmware, current_firmware_variant.id);
}
+36 -65
View File
@@ -1,9 +1,9 @@
#include "generaledit.h"
#include "ui_generaledit.h"
#include "helpers.h"
#include "appdata.h"
#include <QtGui>
#define MAX_PROFILES 10
#define BIT_WARN_THR ( 0x01 )
#define BIT_WARN_SW ( 0x02 )
#define BIT_WARN_MEM ( 0x04 )
@@ -20,18 +20,12 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) :
ui->setupUi(this);
this->setWindowIcon(CompanionIcon("open.png"));
QSettings settings;
QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString();
ui->tabWidget->setCurrentIndex(settings.value("generalEditTab", 0).toInt());
int profile_id=settings.value("profileId", 0).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profile_id);
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
QString firmware_id = g.profile[g.id()].firmware();
ui->tabWidget->setCurrentIndex( g.generalEditTab() );
QString name=g.profile[g.id()].name();
if (name.isEmpty()) {
ui->calstore_PB->setDisabled(true);
}
settings.endGroup();
EEPROMInterface *eepromInterface = GetEepromInterface();
QLabel * pmsl[] = {ui->ro_label,ui->ro1_label,ui->ro2_label,ui->ro3_label,ui->ro4_label,ui->ro5_label,ui->ro6_label,ui->ro7_label,ui->ro8_label, NULL};
QSlider * tpmsld[] = {ui->chkSA, ui->chkSB, ui->chkSC, ui->chkSD, ui->chkSE, ui->chkSF, ui->chkSG, ui->chkSH, NULL};
@@ -76,18 +70,14 @@ GeneralEdit::GeneralEdit(RadioData &radioData, QWidget *parent) :
}
ui->profile_CB->clear();
for ( int i = 0; i < MAX_PROFILES; ++i) {
QString profile=QString("profile%1").arg(i+1);
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
QString name=g.profile[i].name();
if (!name.isEmpty()) {
ui->profile_CB->addItem(name, i+1);
if ((i+1)==profile_id) {
ui->profile_CB->setCurrentIndex(ui->profile_CB->count()-1);
ui->profile_CB->addItem(name, i);
if (i==g.id()) {
ui->profile_CB->setCurrentIndex(ui->profile_CB->count());
}
}
settings.endGroup();
}
settings.endGroup();
QRegExp rx(CHAR_FOR_NAMES_REGEX);
ui->ownerNameLE->setValidator(new QRegExpValidator(rx, this));
@@ -970,9 +960,7 @@ void GeneralEdit::on_PPM4_editingFinished()
void GeneralEdit::on_tabWidget_currentChanged(int index)
{
// TODO why er9x here
QSettings settings;
settings.setValue("generalEditTab",index);//ui->tabWidget->currentIndex());
g.generalEditTab(index);
}
@@ -1220,31 +1208,23 @@ void GeneralEdit::on_swGEAChkB_stateChanged(int )
void GeneralEdit::on_calretrieve_PB_clicked()
{
QSettings settings;
int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profile_id);
settings.beginGroup(profile);
QString calib=settings.value("StickPotCalib","").toString();
QString calib=g.profile[profile_id].stickPotCalib();
int potsnum=GetEepromInterface()->getCapability(Pots);
if (calib.isEmpty()) {
settings.endGroup();
settings.endGroup();
return;
} else {
QString trainercalib=settings.value("TrainerCalib","").toString();
int8_t vBatCalib=(int8_t)settings.value("VbatCalib", g_eeGeneral.vBatCalib).toInt();
int8_t currentCalib=(int8_t)settings.value("currentCalib", g_eeGeneral.currentCalib).toInt();
int8_t PPM_Multiplier=(int8_t)settings.value("PPM_Multiplier", g_eeGeneral.PPM_Multiplier).toInt();
uint8_t GSStickMode=(uint8_t)settings.value("GSStickMode", g_eeGeneral.stickMode).toUInt();
uint8_t vBatWarn=(uint8_t)settings.value("vBatWarn",g_eeGeneral.vBatWarn).toUInt();
QString DisplaySet=settings.value("Display","").toString();
QString BeeperSet=settings.value("Beeper","").toString();
QString HapticSet=settings.value("Haptic","").toString();
QString SpeakerSet=settings.value("Speaker","").toString();
QString CountrySet=settings.value("countryCode","").toString();
settings.endGroup();
settings.endGroup();
QString trainercalib = g.profile[profile_id].trainerCalib();
int8_t vBatCalib = (int8_t)g.profile[profile_id].vBatCalib();
int8_t currentCalib = (int8_t)g.profile[profile_id].currentCalib();
int8_t PPM_Multiplier = (int8_t)g.profile[profile_id].ppmMultiplier();
uint8_t GSStickMode = (uint8_t)g.profile[profile_id].gsStickMode();
uint8_t vBatWarn = (uint8_t)g.profile[profile_id].vBatWarn();
QString DisplaySet = g.profile[profile_id].display();
QString BeeperSet = g.profile[profile_id].beeper();
QString HapticSet = g.profile[profile_id].haptic();
QString SpeakerSet = g.profile[profile_id].speaker();
QString CountrySet = g.profile[profile_id].countryCode();
if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) {
QString Byte;
@@ -1337,27 +1317,20 @@ void GeneralEdit::on_calretrieve_PB_clicked()
void GeneralEdit::on_calstore_PB_clicked()
{
QSettings settings;
int profile_id=ui->profile_CB->itemData(ui->profile_CB->currentIndex()).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profile_id);
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
QString name=g.profile[profile_id].name();
int potsnum=GetEepromInterface()->getCapability(Pots);
if (name.isEmpty()) {
ui->calstore_PB->setDisabled(true);
settings.endGroup();
settings.endGroup();
return;
} else {
QString calib=settings.value("StickPotCalib","").toString();
QString calib=g.profile[profile_id].stickPotCalib();
if (!(calib.isEmpty())) {
int ret = QMessageBox::question(this, "Companion",
tr("Do you want to store calibration in %1 profile<br>overwriting existing calibration?").arg(name) ,
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No) {
settings.endGroup();
settings.endGroup();
return;
}
}
@@ -1367,24 +1340,22 @@ void GeneralEdit::on_calstore_PB_clicked()
calib.append(QString("%1").arg((uint16_t)g_eeGeneral.calibSpanNeg[i], 4, 16, QChar('0')));
calib.append(QString("%1").arg((uint16_t)g_eeGeneral.calibSpanPos[i], 4, 16, QChar('0')));
}
settings.setValue("StickPotCalib",calib);
g.profile[profile_id].stickPotCalib( calib );
calib.clear();
for (int i=0; i< 4; i++) {
calib.append(QString("%1").arg((uint16_t)g_eeGeneral.trainer.calib[i], 4, 16, QChar('0')));
}
settings.setValue("TrainerCalib",calib);
settings.setValue("VbatCalib",g_eeGeneral.vBatCalib);
settings.setValue("currentCalib",g_eeGeneral.currentCalib);
settings.setValue("vBatWarn",g_eeGeneral.vBatWarn);
settings.setValue("PPM_Multiplier",g_eeGeneral.PPM_Multiplier);
settings.setValue("GSStickMode",g_eeGeneral.stickMode);
settings.setValue("Display",QString("%1%2%3").arg((g_eeGeneral.optrexDisplay ? 1:0), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.contrast, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.backlightBright, 2, 16, QChar('0')));
settings.setValue("Beeper",QString("%1%2").arg(((uint8_t)g_eeGeneral.beeperMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.beeperLength, 2, 16, QChar('0')));
settings.setValue("Haptic",QString("%1%2%3").arg(((uint8_t)g_eeGeneral.hapticMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticStrength, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticLength, 2, 16, QChar('0')));
settings.setValue("Speaker",QString("%1%2%3").arg((uint8_t)g_eeGeneral.speakerMode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerPitch, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerVolume, 2, 16, QChar('0')));
settings.setValue("countryCode",QString("%1%2%3").arg((uint8_t)g_eeGeneral.countryCode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.imperial, 2, 16, QChar('0')).arg(g_eeGeneral.ttsLanguage));
settings.endGroup();
settings.endGroup();
g.profile[profile_id].trainerCalib( calib );
g.profile[profile_id].vBatCalib( g_eeGeneral.vBatCalib );
g.profile[profile_id].currentCalib( g_eeGeneral.currentCalib );
g.profile[profile_id].vBatWarn( g_eeGeneral.vBatWarn );
g.profile[profile_id].ppmMultiplier( g_eeGeneral.PPM_Multiplier );
g.profile[profile_id].gsStickMode( g_eeGeneral.stickMode );
g.profile[profile_id].display( QString("%1%2%3").arg((g_eeGeneral.optrexDisplay ? 1:0), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.contrast, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.backlightBright, 2, 16, QChar('0')) );
g.profile[profile_id].beeper( QString("%1%2").arg(((uint8_t)g_eeGeneral.beeperMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.beeperLength, 2, 16, QChar('0')));
g.profile[profile_id].haptic( QString("%1%2%3").arg(((uint8_t)g_eeGeneral.hapticMode), 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticStrength, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.hapticLength, 2, 16, QChar('0')));
g.profile[profile_id].speaker( QString("%1%2%3").arg((uint8_t)g_eeGeneral.speakerMode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerPitch, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.speakerVolume, 2, 16, QChar('0')));
g.profile[profile_id].countryCode( QString("%1%2%3").arg((uint8_t)g_eeGeneral.countryCode, 2, 16, QChar('0')).arg((uint8_t)g_eeGeneral.imperial, 2, 16, QChar('0')).arg(g_eeGeneral.ttsLanguage));
QMessageBox::information(this, "Companion", tr("Calibration and HW parameters saved."));
}
}
+2 -2
View File
@@ -1,4 +1,5 @@
#include <QtGui>
#include "appdata.h"
#include "helpers.h"
#include "simulatordialog.h"
@@ -875,8 +876,7 @@ QString getCenterBeep(ModelData * g_model)
QString getTheme()
{
QSettings settings;
int theme_set = settings.value("theme", 1).toInt();
int theme_set = g.theme();
QString Theme;
switch(theme_set) {
case 0:
+5 -7
View File
@@ -1,4 +1,5 @@
#include "logsdialog.h"
#include "appdata.h"
#include "ui_logsdialog.h"
#include "qcustomplot.h"
#include "helpers.h"
@@ -40,8 +41,7 @@ logsDialog::logsDialog(QWidget *parent) :
ui->customPlot->legend->setSelectedFont(legendFont);
ui->customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items
ui->customPlot->legend->setVisible(false);
QSettings settings;
QString Path=settings.value("gePath", "").toString();
QString Path=g.gePath();
if (Path.isEmpty() || !QFile(Path).exists()) {
ui->mapsButton->hide();
}
@@ -204,8 +204,7 @@ void logsDialog::on_mapsButton_clicked() {
,F_F,F_F,F_F,F_F,I_F,I_F,I_F,I_F\
,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F,I_F};
QSettings settings;
QString gePath=settings.value("gePath", "").toString();
QString gePath=g.gePath();
if (gePath.isEmpty() || !QFile(gePath).exists()) {
ui->FieldsTW->setDisabled(false);
ui->logTable->setDisabled(false);
@@ -587,10 +586,9 @@ void logsDialog::moveLegend()
void logsDialog::on_fileOpen_BT_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), settings.value("lastLogDir").toString());
QString fileName = QFileDialog::getOpenFileName(this,tr("Select your log file"), g.logDir());
if (!fileName.isEmpty()) {
settings.setValue("lastLogDir", fileName);
g.logDir( fileName );
ui->FileName_LE->setText(fileName);
if (cvsFileParse()) {
ui->FieldsTW->clear();
+102 -197
View File
@@ -49,7 +49,6 @@
#include "avroutputdialog.h"
#include "comparedialog.h"
#include "logsdialog.h"
#include "preferencesdialog.h"
#include "apppreferencesdialog.h"
#include "fwpreferencesdialog.h"
#include "flashinterface.h"
@@ -63,6 +62,7 @@
#include "hexinterface.h"
#include "warnings.h"
#include "helpers.h"
#include "appdata.h"
#include "firmwares/opentx/opentxinterface.h" // TODO get rid of this include
#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2"
@@ -90,23 +90,17 @@ MainWindow::MainWindow():
mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setCentralWidget(mdiArea);
connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),
this, SLOT(updateMenus()));
connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(updateMenus()));
windowMapper = new QSignalMapper(this);
connect(windowMapper, SIGNAL(mapped(QWidget*)),
this, SLOT(setActiveSubWindow(QWidget*)));
connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*)));
MaxRecentFiles=MAX_RECENT;
QSettings settings;
restoreGeometry(settings.value("mainWindowGeometry").toByteArray());
createActions();
createMenus();
createToolBars();
createStatusBar();
updateMenus();
readSettings();
restoreState(g.mainWinState());
setUnifiedTitleAndToolBarOnMac(true);
this->setWindowIcon(QIcon(":/icon.png"));
@@ -116,7 +110,7 @@ MainWindow::MainWindow():
// give time to the splash to disappear and main window to open before starting updates
int updateDelay = 1000;
bool showSplash = settings.value("show_splash", true).toBool();
bool showSplash = g.showSplash();
if (showSplash) {
updateDelay += (SPLASH_TIME*1000);
}
@@ -169,8 +163,7 @@ MainWindow::MainWindow():
void MainWindow::displayWarnings()
{
QSettings settings;
int warnId=settings.value("warningId", 0 ).toInt();
int warnId=g.warningId();
if (warnId<WARNING_ID && warnId!=0) {
int res=0;
if (WARNING_LEVEL>0) {
@@ -181,10 +174,10 @@ void MainWindow::displayWarnings()
res = QMessageBox::question(this, "Companion",tr("Display previous message again at startup ?"),QMessageBox::Yes | QMessageBox::No);
}
if (res == QMessageBox::No) {
settings.setValue("warningId", WARNING_ID);
g.warningId(WARNING_ID);
}
} else if (warnId==0) {
settings.setValue("warningId", WARNING_ID);
g.warningId(WARNING_ID);
}
}
@@ -203,12 +196,11 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId)
showcheckForUpdatesResult = ignoreSettings;
check1done = true;
check2done = true;
QSettings settings;
fwToUpdate = fwId;
QString stamp = GetFirmware(fwToUpdate)->stamp;
if (!stamp.isEmpty()) {
if (checkFW || ignoreSettings) {
if (g.autoCheckFw() || ignoreSettings) {
check1done=false;
manager1 = new QNetworkAccessManager(this);
connect(manager1, SIGNAL(finished(QNetworkReply*)), this, SLOT(reply1Finished(QNetworkReply*)));
@@ -219,7 +211,7 @@ void MainWindow::checkForUpdates(bool ignoreSettings, QString & fwId)
}
}
if (checkCompanion || ignoreSettings) {
if (g.autoCheckApp() || ignoreSettings) {
check2done = false;
manager2 = new QNetworkAccessManager(this);
connect(manager2, SIGNAL(finished(QNetworkReply*)),this, SLOT(checkForUpdateFinished(QNetworkReply*)));
@@ -269,16 +261,14 @@ void MainWindow::checkForUpdateFinished(QNetworkReply * reply)
"Would you like to download it?").arg(version) ,
QMessageBox::Yes | QMessageBox::No);
QSettings settings;
if (ret == QMessageBox::Yes) {
#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"), g.updatesDir() + QString(C9X_INSTALLER).arg(version));
#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"), g.updatesDir() + QString(C9X_INSTALLER).arg(version), tr("Executable (*.exe)"));
#endif
if (!fileName.isEmpty()) {
settings.setValue("lastUpdatesDir", QFileInfo(fileName).dir().absolutePath());
g.updatesDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, QString(OPENTX_COMPANION_DOWNLOADS C9X_INSTALLER).arg(version), fileName);
installer_fileName = fileName;
connect(dd, SIGNAL(accepted()), this, SLOT(updateDownloaded()));
@@ -311,11 +301,10 @@ void MainWindow::updateDownloaded()
void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmwareId)
{
QString url, ext, cpuid;
QSettings settings;
url = firmware->getUrl(firmwareId);
cpuid=settings.value("cpuid","").toString();
cpuid=g.cpuId();
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"), g.flashDir() + "/" + firmwareId + ext);
if (!fileName.isEmpty()) {
downloadedFW = firmwareId;
needRename=true;
@@ -324,7 +313,7 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw
url.append("&cpuid=");
url.append(cpuid);
}
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
g.flashDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, url, fileName);
connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted()));
dd->exec();
@@ -334,8 +323,6 @@ void MainWindow::downloadLatestFW(FirmwareInfo * firmware, const QString & firmw
void MainWindow::reply1Accepted()
{
QString errormsg;
QSettings settings;
settings.beginGroup("FwRevisions");
if (downloadedFWFilename.isEmpty()) {
if (!(downloadedFW.isEmpty())) {
QFile file(downloadedFW);
@@ -370,12 +357,11 @@ void MainWindow::reply1Accepted()
}
file.close();
QMessageBox::critical(this, tr("Error"), errormsg);
settings.endGroup();
return;
}
file.close();
currentFWrev = currentFWrev_temp;
settings.setValue(downloadedFW, currentFWrev);
g.fwRev.set(downloadedFW, currentFWrev);
}
} else {
QFile file(downloadedFWFilename);
@@ -410,7 +396,6 @@ void MainWindow::reply1Accepted()
}
file.close();
QMessageBox::critical(this, tr("Error"), errormsg);
settings.endGroup();
return;
}
file.close();
@@ -419,7 +404,7 @@ void MainWindow::reply1Accepted()
int pos=rev.lastIndexOf("-r");
if (pos>0) {
currentFWrev=rev.mid(pos+2).toInt();
if (settings.value("rename_firmware_files", false).toBool() && needRename) {
if (g.profile[g.id()].renameFwFiles() && needRename) {
QFileInfo fi(downloadedFWFilename);
QString path=fi.path()+QDir::separator ();
path.append(fi.completeBaseName());
@@ -431,8 +416,8 @@ void MainWindow::reply1Accepted()
qd.rename(downloadedFWFilename,path);
downloadedFWFilename=path;
}
settings.setValue(downloadedFW, currentFWrev);
if (settings.value("burnFirmware", true).toBool()) {
g.fwRev.set(downloadedFW, currentFWrev);
if (g.profile[g.id()].burnFirmware()) {
int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the transmitter now ?"), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
writeFlash(downloadedFWFilename);
@@ -440,7 +425,6 @@ void MainWindow::reply1Accepted()
}
}
}
settings.endGroup();
}
void MainWindow::reply1Finished(QNetworkReply * reply)
@@ -456,8 +440,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
// TODO delete downloadDialog_forWait?
}
QSettings settings;
cpuid=settings.value("cpuid","").toString();
cpuid=g.cpuId();
QByteArray qba = reply->readAll();
int i = qba.indexOf("SVN_VERS");
int warning = qba.indexOf("WARNING");
@@ -471,17 +454,13 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
if(!cres) {
QMessageBox::warning(this, "Companion", tr("Unable to check for updates."));
int server = settings.value("fwserver",0).toInt();
server++;
settings.setValue("fwserver",server);
g.fwServerFails(g.fwServerFails()+1);
return;
}
if(rev>0) {
NewFwRev=rev;
settings.beginGroup("FwRevisions");
OldFwRev = settings.value(fwToUpdate, 0).toInt();
settings.endGroup();
OldFwRev = g.fwRev.get(fwToUpdate);
QMessageBox msgBox;
QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout* layout = (QGridLayout*)msgBox.layout();
@@ -552,9 +531,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
if (ignore) {
int res = QMessageBox::question(this, "Companion",tr("Ignore this version (r%1)?").arg(rev), QMessageBox::Yes | QMessageBox::No);
if (res==QMessageBox::Yes) {
settings.beginGroup("FwRevisions");
settings.setValue(fwToUpdate, NewFwRev);
settings.endGroup();
g.fwRev.set(fwToUpdate, NewFwRev);
}
} else if (download == true) {
if (warning>0) {
@@ -571,12 +548,12 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
QString url = GetFirmware(fwToUpdate)->getUrl(fwToUpdate);
QString ext = url.mid(url.lastIndexOf("."));
needRename=false;
bool addversion=settings.value("rename_firmware_files", false).toBool();
bool addversion=g.profile[g.id()].renameFwFiles();
QString fileName;
if (addversion) {
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + newrev + ext);
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + fwToUpdate + newrev + ext);
} else {
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastFlashDir").toString() + "/" + fwToUpdate + ext);
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + fwToUpdate + ext);
}
if (!fileName.isEmpty()) {
if (!cpuid.isEmpty()) {
@@ -584,7 +561,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
url.append(cpuid);
}
downloadedFWFilename = fileName;
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
g.flashDir(QFileInfo(fileName).dir().absolutePath());
downloadDialog * dd = new downloadDialog(this, url, fileName);
currentFWrev_temp = NewFwRev;
connect(dd, SIGNAL(accepted()), this, SLOT(reply1Accepted()));
@@ -598,9 +575,7 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
} else {
if(check1done && check2done) {
QMessageBox::warning(this, "Companion", tr("Unable to check for updates."));
int server = settings.value("fwserver",0).toInt();
server++;
settings.setValue("fwserver",server);
g.fwServerFails(g.fwServerFails()+1);
return;
}
}
@@ -608,9 +583,8 @@ void MainWindow::reply1Finished(QNetworkReply * reply)
void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("mainWindowGeometry", saveGeometry());
settings.setValue("mainWindowState", saveState());
g.mainWinGeo(saveGeometry());
g.mainWinState(saveState());
mdiArea->closeAllSubWindows();
if (mdiArea->currentSubWindow()) {
event->ignore();
@@ -622,8 +596,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::setLanguage(QString langString)
{
QSettings settings;
settings.setValue("locale", langString );
g.locale( langString );
QMessageBox msgBox;
msgBox.setText(tr("The selected language will be used the next time you start Companion."));
@@ -634,8 +607,7 @@ void MainWindow::setLanguage(QString langString)
void MainWindow::setTheme(int index)
{
QSettings settings;
settings.setValue("theme", index );
g.theme( index );
QMessageBox msgBox;
msgBox.setText(tr("The new theme will be loaded the next time you start Companion."));
@@ -646,8 +618,7 @@ void MainWindow::setTheme(int index)
void MainWindow::setIconThemeSize(int index)
{
QSettings settings;
settings.setValue("icon_size", index );
g.iconSize( index );
QMessageBox msgBox;
msgBox.setText(tr("The icon size will be used the next time you start Companion."));
@@ -671,10 +642,9 @@ void MainWindow::openDocURL()
void MainWindow::openFile()
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Models and Settings file"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.eepromDir(), tr(EEPROM_FILES_FILTER));
if (!fileName.isEmpty()) {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
g.eepromDir(QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) {
@@ -704,11 +674,9 @@ void MainWindow::saveAs()
void MainWindow::openRecentFile()
{
QSettings settings;
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
QString fileName=action->data().toString();
// settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) {
@@ -724,42 +692,17 @@ void MainWindow::openRecentFile()
}
}
void MainWindow::loadProfile()
void MainWindow::loadProfile() //TODO Load all variables - Also HW!
{
QSettings settings;
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
// Set the new profile number
int profnum=action->data().toInt();
QSettings settings;
settings.setValue("profileId",profnum);
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profnum);
settings.beginGroup(profile);
QString profileName=settings.value("Name", "").toString();
int chord=settings.value("default_channel_order", 0).toInt();
int defmod=settings.value("default_mode", 0).toInt();
bool burnfw=settings.value("burnFirmware", false).toBool();
QString sdPath=settings.value("sdPath", ".").toString();
bool renfw=settings.value("rename_firmware_files", false).toBool();
QString SplashFileName=settings.value("SplashFileName","").toString();
QString SplashImage=settings.value("SplashImage", "").toString();
QString firmware_id=settings.value("firmware", default_firmware_variant.id).toString();
firmware_id.replace("open9x","opentx");
firmware_id.replace("x9da","taranis");
settings.setValue("firmware", firmware_id);
settings.endGroup();
settings.endGroup();
settings.setValue("Name", profileName );
settings.setValue("default_channel_order", chord);
settings.setValue("default_mode", defmod);
settings.setValue("burnFirmware", burnfw);
settings.setValue("rename_firmware_files", renfw);
settings.setValue("sdPath", sdPath);
settings.setValue("SplashFileName", SplashFileName);
settings.setValue("SplashImage", SplashImage);
settings.setValue("firmware", firmware_id);
current_firmware_variant = GetFirmwareVariant(firmware_id);
g.id( profnum );
// TODO Get rid of this global variable - The profile.firmware is the real source
current_firmware_variant = GetFirmwareVariant(g.profile[g.id()].firmware());
foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
@@ -1107,20 +1050,19 @@ void MainWindow::readEeprom()
void MainWindow::writeFileToEeprom()
{
QSettings settings;
QString fileName;
bool backup = false;
burnDialog *cd = new burnDialog(this, 1, &fileName, &backup);
cd->exec();
if (!fileName.isEmpty()) {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
g.eepromDir(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);
if (ret != QMessageBox::Yes) return;
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);
if (ret != QMessageBox::Yes) return;
bool backupEnable = settings.value("backupEnable", true).toBool();
QString backupPath = settings.value("backupPath", "").toString();
bool backupEnable = g.enableBackup();
QString backupPath = g.backupDir();
if (!backupPath.isEmpty()) {
if (!QDir(backupPath).exists()) {
if (backupEnable) {
@@ -1361,9 +1303,8 @@ bool MainWindow::convertEEPROM(QString backupFile, QString restoreFile, QString
void MainWindow::writeFlash(QString fileToFlash)
{
QSettings settings;
QString fileName;
bool backup = settings.value("backupOnFlash", false).toBool();
bool backup = g.backupOnFlash();
if(!fileToFlash.isEmpty())
fileName = fileToFlash;
burnDialog *cd = new burnDialog(this, 2, &fileName, &backup);
@@ -1371,12 +1312,12 @@ void MainWindow::writeFlash(QString fileToFlash)
if (IS_TARANIS(GetEepromInterface()->getBoard()))
backup=false;
if (!fileName.isEmpty()) {
settings.setValue("backupOnFlash", backup);
g.backupOnFlash(backup);
if (backup) {
QString tempDir = QDir::tempPath();
QString backupFile = tempDir + "/backup.bin";
bool backupEnable=settings.value("backupEnable", true).toBool();
QString backupPath=settings.value("backupPath", "").toString();
bool backupEnable=g.enableBackup();
QString backupPath=g.backupDir();
if (!backupPath.isEmpty() && !IS_TARANIS(GetEepromInterface()->getBoard())) {
if (!QDir(backupPath).exists()) {
if (backupEnable) {
@@ -1430,8 +1371,8 @@ void MainWindow::writeFlash(QString fileToFlash)
}
}
else {
bool backupEnable=settings.value("backupEnable", true).toBool();
QString backupPath=settings.value("backupPath", "").toString();
bool backupEnable=g.enableBackup();
QString backupPath=g.backupDir();
if (!QDir(backupPath).exists()) {
if (backupEnable) {
QMessageBox::warning(this, tr("Backup is impossible"), tr("The backup dir set in preferences does not exist"));
@@ -1460,8 +1401,7 @@ void MainWindow::writeFlash(QString fileToFlash)
void MainWindow::readEepromToFile()
{
QSettings settings;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), settings.value("lastDir").toString(), tr(EXTERNAL_EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getSaveFileName(this, tr("Save transmitter Models and Settings to File"), g.eepromDir(), tr(EXTERNAL_EEPROM_FILES_FILTER));
if (!fileName.isEmpty()) {
EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_TARANIS(eepromInterface->getBoard())) {
@@ -1480,7 +1420,7 @@ void MainWindow::readEepromToFile()
}
}
else {
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
g.eepromDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveEEpromCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, tr("Read Models and Settings From Tx"));
ad->setWindowIcon(CompanionIcon("read_eeprom.png"));
@@ -1492,14 +1432,13 @@ void MainWindow::readEepromToFile()
void MainWindow::readFlash()
{
QSettings settings;
QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), settings.value("lastFlashDir").toString(),tr(FLASH_FILES_FILTER));
QString fileName = QFileDialog::getSaveFileName(this,tr("Read Tx Firmware to File"), g.flashDir(),tr(FLASH_FILES_FILTER));
if (!fileName.isEmpty()) {
QFile file(fileName);
if (file.exists()) {
file.remove();
}
settings.setValue("lastFlashDir",QFileInfo(fileName).dir().absolutePath());
g.flashDir(QFileInfo(fileName).dir().absolutePath());
QStringList str = GetReceiveFlashCommand(fileName);
avrOutputDialog *ad = new avrOutputDialog(this, GetAvrdudeLocation(), str, "Read Firmware From Tx");
ad->setWindowIcon(CompanionIcon("read_flash.png"));
@@ -1579,8 +1518,7 @@ void MainWindow::updateMenus()
updateIconSizeActions();
updateIconThemeActions();
QSettings settings;
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg(settings.value("profileId").toString()));
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( g.profile[g.id()].name() ));
}
MdiChild *MainWindow::createMdiChild()
@@ -1631,7 +1569,7 @@ void MainWindow::createActions()
separatorAct = new QAction(this);
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]->setVisible(false);
connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
@@ -1729,7 +1667,7 @@ void MainWindow::createMenus()
fileMenu->addAction(saveAsAct);
fileMenu->addMenu(recentFileMenu);
recentFileMenu->setIcon(CompanionIcon("recentdocument.png"));
for (int i=0; i<MaxRecentFiles; ++i)
for (int i=0; i<MAX_RECENT; ++i)
recentFileMenu->addAction(recentFileActs[i]);
fileMenu->addSeparator();
fileMenu->addAction(logsAct);
@@ -1811,7 +1749,7 @@ void MainWindow::createMenus()
QMenu *MainWindow::createRecentFileMenu()
{
QMenu *recentFileMenu = new QMenu(this);
for ( int i = 0; i < MaxRecentFiles; ++i)
for ( int i = 0; i < MAX_RECENT; ++i)
recentFileMenu->addAction(recentFileActs[i]);
return recentFileMenu;
}
@@ -1823,8 +1761,8 @@ QMenu *MainWindow::createProfilesMenu()
for ( i = 0; i < MAX_PROFILES; ++i) {
profilesMenu->addAction(profileActs[i]);
}
if ( i>0 )
profilesMenu->addSeparator();
profilesMenu->addSeparator();
profilesMenu->addAction(createProfileAct);
profilesMenu->setIcon(CompanionIcon("profiles.png"));
return profilesMenu;
@@ -1832,10 +1770,8 @@ QMenu *MainWindow::createProfilesMenu()
void MainWindow::createToolBars()
{
QSettings settings;
int icon_size=settings.value("icon_size",2 ).toInt();
QSize size;
switch(icon_size) {
switch(g.iconSize()) {
case 0:
size=QSize(16,16);
break;
@@ -1920,20 +1856,6 @@ void MainWindow::createStatusBar()
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()
{
if (QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
@@ -1962,27 +1884,31 @@ void MainWindow::setActiveSubWindow(QWidget *window)
void MainWindow::updateRecentFileActions()
{
int i,j, numRecentFiles;
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
int i, numRecentFiles;
numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
// Hide all document slots
for ( i=0 ; i < g.historySize(); i++)
recentFileActs[i]->setVisible(false);
// Fill slots with content and unhide them
QStringList files = g.recentFiles();
numRecentFiles = qMin(files.size(), g.historySize());
for ( i = 0; i < numRecentFiles; ++i) {
QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
recentFileActs[i]->setText(text);
recentFileActs[i]->setData(files[i]);
recentFileActs[i]->setVisible(true);
for ( i = 0; i < numRecentFiles; i++) {
QString text = strippedName(files[i]);
if (!text.trimmed().isEmpty())
{
recentFileActs[i]->setText(text);
recentFileActs[i]->setData(files[i]);
recentFileActs[i]->setVisible(true);
}
}
for ( j = numRecentFiles; j < MaxRecentFiles; ++j)
recentFileActs[j]->setVisible(false);
}
void MainWindow::updateIconSizeActions()
{
QSettings settings;
int size = settings.value("icon_size","0").toInt();
switch (size){
switch (g.iconSize())
{
case 0: smallIconAct->setChecked(true); break;
case 1: normalIconAct->setChecked(true); break;
case 2: bigIconAct->setChecked(true); break;
@@ -1992,8 +1918,7 @@ void MainWindow::updateIconSizeActions()
void MainWindow::updateLanguageActions()
{
QSettings settings;
QString langId = settings.value("locale","").toString();
QString langId = g.locale();
if (langId=="")
sysLangAct->setChecked(true);
@@ -2023,9 +1948,8 @@ void MainWindow::updateLanguageActions()
void MainWindow::updateIconThemeActions()
{
QSettings settings;
int size = settings.value("theme","1").toInt();
switch (size){
switch (g.theme())
{
case 0: classicThemeAct->setChecked(true); break;
case 1: yericoThemeAct->setChecked(true); break;
case 2: monoWhiteAct->setChecked(true); break;
@@ -2036,52 +1960,34 @@ void MainWindow::updateIconThemeActions()
void MainWindow::updateProfilesActions()
{
int i;
QSettings settings;
int activeProfile = settings.value("profileId").toInt();
settings.beginGroup("Profiles");
for (i=0; i<MAX_PROFILES; i++) {
QString profile=QString("profile%1").arg(i+1);
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
if (!name.isEmpty()) {
QString text = tr("&%1 %2").arg(i + 1).arg(name);
for (int i=0; i<MAX_PROFILES; i++)
{
if (!g.profile[i].name().isEmpty())
{
QString text = tr("&%1: %2").arg(i).arg(g.profile[i].name());
profileActs[i]->setText(text);
profileActs[i]->setData(i+1);
profileActs[i]->setData(i);
profileActs[i]->setVisible(true);
if ((i+1) == activeProfile)
if (i == g.id())
profileActs[i]->setChecked(true);
}
else {
else
{
profileActs[i]->setVisible(false);
}
settings.endGroup();
}
}
void MainWindow::createProfile()
{
int firstFreeIndex = 0;
QSettings settings;
settings.beginGroup("Profiles");
for (int i=0; firstFreeIndex ==0 && i<MAX_PROFILES; i++) {
QString profile=QString("profile%1").arg(i+1);
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
if (name.isEmpty())
firstFreeIndex = i+1;
settings.endGroup();
}
settings.endGroup();
if (firstFreeIndex == 0) // Could not find free index
{ int i;
for (i=0; i<MAX_PROFILES && !g.profile[i].name().isEmpty(); i++)
;
if (i==MAX_PROFILES) //Failed to find free slot
return;
settings.beginGroup("Profiles");
settings.beginGroup(QString("profile%1").arg(firstFreeIndex));
settings.setValue("Name",QString("profile%1").arg(firstFreeIndex));
settings.endGroup();
settings.endGroup();
// Create profile name and force a flush to file
g.profile[i].name( QString("profile%1").arg(i));
g.profile[i].flush();
updateMenus();
}
@@ -2183,8 +2089,7 @@ void MainWindow::dropEvent(QDropEvent *event)
QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty())
return;
QSettings settings;
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
g.eepromDir(QFileInfo(fileName).dir().absolutePath());
QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) {
+2 -6
View File
@@ -48,9 +48,9 @@
#include "downloaddialog.h"
#include "eeprominterface.h"
#define MAX_RECENT 15
#define MAX_PROFILES 10
#define SPLASH_TIME 5
#define MAX_RECENT 10
#define MAX_PROFILES 15
class MdiChild;
QT_BEGIN_NAMESPACE
@@ -165,7 +165,6 @@ private:
void createMenus();
void createToolBars();
void createStatusBar();
void readSettings();
void updateRecentFileActions();
void updateProfilesActions();
void updateIconSizeActions();
@@ -201,11 +200,8 @@ private:
QString downloadedFWFilename;
downloadDialog * downloadDialog_forWait;
bool checkCompanion;
bool checkFW;
bool needRename;
bool showcheckForUpdatesResult;
int MaxRecentFiles;
int currentFWrev;
int currentFWrev_temp;
int NewFwRev;
+17 -27
View File
@@ -51,6 +51,7 @@
#include "printdialog.h"
#include "burndialog.h"
#include "helpers.h"
#include "appdata.h"
#include <QFileInfo>
#if defined WIN32 || !defined __GNUC__
@@ -160,8 +161,7 @@ void MdiChild::OpenEditWindow(bool wizard=false)
}
if (isNew && !wizard) {
int ret;
QSettings settings;
bool wizardEnable=settings.value("wizardEnable", true).toBool();
bool wizardEnable=g.enableWizard();
if (wizardEnable) {
ret = QMessageBox::question(this, tr("Companion"), tr("Do you want to use model wizard? "), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
@@ -170,7 +170,7 @@ void MdiChild::OpenEditWindow(bool wizard=false)
qSleep(500);
ret = QMessageBox::question(this, tr("Companion"), tr("Ask this question again ? "), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No) {
settings.setValue("wizardEnable", false);
g.enableWizard( false );
}
}
}
@@ -327,34 +327,33 @@ bool MdiChild::save()
bool MdiChild::saveAs(bool isNew)
{
QSettings settings;
QString fileName;
if (GetEepromInterface()->getBoard() == BOARD_SKY9X) {
curFile.replace(".eepe", ".bin");
QFileInfo fi(curFile);
#ifdef __APPLE__
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName());
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
#else
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(BIN_FILES_FILTER));
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER));
#endif
}
else {
QFileInfo fi(curFile);
#ifdef __APPLE__
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName());
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
#else
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), settings.value("lastDir").toString() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER));
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER));
#endif
}
if (fileName.isEmpty())
return false;
if (fileName.contains("rev4a")) {
settings.setValue("rev4asupport", 1);
g.rev4aSupport( true );
}
if (fileName.contains("norev4a")) {
settings.setValue("rev4asupport", 0);
g.rev4aSupport( false );
}
settings.setValue("lastDir", QFileInfo(fileName).dir().absolutePath());
g.eepromDir( QFileInfo(fileName).dir().absolutePath() );
if (isNew)
return saveFile(fileName);
else
@@ -471,15 +470,14 @@ void MdiChild::setCurrentFile(const QString &fileName)
fileChanged = false;
setWindowModified(false);
updateTitle();
QSettings settings;
int MaxRecentFiles =settings.value("history_size",10).toInt();
QStringList files = settings.value("recentFileList").toStringList();
int MaxRecentFiles = g.historySize();
QStringList files = g.recentFiles();
files.removeAll(fileName);
files.prepend(fileName);
while (files.size() > MaxRecentFiles)
files.removeLast();
settings.setValue("recentFileList", files);
g.recentFiles( files );
}
QString MdiChild::strippedName(const QString &fullFileName)
@@ -489,9 +487,8 @@ QString MdiChild::strippedName(const QString &fullFileName)
void MdiChild::writeEeprom() // write to Tx
{
QSettings settings;
bool backupEnable=settings.value("backupEnable", true).toBool();
QString backupPath=settings.value("backupPath", "").toString();
bool backupEnable=g.enableBackup();
QString backupPath=g.backupDir();
if (!backupPath.isEmpty()) {
if (!QDir(backupPath).exists()) {
if (backupEnable) {
@@ -502,13 +499,7 @@ void MdiChild::writeEeprom() // write to Tx
} else {
backupEnable=false;
}
int profileid=settings.value("profileId", 1).toInt();
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(profileid);
settings.beginGroup(profile);
QString stickCal=settings.value("StickPotCalib","").toString();
settings.endGroup();
settings.endGroup();
QString stickCal=g.profile[g.id()].stickPotCalib();
burnConfigDialog bcd;
QString tempDir = QDir::tempPath();
QString tempFile = tempDir + "/temp.bin";
@@ -658,8 +649,7 @@ void MdiChild::setEEpromAvail(int eavail)
bool MdiChild::loadBackup()
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastDir").toString(),tr(EEPROM_FILES_FILTER));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), g.eepromDir(),tr(EEPROM_FILES_FILTER));
if (fileName.isEmpty())
return false;
QFile file(fileName);
+3 -4
View File
@@ -6,6 +6,7 @@
#include <QCheckBox>
#include <QDoubleSpinBox>
#include "helpers.h"
#include "appdata.h"
RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam):
QComboBox(parent),
@@ -74,8 +75,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model,
}
}
QSettings settings;
QString path = settings.value("sdPath", ".").toString();
QString path = g.profile[g.id()].sdPath();
path.append("/SOUNDS/");
QString lang = generalSettings.ttsLanguage;
if (lang.isEmpty())
@@ -225,8 +225,7 @@ void CustomFunctionsPanel::playMusic()
QPushButton *playButton = qobject_cast<QPushButton*>(sender());
int index=playButton->objectName().mid(5,2).toInt();
QString function=playButton->objectName().left(4);
QSettings settings;
QString path = settings.value("sdPath", ".").toString();
QString path = g.profile[g.id()].sdPath();
QDir qd(path);
QString track;
if (qd.exists()) {
+3 -4
View File
@@ -11,6 +11,7 @@
#include "customswitches.h"
#include "customfunctions.h"
#include "telemetry.h"
#include "appdata.h"
#include <QScrollArea>
ModelEdit::ModelEdit(RadioData & radioData, int modelId, bool openWizard, bool isNew, QWidget *parent) :
@@ -21,8 +22,7 @@ ModelEdit::ModelEdit(RadioData & radioData, int modelId, bool openWizard, bool i
generalSettings(radioData.generalSettings)
{
ui->setupUi(this);
QSettings settings;
restoreGeometry(settings.value("modelEditGeometry").toByteArray());
restoreGeometry(g.modelEditGeo());
ui->pushButton->setIcon(CompanionIcon("simulate.png"));
addTab(new Setup(this, model), tr("Setup"));
addTab(new HeliPanel(this, model), tr("Heli"));
@@ -45,8 +45,7 @@ ModelEdit::~ModelEdit()
void ModelEdit::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("modelEditGeometry", saveGeometry());
g.modelEditGeo( saveGeometry() );
}
class VerticalScrollArea : public QScrollArea
+3 -4
View File
@@ -3,6 +3,7 @@
#include "ui_setup_timer.h"
#include "ui_setup_module.h"
#include "helpers.h"
#include "appdata.h"
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer):
ModelPanel(parent, model),
@@ -347,8 +348,7 @@ Setup::Setup(QWidget *parent, ModelData & model):
if (GetEepromInterface()->getCapability(ModelImage)) {
QStringList items;
items.append("");
QSettings settings;
QString path = settings.value("sdPath", ".").toString();
QString path = g.profile[g.id()].sdPath();
path.append("/BMP/");
QDir qd(path);
int vml = GetEepromInterface()->getCapability(VoicesMaxLength)+4;
@@ -515,8 +515,7 @@ void Setup::on_image_currentIndexChanged(int index)
{
if (!lock) {
strncpy(model.bitmap, ui->image->currentText().toAscii(), GetEepromInterface()->getCapability(VoicesMaxLength));
QSettings settings;
QString path=settings.value("sdPath", ".").toString();
QString path=g.profile[g.id()].sdPath();
path.append("/BMP/");
QDir qd(path);
if (qd.exists()) {
+2 -2
View File
@@ -3,6 +3,7 @@
#include "ui_telemetry_analog.h"
#include "ui_telemetry_customscreen.h"
#include "helpers.h"
#include "appdata.h"
TelemetryAnalog::TelemetryAnalog(QWidget *parent, FrSkyChannelData & analog):
QWidget(parent),
@@ -456,8 +457,7 @@ TelemetryPanel::~TelemetryPanel()
void TelemetryPanel::setup()
{
QSettings settings;
QString firmware_id = settings.value("firmware", default_firmware_variant.id).toString();
QString firmware_id = g.profile[g.id()].firmware();
lock=true;
-827
View File
@@ -1,827 +0,0 @@
#include "preferencesdialog.h"
#include "ui_preferencesdialog.h"
#include "mainwindow.h"
#include "eeprominterface.h"
#include "splashlibrary.h"
#include "helpers.h"
#ifdef JOYSTICKS
#include "joystick.h"
#include "joystickdialog.h"
#endif
#include <QDesktopServices>
#include <QtGui>
preferencesDialog::preferencesDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::preferencesDialog),
updateLock(false)
{
ui->setupUi(this);
setWindowIcon(CompanionIcon("preferences.png"));
ui->splashLibraryButton->setIcon(CompanionIcon("library.png"));
ui->clearImageButton->setIcon(CompanionIcon("clear.png"));
QCheckBox * OptionCheckBox[]= {
ui->optionCheckBox_1, ui->optionCheckBox_2, ui->optionCheckBox_3, ui->optionCheckBox_4, ui->optionCheckBox_5, ui->optionCheckBox_6, ui->optionCheckBox_7,
ui->optionCheckBox_8, ui->optionCheckBox_9, ui->optionCheckBox_10, ui->optionCheckBox_11, ui->optionCheckBox_12, ui->optionCheckBox_13, ui->optionCheckBox_14,
ui->optionCheckBox_15,ui->optionCheckBox_16, ui->optionCheckBox_17, ui->optionCheckBox_18, ui->optionCheckBox_19, ui->optionCheckBox_20, ui->optionCheckBox_21,
ui->optionCheckBox_22, ui->optionCheckBox_23, ui->optionCheckBox_24, ui->optionCheckBox_25, ui->optionCheckBox_26, ui->optionCheckBox_27, ui->optionCheckBox_28,
ui->optionCheckBox_29, ui->optionCheckBox_30, ui->optionCheckBox_31, ui->optionCheckBox_32, ui->optionCheckBox_33, ui->optionCheckBox_34, ui->optionCheckBox_35,
ui->optionCheckBox_36, ui->optionCheckBox_37, ui->optionCheckBox_38, ui->optionCheckBox_39, ui->optionCheckBox_40, ui->optionCheckBox_41, ui->optionCheckBox_42,
NULL };
voice=NULL;
connect(ui->langCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged()));
connect(ui->voiceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged()));
for (int i=0; OptionCheckBox[i]; i++) {
optionsCheckBoxes.push_back(OptionCheckBox[i]);
connect(OptionCheckBox[i], SIGNAL(toggled(bool)), this, SLOT(firmwareOptionChanged(bool)));
}
initSettings();
connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged()));
connect(this, SIGNAL(accepted()), this, SLOT(writeValues()));
#ifndef JOYSTICKS
ui->joystickCB->hide();
ui->joystickCB->setDisabled(true);
ui->joystickcalButton->hide();
ui->joystickChkB->hide();
ui->label_11->hide();
#endif
resize(0,0);
}
preferencesDialog::~preferencesDialog()
{
delete ui;
}
void preferencesDialog::baseFirmwareChanged()
{
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
voice=NULL;
foreach(FirmwareInfo * firmware, firmwares) {
if (firmware->id == selected_firmware) {
if (firmware->voice) {
ui->voiceLabel->show();
ui->voiceCombo->show();
ui->voice_dnld->show();
ui->sdPathButton->show();
ui->sdPath->show();
ui->sdPathLabel->show();
ui->voiceLabel->setEnabled(true);
ui->voiceCombo->setEnabled(true);
ui->voice_dnld->setEnabled(true);
ui->sdPathButton->setEnabled(true);
ui->sdPath->setEnabled(true);
ui->ge_label->show();
ui->ge_lineedit->show();
ui->ge_pathButton->show();
} else {
ui->voiceLabel->hide();
ui->voiceCombo->hide();
ui->voice_dnld->hide();
ui->sdPathButton->hide();
ui->sdPath->hide();
ui->sdPathLabel->hide();
ui->ge_label->hide();
ui->ge_lineedit->hide();
ui->ge_pathButton->hide();
}
populateFirmwareOptions(firmware);
int width=firmware->eepromInterface->getCapability(LCDWidth);
ui->imageLabel->setFixedWidth(width);
break;
}
}
firmwareChanged();
}
FirmwareVariant preferencesDialog::getFirmwareVariant()
{
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
bool voice=false;
foreach(FirmwareInfo * firmware, firmwares) {
if (firmware->id == selected_firmware) {
QString id = firmware->id;
foreach(QCheckBox *cb, optionsCheckBoxes) {
if (cb->isChecked()) {
if (cb->text()=="voice" && cb->isChecked())
voice=true;
id += QString("-") + cb->text();
}
}
if (! firmware->eepromInterface->getCapability(MultiLangVoice)) {
if (ui->voiceCombo->count() && (voice || firmware->voice))
id += QString("-tts") + ui->voiceCombo->currentText();
}
if (ui->langCombo->count())
id += QString("-") + ui->langCombo->currentText();
return GetFirmwareVariant(id);
}
}
// Should never occur...
return default_firmware_variant;
}
void preferencesDialog::firmwareLangChanged()
{
firmwareChanged();
}
void preferencesDialog::firmwareOptionChanged(bool state)
{
QCheckBox *cb = qobject_cast<QCheckBox*>(sender());
FirmwareInfo * firmware=NULL;
if (cb && state) {
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
foreach(firmware, firmwares) {
if (firmware->id == selected_firmware) {
foreach(QList<Option> opts, firmware->opts) {
foreach(Option opt, opts) {
if (cb->text() == opt.name) {
foreach(Option other, opts) {
if (other.name != opt.name) {
foreach(QCheckBox *ocb, optionsCheckBoxes) {
if (ocb->text() == other.name)
ocb->setChecked(false);
}
}
}
if (voice) {
if (voice->isChecked()) {
ui->voiceLabel->setEnabled(true);
ui->voiceCombo->setEnabled(true);
ui->voice_dnld->setEnabled(true);
ui->sdPathButton->setEnabled(true);
ui->sdPath->setEnabled(true);
} else {
ui->voiceLabel->setDisabled(true);
ui->voiceCombo->setDisabled(true);
ui->voice_dnld->setDisabled(true);
ui->sdPathButton->setDisabled(true);
ui->sdPath->setDisabled(true);
}
}
return firmwareChanged();
}
}
}
}
}
} else if (cb && !state) {
if (cb->text()=="voice") {
ui->voiceLabel->setDisabled(true);
ui->voiceCombo->setDisabled(true);
ui->voice_dnld->setDisabled(true);
ui->sdPathButton->setEnabled(true);
ui->sdPath->setEnabled(true);
}
}
if (voice ) {
if (voice->isChecked()) {
ui->voiceLabel->setEnabled(true);
ui->voiceCombo->setEnabled(true);
ui->voice_dnld->setEnabled(true);
} else {
ui->voiceLabel->setDisabled(true);
ui->voiceCombo->setDisabled(true);
ui->voice_dnld->setDisabled(true);
ui->sdPathButton->setDisabled(true);
ui->sdPath->setDisabled(true);
}
} else if (firmware) {
if (firmware->voice) {
ui->voiceLabel->setEnabled(true);
ui->voiceCombo->setEnabled(true);
ui->voice_dnld->setEnabled(true);
ui->sdPathButton->setEnabled(true);
ui->sdPath->setEnabled(true);
}
}
return firmwareChanged();
}
void preferencesDialog::firmwareChanged()
{
if (updateLock)
return;
FirmwareVariant variant = getFirmwareVariant();
QString stamp;
stamp.append(variant.firmware->stamp);
ui->fw_dnld->setEnabled(!variant.firmware->getUrl(variant.id).isNull());
QString url=variant.firmware->getUrl(variant.id);
// B-Plan
if (false) {
ui->CPU_ID_LE->show();
ui->CPU_ID_LABEL->show();
} else {
ui->CPU_ID_LE->hide();
ui->CPU_ID_LABEL->hide();
}
QSettings settings;
settings.beginGroup("FwRevisions");
int fwrev = settings.value(variant.id, -1).toInt();
settings.endGroup();
if (fwrev != -1) {
ui->FwInfo->setText(tr("Last downloaded release: %1").arg(fwrev));
if (!stamp.isEmpty()) {
ui->checkFWUpdates->show();
} else {
ui->checkFWUpdates->hide();
}
}
else {
if (ui->fw_dnld->isEnabled()) {
ui->FwInfo->setText(tr("The selected firmware has never been downloaded by Companion."));
ui->checkFWUpdates->hide();
}
else {
ui->FwInfo->setText(tr("The selected firmware cannot be downloaded by Companion."));
ui->checkFWUpdates->hide();
}
}
}
void preferencesDialog::writeValues()
{
QSettings settings;
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex());
settings.setValue("cpu_id", ui->CPU_ID_LE->text());
settings.setValue("startup_check_companion", ui->startupCheck_companion9x->isChecked());
settings.setValue("startup_check_fw", ui->startupCheck_fw->isChecked());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked());
settings.setValue("wizardEnable", ui->wizardEnable_ChkB->isChecked());
settings.setValue("show_splash", ui->showSplash->isChecked());
settings.setValue("simuSW", ui->simuSW->isChecked());
settings.setValue("history_size", ui->historySize->value());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked());
current_firmware_variant = getFirmwareVariant();
settings.setValue("firmware", current_firmware_variant.id);
settings.setValue("profileId", ui->ProfSlot_SB->value());
settings.setValue("backLight", ui->backLightColor->currentIndex());
settings.setValue("libraryPath", ui->libraryPath->text());
settings.setValue("sdPath", ui->sdPath->text());
settings.setValue("gePath", ui->ge_lineedit->text());
settings.setValue("embedded_splashes", ui->splashincludeCB->currentIndex());
if (!ui->SplashFileName->text().isEmpty()) {
QImage Image = ui->imageLabel->pixmap()->toImage();
settings.setValue("SplashImage", image2qstring(Image));
settings.setValue("SplashFileName", ui->SplashFileName->text());
}
else {
settings.setValue("SplashFileName", "");
settings.setValue("SplashImage", "");
}
if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) {
settings.setValue("js_support", ui->joystickChkB ->isChecked());
settings.setValue("js_ctrl", ui->joystickCB ->currentIndex());
}
else {
settings.remove("js_support");
settings.remove("js_ctrl");
}
settings.setValue("backupEnable", ui->backupEnable->isChecked());
MainWindow * mw = (MainWindow *)this->parent();
mw->unloadProfile();
}
void preferencesDialog::populateFirmwareOptions(const FirmwareInfo * firmware)
{
const FirmwareInfo * parent = firmware->parent ? firmware->parent : firmware;
updateLock = true;
ui->langCombo->clear();
foreach(const char *lang, parent->languages) {
ui->langCombo->addItem(lang);
if (current_firmware_variant.id.endsWith(lang))
ui->langCombo->setCurrentIndex(ui->langCombo->count() - 1);
}
ui->voiceCombo->clear();
foreach(const char *lang, parent->ttslanguages) {
ui->voiceCombo->addItem(lang);
if (current_firmware_variant.id.contains(QString("-tts%1").arg(lang)))
ui->voiceCombo->setCurrentIndex(ui->voiceCombo->count() - 1);
}
if (ui->langCombo->count()) {
ui->langCombo->show();
ui->langLabel->show();
}
else {
ui->langCombo->hide();
ui->langLabel->hide();
}
int index = 0;
foreach(QList<Option> opts, parent->opts) {
foreach(Option opt, opts) {
if (index >= optionsCheckBoxes.size()) {
qDebug() << "This firmware needs more options checkboxes!";
}
else {
QCheckBox *cb = optionsCheckBoxes.at(index++);
if (cb) {
cb->show();
cb->setText(opt.name);
cb->setToolTip(opt.tooltip);
cb->setCheckState(current_firmware_variant.id.contains(opt.name) ? Qt::Checked : Qt::Unchecked);
if (opt.name==QString("voice")) {
voice=cb;
ui->voiceLabel->show();
ui->voiceCombo->show();
ui->voice_dnld->show();
ui->sdPathButton->show();
ui->sdPath->show();
ui->sdPathLabel->show();
ui->ge_label->show();
ui->ge_lineedit->show();
ui->ge_pathButton->show();
if (current_firmware_variant.id.contains(opt.name) ||firmware->voice) {
ui->voiceLabel->setEnabled(true);
ui->voiceCombo->setEnabled(true);
ui->voice_dnld->setEnabled(true);
ui->sdPathButton->setEnabled(true);
ui->sdPath->setEnabled(true);
} else {
ui->voiceLabel->setDisabled(true);
ui->voiceCombo->setDisabled(true);
ui->voice_dnld->setDisabled(true);
ui->sdPathButton->setDisabled(true);
ui->sdPath->setDisabled(true);
}
}
}
}
}
}
for (; index<optionsCheckBoxes.size(); index++) {
QCheckBox *cb = optionsCheckBoxes.at(index);
cb->hide();
cb->setCheckState(Qt::Unchecked);
}
updateLock = false;
QTimer::singleShot(0, this, SLOT(shrink()));
}
void preferencesDialog::initSettings()
{
QSettings settings;
ui->snapshotClipboardCKB->setChecked(settings.value("snapshot_to_clipboard", false).toBool());
if (ui->snapshotClipboardCKB->isChecked()) {
ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true);
} else {
QString Path=settings.value("snapshotPath", "").toString();
if (QDir(Path).exists()) {
ui->snapshotPath->setText(Path);
ui->snapshotPath->setReadOnly(true);
ui->snapshotPathButton->setEnabled(true);
}
}
ui->channelorderCB->setCurrentIndex(settings.value("default_channel_order", 0).toInt());
ui->stickmodeCB->setCurrentIndex(settings.value("default_mode", 1).toInt());
ui->startupCheck_companion9x->setChecked(settings.value("startup_check_companion", true).toBool());
ui->renameFirmware->setChecked(settings.value("rename_firmware_files", false).toBool());
ui->wizardEnable_ChkB->setChecked(settings.value("wizardEnable", true).toBool());
ui->showSplash->setChecked(settings.value("show_splash", true).toBool());
ui->historySize->setValue(settings.value("history_size", 10).toInt());
ui->backLightColor->setCurrentIndex(settings.value("backLight", 0).toInt());
ui->startupCheck_fw->setChecked(settings.value("startup_check_fw", true).toBool());
ui->burnFirmware->setChecked(settings.value("burnFirmware", true).toBool());
ui->simuSW->setChecked(settings.value("simuSW", false).toBool());
ui->CPU_ID_LE->setText(settings.value("cpu_id", "").toString());
QString Path=settings.value("libraryPath", "").toString();
if (QDir(Path).exists()) {
ui->libraryPath->setText(Path);
}
Path=settings.value("sdPath", "").toString();
if (QDir(Path).exists()) {
ui->sdPath->setText(Path);
}
Path=settings.value("gePath", "").toString();
if (QFile(Path).exists()) {
ui->ge_lineedit->setText(Path);
}
Path=settings.value("backupPath", "").toString();
if (!Path.isEmpty()) {
if (QDir(Path).exists()) {
ui->backupPath->setText(Path);
ui->backupEnable->setEnabled(true);
ui->backupEnable->setChecked(settings.value("backupEnable", true).toBool());
} else {
ui->backupEnable->setDisabled(true);
}
} else {
ui->backupEnable->setDisabled(true);
}
ui->splashincludeCB->setCurrentIndex(settings.value("embedded_splashes", 0).toInt());
FirmwareInfo * current_firmware = GetCurrentFirmware();
// qDebug() << current_firmware->id;
foreach(FirmwareInfo * firmware, firmwares) {
ui->downloadVerCB->addItem(firmware->name, firmware->id);
if (current_firmware == firmware) {
ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1);
}
}
baseFirmwareChanged();
ui->ProfSlot_SB->setValue(settings.value("profileId", 1).toInt());
on_ProfSlot_SB_valueChanged();
QString ImageStr = settings.value("SplashImage", "").toString();
if (!ImageStr.isEmpty()) {
QImage Image = qstring2image(ImageStr);
ui->imageLabel->setPixmap(QPixmap::fromImage(Image.convertToFormat(QImage::Format_Mono)));
ui->InvertPixels->setEnabled(true);
QString fileName=settings.value("SplashFileName","").toString();
if (!fileName.isEmpty()) {
QFile file(fileName);
if (!file.exists()) {
ui->SplashFileName->setText(tr("Image stored in settings"));
}
else {
ui->SplashFileName->setText(fileName);
}
}
}
#ifdef JOYSTICKS
ui->joystickChkB->setChecked(settings.value("js_support", false).toBool());
if (ui->joystickChkB->isChecked()) {
QStringList joystickNames;
joystickNames << tr("No joysticks found");
joystick = new Joystick(0,false,0,0);
ui->joystickcalButton->setDisabled(true);
ui->joystickCB->setDisabled(true);
if ( joystick ) {
if ( joystick->joystickNames.count() > 0 ) {
joystickNames = joystick->joystickNames;
ui->joystickCB->setEnabled(true);
ui->joystickcalButton->setEnabled(true);
}
joystick->close();
}
ui->joystickCB->clear();
ui->joystickCB->insertItems(0, joystickNames);
ui->joystickCB->setCurrentIndex(settings.value("js_ctrl", 0).toInt());
}
else {
ui->joystickCB->clear();
ui->joystickCB->setDisabled(true);
ui->joystickcalButton->setDisabled(true);
}
#endif
firmwareChanged();
}
void preferencesDialog::on_fw_dnld_clicked()
{
MainWindow * mw = (MainWindow *)this->parent();
FirmwareVariant variant = getFirmwareVariant();
writeValues();
if (!variant.firmware->getUrl(variant.id).isNull()) {
if (ui->burnFirmware->isChecked()) {
QSettings settings;
current_firmware_variant = getFirmwareVariant();
settings.setValue("firmware", current_firmware_variant.id);
}
mw->downloadLatestFW(current_firmware_variant.firmware, current_firmware_variant.id);
}
firmwareChanged();
}
void preferencesDialog::on_voice_dnld_clicked()
{
ui->ProfSave_PB->setEnabled(true);
QString url="http://fw.opentx.it/voices/";
FirmwareVariant variant = getFirmwareVariant();
url.append(QString("%1/%2/").arg(variant.firmware->id).arg(ui->voiceCombo->currentText()));
QDesktopServices::openUrl(url);
}
void preferencesDialog::on_libraryPathButton_clicked()
{
ui->ProfSave_PB->setEnabled(true);
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), settings.value("libraryPath").toString());
if (!fileName.isEmpty()) {
settings.setValue("libraryPath", fileName);
ui->libraryPath->setText(fileName);
}
}
void preferencesDialog::on_snapshotPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), settings.value("snapshotPath").toString());
if (!fileName.isEmpty()) {
settings.setValue("snapshotpath", fileName);
settings.setValue("snapshot_to_clipboard", false);
ui->snapshotPath->setText(fileName);
}
}
void preferencesDialog::on_snapshotClipboardCKB_clicked()
{
QSettings settings;
if (ui->snapshotClipboardCKB->isChecked()) {
ui->snapshotPath->setDisabled(true);
ui->snapshotPathButton->setDisabled(true);
settings.setValue("snapshot_to_clipboard", true);
} else {
ui->snapshotPath->setEnabled(true);
ui->snapshotPath->setReadOnly(true);
ui->snapshotPathButton->setEnabled(true);
settings.setValue("snapshot_to_clipboard", false);
}
}
void preferencesDialog::on_backupPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), settings.value("backupPath").toString());
if (!fileName.isEmpty()) {
settings.setValue("backupPath", fileName);
ui->backupPath->setText(fileName);
}
ui->backupEnable->setEnabled(true);
}
void preferencesDialog::on_ge_pathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text());
if (!fileName.isEmpty()) {
ui->ge_lineedit->setText(fileName);
}
}
void preferencesDialog::on_splashLibraryButton_clicked()
{
QString fileName;
splashLibrary *ld = new splashLibrary(this,&fileName);
ld->exec();
if (!fileName.isEmpty()) {
QImage image(fileName);
if (image.isNull()) {
QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName));
return;
}
ui->SplashFileName->setText(fileName);
ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(128, 64).convertToFormat(QImage::Format_Mono)));
ui->InvertPixels->setEnabled(true);
}
}
void preferencesDialog::on_sdPathButton_clicked()
{
QSettings settings;
QString fileName = QFileDialog::getExistingDirectory(this,tr("Select the folder replicating your SD structure"), settings.value("sdPath").toString());
if (!fileName.isEmpty()) {
ui->sdPath->setText(fileName);
}
ui->ProfSave_PB->setEnabled(true);
}
void preferencesDialog::on_ProfSlot_SB_valueChanged()
{
QSettings settings;
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value());
settings.beginGroup(profile);
QString name=settings.value("Name","").toString();
ui->ProfName_LE->setText(name);
/* if (!(name.isEmpty())) {
QString firmwarename=settings.value("firmware", default_firmware_id).toString();
FirmwareInfo * fw = getFirmware(firmwarename);
int i=0;
foreach(FirmwareInfo * firmware, firmwares) {
if (fw == firmware) {
qDebug() << fw->id;
qDebug() << firmware->id;
qDebug() << i;
ui->downloadVerCB->setCurrentIndex(i);
break;
}
i++;
}
baseFirmwareChanged();
populateFirmwareOptions(fw);
}*/
settings.endGroup();
settings.endGroup();
}
void preferencesDialog::on_ProfSave_PB_clicked()
{
QSettings settings;
settings.beginGroup("Profiles");
QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value());
QString name=ui->ProfName_LE->text();
if (name.isEmpty()) {
int ret = QMessageBox::question(this, "Companion",
tr("Profile name is empty, profile slot %1 will be deleted.<br>Are you sure ?").arg(ui->ProfSlot_SB->value()) ,
QMessageBox::Yes | QMessageBox::No);
if (ret==QMessageBox::Yes) {
settings.remove(profile);
} else {
settings.beginGroup(profile);
ui->ProfName_LE->setText(settings.value("Name","").toString());
}
} else {
settings.beginGroup(profile);
settings.setValue("Name",name);
settings.setValue("default_channel_order", ui->channelorderCB->currentIndex());
settings.setValue("default_mode", ui->stickmodeCB->currentIndex());
settings.setValue("burnFirmware", ui->burnFirmware->isChecked());
settings.setValue("rename_firmware_files", ui->renameFirmware->isChecked());
settings.setValue("sdPath", ui->sdPath->text());
settings.setValue("SplashFileName", ui->SplashFileName->text());
settings.setValue("gePath", ui->ge_lineedit->text());
if (ui->imageLabel->pixmap()) {
QImage Image = ui->imageLabel->pixmap()->toImage();
settings.setValue("SplashImage", image2qstring(Image));
} else {
settings.remove("SplashImage");
}
current_firmware_variant = getFirmwareVariant();
settings.setValue("firmware", current_firmware_variant.id);
settings.endGroup();
settings.endGroup();
}
}
void preferencesDialog::on_export_PB_clicked()
{
QSettings settings;
QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value());
QString name=ui->ProfName_LE->text();
if (!name.isEmpty()) {
QString fileName = QFileDialog::getSaveFileName(this, tr("Export profile As"), settings.value("lastDir").toString() + "/" +name+".ini" , "*.ini");
if (fileName.isEmpty())
return;
QSettings exportfile(fileName, QSettings::IniFormat);
settings.beginGroup("Profiles");
settings.beginGroup(profile);
QStringList keys = settings.childKeys();
foreach (QString key, keys) {
exportfile.setValue(key,settings.value(key));
}
settings.endGroup();
}
settings.endGroup();
}
void preferencesDialog::on_import_PB_clicked()
{
QSettings settings;
QString profile=QString("profile%1").arg(ui->ProfSlot_SB->value());
QString name=ui->ProfName_LE->text();
if (!name.isEmpty()) {
int ret = QMessageBox::question(this, "Companion",
tr("Profile slot is not empty, profile slot %1 will we overwritten.<br>Are you sure ?").arg(ui->ProfSlot_SB->value()) ,
QMessageBox::Yes | QMessageBox::No);
if (ret==QMessageBox::No) {
return;
}
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Profile to import"), settings.value("lastDir").toString(), "*.ini");
if (fileName.isEmpty())
return;
QSettings importfile(fileName, QSettings::IniFormat);
settings.beginGroup("Profiles");
settings.beginGroup(profile);
QStringList keys = importfile.childKeys();
foreach (QString key, keys) {
settings.setValue(key,importfile.value(key));
}
settings.endGroup();
settings.endGroup();
on_ProfSlot_SB_valueChanged();
}
void preferencesDialog::on_SplashSelect_clicked()
{
QString supportedImageFormats;
for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) {
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
}
QSettings settings;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats));
if (!fileName.isEmpty()) {
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
QImage image(fileName);
if (image.isNull()) {
QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName));
return;
}
ui->SplashFileName->setText(fileName);
int width=ui->imageLabel->width();
ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, 64)));
if (width==212) {
image=image.convertToFormat(QImage::Format_RGB32);
QRgb col;
int gray;
int height = image.height();
for (int i = 0; i < width; ++i)
{
for (int j = 0; j < height; ++j)
{
col = image.pixel(i, j);
gray = qGray(col);
image.setPixel(i, j, qRgb(gray, gray, gray));
}
}
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
} else {
ui->imageLabel->setPixmap(QPixmap::fromImage(image.convertToFormat(QImage::Format_Mono)));
}
ui->InvertPixels->setEnabled(true);
}
}
void preferencesDialog::on_InvertPixels_clicked() {
QImage image = ui->imageLabel->pixmap()->toImage();
image.invertPixels();
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
}
void preferencesDialog::on_clearImageButton_clicked() {
ui->imageLabel->clear();
ui->SplashFileName->clear();
}
#ifdef JOYSTICKS
void preferencesDialog::on_joystickChkB_clicked() {
if (ui->joystickChkB->isChecked()) {
QStringList joystickNames;
joystickNames << tr("No joysticks found");
joystick = new Joystick(0,false,0,0);
ui->joystickcalButton->setDisabled(true);
ui->joystickCB->setDisabled(true);
if ( joystick ) {
if ( joystick->joystickNames.count() > 0 ) {
joystickNames = joystick->joystickNames;
ui->joystickCB->setEnabled(true);
ui->joystickcalButton->setEnabled(true);
}
joystick->close();
}
ui->joystickCB->clear();
ui->joystickCB->insertItems(0, joystickNames);
}
else {
ui->joystickCB->clear();
ui->joystickCB->setDisabled(true);
ui->joystickcalButton->setDisabled(true);
}
}
void preferencesDialog::on_joystickcalButton_clicked() {
//QSettings settings;
//settings.setValue("joystick-name",ui->joystickCB->currentText());
joystickDialog * jd=new joystickDialog(this, ui->joystickCB->currentIndex());
jd->exec();
}
#endif
void preferencesDialog::on_checkFWUpdates_clicked()
{
FirmwareVariant variant = getFirmwareVariant();
if (ui->burnFirmware->isChecked()) {
QSettings settings;
current_firmware_variant = variant;
settings.setValue("firmware", variant.id);
}
MainWindow * mw = (MainWindow *)this->parent();
mw->checkForUpdates(true, variant.id);
firmwareChanged();
}
void preferencesDialog::shrink()
{
resize(0,0);
}
-65
View File
@@ -1,65 +0,0 @@
#ifndef PREFERENCESDIALOG_H
#define PREFERENCESDIALOG_H
#include <QDialog>
#include <QCheckBox>
#include "eeprominterface.h"
namespace Ui {
class preferencesDialog;
}
class Joystick;
class preferencesDialog : public QDialog
{
Q_OBJECT
public:
explicit preferencesDialog(QWidget *parent = 0);
~preferencesDialog();
Joystick *joystick;
private:
Ui::preferencesDialog *ui;
QList<QCheckBox *> optionsCheckBoxes;
bool updateLock;
void populateLocale();
void populateFirmwareOptions(const FirmwareInfo *);
FirmwareVariant getFirmwareVariant();
void initSettings();
QCheckBox * voice;
private slots:
void shrink();
void writeValues();
void firmwareLangChanged();
void baseFirmwareChanged();
void firmwareOptionChanged(bool state);
void firmwareChanged();
void on_fw_dnld_clicked();
void on_voice_dnld_clicked();
void on_SplashSelect_clicked();
void on_InvertPixels_clicked();
void on_clearImageButton_clicked();
void on_libraryPathButton_clicked();
void on_snapshotPathButton_clicked();
void on_snapshotClipboardCKB_clicked();
void on_backupPathButton_clicked();
void on_ge_pathButton_clicked();
void on_sdPathButton_clicked();
void on_splashLibraryButton_clicked();
void on_checkFWUpdates_clicked();
void on_ProfSlot_SB_valueChanged();
void on_ProfSave_PB_clicked();
void on_export_PB_clicked();
void on_import_PB_clicked();
#ifdef JOYSTICKS
void on_joystickChkB_clicked();
void on_joystickcalButton_clicked();
#endif
};
#endif // PREFERENCESDIALOG_H
+8 -14
View File
@@ -1,5 +1,6 @@
#include "joystickdialog.h"
#include "ui_joystickdialog.h"
#include "appdata.h"
#include <QtGui>
joystickDialog::joystickDialog(QWidget *parent, int stick) :
@@ -130,27 +131,20 @@ void joystickDialog::on_okButton_clicked() {
return;
}
joystick->close();
QSettings settings;
settings.beginGroup("JsCalibration");
for (int i=0; i<8;i++) {
settings.remove(QString("stick%1_axe").arg(i));
settings.remove(QString("stick%1_max").arg(i));
settings.remove(QString("stick%1_med").arg(i));
settings.remove(QString("stick%1_min").arg(i));
settings.remove(QString("stick%1_inv").arg(i));
g.joystick[i].remove();
}
QCheckBox * ib[]={ui->ChInv_1, ui->ChInv_2, ui->ChInv_3, ui->ChInv_4, ui->ChInv_5, ui->ChInv_6, ui->ChInv_7, ui->ChInv_8};
foreach(QComboBox *cb, findChildren<QComboBox *>(QRegExp("jsmapCB_[0-9]+"))) {
int axe=cb->objectName().mid(cb->objectName().lastIndexOf("_")+1).toInt()-1;
int stick=cb->currentIndex();
if (stick>0) {
settings.setValue(QString("stick%1_axe").arg(stick),axe);
settings.setValue(QString("stick%1_max").arg(stick),jscal[axe][2]);
settings.setValue(QString("stick%1_med").arg(stick),jscal[axe][1]);
settings.setValue(QString("stick%1_min").arg(stick),jscal[axe][0]);
settings.setValue(QString("stick%1_inv").arg(stick),ib[axe]->isChecked() ? 1 : 0);
if (stick > 0) {
g.joystick[stick].stick_axe( axe );
g.joystick[stick].stick_max( jscal[axe][2] );
g.joystick[stick].stick_med( jscal[axe][1] );
g.joystick[stick].stick_min( jscal[axe][0] );
g.joystick[stick].stick_inv( ib[axe]->isChecked() ? 1 : 0 );
}
}
settings.endGroup();
this->close();
}
+9 -9
View File
@@ -18,6 +18,7 @@
#define lcd_widget_h
#include <QWidget>
#include "appdata.h"
class lcdWidget : public QWidget {
public:
@@ -48,9 +49,9 @@ class lcdWidget : public QWidget {
void setBackgroundColor(int red, int green, int blue)
{
r = red;
g = green;
b = blue;
_r = red;
_g = green;
_b = blue;
}
void makeScreenshot(const QString & fileName)
@@ -58,11 +59,10 @@ class lcdWidget : public QWidget {
QPixmap buffer(2*lcdWidth, 2*lcdHeight);
QPainter p(&buffer);
doPaint(p);
QSettings settings;
bool toclipboard=settings.value("snapshot_to_clipboard", false).toBool();
bool toclipboard=g.snapToClpbrd();
QApplication::clipboard()->setPixmap( buffer );
if (!toclipboard) {
QString Path=settings.value("snapshotPath", "").toString();
QString Path=g.snapshotDir();
if (Path.isEmpty() || !QDir(Path).exists()) {
Path=".";
}
@@ -98,14 +98,14 @@ class lcdWidget : public QWidget {
unsigned char *previousBuf;
bool lightEnable;
int r, g, b;
int _r, _g, _b;
inline void doPaint(QPainter & p)
{
QRgb rgb;
if (lightEnable)
rgb = qRgb(r, g, b);
rgb = qRgb(_r, _g, _b);
else
rgb = qRgb(161, 161, 161);
@@ -136,7 +136,7 @@ class lcdWidget : public QWidget {
if (z != previousDepth) {
previousDepth = z;
if (lightEnable)
rgb = qRgb(r-(z*r)/15, g-(z*g)/15, b-(z*b)/15);
rgb = qRgb(_r-(z*_r)/15, _g-(z*_g)/15, _b-(z*_b)/15);
else
rgb = qRgb(161-(z*161)/15, 161-(z*161)/15, 161-(z*161)/15);
p.setPen(rgb);
+3 -4
View File
@@ -1,6 +1,6 @@
#include "splashlibrary.h"
#include "ui_splashlibrary.h"
#include "appdata.h"
#include <QtGui>
#include "helpers.h"
//#include "splashlabel.h"
@@ -63,9 +63,8 @@ void splashLibrary::setupPage(int page) {
}
void splashLibrary::getFileList() {
QSettings settings;
imageList.clear();
if (settings.value("embedded_splashes", 0).toInt() == 0) {
if (g.embedSplashes()) {
QDir myRes(":/images/library");
QStringList tmp = myRes.entryList();
for (int i = 0; i < tmp.size(); i++) {
@@ -73,7 +72,7 @@ void splashLibrary::getFileList() {
imageList.append(":/images/library/" + fileInfo.fileName());
}
}
QString libraryPath = settings.value("libraryPath", "").toString();
QString libraryPath = g.libDir();
if (!libraryPath.isEmpty()) {
if (QDir(libraryPath).exists()) {
QStringList supportedImageFormats;