diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-12 10:52:03 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-12 10:52:03 (GMT) |
commit | edd726abb1d0f7532218efbb8067a75a313e9e98 (patch) | |
tree | 7eec4f7912a59bb9a383a61c2c96616d5b5847b6 /Swift/Controllers | |
parent | 6e9fb4e4a3aeee8c40617a4dda6e5e0892ceebad (diff) | |
download | swift-contrib-edd726abb1d0f7532218efbb8067a75a313e9e98.zip swift-contrib-edd726abb1d0f7532218efbb8067a75a313e9e98.tar.bz2 |
Improved whiteboard session handling
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindow.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.cpp | 48 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.h | 5 |
4 files changed, 35 insertions, 22 deletions
diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h index bedb057..ae736d7 100644 --- a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h @@ -11,6 +11,7 @@ #include <string> namespace Swift { + class WhiteboardSession; class WhiteboardWindow { public: @@ -18,6 +19,7 @@ namespace Swift { virtual void show() = 0; virtual void addItem(const std::string& item) = 0; + virtual void setSession(boost::shared_ptr<WhiteboardSession> session) = 0; boost::signal<void (std::string)> onItemAdd; }; diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h index 7e0fe81..c2d2f6c 100644 --- a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h @@ -14,6 +14,6 @@ namespace Swift { public : virtual ~WhiteboardWindowFactory() {}; - virtual WhiteboardWindow* createWhiteboardWindow(WhiteboardSession* whiteboardSession) = 0; + virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) = 0; }; } diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp index 37c3263..f6db4ff 100644 --- a/Swift/Controllers/WhiteboardManager.cpp +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -20,7 +20,6 @@ namespace Swift { WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), whiteboardSessionManager_(whiteboardSessionManager) { uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); - whiteboardSessionManager_->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleAcceptedRequest, this, _1, _2)); } WhiteboardManager::~WhiteboardManager() { @@ -29,23 +28,30 @@ namespace Swift { } } - WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession* session) { + WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) { WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session); - whiteboardWindows_[contact] = window; + whiteboardWindows_[contact.toBare()] = window; return window; } WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) { - if (whiteboardWindows_.find(contact) == whiteboardWindows_.end()) { + if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) { return NULL; } - return whiteboardWindows_[contact]; + return whiteboardWindows_[contact.toBare()]; } void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { - boost::shared_ptr<RequestWhiteboardUIEvent> whiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); - if (whiteboardEvent) { - whiteboardSessionManager_->requestSession(whiteboardEvent->getContact()); + boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); + if (requestWhiteboardEvent) { + JID contact = requestWhiteboardEvent->getContact(); + WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact); + WhiteboardWindow* window = findWhiteboardWindow(contact); + if (window == NULL) { + createNewWhiteboardWindow(contact, session); + } else { + window->setSession(session); + } } boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event); if (sessionAcceptEvent) { @@ -53,24 +59,28 @@ namespace Swift { } boost::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = boost::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event); if (sessionCancelEvent) { - whiteboardSessionManager_->cancelSession(sessionCancelEvent->getContact()); + cancelSession(sessionCancelEvent->getContact()); } } void WhiteboardManager::acceptSession(const JID& from) { - WhiteboardSession* session = whiteboardSessionManager_->acceptSession(from); - WhiteboardWindow* window = findWhiteboardWindow(from); - if (window == NULL) { - window = createNewWhiteboardWindow(from, session); + IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from)); + if (session) { + session->accept(); + WhiteboardWindow* window = findWhiteboardWindow(from); + if (window == NULL) { + window = createNewWhiteboardWindow(from, session); + } else { + window->setSession(session); + } + window->show(); } - window->show(); } - void WhiteboardManager::handleAcceptedRequest(const JID& from, WhiteboardSession* session) { - WhiteboardWindow* window = findWhiteboardWindow(from); - if (window == NULL) { - window = createNewWhiteboardWindow(from, session); + void WhiteboardManager::cancelSession(const JID& from) { + IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from)); + if (session) { + session->cancel(); } - window->show(); } } diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h index 2690f36..52d9bae 100644 --- a/Swift/Controllers/WhiteboardManager.h +++ b/Swift/Controllers/WhiteboardManager.h @@ -16,6 +16,7 @@ #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> #include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> +#include <Swiften/Whiteboard/WhiteboardSession.h> namespace Swift { class WhiteboardSessionManager; @@ -25,12 +26,12 @@ namespace Swift { WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, WhiteboardSessionManager* whiteboardSessionManager); ~WhiteboardManager(); - WhiteboardWindow* createNewWhiteboardWindow(const JID& contact, WhiteboardSession* session); + WhiteboardWindow* createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session); private: void handleUIEvent(boost::shared_ptr<UIEvent> event); void acceptSession(const JID& from); - void handleAcceptedRequest(const JID& from, WhiteboardSession* session); + void cancelSession(const JID& from); WhiteboardWindow* findWhiteboardWindow(const JID& contact); private: |