summaryrefslogtreecommitdiffstats
blob: 844a7f7fb5568bc14d5f3c997f76a5f5c5437c49 (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/QtEvent.h"

#include "Swiften/Events/MessageEvent.h"
#include "Swiften/Events/ErrorEvent.h"
#include "Swiften/Events/SubscriptionRequestEvent.h"

#include "Swift/QtUI/QtSwiftUtil.h"

namespace Swift {

QtEvent::QtEvent(boost::shared_ptr<StanzaEvent> event, bool active) : event_(event) {
	active_ = active;
}

QVariant QtEvent::data(int role) {
 	switch (role) {
		case Qt::ToolTipRole:
		case Qt::DisplayRole: return QVariant(text());
		case Qt::TextColorRole: return active_ ? Qt::black : Qt::darkGray;
		case Qt::BackgroundColorRole: return active_ ? Qt::white : Qt::lightGray;
		case SenderRole: return QVariant(sender());
			/*case StatusTextRole: return statusText_;
		case AvatarRole: return avatar_;
		case PresenceIconRole: return getPresenceIcon();*/
	 	default: return QVariant();
	}
}

QString QtEvent::sender() {
	boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
	if (messageEvent) {
		return P2QSTRING(messageEvent->getStanza()->getFrom().toString());
	}
	boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
	if (subscriptionRequestEvent) {
		return P2QSTRING(subscriptionRequestEvent->getJID().toBare().toString());
	}
	boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
	if (errorEvent) {
		return P2QSTRING(errorEvent->getJID().toBare().toString());
	}
	return "";
}

QString QtEvent::text() {
	boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
	if (messageEvent) {
		return P2QSTRING(messageEvent->getStanza()->getBody());
	}
	boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_);
	if (subscriptionRequestEvent) {
		String reason = subscriptionRequestEvent->getReason();
		String message = subscriptionRequestEvent->getJID().toBare().toString() + " would like to add you to their roster" + (reason.isEmpty() ? "." : ", saying '" + reason + "'.");
		return P2QSTRING(message);
	}
	boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_);
	if (errorEvent) {
		return P2QSTRING(errorEvent->getText());
	}
	return "";
}

}