summaryrefslogtreecommitdiffstats
blob: 84758ae801835dc4319dcc2d5a5f73de9aa1f180 (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
59
60
61
62
63
64
65
66
67
68
69

/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include "Swift/QtUI/EventViewer/QtEventWindow.h"

#include <QtDebug>

#include "Swiften/Events/MessageEvent.h"
#include "Swift/QtUI/QtSubscriptionRequestWindow.h"
#include "Swiften/Events/SubscriptionRequestEvent.h"
#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"


#include "Swiften/Base/Platform.h"

namespace Swift {

QtEventWindow::QtEventWindow(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) {
	eventStream_ = eventStream;
	model_ = new EventModel();
	setModel(model_);
	delegate_ = new EventDelegate();
	setItemDelegate(delegate_);
	setHeaderHidden(true);
#ifdef SWIFT_PLATFORM_MACOSX
	setAlternatingRowColors(true);
#endif
	setAnimated(true);
	setIndentation(0);
	setRootIsDecorated(true);
	connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}

QtEventWindow::~QtEventWindow() {
	delete model_;
	delete delegate_;
}

void QtEventWindow::handleItemActivated(const QModelIndex& item) {
	QtEvent* event = model_->getItem(item.row());
	boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent());
	boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent());
	
	if (messageEvent) {
		eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(messageEvent->getStanza()->getFrom())));
	} else if (subscriptionEvent) {
		QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
		window->show();
	} else {
		qWarning() << "Trying to activate an unexpected event";
	}

}

void QtEventWindow::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
	model_->addEvent(event, active);
	emit onNewEventCountUpdated(model_->getNewEventCount());
}

void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) {
	model_->removeEvent(event);
	emit onNewEventCountUpdated(model_->getNewEventCount());
}

}