diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Avatars/AvatarManager.cpp | 9 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarManager.h | 3 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarProvider.cpp | 14 | ||||
-rw-r--r-- | Swiften/Avatars/AvatarProvider.h | 23 | ||||
-rw-r--r-- | Swiften/Avatars/SConscript | 10 | ||||
-rw-r--r-- | Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp | 22 | ||||
-rw-r--r-- | Swiften/Avatars/VCardUpdateAvatarManager.cpp | 10 | ||||
-rw-r--r-- | Swiften/Avatars/VCardUpdateAvatarManager.h | 12 | ||||
-rw-r--r-- | Swiften/SConscript | 5 |
9 files changed, 72 insertions, 36 deletions
diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp index cd691c0..9c3255d 100644 --- a/Swiften/Avatars/AvatarManager.cpp +++ b/Swiften/Avatars/AvatarManager.cpp @@ -9,10 +9,11 @@ #include <boost/bind.hpp> #include "Swiften/Avatars/VCardUpdateAvatarManager.h" +#include "Swiften/Avatars/AvatarStorage.h" namespace Swift { -AvatarManager::AvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) { +AvatarManager::AvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : avatarStorage(avatarStorage) { vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry); vcardUpdateAvatarManager->onAvatarChanged.connect(boost::ref(onAvatarChanged)); } @@ -22,7 +23,11 @@ AvatarManager::~AvatarManager() { } boost::filesystem::path AvatarManager::getAvatarPath(const JID& jid) const { - return vcardUpdateAvatarManager->getAvatarPath(jid); + String hash = vcardUpdateAvatarManager->getAvatarHash(jid); + if (!hash.isEmpty()) { + return avatarStorage->getAvatarPath(hash); + } + return boost::filesystem::path(); } diff --git a/Swiften/Avatars/AvatarManager.h b/Swiften/Avatars/AvatarManager.h index 90f0076..d3cdbae 100644 --- a/Swiften/Avatars/AvatarManager.h +++ b/Swiften/Avatars/AvatarManager.h @@ -32,9 +32,10 @@ namespace Swift { virtual boost::filesystem::path getAvatarPath(const JID&) const; public: - boost::signal<void (const JID&, const String& /*hash*/)> onAvatarChanged; + boost::signal<void (const JID&)> onAvatarChanged; private: VCardUpdateAvatarManager* vcardUpdateAvatarManager; + AvatarStorage* avatarStorage; }; } diff --git a/Swiften/Avatars/AvatarProvider.cpp b/Swiften/Avatars/AvatarProvider.cpp new file mode 100644 index 0000000..680b58d --- /dev/null +++ b/Swiften/Avatars/AvatarProvider.cpp @@ -0,0 +1,14 @@ +/* + * 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/AvatarProvider.h" + +namespace Swift { + +AvatarProvider::~AvatarProvider() { +} + +} diff --git a/Swiften/Avatars/AvatarProvider.h b/Swiften/Avatars/AvatarProvider.h new file mode 100644 index 0000000..b953ad3 --- /dev/null +++ b/Swiften/Avatars/AvatarProvider.h @@ -0,0 +1,23 @@ +/* + * 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/Base/boost_bsignals.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class JID; + + class AvatarProvider { + public: + virtual ~AvatarProvider(); + + virtual String getAvatarHash(const JID&) const = 0; + + boost::signal<void (const JID&)> onAvatarChanged; + }; +} diff --git a/Swiften/Avatars/SConscript b/Swiften/Avatars/SConscript new file mode 100644 index 0000000..f9ce320 --- /dev/null +++ b/Swiften/Avatars/SConscript @@ -0,0 +1,10 @@ +Import("swiften_env") + +objects = swiften_env.StaticObject([ + "AvatarFileStorage.cpp", + "VCardUpdateAvatarManager.cpp", + "AvatarManager.cpp", + "AvatarStorage.cpp", + "AvatarProvider.cpp", + ]) +swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp index 5a98a0e..3e8dbdf 100644 --- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp @@ -70,8 +70,8 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { stanzaChannel->onIQReceived(createVCardResult(avatar1)); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); - CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0].first); - CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); + CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0]); + CPPUNIT_ASSERT_EQUAL(avatar1Hash, testling->getAvatarHash(user1.toBare())); CPPUNIT_ASSERT(avatarStorage->hasAvatar(avatar1Hash)); CPPUNIT_ASSERT_EQUAL(avatar1, avatarStorage->getAvatar(avatar1Hash)); } @@ -100,8 +100,8 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel->sentStanzas.size())); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); - CPPUNIT_ASSERT_EQUAL(user2.toBare(), changes[0].first); - CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); + CPPUNIT_ASSERT_EQUAL(user2.toBare(), changes[0]); + CPPUNIT_ASSERT_EQUAL(avatar1Hash, testling->getAvatarHash(user2.toBare())); } void testVCardWithEmptyPhoto() { @@ -110,7 +110,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { stanzaChannel->onIQReceived(createVCardResult(ByteArray())); CPPUNIT_ASSERT(!avatarStorage->hasAvatar(Hexify::hexify(SHA1::getHash(ByteArray())))); - CPPUNIT_ASSERT_EQUAL(boost::filesystem::path(), testling->getAvatarPath(JID("foo@bar.com"))); + CPPUNIT_ASSERT_EQUAL(String(), testling->getAvatarHash(JID("foo@bar.com"))); } void testStanzaChannelReset() { @@ -125,14 +125,14 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size())); - CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0].first); - CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); + CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0]); + CPPUNIT_ASSERT_EQUAL(avatar1Hash, testling->getAvatarHash(user1.toBare())); } private: std::auto_ptr<VCardUpdateAvatarManager> createManager() { std::auto_ptr<VCardUpdateAvatarManager> result(new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry)); - result->onAvatarChanged.connect(boost::bind(&VCardUpdateAvatarManagerTest::handleAvatarChanged, this, _1, _2)); + result->onAvatarChanged.connect(boost::bind(&VCardUpdateAvatarManagerTest::handleAvatarChanged, this, _1)); return result; } @@ -151,8 +151,8 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { return IQ::createResult(JID("baz@fum.com"), stanzaChannel->sentStanzas[0]->getID(), vcard); } - void handleAvatarChanged(const JID& jid, const String& hash) { - changes.push_back(std::pair<JID,String>(jid, hash)); + void handleAvatarChanged(const JID& jid) { + changes.push_back(jid); } private: @@ -170,7 +170,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { VCardMemoryStorage* vcardStorage; ByteArray avatar1; String avatar1Hash; - std::vector<std::pair<JID,String> > changes; + std::vector<JID> changes; JID user1; JID user2; }; diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index 24abfa1..9d0ae2d 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -64,7 +64,7 @@ void VCardUpdateAvatarManager::handleVCardChanged(const JID& from, VCard::ref vC void VCardUpdateAvatarManager::setAvatarHash(const JID& from, const String& hash) { avatarHashes_[from] = hash; - onAvatarChanged(from, hash); + onAvatarChanged(from); } /* @@ -85,14 +85,6 @@ String VCardUpdateAvatarManager::getAvatarHash(const JID& jid) const { } } -boost::filesystem::path VCardUpdateAvatarManager::getAvatarPath(const JID& jid) const { - String hash = getAvatarHash(jid); - if (!hash.isEmpty()) { - return avatarStorage_->getAvatarPath(hash); - } - return boost::filesystem::path(); -} - JID VCardUpdateAvatarManager::getAvatarJID(const JID& jid) const { JID bareFrom = jid.toBare(); return (mucRegistry_ && mucRegistry_->isMUC(bareFrom)) ? jid : bareFrom; diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.h b/Swiften/Avatars/VCardUpdateAvatarManager.h index e29db1c..2220906 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.h +++ b/Swiften/Avatars/VCardUpdateAvatarManager.h @@ -6,12 +6,10 @@ #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/Avatars/AvatarProvider.h" #include "Swiften/JID/JID.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Elements/VCard.h" @@ -23,15 +21,12 @@ namespace Swift { class StanzaChannel; class VCardManager; - class VCardUpdateAvatarManager { + class VCardUpdateAvatarManager : public AvatarProvider { public: VCardUpdateAvatarManager(VCardManager*, StanzaChannel*, AvatarStorage*, MUCRegistry* = NULL); virtual ~VCardUpdateAvatarManager(); - virtual boost::filesystem::path getAvatarPath(const JID&) const; - - public: - boost::signal<void (const JID&, const String& /*hash*/)> onAvatarChanged; + String getAvatarHash(const JID&) const; private: void handlePresenceReceived(boost::shared_ptr<Presence>); @@ -39,7 +34,6 @@ namespace Swift { void handleVCardChanged(const JID& from, VCard::ref); void setAvatarHash(const JID& from, const String& hash); JID getAvatarJID(const JID& o) const; - String getAvatarHash(const JID&) const; private: VCardManager* vcardManager_; diff --git a/Swiften/SConscript b/Swiften/SConscript index a9e3a01..f19698e 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -24,10 +24,6 @@ if env["SCONS_STAGE"] == "build" : myenv.MergeFlags(myenv["ZLIB_FLAGS"]) myenv.MergeFlags(myenv["OPENSSL_FLAGS"]) sources = [ - "Avatars/AvatarFileStorage.cpp", - "Avatars/VCardUpdateAvatarManager.cpp", - "Avatars/AvatarManager.cpp", - "Avatars/AvatarStorage.cpp", "Chat/ChatStateTracker.cpp", "Chat/ChatStateNotifier.cpp", "Chat/ChatStateMessageSender.cpp", @@ -117,6 +113,7 @@ if env["SCONS_STAGE"] == "build" : sources += ["TLS/OpenSSL/OpenSSLContext.cpp"] SConscript(dirs = [ + "Avatars", "Base", "StringPrep", "SASL", |