summaryrefslogtreecommitdiffstats
blob: 1061e78a26030983c7f497a02db8d4c8eea7830a (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
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (c) 2012 Catalin Badea
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <Swift/Controllers/HistoryViewController.h>

#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
#include <Swift/Controllers/HistoryController.h>
#include <Swiften/History/HistoryMessage.h>

namespace Swift {

HistoryViewController::HistoryViewController(
		UIEventStream* uiEventStream,
		HistoryController* historyController,
		HistoryWindowFactory* historyWindowFactory) :
			uiEventStream_(uiEventStream),
			historyController_(historyController),
			historyWindowFactory_(historyWindowFactory),
			historyWindow_(NULL) {
	uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
}

HistoryViewController::~HistoryViewController() {
	uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1));
	delete historyWindow_;
	delete roster_;
}

void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
	boost::shared_ptr<RequestHistoryUIEvent> event = boost::dynamic_pointer_cast<RequestHistoryUIEvent>(rawEvent);
	if (event != NULL) {
		if (historyWindow_ == NULL) {
			historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_);
			roster_ = new Roster(false, true);
			historyWindow_->setRosterModel(roster_);

			JID putin("vputin@karla.com");
			JID medvedev("dmedvedev@karla.com");
			JID kev("kevin@doomsong.co.uk");
			const std::set<ContactRosterItem::Feature> none;
			roster_->addContact(putin, putin, "Vladimir Putin", "Recent", "");
			roster_->addContact(medvedev, medvedev, "Dmitri Medvedev", "Recent", "");
			roster_->addContact(kev, kev, "Kev", "Recent", "");
		}

		std::vector<HistoryMessage> messages = historyController_->getMessages();
		for (std::vector<HistoryMessage>::iterator it = messages.begin(); it != messages.end(); it++) {
			historyWindow_->addMessage(*it);
		}
		historyWindow_->activate();
	}
}

}