Fix for duplicate key/value pairs being written to settings.cfg, Bug #755

pull/16/head
pvdk 12 years ago
parent 512dcdc735
commit b3595a6a2e

@ -310,6 +310,8 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
bool MainDialog::setupLauncherSettings()
{
mLauncherSettings.setMultiValueEnabled(true);
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
QStringList paths;
@ -427,6 +429,8 @@ bool MainDialog::setupGameSettings()
bool MainDialog::setupGraphicsSettings()
{
mGraphicsSettings.setMultiValueEnabled(false);
QString userPath = QString::fromStdString(mCfgMgr.getUserPath().string());
QString globalPath = QString::fromStdString(mCfgMgr.getGlobalPath().string());

@ -103,8 +103,8 @@ bool GameSettings::readFile(QTextStream &stream)
if (keyRe.indexIn(line) != -1) {
QString key = keyRe.cap(1);
QString value = keyRe.cap(2);
QString key = keyRe.cap(1).trimmed();
QString value = keyRe.cap(2).trimmed();
// Don't remove existing data entries
if (key != QLatin1String("data"))

@ -14,7 +14,7 @@ class SettingsBase
{
public:
SettingsBase() {}
SettingsBase() { mMultiValue = false; }
~SettingsBase() {}
inline QString value(const QString &key, const QString &defaultValue = QString())
@ -36,6 +36,11 @@ public:
mSettings.insertMulti(key, value);
}
inline void setMultiValueEnabled(bool enable)
{
mMultiValue = enable;
}
inline void remove(const QString &key)
{
mSettings.remove(key);
@ -66,8 +71,8 @@ public:
if (keyRe.indexIn(line) != -1) {
QString key = keyRe.cap(1);
QString value = keyRe.cap(2);
QString key = keyRe.cap(1).trimmed();
QString value = keyRe.cap(2).trimmed();
if (!sectionPrefix.isEmpty())
key.prepend(sectionPrefix);
@ -75,8 +80,13 @@ public:
mSettings.remove(key);
QStringList values = mCache.values(key);
if (!values.contains(value)) {
mCache.insertMulti(key, value);
if (mMultiValue) {
mCache.insertMulti(key, value);
} else {
mCache.insert(key, value);
}
}
}
}
@ -94,6 +104,8 @@ public:
private:
Map mSettings;
Map mCache;
bool mMultiValue;
};
#endif // SETTINGSBASE_HPP

@ -2,9 +2,17 @@
<ui version="4.0">
<class>PlayPage</class>
<widget class="QWidget" name="PlayPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>274</width>
<height>317</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="Scroll">
<widget class="QWidget" name="Scroll" native="true">
<property name="styleSheet">
<string notr="true">#Scroll {
background-image: url(&quot;:/images/playpage-background.png&quot;);
@ -13,15 +21,6 @@
}
</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>30</number>

Loading…
Cancel
Save