summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-10-02 08:53:43 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-10-02 09:02:15 (GMT)
commit087bc243ffb53e3273580bce5ce66305841a3bff (patch)
treea09a7fd1d564f0e7164198c501d95c949f20b8dd /Swift/Controllers/RosterGroupExpandinessPersister.cpp
parent2fb3d3266bd22d84604688dc9ee18b17b211b91d (diff)
downloadswift-087bc243ffb53e3273580bce5ce66305841a3bff.zip
swift-087bc243ffb53e3273580bce5ce66305841a3bff.tar.bz2
Persist roster group expandiness.
Release-Notes: Whether roster groups are expanded or collapsed is now persisted between sessions. Resolves: #399
Diffstat (limited to 'Swift/Controllers/RosterGroupExpandinessPersister.cpp')
-rw-r--r--Swift/Controllers/RosterGroupExpandinessPersister.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Swift/Controllers/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/RosterGroupExpandinessPersister.cpp
new file mode 100644
index 0000000..a6a998a
--- /dev/null
+++ b/Swift/Controllers/RosterGroupExpandinessPersister.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/Controllers/RosterGroupExpandinessPersister.h"
+
+#include <boost/bind.hpp>
+#include <vector>
+
+#include "Swiften/Roster/GroupRosterItem.h"
+
+namespace Swift {
+
+RosterGroupExpandinessPersister::RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings) : roster_(roster), settings_(settings) {
+ load();
+ roster_->onGroupAdded.connect(boost::bind(&RosterGroupExpandinessPersister::handleGroupAdded, this, _1));
+}
+
+void RosterGroupExpandinessPersister::handleGroupAdded(GroupRosterItem* group) {
+ if (collapsed_.find(group->getDisplayName()) != collapsed_.end()) {
+ group->setExpanded(false);
+ } else {
+ group->setExpanded(true);
+ }
+ group->onExpandedChanged.connect(boost::bind(&RosterGroupExpandinessPersister::handleExpandedChanged, this, group, _1));
+}
+
+void RosterGroupExpandinessPersister::handleExpandedChanged(GroupRosterItem* group, bool expanded) {
+ if (expanded) {
+ collapsed_.erase(collapsed_.find(group->getDisplayName()));
+ } else {
+ collapsed_.insert(group->getDisplayName());
+ }
+ save();
+}
+
+void RosterGroupExpandinessPersister::save() {
+ String setting;
+ foreach (const String& group, collapsed_) {
+ if (setting.isEmpty()) {
+ setting += "\n";
+ }
+ setting += group;
+ }
+ settings_->storeString(SettingPath, setting);
+}
+
+void RosterGroupExpandinessPersister::load() {
+ String saved = settings_->getStringSetting(SettingPath);
+ std::vector<String> collapsed = saved.split('\n');
+ foreach (const String& group, collapsed) {
+ collapsed_.insert(group);
+ }
+}
+
+const String RosterGroupExpandinessPersister::SettingPath = "GroupExpandiness";
+
+}