Fixed setting conversion and initialization problems

This commit is contained in:
Kjell Kernen
2014-02-21 20:49:00 +01:00
parent ea57e3e40a
commit e9ce69c6a4
2 changed files with 324 additions and 313 deletions
+47 -33
View File
@@ -336,27 +336,27 @@ Profile::Profile()
// The default copy operator can not be used since the index variable would be destroyed // The default copy operator can not be used since the index variable would be destroyed
Profile& Profile::operator=(const Profile& rhs) Profile& Profile::operator=(const Profile& rhs)
{ {
_name = rhs.name(); name ( rhs.name() );
_firmware = rhs.firmware(); firmware ( rhs.firmware() );
_sdPath = rhs.sdPath(); sdPath ( rhs.sdPath() );
_splashFile = rhs.splashFile(); splashFile ( rhs.splashFile() );
_burnFirmware = rhs.burnFirmware(); burnFirmware ( rhs.burnFirmware() );
_renameFwFiles = rhs.renameFwFiles(); renameFwFiles( rhs.renameFwFiles() );
_patchImage = rhs.patchImage(); patchImage ( rhs.patchImage() );
_channelOrder = rhs.channelOrder(); channelOrder ( rhs.channelOrder() );
_defaultMode = rhs.defaultMode(); defaultMode ( rhs.defaultMode() );
_beeper = rhs.beeper(); beeper ( rhs.beeper() );
_countryCode = rhs.countryCode(); countryCode ( rhs.countryCode() );
_display = rhs.display(); display ( rhs.display() );
_haptic = rhs.haptic(); haptic ( rhs.haptic() );
_speaker = rhs.speaker(); speaker ( rhs.speaker() );
_stickPotCalib = rhs.stickPotCalib(); stickPotCalib( rhs.stickPotCalib() );
_trainerCalib = rhs.trainerCalib(); trainerCalib ( rhs.trainerCalib() );
_currentCalib = rhs.currentCalib(); currentCalib ( rhs.currentCalib() );
_gsStickMode = rhs.gsStickMode(); gsStickMode ( rhs.gsStickMode() );
_ppmMultiplier = rhs.ppmMultiplier(); ppmMultiplier( rhs.ppmMultiplier() );
_vBatCalib = rhs.vBatCalib(); vBatCalib ( rhs.vBatCalib() );
_vBatWarn = rhs.vBatWarn(); vBatWarn ( rhs.vBatWarn() );
return *this; return *this;
} }
@@ -572,23 +572,27 @@ AppData::AppData()
joystick[i].init( i ); joystick[i].init( i );
// Import settings from companion9x, but only do it one time. // 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 c9x_settings("companion9x", "companion9x");
QSettings settings(PRODUCT, COMPANY); QSettings settings(PRODUCT, COMPANY);
if (!settings.contains("locale")) if (profile[0].name().isEmpty() )
{ {
// Copy all settings from companion9x to companion
QStringList keys = c9x_settings.allKeys(); QStringList keys = c9x_settings.allKeys();
for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++) for (QStringList::iterator i=keys.begin(); i!=keys.end(); i++)
{ {
settings.setValue(*i, c9x_settings.value(*i)); settings.setValue(*i, c9x_settings.value(*i));
} }
// Convert firmware name
// Store old values in new locations
autoCheckApp(settings.value("startup_check_companion9x", true).toBool());
// Convert and store the firmware name
QString firmware = settings.value("firmware", "").toString(); QString firmware = settings.value("firmware", "").toString();
firmware.replace("open9x","opentx"); firmware.replace("open9x","opentx");
firmware.replace("x9da","taranis"); firmware.replace("x9da","taranis");
// Move Companion9x settings to profile0, the new default profile
profile[0].firmware( firmware ); profile[0].firmware( firmware );
// Move the Companion9x profile settings to profile0, the new default profile
profile[0].name( settings.value( "Name", "" ).toString()); profile[0].name( settings.value( "Name", "" ).toString());
profile[0].sdPath( settings.value( "sdPath", "" ).toString()); profile[0].sdPath( settings.value( "sdPath", "" ).toString());
profile[0].splashFile( settings.value( "SplashFileName", "" ).toString()); profile[0].splashFile( settings.value( "SplashFileName", "" ).toString());
@@ -598,16 +602,26 @@ AppData::AppData()
profile[0].channelOrder( settings.value( "default_channel_order", "0" ).toInt()); profile[0].channelOrder( settings.value( "default_channel_order", "0" ).toInt());
profile[0].defaultMode( settings.value( "default_mode", "1" ).toInt()); profile[0].defaultMode( settings.value( "default_mode", "1" ).toInt());
// Delete unused settings // Ensure that the default profile has a name
settings.remove("firmware"); if ( profile[0].name().isEmpty() )
settings.remove("Name"); profile[0].name("My Radio");
settings.remove("sdPath");
settings.remove("SplashFileName"); // Delete obsolete settings fields
settings.remove("ActiveProfile");
settings.remove("burnFirmware"); settings.remove("burnFirmware");
settings.remove("rename_firmware_files"); settings.remove("custom_id");
settings.remove("patchImage");
settings.remove("default_channel_order"); settings.remove("default_channel_order");
settings.remove("default_mode"); settings.remove("default_mode");
settings.remove("firmware");
settings.remove("Name");
settings.remove("patchImage");
settings.remove("rename_firmware_files");
settings.remove("sdPath");
settings.remove("SplashFileName");
settings.remove("startup_check_companion9x");
// Select the new default profile as current profile
id( 0 );
} }
// Load and store all variables. Use default values if setting values are missing // Load and store all variables. Use default values if setting values are missing
+1 -4
View File
@@ -1981,14 +1981,11 @@ void MainWindow::updateProfilesActions()
void MainWindow::createProfile() void MainWindow::createProfile()
{ int i; { int i;
for (i=0; i<MAX_PROFILES && !g.profile[i].name().isEmpty(); i++) for (i=0; i<MAX_PROFILES && g.profile[i].existsOnDisk(); i++)
; ;
if (i==MAX_PROFILES) //Failed to find free slot if (i==MAX_PROFILES) //Failed to find free slot
return; return;
// Create profile by forcing it to write to disk
g.profile[i].flush();
// Copy current profile to new and give it a new name // Copy current profile to new and give it a new name
g.profile[i] = g.profile[g.id()]; g.profile[i] = g.profile[g.id()];
g.profile[i].name( QString("New Radio")); g.profile[i].name( QString("New Radio"));