From fa2edf2f9dfa77129e749373d7045b98d1dcced5 Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Tue, 5 Jun 2012 17:54:11 +0200 Subject: Added function responsible for instances of WhiteboardWindows diff --git a/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h index 679bdc2..f5b995b 100644 --- a/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h +++ b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h @@ -14,7 +14,7 @@ namespace Swift { class RequestWhiteboardUIEvent : public UIEvent { public: RequestWhiteboardUIEvent(const JID& contact) : contact_(contact) {}; - JID getContact() {return contact_;} + const JID& getContact() const {return contact_;} private: JID contact_; }; diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp index 3a87387..6237426 100644 --- a/Swift/Controllers/WhiteboardManager.cpp +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -8,21 +8,40 @@ #include +#include #include #include namespace Swift { + typedef std::pair JIDWhiteboardWindowPair; + WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), stanzaChannel_(stanzaChannel) { uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); } WhiteboardManager::~WhiteboardManager() { + foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) { + delete whiteboardWindowPair.second; + } + } + + WhiteboardWindow* WhiteboardManager::getWhiteboardWindowOrCreate(const JID& contact) { + if (whiteboardWindows_.find(contact) == whiteboardWindows_.end()) { + return createNewWhiteboardWindow(contact); + } + return whiteboardWindows_[contact]; + } + + WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact) { + WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(stanzaChannel_, contact); + whiteboardWindows_[contact] = window; + return window; } void WhiteboardManager::handleUIEvent(boost::shared_ptr event) { boost::shared_ptr whiteboardEvent = boost::dynamic_pointer_cast(event); - if(whiteboardEvent) { - WhiteboardWindow* window = whiteboardWindowFactory_->createWhiteboardWindow(stanzaChannel_, whiteboardEvent->getContact()); + if (whiteboardEvent) { + WhiteboardWindow* window = getWhiteboardWindowOrCreate(whiteboardEvent->getContact()); window->show(); } } diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h index 5876adf..c28492c 100644 --- a/Swift/Controllers/WhiteboardManager.h +++ b/Swift/Controllers/WhiteboardManager.h @@ -25,6 +25,9 @@ namespace Swift { WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel); ~WhiteboardManager(); + WhiteboardWindow* getWhiteboardWindowOrCreate(const JID& contact); + WhiteboardWindow* createNewWhiteboardWindow(const JID& contact); + private: void handleUIEvent(boost::shared_ptr event); -- cgit v0.10.2-6-g49f6