diff options
| author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-05 15:54:11 (GMT) | 
|---|---|---|
| committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-05 15:54:11 (GMT) | 
| commit | fa2edf2f9dfa77129e749373d7045b98d1dcced5 (patch) | |
| tree | 037e6a8322d7bd323d665ab47c36ec4a86ba50e3 | |
| parent | 21e358a55e6eee1036fe95993c5715382d08c0c8 (diff) | |
| download | swift-contrib-fa2edf2f9dfa77129e749373d7045b98d1dcced5.zip swift-contrib-fa2edf2f9dfa77129e749373d7045b98d1dcced5.tar.bz2 | |
Added function responsible for instances of WhiteboardWindows
| -rw-r--r-- | Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h | 2 | ||||
| -rw-r--r-- | Swift/Controllers/WhiteboardManager.cpp | 23 | ||||
| -rw-r--r-- | Swift/Controllers/WhiteboardManager.h | 3 | 
3 files changed, 25 insertions, 3 deletions
| 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 <boost/bind.hpp> +#include <Swiften/Base/foreach.h>  #include <Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h>  #include <Swiften/Client/StanzaChannel.h>  namespace Swift { +	typedef std::pair<JID, WhiteboardWindow*> 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<UIEvent> event) {  		boost::shared_ptr<RequestWhiteboardUIEvent> whiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(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<UIEvent> event); | 
 Swift
 Swift