summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-08 13:37:12 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-08 13:37:12 (GMT)
commit6e9fb4e4a3aeee8c40617a4dda6e5e0892ceebad (patch)
treefd2c0a48c6f5d033fe742790fb2e640d7e13ba91 /Swift/Controllers/WhiteboardManager.cpp
parent13ededd86bfb5dc5115af69d79810122313273b5 (diff)
downloadswift-contrib-6e9fb4e4a3aeee8c40617a4dda6e5e0892ceebad.zip
swift-contrib-6e9fb4e4a3aeee8c40617a4dda6e5e0892ceebad.tar.bz2
Added handling of whiteboard session requests
Diffstat (limited to 'Swift/Controllers/WhiteboardManager.cpp')
-rw-r--r--Swift/Controllers/WhiteboardManager.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp
index 25a661c..37c3263 100644
--- a/Swift/Controllers/WhiteboardManager.cpp
+++ b/Swift/Controllers/WhiteboardManager.cpp
@@ -10,6 +10,8 @@
#include <Swiften/Base/foreach.h>
#include <Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h>
+#include <Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h>
+#include <Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h>
#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Whiteboard/WhiteboardSessionManager.h>
@@ -18,6 +20,7 @@ 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() {
@@ -26,25 +29,48 @@ namespace Swift {
}
}
- WhiteboardWindow* WhiteboardManager::getWhiteboardWindowOrCreate(const JID& contact) {
- if (whiteboardWindows_.find(contact) == whiteboardWindows_.end()) {
- return createNewWhiteboardWindow(contact);
- }
- return whiteboardWindows_[contact];
- }
-
- WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact) {
- WhiteboardSession* session = whiteboardSessionManager_->createSession(contact);
+ WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession* session) {
WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session);
whiteboardWindows_[contact] = window;
return window;
}
+ WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) {
+ if (whiteboardWindows_.find(contact) == whiteboardWindows_.end()) {
+ return NULL;
+ }
+ return whiteboardWindows_[contact];
+ }
+
void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
boost::shared_ptr<RequestWhiteboardUIEvent> whiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event);
if (whiteboardEvent) {
- WhiteboardWindow* window = getWhiteboardWindowOrCreate(whiteboardEvent->getContact());
- window->show();
+ whiteboardSessionManager_->requestSession(whiteboardEvent->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) {
+ whiteboardSessionManager_->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);
+ }
+ window->show();
+ }
+
+ void WhiteboardManager::handleAcceptedRequest(const JID& from, WhiteboardSession* session) {
+ WhiteboardWindow* window = findWhiteboardWindow(from);
+ if (window == NULL) {
+ window = createNewWhiteboardWindow(from, session);
}
+ window->show();
}
}