summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-12-22 21:00:48 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-12-22 21:15:38 (GMT)
commit308ff634379e73a0c8668ffb0593d23f95b4dfa5 (patch)
tree21b0dd5fd9cbd90e141fd32449e298b65a40e04c /Swift
parent333136df0bf355ef3ae3566f12bbdaf2795bcdaf (diff)
downloadswift-308ff634379e73a0c8668ffb0593d23f95b4dfa5.zip
swift-308ff634379e73a0c8668ffb0593d23f95b4dfa5.tar.bz2
Add a PreviousStatusStore.
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/PreviousStatusStore.cpp47
-rw-r--r--Swift/Controllers/PreviousStatusStore.h22
-rw-r--r--Swift/Controllers/SConscript4
-rw-r--r--Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp39
4 files changed, 111 insertions, 1 deletions
diff --git a/Swift/Controllers/PreviousStatusStore.cpp b/Swift/Controllers/PreviousStatusStore.cpp
new file mode 100644
index 0000000..42f2124
--- /dev/null
+++ b/Swift/Controllers/PreviousStatusStore.cpp
@@ -0,0 +1,47 @@
+#include "PreviousStatusStore.h"
+
+#include "Swiften/Base/foreach.h"
+
+namespace Swift {
+
+PreviousStatusStore::PreviousStatusStore() {
+
+}
+
+PreviousStatusStore::~PreviousStatusStore() {
+
+}
+
+void PreviousStatusStore::addStatus(StatusShow::Type status, const String& message) {
+ //FIXME: remove old entries
+ store_.push_back(TypeStringPair(status, message));
+}
+
+std::vector<TypeStringPair> PreviousStatusStore::exactMatchSuggestions(StatusShow::Type status, const String& message) {
+ std::vector<TypeStringPair> suggestions;
+ suggestions.push_back(TypeStringPair(status, message));
+ return suggestions;
+}
+
+std::vector<TypeStringPair> PreviousStatusStore::getSuggestions(const String& message) {
+ std::vector<TypeStringPair> suggestions;
+ foreach (TypeStringPair status, store_) {
+ if (status.second == message) {
+ suggestions.clear();
+ suggestions.push_back(status);
+ break;
+ } else if (status.second.contains(message)) {
+ suggestions.push_back(status);
+ }
+ }
+ if (suggestions.size() == 0) {
+ TypeStringPair suggestion(StatusShow::Online, message);
+ suggestions.push_back(suggestion);
+ }
+ if (suggestions.size() == 1) {
+ suggestions = exactMatchSuggestions(suggestions[0].first, suggestions[0].second);
+ }
+ return suggestions;
+}
+
+}
diff --git a/Swift/Controllers/PreviousStatusStore.h b/Swift/Controllers/PreviousStatusStore.h
new file mode 100644
index 0000000..476febe
--- /dev/null
+++ b/Swift/Controllers/PreviousStatusStore.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <utility> /* std::pair */
+#include <vector>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/StatusShow.h"
+
+namespace Swift {
+ typedef std::pair<StatusShow::Type, String> TypeStringPair;
+ class PreviousStatusStore {
+ public:
+ PreviousStatusStore();
+ ~PreviousStatusStore();
+ void addStatus(StatusShow::Type status, const String& message);
+ std::vector<TypeStringPair> getSuggestions(const String& message);
+
+ private:
+ std::vector<TypeStringPair> exactMatchSuggestions(StatusShow::Type status, const String& message);
+ std::vector<TypeStringPair> store_;
+ };
+}
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index 79357b5..02d0b52 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -21,10 +21,12 @@ myenv.StaticLibrary("SwiftControllers", [
"XMLConsoleController.cpp",
"UIEvents/UIEvent.cpp",
"UIInterfaces/XMLConsoleWidget.cpp",
+ "PreviousStatusStore.cpp",
])
env.Append(UNITTEST_SOURCES = [
File("UnitTest/NickResolverTest.cpp"),
File("UnitTest/RosterControllerTest.cpp"),
- File("UnitTest/XMPPRosterControllerTest.cpp")
+ File("UnitTest/XMPPRosterControllerTest.cpp"),
+ File("UnitTest/PreviousStatusStoreTest.cpp"),
])
diff --git a/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp b/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp
new file mode 100644
index 0000000..c9e55e4
--- /dev/null
+++ b/Swift/Controllers/UnitTest/PreviousStatusStoreTest.cpp
@@ -0,0 +1,39 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swift/Controllers/PreviousStatusStore.h"
+
+using namespace Swift;
+
+class PreviousStatusStoreTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(PreviousStatusStoreTest);
+ CPPUNIT_TEST(testGetAll);
+ //CPPUNIT_TEST(testGetAllLimited);
+ //CPPUNIT_TEST(testGetSuggestionsInexact);
+ //CPPUNIT_TEST(testGetSuggestionsExact);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ PreviousStatusStoreTest() {};
+
+ void setUp() {
+ store_ = new PreviousStatusStore();
+ store_->addStatus(StatusShow::Online, "At home in the study");
+ store_->addStatus(StatusShow::DND, "In a meeting");
+ store_->addStatus(StatusShow::DND, "With a client");
+ store_->addStatus(StatusShow::Away, "Walking the elephant");
+ store_->addStatus(StatusShow::Online, "In the office, at my desk");
+ }
+
+ void tearDown() {
+
+ }
+
+ void testGetAll() {
+
+ }
+
+private:
+ PreviousStatusStore* store_;
+};