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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (c) 2010 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include "Swift/QtUI/EventViewer/QtEventWindow.h"
#include <QtDebug>
#include <QBoxLayout>
#include <QPushButton>
#include <QMessageBox>
#include "Swift/Controllers/XMPPEvents/MessageEvent.h"
#include "Swift/Controllers/XMPPEvents/ErrorEvent.h"
#include "Swift/QtUI/QtSubscriptionRequestWindow.h"
#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h"
#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h"
#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h"
#include "Swiften/Base/Platform.h"
namespace Swift {
QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) {
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
view_ = new QTreeView(this);
layout->addWidget(view_);
eventStream_ = eventStream;
model_ = new EventModel();
view_->setModel(model_);
delegate_ = new EventDelegate();
view_->setItemDelegate(delegate_);
view_->setHeaderHidden(true);
#ifdef SWIFT_PLATFORM_MACOSX
view_->setAlternatingRowColors(true);
#endif
view_->setAnimated(true);
view_->setIndentation(0);
view_->setRootIsDecorated(true);
readButton_ = new QPushButton(tr("Display Notice"), this);
layout->addWidget(readButton_);
readButton_->setEnabled(false);
connect(readButton_, SIGNAL(clicked()), this, SLOT(handleReadClicked()));
connect(view_, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleItemClicked(const QModelIndex&)));
connect(view_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
}
QtEventWindow::~QtEventWindow() {
delete model_;
delete delegate_;
/* Not view_ because this is the parent */
}
void QtEventWindow::handleItemClicked(const QModelIndex&) {
readButton_->setEnabled(true);
}
void QtEventWindow::handleReadClicked() {
QModelIndex index = view_->currentIndex();
if (!index.isValid()) {
return;
}
handleItemActivated(index);
}
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());
boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent());
boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event->getEvent());
if (messageEvent) {
if (messageEvent->getStanza()->getType() == Message::Groupchat) {
eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource())));
} else {
eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(messageEvent->getStanza()->getFrom())));
}
} else if (subscriptionEvent) {
QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
window->show();
} else if (mucInviteEvent) {
eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(mucInviteEvent->getInviter())));
mucInviteEvent->conclude();
} else {
if (errorEvent) {
errorEvent->conclude();
}
QMessageBox msgBox;
msgBox.setText(model_->data(item, Qt::DisplayRole).toString());
msgBox.exec();
}
}
void QtEventWindow::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) {
view_->clearSelection();
model_->addEvent(event, active);
emit onNewEventCountUpdated(model_->getNewEventCount());
}
void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) {
view_->clearSelection();
model_->removeEvent(event);
emit onNewEventCountUpdated(model_->getNewEventCount());
}
}
|