blob: 6237426ad2b70d693a0cb2ccfa0cfa5dbf8e9dde (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/*
* Copyright (c) 2012 Mateusz Piękos
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swift/Controllers/WhiteboardManager.h>
#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 = getWhiteboardWindowOrCreate(whiteboardEvent->getContact());
window->show();
}
}
}
|