summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-07-09 08:30:11 (GMT)
committerTobias Markmann <tm@ayena.de>2015-07-10 14:00:16 (GMT)
commit7af21fdd59af3b3112cff69996301605859af84c (patch)
tree5a1c79ac5d8c3a5521b098f68ae6c190a291455c /Swift/QtUI
parenta23d903d67f05257f0e9376a212b83045ea768f1 (diff)
downloadswift-7af21fdd59af3b3112cff69996301605859af84c.zip
swift-7af21fdd59af3b3112cff69996301605859af84c.tar.bz2
Create notice events for incoming file-transfers
Test-Information: Send a file from one Swift instance to another. The UX is similar to that of a MUC invite, clicking the notice will bring the relevant chat in front. Change-Id: Ief3cd7371ae01b2b38b6d1af36189df961eacef4
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.cpp26
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.h9
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.cpp24
-rw-r--r--Swift/QtUI/EventViewer/QtEventWindow.cpp28
4 files changed, 57 insertions, 30 deletions
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp
index 7bbfee2..cd657b8 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.cpp
+++ b/Swift/QtUI/EventViewer/EventDelegate.cpp
@@ -1,23 +1,29 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#include "EventDelegate.h" 7#include <Swift/QtUI/EventViewer/EventDelegate.h>
8 8
9#include <QDebug> 9#include <QDebug>
10 10
11#include "Swift/Controllers/XMPPEvents/MessageEvent.h" 11#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
12#include "Swift/Controllers/XMPPEvents/ErrorEvent.h" 12#include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h>
13#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" 13#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h>
14#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" 14#include <Swift/Controllers/XMPPEvents/MessageEvent.h>
15#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h>
15 16
16namespace Swift { 17namespace Swift {
17 18
18EventDelegate::EventDelegate() : QStyledItemDelegate(), messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false), subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) { 19EventDelegate::EventDelegate() : QStyledItemDelegate(),
20 messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
21 subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
22 errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true),
23 mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false),
24 incomingFileTransferDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) {
19 25
20} 26}
21 27
22QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { 28QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
23 QtEvent* item = static_cast<QtEvent*>(index.internalPointer()); 29 QtEvent* item = static_cast<QtEvent*>(index.internalPointer());
@@ -27,10 +33,11 @@ QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIn
27 switch (getEventType(item->getEvent())) { 33 switch (getEventType(item->getEvent())) {
28 case MessageEventType: return messageDelegate_.sizeHint(option, item); 34 case MessageEventType: return messageDelegate_.sizeHint(option, item);
29 case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item); 35 case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item);
30 case ErrorEventType: return errorDelegate_.sizeHint(option, item); 36 case ErrorEventType: return errorDelegate_.sizeHint(option, item);
31 case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item); 37 case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item);
38 case IncomingFileTransferEventType: return incomingFileTransferDelegate_.sizeHint(option, item);
32 } 39 }
33 assert(false); 40 assert(false);
34 return QSize(); 41 return QSize();
35} 42}
36 43
@@ -43,10 +50,11 @@ void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
43 switch (getEventType(item->getEvent())) { 50 switch (getEventType(item->getEvent())) {
44 case MessageEventType: messageDelegate_.paint(painter, option, item);break; 51 case MessageEventType: messageDelegate_.paint(painter, option, item);break;
45 case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break; 52 case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break;
46 case ErrorEventType: errorDelegate_.paint(painter, option, item);break; 53 case ErrorEventType: errorDelegate_.paint(painter, option, item);break;
47 case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break; 54 case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break;
55 case IncomingFileTransferEventType: incomingFileTransferDelegate_.paint(painter, option, item);break;
48 } 56 }
49} 57}
50 58
51EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const { 59EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const {
52 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event); 60 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event);
@@ -63,10 +71,14 @@ EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) cons
63 } 71 }
64 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event); 72 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event);
65 if (mucInviteEvent) { 73 if (mucInviteEvent) {
66 return MUCInviteEventType; 74 return MUCInviteEventType;
67 } 75 }
76 boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event);
77 if (incomingFileTransferEvent) {
78 return IncomingFileTransferEventType;
79 }
68 //I don't know what this is. 80 //I don't know what this is.
69 assert(false); 81 assert(false);
70 return MessageEventType; 82 return MessageEventType;
71} 83}
72 84
diff --git a/Swift/QtUI/EventViewer/EventDelegate.h b/Swift/QtUI/EventViewer/EventDelegate.h
index f5dd196..6ab96e4 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.h
+++ b/Swift/QtUI/EventViewer/EventDelegate.h
@@ -1,20 +1,20 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#pragma once 7#pragma once
8 8
9#include <QStyledItemDelegate> 9#include <QStyledItemDelegate>
10 10
11#include "Swift/QtUI/Roster/DelegateCommons.h" 11#include <Swift/QtUI/EventViewer/TwoLineDelegate.h>
12#include "Swift/QtUI/EventViewer/TwoLineDelegate.h" 12#include <Swift/QtUI/Roster/DelegateCommons.h>
13 13
14namespace Swift { 14namespace Swift {
15 enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType}; 15 enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType, IncomingFileTransferEventType};
16 class EventDelegate : public QStyledItemDelegate { 16 class EventDelegate : public QStyledItemDelegate {
17 Q_OBJECT 17 Q_OBJECT
18 public: 18 public:
19 EventDelegate(); 19 EventDelegate();
20 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; 20 QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
@@ -24,8 +24,9 @@ namespace Swift {
24 DelegateCommons common_; 24 DelegateCommons common_;
25 TwoLineDelegate messageDelegate_; 25 TwoLineDelegate messageDelegate_;
26 TwoLineDelegate subscriptionDelegate_; 26 TwoLineDelegate subscriptionDelegate_;
27 TwoLineDelegate errorDelegate_; 27 TwoLineDelegate errorDelegate_;
28 TwoLineDelegate mucInviteDelegate_; 28 TwoLineDelegate mucInviteDelegate_;
29 TwoLineDelegate incomingFileTransferDelegate_;
29 }; 30 };
30} 31}
31 32
diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp
index a84a440..4d90bd9 100644
--- a/Swift/QtUI/EventViewer/QtEvent.cpp
+++ b/Swift/QtUI/EventViewer/QtEvent.cpp
@@ -1,20 +1,21 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#include "Swift/QtUI/EventViewer/QtEvent.h" 7#include <Swift/QtUI/EventViewer/QtEvent.h>
8 8
9#include <QDateTime>
10#include <QColor> 9#include <QColor>
10#include <QDateTime>
11 11
12#include "Swift/Controllers/XMPPEvents/MessageEvent.h" 12#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
13#include "Swift/Controllers/XMPPEvents/ErrorEvent.h" 13#include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h>
14#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" 14#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h>
15#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" 15#include <Swift/Controllers/XMPPEvents/MessageEvent.h>
16#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h>
16 17
17#include "Swift/QtUI/QtSwiftUtil.h" 18#include "Swift/QtUI/QtSwiftUtil.h"
18 19
19namespace Swift { 20namespace Swift {
20 21
@@ -51,10 +52,14 @@ QString QtEvent::sender() {
51 } 52 }
52 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_); 53 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
53 if (mucInviteEvent) { 54 if (mucInviteEvent) {
54 return P2QSTRING(mucInviteEvent->getInviter().toString()); 55 return P2QSTRING(mucInviteEvent->getInviter().toString());
55 } 56 }
57 boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
58 if (incomingFTEvent) {
59 return P2QSTRING(incomingFTEvent->getSender().toString());
60 }
56 return ""; 61 return "";
57} 62}
58 63
59QString QtEvent::text() { 64QString QtEvent::text() {
60 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_); 65 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_);
@@ -80,9 +85,14 @@ QString QtEvent::text() {
80 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_); 85 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_);
81 if (mucInviteEvent) { 86 if (mucInviteEvent) {
82 QString message = QString(QObject::tr("%1 has invited you to enter the %2 room.")).arg(P2QSTRING(mucInviteEvent->getInviter().toBare().toString())).arg(P2QSTRING(mucInviteEvent->getRoomJID().toString())); 87 QString message = QString(QObject::tr("%1 has invited you to enter the %2 room.")).arg(P2QSTRING(mucInviteEvent->getInviter().toBare().toString())).arg(P2QSTRING(mucInviteEvent->getRoomJID().toString()));
83 return message; 88 return message;
84 } 89 }
90 boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_);
91 if (incomingFTEvent) {
92 QString message = QString(QObject::tr("%1 would like to send a file to you.")).arg(P2QSTRING(incomingFTEvent->getSender().toBare().toString()));
93 return message;
94 }
85 return ""; 95 return "";
86} 96}
87 97
88} 98}
diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp
index 3072497..f92cd07 100644
--- a/Swift/QtUI/EventViewer/QtEventWindow.cpp
+++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp
@@ -1,29 +1,29 @@
1
2/* 1/*
3 * Copyright (c) 2010-2015 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
4 * All rights reserved. 3 * All rights reserved.
5 * See the COPYING file for more information. 4 * See the COPYING file for more information.
6 */ 5 */
7 6
8#include "Swift/QtUI/EventViewer/QtEventWindow.h" 7#include <Swift/QtUI/EventViewer/QtEventWindow.h>
9 8
10#include <QtDebug>
11#include <QBoxLayout> 9#include <QBoxLayout>
12#include <QPushButton>
13#include <QMessageBox> 10#include <QMessageBox>
11#include <QPushButton>
12#include <QtDebug>
14 13
15#include "Swift/Controllers/XMPPEvents/MessageEvent.h" 14#include <Swiften/Base/Platform.h>
16#include "Swift/Controllers/XMPPEvents/ErrorEvent.h"
17#include "Swift/QtUI/QtSubscriptionRequestWindow.h"
18#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h"
19#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h"
20#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
21#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h"
22 15
16#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
17#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
18#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
19#include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h>
20#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h>
21#include <Swift/Controllers/XMPPEvents/MessageEvent.h>
22#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h>
23 23
24#include "Swiften/Base/Platform.h" 24#include <Swift/QtUI/QtSubscriptionRequestWindow.h>
25 25
26namespace Swift { 26namespace Swift {
27 27
28QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) { 28QtEventWindow::QtEventWindow(UIEventStream* eventStream) : EventWindow(false) {
29 QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this); 29 QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
@@ -74,10 +74,11 @@ void QtEventWindow::handleReadClicked() {
74void QtEventWindow::handleItemActivated(const QModelIndex& item) { 74void QtEventWindow::handleItemActivated(const QModelIndex& item) {
75 QtEvent* event = model_->getItem(item.row()); 75 QtEvent* event = model_->getItem(item.row());
76 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent()); 76 boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event->getEvent());
77 boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent()); 77 boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent());
78 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent()); 78 boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent());
79 boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event->getEvent());
79 boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event->getEvent()); 80 boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event->getEvent());
80 81
81 if (messageEvent) { 82 if (messageEvent) {
82 if (messageEvent->getStanza()->getType() == Message::Groupchat) { 83 if (messageEvent->getStanza()->getType() == Message::Groupchat) {
83 eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource()))); 84 eventStream_->send(boost::shared_ptr<UIEvent>(new JoinMUCUIEvent(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource())));
@@ -88,10 +89,13 @@ void QtEventWindow::handleItemActivated(const QModelIndex& item) {
88 QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this); 89 QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this);
89 window->show(); 90 window->show();
90 } else if (mucInviteEvent) { 91 } else if (mucInviteEvent) {
91 eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(mucInviteEvent->getInviter()))); 92 eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(mucInviteEvent->getInviter())));
92 mucInviteEvent->conclude(); 93 mucInviteEvent->conclude();
94 } else if (incomingFTEvent) {
95 eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(incomingFTEvent->getSender())));
96 incomingFTEvent->conclude();
93 } else { 97 } else {
94 if (errorEvent) { 98 if (errorEvent) {
95 errorEvent->conclude(); 99 errorEvent->conclude();
96 } 100 }
97 QMessageBox msgBox; 101 QMessageBox msgBox;