Some code refactoring in Model_Settings class.

This commit is contained in:
LoRd_MuldeR 2020-04-20 21:22:04 +02:00
parent 6d64247d1e
commit 9aa6c39d93
2 changed files with 31 additions and 17 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 4
#define VER_LAMEXP_BUILD 2261
#define VER_LAMEXP_BUILD 2264
#define VER_LAMEXP_CONFG 2188
///////////////////////////////////////////////////////////////////////////////

View File

@ -55,7 +55,7 @@
class SettingsCache
{
public:
SettingsCache(QSettings *configFile)
SettingsCache(QSettings *const configFile)
:
m_configFile(configFile),
m_cache(new cache_data_t()),
@ -355,30 +355,44 @@ SettingsModel::SettingsModel(void)
}
//Create settings
QSettings *configFile = new QSettings(configPath, QSettings::IniFormat);
const QString groupKey = QString().sprintf("LameXP.%04X", lamexp_version_confg());
const QString groupKey = QString().sprintf("LameXP.%u", lamexp_version_confg());
QScopedPointer<QSettings> configFile(new QSettings(configPath, QSettings::IniFormat));
const QStringList childGroups = configFile->childGroups();
//Import legacy settings
if ((lamexp_version_confg() == 2188U) && (!childGroups.contains(groupKey, Qt::CaseInsensitive)))
{
const char* const LEGACY_GROUPS[] = { "LameXP_41802188", "LameXP_41702188", NULL };
for (size_t i = 0; LEGACY_GROUPS[i]; ++i)
{
const QString legacyGroupName = QString::fromLatin1(LEGACY_GROUPS[i]);
if (childGroups.contains(legacyGroupName))
{
qWarning("Importing legay settings: %s -> %s", MUTILS_UTF8(legacyGroupName), MUTILS_UTF8(groupKey));
configFile->beginGroup(legacyGroupName);
const QStringList existingKeys = configFile->allKeys();
configFile->endGroup();
for (QStringList::ConstIterator iter = existingKeys.constBegin(); iter != existingKeys.constEnd(); iter++)
{
configFile->setValue(QString("%1/%2").arg(groupKey, *iter), configFile->value(QString("%1/%2").arg(legacyGroupName, *iter)));
}
break;
}
}
}
//Clean-up settings
if (!childGroups.empty())
{
static const int MAX_GROUPS = 3;
QRegExp filter("^LameXP_(\\d+)(\\d\\d)(\\d\\d\\d\\d\\d)$");
static const int MAX_GROUPS = 5;
QStringList obsoleteGroups;
for (QStringList::ConstIterator iter = childGroups.constBegin(); iter != childGroups.constEnd(); iter++)
{
if (filter.indexIn(*iter) >= 0)
{
quint32 temp[3] = { 0, 0, 0 };
if (MUtils::regexp_parse_uint32(filter, temp, 3))
{
if ((temp[0] < lamexp_version_major()) || ((temp[0] == lamexp_version_major()) && ((temp[1] < lamexp_version_minor()) || ((temp[1] == lamexp_version_minor()) && (temp[2] < lamexp_version_confg())))))
if (iter->compare(groupKey, Qt::CaseInsensitive) != 0)
{
obsoleteGroups.append(*iter);
}
}
}
}
if (obsoleteGroups.count() > MAX_GROUPS)
{
qSort(obsoleteGroups);
@ -400,7 +414,7 @@ SettingsModel::SettingsModel(void)
configFile->sync();
//Create the cache
m_configCache = new SettingsCache(configFile);
m_configCache = new SettingsCache(configFile.take());
}
////////////////////////////////////////////////////////////