summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
Diffstat (limited to 'logic')
-rw-r--r--logic/InstanceList.cpp35
-rw-r--r--logic/InstanceList.h18
2 files changed, 45 insertions, 8 deletions
diff --git a/logic/InstanceList.cpp b/logic/InstanceList.cpp
index 8197fe24..741b8611 100644
--- a/logic/InstanceList.cpp
+++ b/logic/InstanceList.cpp
@@ -133,8 +133,43 @@ QStringList InstanceList::getGroups()
return m_groups.toList();
}
+void InstanceList::suspendGroupSaving()
+{
+ suspendedGroupSave = true;
+}
+
+void InstanceList::resumeGroupSaving()
+{
+ if(suspendedGroupSave)
+ {
+ suspendedGroupSave = false;
+ if(queuedGroupSave)
+ {
+ saveGroupList();
+ }
+ }
+}
+
+void InstanceList::deleteGroup(const QString& name)
+{
+ for(auto & instance: m_instances)
+ {
+ auto instGroupName = instance->group();
+ if(instGroupName == name)
+ {
+ instance->setGroupPost(QString());
+ }
+ }
+}
+
void InstanceList::saveGroupList()
{
+ if(suspendedGroupSave)
+ {
+ queuedGroupSave = true;
+ return;
+ }
+
QString groupFileName = m_instDir + "/instgroups.json";
QMap<QString, QSet<QString>> groupMap;
for (auto instance : m_instances)
diff --git a/logic/InstanceList.h b/logic/InstanceList.h
index 3dbfaf70..074cca7c 100644
--- a/logic/InstanceList.h
+++ b/logic/InstanceList.h
@@ -31,9 +31,10 @@ class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel
Q_OBJECT
private:
void loadGroupList(QMap<QString, QString> &groupList);
+ void suspendGroupSaving();
+ void resumeGroupSaving();
-public
-slots:
+public slots:
void saveGroupList();
public:
@@ -116,6 +117,8 @@ public:
// FIXME: instead of iterating through all instances and forming a set, keep the set around
QStringList getGroups();
+ void deleteGroup(const QString & name);
+
/*!
* \brief Creates a stub instance
*
@@ -155,8 +158,7 @@ public:
signals:
void dataIsInvalid();
-public
-slots:
+public slots:
void on_InstFolderChanged(const Setting &setting, QVariant value);
/*!
@@ -164,8 +166,7 @@ slots:
*/
InstListError loadList();
-private
-slots:
+private slots:
void propertiesChanged(BaseInstance *inst);
void instanceNuked(BaseInstance *inst);
void groupChanged();
@@ -174,12 +175,13 @@ private:
int getInstIndex(BaseInstance *inst) const;
public:
- static bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir,
- QMap<QString, QString> &groupMap);
+ static bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, QMap<QString, QString> &groupMap);
protected:
QString m_instDir;
QList<InstancePtr> m_instances;
QSet<QString> m_groups;
SettingsObjectPtr m_globalSettings;
+ bool suspendedGroupSave = false;
+ bool queuedGroupSave = false;
};