/* * Copyright (c) 2012 Mateusz Piękos * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #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 = getWhiteboardWindowOrCreate(whiteboardEvent->getContact()); window->show(); } } }