diff options
Diffstat (limited to 'Swiften')
-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 |
7 files changed, 117 insertions, 64 deletions
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); |