summaryrefslogtreecommitdiffstats
blob: 00759b8cd32d2259b1870db5bee384940f036a7a (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
/*
 * Copyright (c) 2011 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swift/Controllers/XMPPURIController.h>

#include <boost/bind.hpp>
#include <boost/smart_ptr/make_shared.hpp>

#include <SwifTools/URIHandler/URIHandler.h>
#include <SwifTools/URIHandler/XMPPURI.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>

using namespace Swift;

XMPPURIController::XMPPURIController(URIHandler* uriHandler, UIEventStream* uiEventStream) : uriHandler(uriHandler), uiEventStream(uiEventStream) {
	uriHandler->onURI.connect(boost::bind(&XMPPURIController::handleURI, this, _1));
}

XMPPURIController::~XMPPURIController() {
	uriHandler->onURI.disconnect(boost::bind(&XMPPURIController::handleURI, this, _1));
}

void XMPPURIController::handleURI(const std::string& s) {
	XMPPURI uri = XMPPURI::fromString(s);
	if (!uri.isNull()) {
		if (uri.getQueryType() == "join") {
			uiEventStream->send(boost::make_shared<RequestJoinMUCUIEvent>(uri.getPath()));
		}
		else {
			uiEventStream->send(boost::make_shared<RequestChatUIEvent>(uri.getPath()));
		}
	}
}