From 30c3130def563b76c18f6bc91bd527ef1ba092be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Mon, 13 Sep 2010 21:24:55 +0200 Subject: Moved XMPPRosterController to Swiften. diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 6221f21..4cd9be4 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -35,7 +35,7 @@ #include "Swift/Controllers/SystemTray.h" #include "Swift/Controllers/SystemTrayController.h" #include "Swift/Controllers/XMLConsoleController.h" -#include "Swift/Controllers/XMPPRosterController.h" +#include "Swiften/Roster/XMPPRosterController.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" #include "Swift/Controllers/PresenceNotifier.h" #include "SwifTools/Dock/Dock.h" diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index 30c9590..41461bd 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -29,7 +29,6 @@ if env["SCONS_STAGE"] == "build" : "MainController.cpp", "NickResolver.cpp", "RosterController.cpp", - "XMPPRosterController.cpp", "EventController.cpp", "EventWindowController.cpp", "SoundEventController.cpp", @@ -46,7 +45,6 @@ if env["SCONS_STAGE"] == "build" : env.Append(UNITTEST_SOURCES = [ File("UnitTest/NickResolverTest.cpp"), File("UnitTest/RosterControllerTest.cpp"), - File("UnitTest/XMPPRosterControllerTest.cpp"), File("UnitTest/PreviousStatusStoreTest.cpp"), File("UnitTest/PresenceNotifierTest.cpp"), File("Chat/UnitTest/ChatsManagerTest.cpp"), diff --git a/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp b/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp deleted file mode 100644 index 6787528..0000000 --- a/Swift/Controllers/UnitTest/XMPPRosterControllerTest.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include -#include - -#include "Swift/Controllers/XMPPRosterController.h" -#include "Swiften/Elements/Payload.h" -#include "Swiften/Elements/RosterItemPayload.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Queries/DummyIQChannel.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Roster/XMPPRoster.h" - -using namespace Swift; - -class XMPPRosterControllerTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(XMPPRosterControllerTest); - CPPUNIT_TEST(testAdd); - CPPUNIT_TEST(testModify); - CPPUNIT_TEST(testRemove); - CPPUNIT_TEST_SUITE_END(); - - public: - XMPPRosterControllerTest() {} - - void setUp() { - channel_ = new DummyIQChannel(); - router_ = new IQRouter(channel_); - xmppRoster_ = new XMPPRoster(); - } - - void tearDown() { - delete channel_; - delete router_; - } - - void testAdd() { - XMPPRosterController controller(router_, xmppRoster_); - - boost::shared_ptr payload(new RosterPayload()); - payload->addItem(RosterItemPayload(JID("foo@bar.com"), "Bob", RosterItemPayload::Both)); - channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "eou", payload)); - - CPPUNIT_ASSERT(xmppRoster_->containsJID(JID("foo@bar.com"))); - CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com"))); - } - - void testModify() { - XMPPRosterController controller(router_, xmppRoster_); - boost::shared_ptr payload1(new RosterPayload()); - payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); - channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); - - boost::shared_ptr payload2(new RosterPayload()); - payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob2", RosterItemPayload::Both)); - channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); - - CPPUNIT_ASSERT_EQUAL(String("Bob2"), xmppRoster_->getNameForJID(JID("foo@bar"))); - } - - void testRemove() { - XMPPRosterController controller(router_, xmppRoster_); - boost::shared_ptr payload1(new RosterPayload()); - payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); - channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); - - boost::shared_ptr payload2(new RosterPayload()); - payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Remove)); - channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); - CPPUNIT_ASSERT(!xmppRoster_->containsJID(JID("foo@bar"))); - } - - private: - DummyIQChannel* channel_; - IQRouter* router_; - XMPPRoster* xmppRoster_; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterControllerTest); - - diff --git a/Swift/Controllers/XMPPRosterController.cpp b/Swift/Controllers/XMPPRosterController.cpp deleted file mode 100644 index c3144b7..0000000 --- a/Swift/Controllers/XMPPRosterController.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include "Swift/Controllers/XMPPRosterController.h" - -#include - -#include "Swiften/Base/foreach.h" -#include "Swiften/Elements/RosterItemPayload.h" -#include "Swiften/Queries/IQRouter.h" -#include "Swiften/Queries/Requests/GetRosterRequest.h" -#include "Swiften/EventLoop/MainEventLoop.h" -#include "Swiften/Roster/Roster.h" -#include "Swiften/Roster/SetPresence.h" -#include "Swiften/Roster/OfflineRosterFilter.h" -#include "Swiften/Roster/XMPPRoster.h" - -namespace Swift { - -/** - * The controller does not gain ownership of these parameters. - */ -XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, XMPPRoster* xmppRoster) : iqRouter_(iqRouter), rosterPushResponder_(iqRouter), xmppRoster_(xmppRoster) { - rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1)); -} - -void XMPPRosterController::requestRoster() { - xmppRoster_->clear(); - boost::shared_ptr rosterRequest(new GetRosterRequest(iqRouter_)); - rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1)); - rosterRequest->send(); -} - -void XMPPRosterController::handleRosterReceived(boost::shared_ptr rosterPayload) { - foreach(const RosterItemPayload& item, rosterPayload->getItems()) { - //Don't worry about the updated case, the XMPPRoster sorts that out. - if (item.getSubscription() == RosterItemPayload::Remove) { - xmppRoster_->removeContact(item.getJID()); - } else { - xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription()); - } - } -} - -} diff --git a/Swift/Controllers/XMPPRosterController.h b/Swift/Controllers/XMPPRosterController.h deleted file mode 100644 index 14159c7..0000000 --- a/Swift/Controllers/XMPPRosterController.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swiften/JID/JID.h" -#include "Swiften/Base/String.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Queries/Responders/RosterPushResponder.h" - -#include "Swiften/Base/boost_bsignals.h" -#include - -namespace Swift { - class IQRouter; - class XMPPRoster; - - class XMPPRosterController { - public: - XMPPRosterController(IQRouter *iqRouter, XMPPRoster* xmppRoster); - - void requestRoster(); - - void handleRosterReceived(boost::shared_ptr rosterPayload); - - private: - IQRouter* iqRouter_; - RosterPushResponder rosterPushResponder_; - XMPPRoster* xmppRoster_; - }; -} - diff --git a/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp new file mode 100644 index 0000000..7e76d3a --- /dev/null +++ b/Swiften/Roster/UnitTest/XMPPRosterControllerTest.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include +#include + +#include "Swiften/Roster/XMPPRosterController.h" +#include "Swiften/Elements/Payload.h" +#include "Swiften/Elements/RosterItemPayload.h" +#include "Swiften/Elements/RosterPayload.h" +#include "Swiften/Queries/DummyIQChannel.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Roster/XMPPRoster.h" + +using namespace Swift; + +class XMPPRosterControllerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(XMPPRosterControllerTest); + CPPUNIT_TEST(testAdd); + CPPUNIT_TEST(testModify); + CPPUNIT_TEST(testRemove); + CPPUNIT_TEST_SUITE_END(); + + public: + XMPPRosterControllerTest() {} + + void setUp() { + channel_ = new DummyIQChannel(); + router_ = new IQRouter(channel_); + xmppRoster_ = new XMPPRoster(); + } + + void tearDown() { + delete channel_; + delete router_; + } + + void testAdd() { + XMPPRosterController controller(router_, xmppRoster_); + + boost::shared_ptr payload(new RosterPayload()); + payload->addItem(RosterItemPayload(JID("foo@bar.com"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "eou", payload)); + + CPPUNIT_ASSERT(xmppRoster_->containsJID(JID("foo@bar.com"))); + CPPUNIT_ASSERT_EQUAL(String("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com"))); + } + + void testModify() { + XMPPRosterController controller(router_, xmppRoster_); + boost::shared_ptr payload1(new RosterPayload()); + payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); + + boost::shared_ptr payload2(new RosterPayload()); + payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob2", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); + + CPPUNIT_ASSERT_EQUAL(String("Bob2"), xmppRoster_->getNameForJID(JID("foo@bar"))); + } + + void testRemove() { + XMPPRosterController controller(router_, xmppRoster_); + boost::shared_ptr payload1(new RosterPayload()); + payload1->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Both)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id1", payload1)); + + boost::shared_ptr payload2(new RosterPayload()); + payload2->addItem(RosterItemPayload(JID("foo@bar"), "Bob", RosterItemPayload::Remove)); + channel_->onIQReceived(IQ::createRequest(IQ::Set, JID(), "id2", payload2)); + CPPUNIT_ASSERT(!xmppRoster_->containsJID(JID("foo@bar"))); + } + + private: + DummyIQChannel* channel_; + IQRouter* router_; + XMPPRoster* xmppRoster_; +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(XMPPRosterControllerTest); + + diff --git a/Swiften/Roster/XMPPRosterController.cpp b/Swiften/Roster/XMPPRosterController.cpp new file mode 100644 index 0000000..dca74c0 --- /dev/null +++ b/Swiften/Roster/XMPPRosterController.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Roster/XMPPRosterController.h" + +#include + +#include "Swiften/Base/foreach.h" +#include "Swiften/Elements/RosterItemPayload.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Queries/Requests/GetRosterRequest.h" +#include "Swiften/EventLoop/MainEventLoop.h" +#include "Swiften/Roster/Roster.h" +#include "Swiften/Roster/SetPresence.h" +#include "Swiften/Roster/OfflineRosterFilter.h" +#include "Swiften/Roster/XMPPRoster.h" + +namespace Swift { + +/** + * The controller does not gain ownership of these parameters. + */ +XMPPRosterController::XMPPRosterController(IQRouter* iqRouter, XMPPRoster* xmppRoster) : iqRouter_(iqRouter), rosterPushResponder_(iqRouter), xmppRoster_(xmppRoster) { + rosterPushResponder_.onRosterReceived.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1)); +} + +void XMPPRosterController::requestRoster() { + xmppRoster_->clear(); + boost::shared_ptr rosterRequest(new GetRosterRequest(iqRouter_)); + rosterRequest->onResponse.connect(boost::bind(&XMPPRosterController::handleRosterReceived, this, _1)); + rosterRequest->send(); +} + +void XMPPRosterController::handleRosterReceived(boost::shared_ptr rosterPayload) { + foreach(const RosterItemPayload& item, rosterPayload->getItems()) { + //Don't worry about the updated case, the XMPPRoster sorts that out. + if (item.getSubscription() == RosterItemPayload::Remove) { + xmppRoster_->removeContact(item.getJID()); + } else { + xmppRoster_->addContact(item.getJID(), item.getName(), item.getGroups(), item.getSubscription()); + } + } +} + +} diff --git a/Swiften/Roster/XMPPRosterController.h b/Swiften/Roster/XMPPRosterController.h new file mode 100644 index 0000000..3ef7795 --- /dev/null +++ b/Swiften/Roster/XMPPRosterController.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include "Swiften/JID/JID.h" +#include "Swiften/Base/String.h" +#include "Swiften/Elements/IQ.h" +#include "Swiften/Elements/RosterPayload.h" +#include "Swiften/Queries/Responders/RosterPushResponder.h" +#include "Swiften/Base/boost_bsignals.h" + +namespace Swift { + class IQRouter; + class XMPPRoster; + + class XMPPRosterController { + public: + XMPPRosterController(IQRouter *iqRouter, XMPPRoster* xmppRoster); + + void requestRoster(); + + void handleRosterReceived(boost::shared_ptr rosterPayload); + + private: + IQRouter* iqRouter_; + RosterPushResponder rosterPushResponder_; + XMPPRoster* xmppRoster_; + }; +} + diff --git a/Swiften/SConscript b/Swiften/SConscript index 11c976e..83306b7 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -56,6 +56,7 @@ if env["SCONS_STAGE"] == "build" : "Roster/RosterItem.cpp", "Roster/Roster.cpp", "Roster/XMPPRoster.cpp", + "Roster/XMPPRosterController.cpp", "Serializer/AuthRequestSerializer.cpp", "Serializer/AuthSuccessSerializer.cpp", "Serializer/AuthChallengeSerializer.cpp", @@ -204,6 +205,7 @@ if env["SCONS_STAGE"] == "build" : File("Roster/UnitTest/OfflineRosterFilterTest.cpp"), File("Roster/UnitTest/RosterTest.cpp"), File("Roster/UnitTest/XMPPRosterTest.cpp"), + File("Roster/UnitTest/XMPPRosterControllerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp"), File("Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp"), File("Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp"), -- cgit v0.10.2-6-g49f6