summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/WhiteboardManager.cpp')
-rw-r--r--Swift/Controllers/WhiteboardManager.cpp23
1 files changed, 21 insertions, 2 deletions
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();
}
}