diff options
Diffstat (limited to 'Swift/Controllers/WhiteboardManager.cpp')
-rw-r--r-- | Swift/Controllers/WhiteboardManager.cpp | 224 |
1 files changed, 112 insertions, 112 deletions
diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp index f62a94a..91f01c8 100644 --- a/Swift/Controllers/WhiteboardManager.cpp +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -25,121 +25,121 @@ #include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h> namespace Swift { - typedef std::pair<JID, WhiteboardWindow*> JIDWhiteboardWindowPair; + typedef std::pair<JID, WhiteboardWindow*> JIDWhiteboardWindowPair; - WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), whiteboardSessionManager_(whiteboardSessionManager) { + WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), whiteboardSessionManager_(whiteboardSessionManager) { #ifdef SWIFT_EXPERIMENTAL_WB - whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1)); + whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1)); #endif - uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); - } - - WhiteboardManager::~WhiteboardManager() { - foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) { - delete whiteboardWindowPair.second; - } - } - - WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) { - WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session); - window->setName(nickResolver_->jidToNick(contact)); - whiteboardWindows_[contact.toBare()] = window; - return window; - } - - WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) { - if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) { - return NULL; - } - return whiteboardWindows_[contact.toBare()]; - } - - void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { - boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); - if (requestWhiteboardEvent) { - requestSession(requestWhiteboardEvent->getContact()); - } - boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event); - if (sessionAcceptEvent) { - acceptSession(sessionAcceptEvent->getContact()); - } - boost::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = boost::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event); - if (sessionCancelEvent) { - cancelSession(sessionCancelEvent->getContact()); - } - boost::shared_ptr<ShowWhiteboardUIEvent> showWindowEvent = boost::dynamic_pointer_cast<ShowWhiteboardUIEvent>(event); - if (showWindowEvent) { - WhiteboardWindow* window = findWhiteboardWindow(showWindowEvent->getContact()); - if (window != NULL) { - window->activateWindow(); - } - } - } - - void WhiteboardManager::acceptSession(const JID& from) { - IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from)); - WhiteboardWindow* window = findWhiteboardWindow(from); - if (session && window) { - session->accept(); - window->show(); - } - } - - void WhiteboardManager::requestSession(const JID& contact) { - WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact); - session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); - session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); - session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1)); - - WhiteboardWindow* window = findWhiteboardWindow(contact); - if (window == NULL) { - createNewWhiteboardWindow(contact, session); - } else { - window->setSession(session); - } - onSessionRequest(session->getTo(), true); - } - - void WhiteboardManager::cancelSession(const JID& from) { - WhiteboardSession::ref session = whiteboardSessionManager_->getSession(from); - if (session) { - session->cancel(); - } - } - - void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) { - session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); - session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); - - WhiteboardWindow* window = findWhiteboardWindow(session->getTo()); - if (window == NULL) { - createNewWhiteboardWindow(session->getTo(), session); - } else { - window->setSession(session); - } - - onSessionRequest(session->getTo(), false); - } - - void WhiteboardManager::handleSessionTerminate(const JID& contact) { - onSessionTerminate(contact); - } - - void WhiteboardManager::handleSessionCancel(const JID& contact) { - onSessionTerminate(contact); - } - - void WhiteboardManager::handleSessionAccept(const JID& contact) { - WhiteboardWindow* window = findWhiteboardWindow(contact); - if (window != NULL) { - window->show(); - } - onRequestAccepted(contact); - } - - void WhiteboardManager::handleRequestReject(const JID& contact) { - onRequestRejected(contact); - } + uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); + } + + WhiteboardManager::~WhiteboardManager() { + foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) { + delete whiteboardWindowPair.second; + } + } + + WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) { + WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session); + window->setName(nickResolver_->jidToNick(contact)); + whiteboardWindows_[contact.toBare()] = window; + return window; + } + + WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) { + if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) { + return NULL; + } + return whiteboardWindows_[contact.toBare()]; + } + + void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { + boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); + if (requestWhiteboardEvent) { + requestSession(requestWhiteboardEvent->getContact()); + } + boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event); + if (sessionAcceptEvent) { + acceptSession(sessionAcceptEvent->getContact()); + } + boost::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = boost::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event); + if (sessionCancelEvent) { + cancelSession(sessionCancelEvent->getContact()); + } + boost::shared_ptr<ShowWhiteboardUIEvent> showWindowEvent = boost::dynamic_pointer_cast<ShowWhiteboardUIEvent>(event); + if (showWindowEvent) { + WhiteboardWindow* window = findWhiteboardWindow(showWindowEvent->getContact()); + if (window != NULL) { + window->activateWindow(); + } + } + } + + void WhiteboardManager::acceptSession(const JID& from) { + IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from)); + WhiteboardWindow* window = findWhiteboardWindow(from); + if (session && window) { + session->accept(); + window->show(); + } + } + + void WhiteboardManager::requestSession(const JID& contact) { + WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact); + session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); + session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); + session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1)); + + WhiteboardWindow* window = findWhiteboardWindow(contact); + if (window == NULL) { + createNewWhiteboardWindow(contact, session); + } else { + window->setSession(session); + } + onSessionRequest(session->getTo(), true); + } + + void WhiteboardManager::cancelSession(const JID& from) { + WhiteboardSession::ref session = whiteboardSessionManager_->getSession(from); + if (session) { + session->cancel(); + } + } + + void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) { + session->onSessionTerminated.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); + session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); + + WhiteboardWindow* window = findWhiteboardWindow(session->getTo()); + if (window == NULL) { + createNewWhiteboardWindow(session->getTo(), session); + } else { + window->setSession(session); + } + + onSessionRequest(session->getTo(), false); + } + + void WhiteboardManager::handleSessionTerminate(const JID& contact) { + onSessionTerminate(contact); + } + + void WhiteboardManager::handleSessionCancel(const JID& contact) { + onSessionTerminate(contact); + } + + void WhiteboardManager::handleSessionAccept(const JID& contact) { + WhiteboardWindow* window = findWhiteboardWindow(contact); + if (window != NULL) { + window->show(); + } + onRequestAccepted(contact); + } + + void WhiteboardManager::handleRequestReject(const JID& contact) { + onRequestRejected(contact); + } } |