diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-08-22 08:55:08 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-08-24 17:10:23 (GMT) |
commit | b6a34463dfcedd454ab42230a47cdb7294a76f21 (patch) | |
tree | 832b0243325451932c0d15e9e33d53948fce0110 /Swift | |
parent | 6e4b357141a6d09632f1e96d0eaf54f79daf52c9 (diff) | |
download | swift-b6a34463dfcedd454ab42230a47cdb7294a76f21.zip swift-b6a34463dfcedd454ab42230a47cdb7294a76f21.tar.bz2 |
Implemented VCardManager.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | 17 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 46 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 11 |
3 files changed, 54 insertions, 20 deletions
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 2204366..d5686bd 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -18,7 +18,10 @@ #include "Swift/Controllers/EventController.h" #include "Swift/Controllers/Chat/MUCController.h" #include "Swiften/Presence/PresenceSender.h" -#include "Swiften/Avatars/UnitTest/MockAvatarManager.h" +#include "Swiften/Avatars/AvatarManager.h" +#include "Swiften/Avatars/AvatarMemoryStorage.h" +#include "Swiften/VCards/VCardManager.h" +#include "Swiften/VCards/VCardMemoryStorage.h" #include "Swift/Controllers/NickResolver.h" #include "Swiften/Roster/XMPPRoster.h" #include "Swift/Controllers/UnitTest/MockChatWindow.h" @@ -65,12 +68,19 @@ public: chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>(); 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); - avatarManager_ = new MockAvatarManager(); + + vcardStorage_ = new VCardMemoryStorage(); + vcardManager_ = new VCardManager(jid_, iqRouter_, vcardStorage_); + avatarStorage_ = new AvatarMemoryStorage(); + avatarManager_ = new AvatarManager(vcardManager_, stanzaChannel_, avatarStorage_, NULL); manager_->setAvatarManager(avatarManager_); }; void tearDown() { delete avatarManager_; + delete avatarStorage_; + delete vcardManager_; + delete vcardStorage_; delete manager_; delete presenceSender_; delete presenceOracle_; @@ -303,6 +313,9 @@ 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 6eb3a2c..1032de1 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -20,6 +20,8 @@ #include "Swift/Controllers/BuildVersion.h" #include "Swift/Controllers/Chat/ChatController.h" #include "Swiften/VCards/VCardStorageFactory.h" +#include "Swiften/VCards/VCardManager.h" +#include "Swiften/VCards/VCardStorage.h" #include "Swift/Controllers/Chat/MUCSearchController.h" #include "Swift/Controllers/Chat/ChatsManager.h" #include "Swift/Controllers/EventController.h" @@ -85,16 +87,16 @@ MainController::MainController( mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), settings_(settings), - loginWindow_(NULL), vcardStorageFactory_(vcardStorageFactory), - useDelayForLatency_(useDelayForLatency) { + loginWindow_(NULL) , + useDelayForLatency_(useDelayForLatency) { presenceOracle_ = NULL; - avatarManager_ = NULL; chatsManager_ = NULL; eventController_ = NULL; eventWindowController_ = NULL; nickResolver_ = NULL; avatarManager_ = NULL; + vcardManager_ = NULL; rosterController_ = NULL; xmppRosterController_ = NULL; clientVersionResponder_ = NULL; @@ -153,11 +155,13 @@ MainController::MainController( MainController::~MainController() { delete systemTrayController_; delete soundEventController_; - delete avatarStorage_; delete xmlConsoleController_; delete uiEventStream_; delete eventController_; resetClient(); + for(VCardStorageMap::iterator i = vcardStorages_.begin(); i != vcardStorages_.end(); ++i) { + delete i->second; + } } void MainController::resetClient() { @@ -173,6 +177,8 @@ void MainController::resetClient() { nickResolver_ = NULL; delete avatarManager_; avatarManager_ = NULL; + delete vcardManager_; + vcardManager_ = NULL; delete eventWindowController_; eventWindowController_ = NULL; delete rosterController_; @@ -223,7 +229,9 @@ void MainController::handleConnected() { presenceOracle_ = new PresenceOracle(client_); nickResolver_ = new NickResolver(xmppRoster_); - avatarManager_ = new AvatarManager(client_, client_, avatarStorage_); + vcardManager_ = new VCardManager(jid_, client_, getVCardStorageForProfile(jid_)); + vcardManager_->onOwnVCardChanged.connect(boost::bind(&MainController::handleOwnVCardReceived, this, _1)); + avatarManager_ = new AvatarManager(vcardManager_, client_, avatarStorage_); rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickResolver_, presenceOracle_, eventController_, uiEventStream_, client_); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); @@ -261,10 +269,7 @@ void MainController::handleConnected() { discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2)); discoInfoRequest->send(); - boost::shared_ptr<GetVCardRequest> vCardRequest(new GetVCardRequest(JID(), client_)); - vCardRequest->onResponse.connect(boost::bind(&MainController::handleOwnVCardReceived, this, _1, _2)); - vCardRequest->send(); - + vcardManager_->requestOwnVCard(); setManagersEnabled(true); //Send presence last to catch all the incoming presences. @@ -480,17 +485,24 @@ void MainController::handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> } } -void MainController::handleOwnVCardReceived(boost::shared_ptr<VCard> vCard, const boost::optional<ErrorPayload>& error) { - if (!vCard) { +void MainController::handleOwnVCardReceived(VCard::ref vCard) { + if (!vCard || vCard->getPhoto().isEmpty()) { return; } - if (!error && !vCard->getPhoto().isEmpty()) { - vCardPhotoHash_ = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); - if (client_ && client_->isAvailable()) { - sendPresence(statusTracker_->getNextPresence()); - } - avatarManager_->setAvatar(jid_, vCard->getPhoto()); + vCardPhotoHash_ = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); + if (client_ && client_->isAvailable()) { + sendPresence(statusTracker_->getNextPresence()); } } +VCardStorage* MainController::getVCardStorageForProfile(const JID& jid) { + String profile = jid.toBare().toString(); + std::pair<VCardStorageMap::iterator, bool> r = vcardStorages_.insert(std::make_pair<String, VCardStorage*>(profile, NULL)); + if (r.second) { + r.first->second = vcardStorageFactory_->createVCardStorage(profile); + } + return r.first->second; +} + + } diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index a612175..cf04e59 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -29,6 +29,8 @@ namespace Swift { class AvatarStorage; + class VCardStorage; + class VCardManager; class Application; class Client; class ChatWindowFactory; @@ -94,7 +96,7 @@ namespace Swift { void handleError(const ClientError& error); void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, const boost::optional<ErrorPayload>&); void handleEventQueueLengthChange(int count); - void handleOwnVCardReceived(boost::shared_ptr<VCard> vCard, const boost::optional<ErrorPayload>& error); + void handleOwnVCardReceived(VCard::ref vCard); void sendPresence(boost::shared_ptr<Presence> presence); void handleInputIdleChanged(bool); void logout(); @@ -107,6 +109,9 @@ namespace Swift { void reconnectAfterError(); void setManagersEnabled(bool enabled); + VCardStorage* getVCardStorageForProfile(const JID& jid); + + private: BoostIOServiceThread boostIOServiceThread_; BoostTimerFactory timerFactory_; PlatformIdleQuerier idleQuerier_; @@ -121,6 +126,7 @@ namespace Swift { ProfileSettingsProvider* profileSettings_; AvatarStorage* avatarStorage_; VCardStorageFactory* vcardStorageFactory_; + VCardManager* vcardManager_; ApplicationMessageDisplay* applicationMessageDisplay_; ChatController* chatController_; XMPPRosterController* xmppRosterController_; @@ -153,5 +159,8 @@ namespace Swift { int timeBeforeNextReconnect_; Timer::ref reconnectTimer_; StatusTracker* statusTracker_; + + typedef std::map<String, VCardStorage*> VCardStorageMap; + VCardStorageMap vcardStorages_; }; } |