summaryrefslogtreecommitdiffstats
blob: 92289010934f694c830e5b165fc14597aaa7c60c (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
/*
 * Copyright (c) 2012 Mateusz Piękos
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <boost/bind.hpp>

#include "Swift/Controllers/WhiteboardController.h"

#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h>
#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h>

#include <Swiften/Elements/WhiteboardPayload.h>

#include <iostream>

namespace Swift {
	WhiteboardController::WhiteboardController(StanzaChannel* stanzaChannel, const JID& toJID, WhiteboardWindowFactory* whiteboardWindowFactory) : stanzaChannel_(stanzaChannel), toJID_(toJID) {
		whiteboardWindow_ = whiteboardWindowFactory->createWhiteboardWindow();
		whiteboardWindow_->show();
		whiteboardWindow_->onItemAdd.connect(boost::bind(&WhiteboardController::handleItemChange, this, _1));
	}

	WhiteboardController::~WhiteboardController() {
		delete whiteboardWindow_;
	}

	void WhiteboardController::handleIncomingMessage(boost::shared_ptr<MessageEvent> message) {
		boost::shared_ptr<WhiteboardPayload> wb = message->getStanza()->getPayload<WhiteboardPayload>();
		if(wb) {
			whiteboardWindow_->addItem(wb->getData());
		}
	}

	void WhiteboardController::handleItemChange(std::string item) {
		boost::shared_ptr<Message> mes(new Message());
		mes->setTo(toJID_);
		boost::shared_ptr<WhiteboardPayload> wbPayload(new WhiteboardPayload);
		wbPayload->setData(item);
//		mes->setType(Swift::Message::Chat);
		mes->addPayload(wbPayload);
		stanzaChannel_->sendMessage(mes);
	}
}