summaryrefslogtreecommitdiffstats
path: root/logic/lists
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-12-15 15:01:34 -0600
committerAndrew <forkk@forkk.net>2013-12-15 15:01:34 -0600
commit9d8006b597aead06f1d51dacbdb346ebab3d5e8f (patch)
tree1f99ca1da321be32930198e3d72b2fc9d3bf53de /logic/lists
parent0ee8f90d40f5b3ddb177286c9066a4e59748c681 (diff)
parentb0e8037feb5b9d48defe6b8263d068f87bdb141c (diff)
downloadMultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.gz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.lz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.xz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.zip
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into feature_news
Conflicts: CMakeLists.txt
Diffstat (limited to 'logic/lists')
-rw-r--r--logic/lists/InstanceList.cpp21
-rw-r--r--logic/lists/InstanceList.h8
2 files changed, 27 insertions, 2 deletions
diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp
index b9595578..15fd10ba 100644
--- a/logic/lists/InstanceList.cpp
+++ b/logic/lists/InstanceList.cpp
@@ -36,11 +36,16 @@ const static int GROUP_FILE_FORMAT_VERSION = 1;
InstanceList::InstanceList(const QString &instDir, QObject *parent)
: QAbstractListModel(parent), m_instDir(instDir)
{
+ connect(MMC, &MultiMC::aboutToQuit, this, &InstanceList::saveGroupList);
+
+ if (!QDir::current().exists(m_instDir))
+ {
+ QDir::current().mkpath(m_instDir);
+ }
}
InstanceList::~InstanceList()
{
- saveGroupList();
}
int InstanceList::rowCount(const QModelIndex &parent) const
@@ -112,6 +117,11 @@ void InstanceList::groupChanged()
saveGroupList();
}
+QStringList InstanceList::getGroups()
+{
+ return m_groups.toList();
+}
+
void InstanceList::saveGroupList()
{
QString groupFileName = m_instDir + "/instgroups.json";
@@ -121,7 +131,7 @@ void InstanceList::saveGroupList()
if (!groupFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
// An error occurred. Ignore it.
- QLOG_ERROR() << "Failed to read instance group file.";
+ QLOG_ERROR() << "Failed to save instance group file.";
return;
}
QTextStream out(&groupFile);
@@ -132,6 +142,10 @@ void InstanceList::saveGroupList()
QString group = instance->group();
if (group.isEmpty())
continue;
+
+ // keep a list/set of groups for choosing
+ m_groups.insert(group);
+
if (!groupMap.count(group))
{
QSet<QString> set;
@@ -248,6 +262,9 @@ void InstanceList::loadGroupList(QMap<QString, QString> &groupMap)
continue;
}
+ // keep a list/set of groups for choosing
+ m_groups.insert(groupName);
+
// Iterate through the list of instances in the group.
QJsonArray instancesArray = groupObj.value("instances").toArray();
diff --git a/logic/lists/InstanceList.h b/logic/lists/InstanceList.h
index 8cd39746..f23b7763 100644
--- a/logic/lists/InstanceList.h
+++ b/logic/lists/InstanceList.h
@@ -17,6 +17,7 @@
#include <QObject>
#include <QAbstractListModel>
+#include <QSet>
#include "categorizedsortfilterproxymodel.h"
#include <QIcon>
@@ -29,6 +30,9 @@ class InstanceList : public QAbstractListModel
Q_OBJECT
private:
void loadGroupList(QMap<QString, QString> &groupList);
+
+private
+slots:
void saveGroupList();
public:
@@ -94,6 +98,9 @@ public:
InstancePtr getInstanceById(QString id) const;
QModelIndex getInstanceIndexById(const QString &id) const;
+
+ // FIXME: instead of iterating through all instances and forming a set, keep the set around
+ QStringList getGroups();
signals:
void dataIsInvalid();
@@ -113,6 +120,7 @@ private:
protected:
QString m_instDir;
QList<InstancePtr> m_instances;
+ QSet<QString> m_groups;
};
class InstanceProxyModel : public KCategorizedSortFilterProxyModel