From dd9e04000ccd02a868138de9276f8fb93b855550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 15 Dec 2013 18:10:51 +0100 Subject: Improve group changing, update instance on version change Gives a list of existing groups to choose from. Instances are updated as long as there is at least one valid account. --- logic/lists/InstanceList.cpp | 14 +++++++++++++- logic/lists/InstanceList.h | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'logic/lists') diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 94481fb9..15fd10ba 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -117,6 +117,11 @@ void InstanceList::groupChanged() saveGroupList(); } +QStringList InstanceList::getGroups() +{ + return m_groups.toList(); +} + void InstanceList::saveGroupList() { QString groupFileName = m_instDir + "/instgroups.json"; @@ -126,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); @@ -137,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 set; @@ -253,6 +262,9 @@ void InstanceList::loadGroupList(QMap &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 c3bb74cd..f23b7763 100644 --- a/logic/lists/InstanceList.h +++ b/logic/lists/InstanceList.h @@ -17,6 +17,7 @@ #include #include +#include #include "categorizedsortfilterproxymodel.h" #include @@ -97,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(); @@ -116,6 +120,7 @@ private: protected: QString m_instDir; QList m_instances; + QSet m_groups; }; class InstanceProxyModel : public KCategorizedSortFilterProxyModel -- cgit v1.2.3