5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
23 // Global data and storage object
26 // ** CompStoreObj class********************
27 void CompStoreObj::clear (const QString
&tag1
, const QString
&tag2
, const QString
&tag3
)
29 QSettings
settings(COMPANY
, PRODUCT
);
32 settings
.remove(tag1
);
34 else if (tag3
.isEmpty())
36 settings
.beginGroup(tag1
);
37 settings
.remove(tag2
);
42 settings
.beginGroup(tag1
);
43 settings
.beginGroup(tag2
);
44 settings
.remove(tag3
);
50 template <typename OBJ_T
, typename TAG_T
, typename GP1_T
, typename GP2_T
>
51 void CompStoreObj::store(const OBJ_T newValue
, OBJ_T
& destValue
, const TAG_T tag
, const GP1_T group1
, const GP2_T group2
)
53 QSettings
settings(COMPANY
, PRODUCT
);
54 QString g1
= group1
; // these may come in as const char * or QString
57 settings
.beginGroup(g1
);
59 settings
.beginGroup(g2
);
62 settings
.setValue(tag
, QVariant::fromValue(newValue
));
72 template <typename OBJ_T
, typename TAG_T
, typename DEF_T
, typename GP1_T
, typename GP2_T
>
73 void CompStoreObj::retrieve(OBJ_T
& destValue
, const TAG_T tag
, const DEF_T def
, const GP1_T group1
, const GP2_T group2
)
75 QSettings
settings(COMPANY
, PRODUCT
);
76 QString g1
= group1
; // these may come in as const char * or QString
79 settings
.beginGroup(g1
);
81 settings
.beginGroup(g2
);
84 QVariant val
= settings
.value(QString(tag
), QVariant::fromValue(def
));
85 if (val
.canConvert
<OBJ_T
>())
86 destValue
= val
.value
<OBJ_T
>();
95 template <typename OBJ_T
, typename TAG_T
, typename DEF_T
, typename GP1_T
, typename GP2_T
>
96 void CompStoreObj::getset(OBJ_T
& value
, const TAG_T tag
, const DEF_T def
, const GP1_T group1
, const GP2_T group2
)
98 retrieve(value
, tag
, def
, group1
, group2
);
99 store(value
, value
, tag
, group1
, group2
);
102 template <typename OBJ_T
, typename TAG_T
, typename GP1_T
, typename GP2_T
>
103 void CompStoreObj::getset(OBJ_T
& value
, const TAG_T tag
, const char * def
, const GP1_T group1
, const GP2_T group2
)
105 getset(value
, tag
, QString(def
), group1
, group2
);
109 // ** FwRevision class********************
110 int FwRevision::get( const QString fwType
)
113 retrieve( result
, fwType
, QString(""), "FwRevisions" );
114 return result
.toInt();
117 void FwRevision::set( const QString fwType
, const int fwRevision
)
119 QString tempString
= QString("%1").arg(fwRevision
);
120 store( tempString
, tempString
, fwType
, "FwRevisions" );
123 void FwRevision::remove( const QString tag
)
125 clear( "FwRevisions", tag
);
128 // ** JStickData class********************
130 int JStickData::stick_axe() { return _stickAxe
; }
131 int JStickData::stick_min() { return _stickMin
; }
132 int JStickData::stick_med() { return _stickMed
; }
133 int JStickData::stick_max() { return _stickMax
; }
134 int JStickData::stick_inv() { return _stickInv
; }
137 void JStickData::stick_axe(const int it
) { store( it
, _stickAxe
, QString("stick%1_axe").arg(index
), "JsCalibration" );}
138 void JStickData::stick_min(const int it
) { store( it
, _stickMin
, QString("stick%1_min").arg(index
), "JsCalibration" );}
139 void JStickData::stick_med(const int it
) { store( it
, _stickMed
, QString("stick%1_med").arg(index
), "JsCalibration" );}
140 void JStickData::stick_max(const int it
) { store( it
, _stickMax
, QString("stick%1_max").arg(index
), "JsCalibration" );}
141 void JStickData::stick_inv(const int it
) { store( it
, _stickInv
, QString("stick%1_inv").arg(index
), "JsCalibration" );}
144 JStickData::JStickData()
149 void JStickData::remove()
151 // Remove all JStickData values from settings file
152 QSettings
settings(COMPANY
, PRODUCT
);
153 settings
.beginGroup( "JsCalibration" );
154 settings
.remove( QString( "stick%1_axe").arg(index
) );
155 settings
.remove( QString( "stick%1_min").arg(index
) );
156 settings
.remove( QString( "stick%1_med").arg(index
) );
157 settings
.remove( QString( "stick%1_max").arg(index
) );
158 settings
.remove( QString( "stick%1_inv").arg(index
) );
161 // Reset all JStickData variables to initial values
165 bool JStickData::existsOnDisk()
167 QSettings
settings(COMPANY
, PRODUCT
);
168 settings
.beginGroup("JsCalibration");
169 int axe
= settings
.value( QString("stick%1_axe").arg(index
), -1 ).toInt();
175 void JStickData::init(int newIndex
)
184 // Do not write empty joystick calibrations to disk.
185 if ( !existsOnDisk() )
191 void JStickData::flush()
193 getset( _stickAxe
, QString("stick%1_axe").arg(index
), -1, "JsCalibration" );
194 getset( _stickMin
, QString("stick%1_min").arg(index
), -32767, "JsCalibration" );
195 getset( _stickMed
, QString("stick%1_med").arg(index
), 0, "JsCalibration" );
196 getset( _stickMax
, QString("stick%1_max").arg(index
), 0, "JsCalibration" );
197 getset( _stickInv
, QString("stick%1_inv").arg(index
), 0, "JsCalibration" );
200 // ** Profile class********************
202 QString
Profile::fwName() const { return _fwName
; }
203 QString
Profile::fwType() const { return _fwType
; }
204 QString
Profile::name() const { return _name
; }
205 QString
Profile::sdPath() const { return _sdPath
; }
206 int Profile::volumeGain() const { return _volumeGain
; }
207 QString
Profile::pBackupDir() const { return _pBackupDir
; }
208 QString
Profile::splashFile() const { return _splashFile
; }
209 bool Profile::burnFirmware() const { return _burnFirmware
; }
210 bool Profile::penableBackup() const { return _penableBackup
; }
211 bool Profile::renameFwFiles() const { return _renameFwFiles
; }
212 int Profile::channelOrder() const { return _channelOrder
; }
213 int Profile::defaultMode() const { return _defaultMode
; }
215 QString
Profile::beeper() const { return _beeper
; }
216 QString
Profile::countryCode() const { return _countryCode
; }
217 QString
Profile::display() const { return _display
; }
218 QString
Profile::haptic() const { return _haptic
; }
219 QString
Profile::speaker() const { return _speaker
; }
220 QString
Profile::stickPotCalib() const { return _stickPotCalib
; }
221 QString
Profile::timeStamp() const { return _timeStamp
; }
222 QString
Profile::trainerCalib() const { return _trainerCalib
; }
223 QString
Profile::controlTypes() const { return _controlTypes
; }
224 QString
Profile::controlNames() const { return _controlNames
; }
225 int Profile::gsStickMode() const { return _gsStickMode
; }
226 int Profile::ppmMultiplier() const { return _ppmMultiplier
; }
227 int Profile::vBatWarn() const { return _vBatWarn
; }
228 int Profile::vBatMin() const { return _vBatMin
; }
229 int Profile::vBatMax() const { return _vBatMax
; }
230 int Profile::txCurrentCalibration() const { return _txCurrentCalibration
; }
231 int Profile::txVoltageCalibration() const { return _txVoltageCalibration
; }
233 SimulatorOptions
Profile::simulatorOptions() const { return _simulatorOptions
; }
236 void Profile::name (const QString x
) { store(x
, _name
, "Name" ,"Profiles", groupId());}
237 void Profile::fwName (const QString x
) { store(x
, _fwName
, "fwName" ,"Profiles", groupId());}
238 void Profile::fwType (const QString x
) { store(x
, _fwType
, "fwType" ,"Profiles", groupId());}
239 void Profile::sdPath (const QString x
) { store(x
, _sdPath
, "sdPath" ,"Profiles", groupId());}
240 void Profile::volumeGain (const int x
) { store(x
, _volumeGain
, "volumeGain" ,"Profiles", groupId());}
241 void Profile::pBackupDir (const QString x
) { store(x
, _pBackupDir
, "pBackupDir" ,"Profiles", groupId());}
242 void Profile::splashFile (const QString x
) { store(x
, _splashFile
, "SplashFileName" ,"Profiles", groupId());}
243 void Profile::burnFirmware (const bool x
) { store(x
, _burnFirmware
, "burnFirmware" ,"Profiles", groupId());}
244 void Profile::renameFwFiles (const bool x
) { store(x
, _renameFwFiles
, "rename_firmware_files" ,"Profiles", groupId());}
245 void Profile::penableBackup (const bool x
) { store(x
, _penableBackup
, "penableBackup" ,"Profiles", groupId());}
246 void Profile::channelOrder (const int x
) { store(x
, _channelOrder
, "default_channel_order" ,"Profiles", groupId());}
247 void Profile::defaultMode (const int x
) { store(x
, _defaultMode
, "default_mode" ,"Profiles", groupId());}
248 void Profile::beeper (const QString x
) { store(x
, _beeper
, "Beeper" ,"Profiles", groupId());}
249 void Profile::countryCode (const QString x
) { store(x
, _countryCode
, "countryCode" ,"Profiles", groupId());}
250 void Profile::display (const QString x
) { store(x
, _display
, "Display" ,"Profiles", groupId());}
251 void Profile::haptic (const QString x
) { store(x
, _haptic
, "Haptic" ,"Profiles", groupId());}
252 void Profile::speaker (const QString x
) { store(x
, _speaker
, "Speaker" ,"Profiles", groupId());}
253 void Profile::stickPotCalib (const QString x
) { store(x
, _stickPotCalib
, "StickPotCalib" ,"Profiles", groupId());}
254 void Profile::timeStamp (const QString x
) { store(x
, _timeStamp
, "TimeStamp" ,"Profiles", groupId());}
255 void Profile::trainerCalib (const QString x
) { store(x
, _trainerCalib
, "TrainerCalib" ,"Profiles", groupId());}
256 void Profile::controlTypes (const QString x
) { store(x
, _controlTypes
, "ControlTypes" ,"Profiles", groupId());}
257 void Profile::controlNames (const QString x
) { store(x
, _controlNames
, "ControlNames" ,"Profiles", groupId());}
258 void Profile::gsStickMode (const int x
) { store(x
, _gsStickMode
, "GSStickMode" ,"Profiles", groupId());}
259 void Profile::ppmMultiplier (const int x
) { store(x
, _ppmMultiplier
, "PPM_Multiplier" ,"Profiles", groupId());}
260 void Profile::vBatWarn (const int x
) { store(x
, _vBatWarn
, "vBatWarn" ,"Profiles", groupId());}
261 void Profile::vBatMin (const int x
) { store(x
, _vBatMin
, "VbatMin" ,"Profiles", groupId());}
262 void Profile::vBatMax (const int x
) { store(x
, _vBatMax
, "VbatMax" ,"Profiles", groupId());}
263 void Profile::txCurrentCalibration (const int x
) { store(x
, _txCurrentCalibration
, "currentCalib","Profiles", groupId());}
264 void Profile::txVoltageCalibration (const int x
) { store(x
, _txVoltageCalibration
, "VbatCalib" ,"Profiles", groupId());}
266 void Profile::simulatorOptions(const SimulatorOptions
& x
) { store(x
, _simulatorOptions
, "simulatorOptions" ,"Profiles", groupId()); }
274 // The default copy operator can not be used since the index variable would be destroyed
275 Profile
& Profile::operator=(const Profile
& rhs
)
278 fwName ( rhs
.fwName() );
279 fwType ( rhs
.fwType() );
280 sdPath ( rhs
.sdPath() );
281 volumeGain ( rhs
.volumeGain() );
282 pBackupDir ( rhs
.pBackupDir() );
283 splashFile ( rhs
.splashFile() );
284 burnFirmware ( rhs
.burnFirmware() );
285 renameFwFiles( rhs
.renameFwFiles() );
286 penableBackup( rhs
.penableBackup() );
287 channelOrder ( rhs
.channelOrder() );
288 defaultMode ( rhs
.defaultMode() );
289 beeper ( rhs
.beeper() );
290 countryCode ( rhs
.countryCode() );
291 display ( rhs
.display() );
292 haptic ( rhs
.haptic() );
293 speaker ( rhs
.speaker() );
294 stickPotCalib( rhs
.stickPotCalib() );
295 trainerCalib ( rhs
.trainerCalib() );
296 controlTypes ( rhs
.controlTypes() );
297 controlNames ( rhs
.controlNames() );
298 gsStickMode ( rhs
.gsStickMode() );
299 ppmMultiplier( rhs
.ppmMultiplier() );
300 vBatWarn ( rhs
.vBatWarn() );
301 vBatMin ( rhs
.vBatMin() );
302 vBatMax ( rhs
.vBatMax() );
303 txCurrentCalibration ( rhs
.txCurrentCalibration() );
304 txVoltageCalibration ( rhs
.txVoltageCalibration() );
305 simulatorOptions ( rhs
.simulatorOptions() );
310 void Profile::remove()
312 // Remove all profile values from settings file
313 QSettings
settings(COMPANY
, PRODUCT
);
314 settings
.beginGroup("Profiles");
315 settings
.remove(groupId());
318 // Reset all profile variables to initial values
322 bool Profile::existsOnDisk()
324 QSettings
settings(COMPANY
, PRODUCT
);
325 settings
.beginGroup("Profiles");
326 settings
.beginGroup(groupId());
327 QStringList keyList
= settings
.allKeys();
331 return (keyList
.length() > 0);
334 void Profile::initFwVariables()
347 _txCurrentCalibration
= 0;
350 _txVoltageCalibration
= 0;
356 void Profile::init(int newIndex
)
367 _burnFirmware
= false;
368 _renameFwFiles
= false;
369 _penableBackup
= false;
373 _simulatorOptions
= SimulatorOptions();
377 // Do not write empty profiles to disk except the default (0) profile.
378 if ( index
> 0 && !existsOnDisk())
384 void Profile::flush()
386 // Load and store all variables. Use default values if setting values are missing
387 getset( _fwName
, "fwName" ,"" ,"Profiles", groupId());
388 getset( _fwType
, "fwType" ,"" ,"Profiles", groupId());
389 getset( _name
, "Name" ,"" ,"Profiles", groupId());
390 getset( _sdPath
, "sdPath" ,"" ,"Profiles", groupId());
391 getset( _volumeGain
, "volumeGain" ,10 ,"Profiles", groupId());
392 getset( _pBackupDir
, "pBackupDir" ,"" ,"Profiles", groupId());
393 getset( _splashFile
, "SplashFileName" ,"" ,"Profiles", groupId());
394 getset( _burnFirmware
, "burnFirmware" ,false ,"Profiles", groupId());
395 getset( _penableBackup
, "penableBackup" ,false ,"Profiles", groupId());
396 getset( _renameFwFiles
, "rename_firmware_files" ,false ,"Profiles", groupId());
397 getset( _channelOrder
, "default_channel_order" ,0 ,"Profiles", groupId());
398 getset( _defaultMode
, "default_mode" ,1 ,"Profiles", groupId());
400 getset( _beeper
, "Beeper" ,"" ,"Profiles", groupId());
401 getset( _countryCode
, "countryCode" ,"" ,"Profiles", groupId());
402 getset( _display
, "Display" ,"" ,"Profiles", groupId());
403 getset( _haptic
, "Haptic" ,"" ,"Profiles", groupId());
404 getset( _speaker
, "Speaker" ,"" ,"Profiles", groupId());
405 getset( _stickPotCalib
, "StickPotCalib" ,"" ,"Profiles", groupId());
406 getset( _timeStamp
, "TimeStamp" ,"" ,"Profiles", groupId());
407 getset( _trainerCalib
, "TrainerCalib" ,"" ,"Profiles", groupId());
408 getset( _controlTypes
, "ControlTypes" ,"" ,"Profiles", groupId());
409 getset( _controlNames
, "ControlNames" ,"" ,"Profiles", groupId());
410 getset( _gsStickMode
, "GSStickMode" ,0 ,"Profiles", groupId());
411 getset( _ppmMultiplier
, "PPM_Multiplier" ,0 ,"Profiles", groupId());
412 getset( _vBatWarn
, "vBatWarn" ,0 ,"Profiles", groupId());
413 getset( _vBatMin
, "VbatMin" ,0 ,"Profiles", groupId());
414 getset( _vBatMax
, "VbatMax" ,0 ,"Profiles", groupId());
415 getset( _txCurrentCalibration
, "currentCalib" ,0 ,"Profiles", groupId());
416 getset( _txVoltageCalibration
, "VbatCalib" ,0 ,"Profiles", groupId());
418 getset( _simulatorOptions
, "simulatorOptions", SimulatorOptions(), "Profiles", groupId());
422 QString
Profile::groupId()
424 return QString("profile%1").arg(index
);
428 // ** AppData class********************
431 QStringList
AppData::recentFiles() { return _recentFiles
; }
432 QStringList
AppData::simuDbgFilters() { return _simuDbgFilters
; }
434 QByteArray
AppData::mainWinGeo() { return _mainWinGeo
; }
435 QByteArray
AppData::mainWinState() { return _mainWinState
; }
436 QByteArray
AppData::modelEditGeo() { return _modelEditGeo
; }
437 QByteArray
AppData::mdiWinGeo() { return _mdiWinGeo
; }
438 QByteArray
AppData::mdiWinState() { return _mdiWinState
; }
439 QByteArray
AppData::compareWinGeo(){ return _compareWinGeo
; }
441 QString
AppData::armMcu() { return _armMcu
; }
442 QString
AppData::avrArguments() { return _avrArguments
; }
443 QString
AppData::avrPort() { return _avrPort
; }
444 QString
AppData::avrdudeLocation() { return _avrdudeLocation
; }
445 QString
AppData::dfuArguments() { return _dfuArguments
; }
446 QString
AppData::dfuLocation() { return _dfuLocation
; }
447 QString
AppData::locale() { return _locale
; }
448 QString
AppData::mcu() { return _mcu
; }
449 QString
AppData::programmer() { return _programmer
; }
450 QString
AppData::sambaLocation() { return _sambaLocation
; }
451 QString
AppData::sambaPort() { return _sambaPort
; }
453 QString
AppData::backupDir() { return _backupDir
; }
454 QString
AppData::gePath() { return _gePath
; }
455 QString
AppData::eepromDir() { return _eepromDir
; }
456 QString
AppData::flashDir() { return _flashDir
; }
457 QString
AppData::imagesDir() { return _imagesDir
; }
458 QString
AppData::logDir() { return _logDir
; }
459 QString
AppData::libDir() { return _libDir
; }
460 QString
AppData::snapshotDir() { return _snapshotDir
; }
461 QString
AppData::updatesDir() { return _updatesDir
; }
463 int AppData::newModelAction() { return _newModelAction
; }
464 int AppData::backLight() { return _backLight
; }
465 int AppData::embedSplashes() { return _embedSplashes
; }
466 int AppData::fwServerFails() { return _fwServerFails
; }
467 int AppData::generalEditTab() { return _generalEditTab
; }
468 int AppData::iconSize() { return _iconSize
; }
469 int AppData::historySize() { return _historySize
; }
470 int AppData::jsCtrl() { return _jsCtrl
; }
471 int AppData::id() { return _id
; }
472 int AppData::theme() { return _theme
; }
473 int AppData::warningId() { return _warningId
; }
474 int AppData::simuLastProfId() { return _simuLastProfId
; }
475 int AppData::sessionId() { return _sessionId
; }
478 void AppData::recentFiles (const QStringList x
) { store(x
, _recentFiles
, "recentFileList" );}
479 void AppData::simuDbgFilters (const QStringList x
) { store(x
, _simuDbgFilters
, "simuDbgFilters" );}
481 void AppData::mainWinGeo (const QByteArray x
) { store(x
, _mainWinGeo
, "mainWindowGeometry" );}
482 void AppData::mainWinState (const QByteArray x
) { store(x
, _mainWinState
, "mainWindowState" );}
483 void AppData::modelEditGeo (const QByteArray x
) { store(x
, _modelEditGeo
, "modelEditGeometry" );}
484 void AppData::mdiWinGeo (const QByteArray x
) { store(x
, _mdiWinGeo
, "mdiWinGeo" );}
485 void AppData::mdiWinState (const QByteArray x
) { store(x
, _mdiWinState
, "mdiWinState" );}
486 void AppData::compareWinGeo (const QByteArray x
) { store(x
, _compareWinGeo
, "compareWinGeo" );}
488 void AppData::armMcu (const QString x
) { store(x
, _armMcu
, "arm_mcu" );}
489 void AppData::avrArguments (const QString x
) { store(x
, _avrArguments
, "avr_arguments" );}
490 void AppData::avrPort (const QString x
) { store(x
, _avrPort
, "avr_port" );}
491 void AppData::avrdudeLocation (const QString x
) { store(x
, _avrdudeLocation
, "avrdudeLocation" );}
492 void AppData::dfuArguments (const QString x
) { store(x
, _dfuArguments
, "dfu_arguments" );}
493 void AppData::dfuLocation (const QString x
) { store(x
, _dfuLocation
, "dfu_location" );}
494 void AppData::locale (const QString x
) { store(x
, _locale
, "locale" );}
495 void AppData::mcu (const QString x
) { store(x
, _mcu
, "mcu" );}
496 void AppData::programmer (const QString x
) { store(x
, _programmer
, "programmer" );}
497 void AppData::sambaLocation (const QString x
) { store(x
, _sambaLocation
, "samba_location" );}
498 void AppData::sambaPort (const QString x
) { store(x
, _sambaPort
, "samba_port" );}
500 void AppData::backupDir (const QString x
) { store(x
, _backupDir
, "backupPath" );}
501 void AppData::gePath (const QString x
) { store(x
, _gePath
, "gePath" );}
502 void AppData::eepromDir (const QString x
) { store(x
, _eepromDir
, "lastDir" );}
503 void AppData::flashDir (const QString x
) { store(x
, _flashDir
, "lastFlashDir" );}
504 void AppData::imagesDir (const QString x
) { store(x
, _imagesDir
, "lastImagesDir" );}
505 void AppData::logDir (const QString x
) { store(x
, _logDir
, "lastLogDir" );}
506 void AppData::libDir (const QString x
) { store(x
, _libDir
, "libraryPath" );}
507 void AppData::snapshotDir (const QString x
) { store(x
, _snapshotDir
, "snapshotpath" );}
508 void AppData::updatesDir (const QString x
) { store(x
, _updatesDir
, "lastUpdatesDir" );}
510 void AppData::newModelAction (const int x
) { store(x
, _newModelAction
, "newModelAction" );}
511 void AppData::backLight (const int x
) { store(x
, _backLight
, "backLight" );}
512 void AppData::embedSplashes (const int x
) { store(x
, _embedSplashes
, "embedded_splashes" );}
513 void AppData::fwServerFails (const int x
) { store(x
, _fwServerFails
, "fwserver" );}
514 void AppData::generalEditTab (const int x
) { store(x
, _generalEditTab
, "generalEditTab" );}
515 void AppData::iconSize (const int x
) { store(x
, _iconSize
, "icon_size" );}
516 void AppData::historySize (const int x
) { store(x
, _historySize
, "history_size" );}
517 void AppData::jsCtrl (const int x
) { store(x
, _jsCtrl
, "js_ctrl" );}
518 void AppData::theme (const int x
) { store(x
, _theme
, "theme" );}
519 void AppData::warningId (const int x
) { store(x
, _warningId
, "warningId" );}
520 void AppData::simuLastProfId (const int x
) { store(x
, _simuLastProfId
, "simuLastProfId" );}
522 void AppData::id(const int x
)
524 store(x
, _id
, "profileId");
528 // currently loaded radio profile ID, NOT saved to persistent storage
529 void AppData::sessionId (const int x
) { _sessionId
= x
; }
538 qRegisterMetaTypeStreamOperators
<SimulatorOptions
>("SimulatorOptions");
542 QSettings
settings(COMPANY
, PRODUCT
);
543 if (!settings
.contains("settings_version")) {
546 convertSettings(settings
);
548 // Initialize the profiles
549 for (int i
=0; i
<MAX_PROFILES
; i
++)
550 profile
[i
].init( i
);
552 // Initialize the joysticks
553 for (int i
=0; i
<MAX_JOYSTICKS
; i
++)
554 joystick
[i
].init( i
);
556 // Load and store all variables. Use default values if setting values are missing
557 QString _tempString
; // Do not touch. Do not change the settings version before a new verson update!
558 getset( _tempString
, "settings_version" ,"220" ); // This is a version marker. Will be used to upgrade the settings later on.
560 getset( _recentFiles
, "recentFileList" ,"" );
561 getset( _simuDbgFilters
, "simuDbgFilters" ,"" );
563 getset( _mainWinGeo
, "mainWindowGeometry" ,"" );
564 getset( _mainWinState
, "mainWindowState" ,"" );
565 getset( _modelEditGeo
, "modelEditGeometry" ,"" );
566 getset( _mdiWinGeo
, "mdiWinGeo" ,"" );
567 getset( _mdiWinState
, "mdiWinState" ,"" );
568 getset( _compareWinGeo
, "compareWinGeo" ,"" );
570 getset( _armMcu
, "arm_mcu" ,"at91sam3s4-9x" );
571 getset( _avrArguments
, "avr_arguments" ,"" );
572 getset( _avrPort
, "avr_port" ,"" );
573 getset( _avrdudeLocation
, "avrdudeLocation" ,"" );
574 getset( _dfuArguments
, "dfu_arguments" ,"-a 0" );
575 getset( _dfuLocation
, "dfu_location" ,"" );
576 getset( _locale
, "locale" ,"" );
577 getset( _mcu
, "mcu" ,"m64" );
578 getset( _programmer
, "programmer" ,"usbasp" );
579 getset( _sambaLocation
, "samba_location" ,"" );
580 getset( _sambaPort
, "samba_port" ,"\\USBserial\\COM23" );
582 getset( _backupDir
, "backupPath" ,"" );
583 getset( _gePath
, "gePath" ,"" );
584 getset( _eepromDir
, "lastDir" ,"" );
585 getset( _flashDir
, "lastFlashDir" ,"" );
586 getset( _imagesDir
, "lastImagesDir" ,"" );
587 getset( _logDir
, "lastLogDir" ,"" );
588 getset( _libDir
, "libraryPath" ,"" );
589 getset( _snapshotDir
, "snapshotpath" ,"" );
590 getset( _updatesDir
, "lastUpdatesDir" ,"" );
595 backupOnFlash_init();
596 outputDisplayDetails_init();
597 checkHardwareCompatibility_init();
598 useCompanionNightlyBuilds_init();
599 useFirmwareNightlyBuilds_init();
600 removeModelSlots_init();
612 getset( _newModelAction
, "newModelAction" ,1 );
613 getset( _backLight
, "backLight" ,0 );
614 getset( _embedSplashes
, "embedded_splashes" ,0 );
615 getset( _fwServerFails
, "fwserver" ,0 );
616 getset( _generalEditTab
, "generalEditTab" ,0 );
617 getset( _iconSize
, "icon_size" ,2 );
618 getset( _jsCtrl
, "js_ctrl" ,0 );
619 getset( _historySize
, "history_size" ,10 );
620 getset( _id
, "profileId" ,0 );
621 getset( _theme
, "theme" ,1 );
622 getset( _warningId
, "warningId" ,0 );
623 getset( _simuLastProfId
, "simuLastProfId" ,-1 );
628 QMap
<int, QString
> AppData::getActiveProfiles()
630 QMap
<int, QString
> active
;
631 for (int i
=0; i
<MAX_PROFILES
; i
++) {
632 if (g
.profile
[i
].existsOnDisk())
633 active
.insert(i
, g
.profile
[i
].name());
638 void AppData::convertSettings(QSettings
& settings
)
640 // convert old settings to new
641 if (settings
.contains("useWizard")) {
642 if (!settings
.contains("newModelAction")) {
643 newModelAction(settings
.value("useWizard").toBool() ? 1 : 2);
645 settings
.remove("useWizard");
647 if (settings
.contains("warningId") && settings
.value("warningId").toInt() == 7) {
648 // meaning of warningId changed during v2.2 development but value of "7" indicates old setting, removing it will restore defaults
649 settings
.remove("warningId");
653 bool AppData::hasCurrentSettings()
655 QSettings
settings(COMPANY
, PRODUCT
);
656 if (!settings
.contains("settings_version")) {
662 bool AppData::findPreviousVersionSettings(QString
* version
)
664 QSettings
* fromSettings
= NULL
;
667 QSettings
settings21("OpenTX", "Companion 2.1");
668 if (settings21
.contains("settings_version")) {
669 fromSettings
= &settings21
;
676 QSettings
settings20("OpenTX", "Companion 2.0");
677 if (settings20
.contains("settings_version")) {
679 fromSettings
= &settings20
;
687 QSettings
settings16("OpenTX", "OpenTX Companion");
688 if (settings16
.contains("settings_version")) {
690 fromSettings
= &settings16
;
704 bool AppData::importSettings(QString fromVersion
)
706 QSettings
toSettings(COMPANY
, PRODUCT
);
711 upgradeFromVersion
= "";
713 if (fromVersion
== "2.1") {
714 fromCompany
= "OpenTX";
715 fromProduct
= "Companion 2.1";
717 else if (fromVersion
== "2.0") {
718 fromCompany
= "OpenTX";
719 fromProduct
= "Companion 2.0";
721 else if (fromVersion
== "1.x") {
722 fromCompany
= "OpenTX";
723 fromProduct
= "OpenTX Companion";
728 upgradeFromVersion
= fromVersion
;
730 QSettings
fromSettings(fromCompany
, fromProduct
);
732 // do not copy these settings
733 QStringList excludeKeys
= QStringList() << "compilation-server";
735 // locations of tools which come with Companion distros
736 excludeKeys
<< "avrdude_location" << "avrdudeLocation" << "dfu_location";
737 // install-specific keys; "." is the "default" key which may contain install path
738 excludeKeys
<< "Start Menu Folder" << ".";
742 foreach (const QString
& key
, fromSettings
.allKeys()) {
743 if (fromSettings
.value(key
).isValid() && !excludeKeys
.contains(key
)) {
744 toSettings
.setValue(key
, fromSettings
.value(key
));