summaryrefslogtreecommitdiffstats
path: root/logic/settings
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-05-23 16:07:47 +0200
committerPetr Mrázek <peterix@gmail.com>2015-05-23 16:07:47 +0200
commitce99fabe1396ed2956dc7ecb468760ef88f98765 (patch)
tree603f7c6f1a0f27805b21843ec3f829354ad0ff77 /logic/settings
parent0e0ddf5494ab4a264b0dc18c4b94809844300dc0 (diff)
downloadMultiMC-ce99fabe1396ed2956dc7ecb468760ef88f98765.tar
MultiMC-ce99fabe1396ed2956dc7ecb468760ef88f98765.tar.gz
MultiMC-ce99fabe1396ed2956dc7ecb468760ef88f98765.tar.lz
MultiMC-ce99fabe1396ed2956dc7ecb468760ef88f98765.tar.xz
MultiMC-ce99fabe1396ed2956dc7ecb468760ef88f98765.zip
GH-992 Add a transaction/locking mechanism to settings objects
This can cut the FTB loading by ~66% - worth it, but not ideal. Real solution will have to be implemented later.
Diffstat (limited to 'logic/settings')
-rw-r--r--logic/settings/INISettingsObject.cpp28
-rw-r--r--logic/settings/INISettingsObject.h9
-rw-r--r--logic/settings/SettingsObject.h26
3 files changed, 57 insertions, 6 deletions
diff --git a/logic/settings/INISettingsObject.cpp b/logic/settings/INISettingsObject.cpp
index e872d608..5ccc7446 100644
--- a/logic/settings/INISettingsObject.cpp
+++ b/logic/settings/INISettingsObject.cpp
@@ -33,6 +33,20 @@ bool INISettingsObject::reload()
return m_ini.loadFile(m_filePath) && SettingsObject::reload();
}
+void INISettingsObject::suspendSave()
+{
+ m_suspendSave = true;
+}
+
+void INISettingsObject::resumeSave()
+{
+ m_suspendSave = false;
+ if(m_doSave)
+ {
+ m_ini.saveFile(m_filePath);
+ }
+}
+
void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
{
if (contains(setting.id()))
@@ -51,6 +65,18 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
for(auto iter: setting.configKeys())
m_ini.remove(iter);
}
+ doSave();
+ }
+}
+
+void INISettingsObject::doSave()
+{
+ if(m_suspendSave)
+ {
+ m_doSave = true;
+ }
+ else
+ {
m_ini.saveFile(m_filePath);
}
}
@@ -62,7 +88,7 @@ void INISettingsObject::resetSetting(const Setting &setting)
{
for(auto iter: setting.configKeys())
m_ini.remove(iter);
- m_ini.saveFile(m_filePath);
+ doSave();
}
}
diff --git a/logic/settings/INISettingsObject.h b/logic/settings/INISettingsObject.h
index 4d26ddf1..a93eea78 100644
--- a/logic/settings/INISettingsObject.h
+++ b/logic/settings/INISettingsObject.h
@@ -47,15 +47,18 @@ public:
bool reload() override;
-protected
-slots:
+ void suspendSave();
+ void resumeSave();
+
+protected slots:
virtual void changeSetting(const Setting &setting, QVariant value);
virtual void resetSetting(const Setting &setting);
protected:
virtual QVariant retrieveValue(const Setting &setting);
+ void doSave();
+protected:
INIFile m_ini;
-
QString m_filePath;
};
diff --git a/logic/settings/SettingsObject.h b/logic/settings/SettingsObject.h
index 99782a01..6272d24c 100644
--- a/logic/settings/SettingsObject.h
+++ b/logic/settings/SettingsObject.h
@@ -22,6 +22,9 @@
#include <memory>
class Setting;
+class SettingsObject;
+
+typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;
/*!
* \brief The SettingsObject handles communicating settings between the application and a
@@ -39,6 +42,22 @@ class SettingsObject : public QObject
{
Q_OBJECT
public:
+ class Lock
+ {
+ public:
+ Lock(SettingsObjectPtr locked)
+ :m_locked(locked)
+ {
+ m_locked->suspendSave();
+ }
+ ~Lock()
+ {
+ m_locked->resumeSave();
+ }
+ private:
+ SettingsObjectPtr m_locked;
+ };
+public:
explicit SettingsObject(QObject *parent = 0);
virtual ~SettingsObject();
/*!
@@ -127,6 +146,8 @@ public:
*/
virtual bool reload();
+ virtual void suspendSave() = 0;
+ virtual void resumeSave() = 0;
signals:
/*!
* \brief Signal emitted when one of this SettingsObject object's settings changes.
@@ -184,6 +205,7 @@ protected:
private:
QMap<QString, std::shared_ptr<Setting>> m_settings;
+protected:
+ bool m_suspendSave = false;
+ bool m_doSave = false;
};
-
-typedef std::shared_ptr<SettingsObject> SettingsObjectPtr;