diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-09-10 13:16:00 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-09-11 21:53:46 (GMT) |
commit | bc6a510af449b6e383a11fc20c9859b8bcac247c (patch) | |
tree | 70288194b0f75d9d268c2ac94d70291d988a0bf4 | |
parent | 8bdc3c2e2e520407027ac3a3e09d7af8054a0e5b (diff) | |
download | swift-bc6a510af449b6e383a11fc20c9859b8bcac247c.zip swift-bc6a510af449b6e383a11fc20c9859b8bcac247c.tar.bz2 |
Make AvatarManager abstract
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | 13 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.h | 1 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/RosterControllerTest.cpp | 3 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarManager.cpp | 30 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarManager.h | 25 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarManagerImpl.cpp | 43 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarManagerImpl.h | 43 | ||||
-rw-r--r-- | Swiften/Avatars/NullAvatarManager.h | 18 | ||||
-rw-r--r-- | Swiften/Avatars/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Roster/UnitTest/RosterTest.cpp | 21 |
11 files changed, 124 insertions, 78 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 4b95948..ffd5185 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -18,7 +18,7 @@ #include "Swift/Controllers/EventController.h" #include "Swift/Controllers/Chat/MUCController.h" #include "Swiften/Presence/PresenceSender.h" -#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Avatars/NullAvatarManager.h" #include "Swiften/Avatars/AvatarMemoryStorage.h" #include "Swiften/VCards/VCardManager.h" #include "Swiften/VCards/VCardMemoryStorage.h" @@ -70,18 +70,12 @@ public: mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createWindow).With(uiEventStream_).Return(NULL); manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, nickResolver_, presenceOracle_, serverDiscoInfo_, presenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_); - vcardStorage_ = new VCardMemoryStorage(); - vcardManager_ = new VCardManager(jid_, iqRouter_, vcardStorage_); - avatarStorage_ = new AvatarMemoryStorage(); - avatarManager_ = new AvatarManager(vcardManager_, stanzaChannel_, avatarStorage_, NULL); + avatarManager_ = new NullAvatarManager(); manager_->setAvatarManager(avatarManager_); }; void tearDown() { delete avatarManager_; - delete avatarStorage_; - delete vcardManager_; - delete vcardStorage_; delete manager_; delete presenceSender_; delete presenceOracle_; @@ -315,9 +309,6 @@ private: ChatWindowFactory* chatWindowFactory_; NickResolver* nickResolver_; PresenceOracle* presenceOracle_; - VCardStorage* vcardStorage_; - VCardManager* vcardManager_; - AvatarStorage* avatarStorage_; AvatarManager* avatarManager_; boost::shared_ptr<DiscoInfo> serverDiscoInfo_; boost::shared_ptr<XMPPRoster> xmppRoster_; diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index f3bd6d5..afffa59 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -54,7 +54,7 @@ #include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" #include "Swiften/Queries/Requests/GetVCardRequest.h" #include "Swiften/Avatars/AvatarStorage.h" -#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Avatars/AvatarManagerImpl.h" #include "Swiften/Disco/CapsFileStorage.h" #include "Swiften/Disco/CapsManager.h" #include "Swiften/Disco/EntityCapsManager.h" @@ -243,7 +243,7 @@ void MainController::handleConnected() { mucRegistry_ = new MUCRegistry(); vcardManager_ = new VCardManager(jid_, client_, getVCardStorageForProfile(jid_)); vcardManager_->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2)); - avatarManager_ = new AvatarManager(vcardManager_, client_, avatarStorage_, mucRegistry_); + avatarManager_ = new AvatarManagerImpl(vcardManager_, client_, avatarStorage_, mucRegistry_); capsManager_ = new CapsManager(capsStorage_, client_, client_); entityCapsManager_ = new EntityCapsManager(capsManager_, client_); diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index ba8d4e2..389df44 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -10,6 +10,7 @@ #include "Swiften/JID/JID.h" #include "Swiften/Base/String.h" #include "Swiften/Elements/Presence.h" +#include "Swiften/Elements/ErrorPayload.h" #include "Swiften/Elements/RosterPayload.h" #include "Swiften/Avatars/AvatarManager.h" #include "Swift/Controllers/UIEvents/UIEvent.h" diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp index 23fca2c..fdcc44f 100644 --- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp @@ -20,6 +20,7 @@ #include "Swiften/Roster/Roster.h" #include "Swiften/Roster/GroupRosterItem.h" #include "Swiften/Roster/ContactRosterItem.h" +#include "Swiften/Avatars/NullAvatarManager.h" #include "Swift/Controllers/EventController.h" #include "Swiften/Presence/PresenceOracle.h" #include "Swift/Controllers/NickResolver.h" @@ -43,7 +44,7 @@ class RosterControllerTest : public CppUnit::TestFixture void setUp() { jid_ = JID("testjid@swift.im/swift"); xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster()); - avatarManager_ = NULL;//new AvatarManager(); + avatarManager_ = new NullAvatarManager(); mainWindowFactory_ = new MockMainWindowFactory(); mucRegistry_ = new MUCRegistry(); nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, NULL, mucRegistry_); diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp index 6ad39fb..a2b7200 100644 --- a/Swiften/Avatars/AvatarManager.cpp +++ b/Swiften/Avatars/AvatarManager.cpp @@ -6,39 +6,9 @@ #include "Swiften/Avatars/AvatarManager.h" -#include <boost/bind.hpp> - -#include "Swiften/Avatars/VCardUpdateAvatarManager.h" -#include "Swiften/Avatars/VCardAvatarManager.h" -#include "Swiften/Avatars/AvatarStorage.h" - namespace Swift { -AvatarManager::AvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : avatarStorage(avatarStorage) { - vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry); - combinedAvatarProvider.addProvider(vcardUpdateAvatarManager); - - vcardAvatarManager = new VCardAvatarManager(vcardManager, avatarStorage, mucRegistry); - combinedAvatarProvider.addProvider(vcardAvatarManager); - - combinedAvatarProvider.onAvatarChanged.connect(boost::ref(onAvatarChanged)); -} - AvatarManager::~AvatarManager() { - combinedAvatarProvider.removeProvider(vcardAvatarManager); - delete vcardAvatarManager; - combinedAvatarProvider.removeProvider(vcardUpdateAvatarManager); - delete vcardUpdateAvatarManager; -} - -boost::filesystem::path AvatarManager::getAvatarPath(const JID& jid) const { - String hash = combinedAvatarProvider.getAvatarHash(jid); - if (!hash.isEmpty()) { - std::cout << "getAvatar " << jid << " " << avatarStorage->getAvatarPath(hash) << std::endl; - return avatarStorage->getAvatarPath(hash); - } - return boost::filesystem::path(); } - } diff --git a/Swiften/Avatars/AvatarManager.h b/Swiften/Avatars/AvatarManager.h index 0309b20..74e58f7 100644 --- a/Swiften/Avatars/AvatarManager.h +++ b/Swiften/Avatars/AvatarManager.h @@ -7,39 +7,18 @@ #pragma once #include <boost/filesystem.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/optional.hpp> -#include <map> #include "Swiften/Base/boost_bsignals.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/VCard.h" -#include "Swiften/Elements/ErrorPayload.h" -#include "Swiften/Avatars/CombinedAvatarProvider.h" namespace Swift { - class MUCRegistry; - class AvatarStorage; - class StanzaChannel; - class VCardManager; - class VCardUpdateAvatarManager; - class VCardAvatarManager; + class JID; class AvatarManager { public: - AvatarManager(VCardManager*, StanzaChannel*, AvatarStorage*, MUCRegistry* = NULL); virtual ~AvatarManager(); - virtual boost::filesystem::path getAvatarPath(const JID&) const; + virtual boost::filesystem::path getAvatarPath(const JID&) const = 0; - public: boost::signal<void (const JID&)> onAvatarChanged; - - private: - CombinedAvatarProvider combinedAvatarProvider; - AvatarStorage* avatarStorage; - VCardUpdateAvatarManager* vcardUpdateAvatarManager; - VCardAvatarManager* vcardAvatarManager; }; } diff --git a/Swiften/Avatars/AvatarManagerImpl.cpp b/Swiften/Avatars/AvatarManagerImpl.cpp new file mode 100644 index 0000000..384994b --- /dev/null +++ b/Swiften/Avatars/AvatarManagerImpl.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Avatars/AvatarManagerImpl.h" + +#include <boost/bind.hpp> + +#include "Swiften/Avatars/VCardUpdateAvatarManager.h" +#include "Swiften/Avatars/VCardAvatarManager.h" +#include "Swiften/Avatars/AvatarStorage.h" + +namespace Swift { + +AvatarManagerImpl::AvatarManagerImpl(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : avatarStorage(avatarStorage) { + vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry); + combinedAvatarProvider.addProvider(vcardUpdateAvatarManager); + + vcardAvatarManager = new VCardAvatarManager(vcardManager, avatarStorage, mucRegistry); + combinedAvatarProvider.addProvider(vcardAvatarManager); + + combinedAvatarProvider.onAvatarChanged.connect(boost::ref(onAvatarChanged)); +} + +AvatarManagerImpl::~AvatarManagerImpl() { + combinedAvatarProvider.removeProvider(vcardAvatarManager); + delete vcardAvatarManager; + combinedAvatarProvider.removeProvider(vcardUpdateAvatarManager); + delete vcardUpdateAvatarManager; +} + +boost::filesystem::path AvatarManagerImpl::getAvatarPath(const JID& jid) const { + String hash = combinedAvatarProvider.getAvatarHash(jid); + if (!hash.isEmpty()) { + return avatarStorage->getAvatarPath(hash); + } + return boost::filesystem::path(); +} + + +} diff --git a/Swiften/Avatars/AvatarManagerImpl.h b/Swiften/Avatars/AvatarManagerImpl.h new file mode 100644 index 0000000..f533160 --- /dev/null +++ b/Swiften/Avatars/AvatarManagerImpl.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <boost/filesystem.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/optional.hpp> +#include <map> + +#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Base/boost_bsignals.h" +#include "Swiften/JID/JID.h" +#include "Swiften/Elements/Presence.h" +#include "Swiften/Elements/VCard.h" +#include "Swiften/Elements/ErrorPayload.h" +#include "Swiften/Avatars/CombinedAvatarProvider.h" + +namespace Swift { + class MUCRegistry; + class AvatarStorage; + class StanzaChannel; + class VCardManager; + class VCardUpdateAvatarManager; + class VCardAvatarManager; + + class AvatarManagerImpl : public AvatarManager { + public: + AvatarManagerImpl(VCardManager*, StanzaChannel*, AvatarStorage*, MUCRegistry* = NULL); + virtual ~AvatarManagerImpl(); + + virtual boost::filesystem::path getAvatarPath(const JID&) const; + + private: + CombinedAvatarProvider combinedAvatarProvider; + AvatarStorage* avatarStorage; + VCardUpdateAvatarManager* vcardUpdateAvatarManager; + VCardAvatarManager* vcardAvatarManager; + }; +} diff --git a/Swiften/Avatars/NullAvatarManager.h b/Swiften/Avatars/NullAvatarManager.h new file mode 100644 index 0000000..7f3c646 --- /dev/null +++ b/Swiften/Avatars/NullAvatarManager.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Avatars/AvatarManager.h" + +namespace Swift { + class NullAvatarManager : public AvatarManager { + public: + virtual boost::filesystem::path getAvatarPath(const JID&) const { + return boost::filesystem::path(); + } + }; +} diff --git a/Swiften/Avatars/SConscript b/Swiften/Avatars/SConscript index 60bee08..7922a51 100644 --- a/Swiften/Avatars/SConscript +++ b/Swiften/Avatars/SConscript @@ -5,6 +5,7 @@ objects = swiften_env.StaticObject([ "VCardUpdateAvatarManager.cpp", "VCardAvatarManager.cpp", "AvatarManager.cpp", + "AvatarManagerImpl.cpp", "AvatarStorage.cpp", "AvatarProvider.cpp", "CombinedAvatarProvider.cpp", diff --git a/Swiften/Roster/UnitTest/RosterTest.cpp b/Swiften/Roster/UnitTest/RosterTest.cpp index 9c8e65b..0300188 100644 --- a/Swiften/Roster/UnitTest/RosterTest.cpp +++ b/Swiften/Roster/UnitTest/RosterTest.cpp @@ -14,8 +14,7 @@ using namespace Swift; -class RosterTest : public CppUnit::TestFixture -{ +class RosterTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RosterTest); CPPUNIT_TEST(testGetGroup); CPPUNIT_TEST(testRemoveContact); @@ -24,17 +23,11 @@ class RosterTest : public CppUnit::TestFixture CPPUNIT_TEST(testApplyPresenceLikeMUC); CPPUNIT_TEST_SUITE_END(); - private: - Roster *roster_; - JID jid1_; - JID jid2_; - JID jid3_; - public: - - RosterTest() : jid1_(JID("a@b.c")), jid2_(JID("b@c.d")), jid3_(JID("c@d.e")) {} - void setUp() { + jid1_ = JID("a@b.c"); + jid2_ = JID("b@c.d"); + jid3_ = JID("c@d.e"); roster_ = new Roster(); } @@ -124,6 +117,12 @@ class RosterTest : public CppUnit::TestFixture } + private: + Roster *roster_; + JID jid1_; + JID jid2_; + JID jid3_; }; + CPPUNIT_TEST_SUITE_REGISTRATION(RosterTest); |