diff options
Diffstat (limited to 'Swift/QtUI/EventViewer')
-rw-r--r-- | Swift/QtUI/EventViewer/EventDelegate.cpp | 110 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventDelegate.h | 34 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventModel.cpp | 132 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventModel.h | 38 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventView.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/EventView.h | 10 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/QtEvent.cpp | 132 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/QtEvent.h | 34 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/QtEventWindow.cpp | 149 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/QtEventWindow.h | 62 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/TwoLineDelegate.cpp | 83 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/TwoLineDelegate.h | 30 | ||||
-rw-r--r-- | Swift/QtUI/EventViewer/main.cpp | 42 |
13 files changed, 437 insertions, 425 deletions
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp index cd657b8..1c3ed7f 100644 --- a/Swift/QtUI/EventViewer/EventDelegate.cpp +++ b/Swift/QtUI/EventViewer/EventDelegate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -17,69 +17,69 @@ namespace Swift { EventDelegate::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), - incomingFileTransferDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) { + messageDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false), + subscriptionDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), + errorDelegate_(QtEvent::SenderRole, Qt::DisplayRole, true), + mucInviteDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false), + incomingFileTransferDelegate_(QtEvent::SenderRole, Qt::DisplayRole, false) { } QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QtEvent* item = static_cast<QtEvent*>(index.internalPointer()); - if (!item) { - return QStyledItemDelegate::sizeHint(option, index); - } - switch (getEventType(item->getEvent())) { - case MessageEventType: return messageDelegate_.sizeHint(option, item); - case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item); - case ErrorEventType: return errorDelegate_.sizeHint(option, item); - case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item); - case IncomingFileTransferEventType: return incomingFileTransferDelegate_.sizeHint(option, item); - } - assert(false); - return QSize(); + QtEvent* item = static_cast<QtEvent*>(index.internalPointer()); + if (!item) { + return QStyledItemDelegate::sizeHint(option, index); + } + switch (getEventType(item->getEvent())) { + case MessageEventType: return messageDelegate_.sizeHint(option, item); + case SubscriptionEventType: return subscriptionDelegate_.sizeHint(option, item); + case ErrorEventType: return errorDelegate_.sizeHint(option, item); + case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item); + case IncomingFileTransferEventType: return incomingFileTransferDelegate_.sizeHint(option, item); + } + assert(false); + return QSize(); } void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - QtEvent* item = static_cast<QtEvent*>(index.internalPointer()); - if (!item) { - QStyledItemDelegate::paint(painter, option, index); - return; - } - switch (getEventType(item->getEvent())) { - case MessageEventType: messageDelegate_.paint(painter, option, item);break; - case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break; - case ErrorEventType: errorDelegate_.paint(painter, option, item);break; - case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break; - case IncomingFileTransferEventType: incomingFileTransferDelegate_.paint(painter, option, item);break; - } + QtEvent* item = static_cast<QtEvent*>(index.internalPointer()); + if (!item) { + QStyledItemDelegate::paint(painter, option, index); + return; + } + switch (getEventType(item->getEvent())) { + case MessageEventType: messageDelegate_.paint(painter, option, item);break; + case SubscriptionEventType: subscriptionDelegate_.paint(painter, option, item);break; + case ErrorEventType: errorDelegate_.paint(painter, option, item);break; + case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break; + case IncomingFileTransferEventType: incomingFileTransferDelegate_.paint(painter, option, item);break; + } } -EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const { - boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event); - if (messageEvent) { - return MessageEventType; - } - boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event); - if (subscriptionEvent) { - return SubscriptionEventType; - } - boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event); - if (errorEvent) { - return ErrorEventType; - } - boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event); - if (mucInviteEvent) { - return MUCInviteEventType; - } - boost::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event); - if (incomingFileTransferEvent) { - return IncomingFileTransferEventType; - } - //I don't know what this is. - assert(false); - return MessageEventType; +EventType EventDelegate::getEventType(std::shared_ptr<StanzaEvent> event) const { + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(event); + if (messageEvent) { + return MessageEventType; + } + std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(event); + if (subscriptionEvent) { + return SubscriptionEventType; + } + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(event); + if (errorEvent) { + return ErrorEventType; + } + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(event); + if (mucInviteEvent) { + return MUCInviteEventType; + } + std::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(event); + if (incomingFileTransferEvent) { + return IncomingFileTransferEventType; + } + //I don't know what this is. + assert(false); + return MessageEventType; } } diff --git a/Swift/QtUI/EventViewer/EventDelegate.h b/Swift/QtUI/EventViewer/EventDelegate.h index 6ab96e4..79ee8ed 100644 --- a/Swift/QtUI/EventViewer/EventDelegate.h +++ b/Swift/QtUI/EventViewer/EventDelegate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -12,21 +12,21 @@ #include <Swift/QtUI/Roster/DelegateCommons.h> namespace Swift { - enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType, IncomingFileTransferEventType}; - class EventDelegate : public QStyledItemDelegate { - Q_OBJECT - public: - EventDelegate(); - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; - private: - EventType getEventType(boost::shared_ptr<StanzaEvent> event) const; - DelegateCommons common_; - TwoLineDelegate messageDelegate_; - TwoLineDelegate subscriptionDelegate_; - TwoLineDelegate errorDelegate_; - TwoLineDelegate mucInviteDelegate_; - TwoLineDelegate incomingFileTransferDelegate_; - }; + enum EventType {MessageEventType, SubscriptionEventType, ErrorEventType, MUCInviteEventType, IncomingFileTransferEventType}; + class EventDelegate : public QStyledItemDelegate { + Q_OBJECT + public: + EventDelegate(); + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + private: + EventType getEventType(std::shared_ptr<StanzaEvent> event) const; + DelegateCommons common_; + TwoLineDelegate messageDelegate_; + TwoLineDelegate subscriptionDelegate_; + TwoLineDelegate errorDelegate_; + TwoLineDelegate mucInviteDelegate_; + TwoLineDelegate incomingFileTransferDelegate_; + }; } diff --git a/Swift/QtUI/EventViewer/EventModel.cpp b/Swift/QtUI/EventViewer/EventModel.cpp index 889bcac..5b97b3e 100644 --- a/Swift/QtUI/EventViewer/EventModel.cpp +++ b/Swift/QtUI/EventViewer/EventModel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,100 +11,100 @@ namespace Swift { namespace { - const int inactiveEventsLimit = 50; + const int inactiveEventsLimit = 50; } EventModel::EventModel() { - + } EventModel::~EventModel() { - foreach (QtEvent* event, activeEvents_) { - delete event; - } - foreach (QtEvent* event, inactiveEvents_) { - delete event; - } + for (auto event : activeEvents_) { + delete event; + } + for (auto event : inactiveEvents_) { + delete event; + } } QtEvent* EventModel::getItem(int row) const { - QtEvent* event = NULL; - if (row < activeEvents_.size()) { - event = activeEvents_[row]; - } - else { - int inactiveRow = row - activeEvents_.size(); - if (inactiveRow < inactiveEvents_.size()) { - event = inactiveEvents_[inactiveRow]; - } - else { - SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range"; - } - } - return event; + QtEvent* event = nullptr; + if (row < activeEvents_.size()) { + event = activeEvents_[row]; + } + else { + int inactiveRow = row - activeEvents_.size(); + if (inactiveRow < inactiveEvents_.size()) { + event = inactiveEvents_[inactiveRow]; + } + else { + SWIFT_LOG(error) << "Misbehaving EventModel requests row index outside of range"; + } + } + return event; } int EventModel::getNewEventCount() { - return activeEvents_.size(); + return activeEvents_.size(); } QVariant EventModel::data(const QModelIndex& index, int role) const { - if (!index.isValid()) { - return QVariant(); - } - QtEvent* item = getItem(index.row()); - QVariant result = item ? item->data(role) : QVariant(); - return result; + if (!index.isValid()) { + return QVariant(); + } + QtEvent* item = getItem(index.row()); + QVariant result = item ? item->data(role) : QVariant(); + return result; } /* * We only reimplement this to get the pointers inside the indices. */ QModelIndex EventModel::index(int row, int column, const QModelIndex & parent) const { - if (!hasIndex(row, column, parent) || parent.isValid()) { - return QModelIndex(); - } + if (!hasIndex(row, column, parent) || parent.isValid()) { + return QModelIndex(); + } - return row < rowCount() ? createIndex(row, column, getItem(row)) : QModelIndex(); + return row < rowCount() ? createIndex(row, column, getItem(row)) : QModelIndex(); } int EventModel::rowCount(const QModelIndex& parent) const { - /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/ - int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size(); - return count; + /* Invalid parent = root, valid parent = child, and we're a list not a tree.*/ + int count = parent.isValid() ? 0 : activeEvents_.size() + inactiveEvents_.size(); + return count; } -void EventModel::addEvent(boost::shared_ptr<StanzaEvent> event, bool active) { - beginResetModel(); - if (active) { - activeEvents_.push_front(new QtEvent(event, active)); - } else { - inactiveEvents_.push_front(new QtEvent(event, active)); - if (inactiveEvents_.size() > inactiveEventsLimit) { - removeEvent(inactiveEvents_[inactiveEventsLimit]->getEvent()); - } - } - endResetModel(); +void EventModel::addEvent(std::shared_ptr<StanzaEvent> event, bool active) { + beginResetModel(); + if (active) { + activeEvents_.push_front(new QtEvent(event, active)); + } else { + inactiveEvents_.push_front(new QtEvent(event, active)); + if (inactiveEvents_.size() > inactiveEventsLimit) { + removeEvent(inactiveEvents_[inactiveEventsLimit]->getEvent()); + } + } + endResetModel(); } -void EventModel::removeEvent(boost::shared_ptr<StanzaEvent> event) { - beginResetModel(); - for (int i = inactiveEvents_.size() - 1; i >= 0; i--) { - if (event == inactiveEvents_[i]->getEvent()) { - inactiveEvents_.removeAt(i); - endResetModel(); - return; - } - } - - for (int i = 0; i < activeEvents_.size(); i++) { - if (event == activeEvents_[i]->getEvent()) { - activeEvents_.removeAt(i); - endResetModel(); - return; - } - } - endResetModel(); +void EventModel::removeEvent(std::shared_ptr<StanzaEvent> event) { + beginResetModel(); + for (int i = inactiveEvents_.size() - 1; i >= 0; i--) { + if (event == inactiveEvents_[i]->getEvent()) { + inactiveEvents_.removeAt(i); + endResetModel(); + return; + } + } + + for (int i = 0; i < activeEvents_.size(); i++) { + if (event == activeEvents_[i]->getEvent()) { + activeEvents_.removeAt(i); + endResetModel(); + return; + } + } + endResetModel(); } } diff --git a/Swift/QtUI/EventViewer/EventModel.h b/Swift/QtUI/EventViewer/EventModel.h index cf259f2..de72c1b 100644 --- a/Swift/QtUI/EventViewer/EventModel.h +++ b/Swift/QtUI/EventViewer/EventModel.h @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <QAbstractListModel> #include <QList> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> -#include "Swift/QtUI/EventViewer/QtEvent.h" +#include <Swift/QtUI/EventViewer/QtEvent.h> namespace Swift { class EventModel : public QAbstractListModel { - Q_OBJECT - public: - EventModel(); - virtual ~EventModel(); - void addEvent(boost::shared_ptr<StanzaEvent> event, bool active); - void removeEvent(boost::shared_ptr<StanzaEvent> event); - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - int rowCount(const QModelIndex& parent = QModelIndex()) const; - QtEvent* getItem(int row) const; - int getNewEventCount(); - protected: - QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const; - private: - QList<QtEvent*> activeEvents_; - QList<QtEvent*> inactiveEvents_; + Q_OBJECT + public: + EventModel(); + virtual ~EventModel(); + void addEvent(std::shared_ptr<StanzaEvent> event, bool active); + void removeEvent(std::shared_ptr<StanzaEvent> event); + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; + QtEvent* getItem(int row) const; + int getNewEventCount(); + protected: + QModelIndex index(int row, int column = 0, const QModelIndex & parent = QModelIndex()) const; + private: + QList<QtEvent*> activeEvents_; + QList<QtEvent*> inactiveEvents_; }; } diff --git a/Swift/QtUI/EventViewer/EventView.cpp b/Swift/QtUI/EventViewer/EventView.cpp index 7e89f04..4d56548 100644 --- a/Swift/QtUI/EventViewer/EventView.cpp +++ b/Swift/QtUI/EventViewer/EventView.cpp @@ -1,14 +1,14 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Swift/QtUI/EventViewer/EventView.h" +#include <Swift/QtUI/EventViewer/EventView.h> namespace Swift { EventView::EventView(QWidget* parent) : QListView(parent) { - + } } diff --git a/Swift/QtUI/EventViewer/EventView.h b/Swift/QtUI/EventViewer/EventView.h index 36c67f3..83898bd 100644 --- a/Swift/QtUI/EventViewer/EventView.h +++ b/Swift/QtUI/EventViewer/EventView.h @@ -9,9 +9,9 @@ #include <QListView> namespace Swift { - class EventView : public QListView { - Q_OBJECT - public: - EventView(QWidget* parent); - }; + class EventView : public QListView { + Q_OBJECT + public: + EventView(QWidget* parent); + }; } diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp index 4830aec..5bd0fad 100644 --- a/Swift/QtUI/EventViewer/QtEvent.cpp +++ b/Swift/QtUI/EventViewer/QtEvent.cpp @@ -15,84 +15,84 @@ #include <Swift/Controllers/XMPPEvents/MessageEvent.h> #include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h> -#include "Swift/QtUI/QtSwiftUtil.h" +#include <Swift/QtUI/QtSwiftUtil.h> namespace Swift { -QtEvent::QtEvent(boost::shared_ptr<StanzaEvent> event, bool active) : event_(event) { - active_ = active; +QtEvent::QtEvent(std::shared_ptr<StanzaEvent> event, bool active) : event_(event) { + active_ = active; } QVariant QtEvent::data(int role) { - switch (role) { - case Qt::ToolTipRole: return QVariant(text()).toString() + "\n" + B2QDATE(event_->getTime()).toString(); - case Qt::DisplayRole: return QVariant(text()); - case Qt::TextColorRole: return QColor(active_ ? Qt::black : Qt::darkGray); - case Qt::BackgroundColorRole: return QColor(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(); - } + switch (role) { + case Qt::ToolTipRole: return QVariant(text()).toString() + "\n" + B2QDATE(event_->getTime()).toString(); + case Qt::DisplayRole: return QVariant(text()); + case Qt::TextColorRole: return QColor(active_ ? Qt::black : Qt::darkGray); + case Qt::BackgroundColorRole: return QColor(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()); - } - boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_); - if (mucInviteEvent) { - return P2QSTRING(mucInviteEvent->getInviter().toString()); - } - boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_); - if (incomingFTEvent) { - return P2QSTRING(incomingFTEvent->getSender().toString()); - } - return ""; + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(event_); + if (messageEvent) { + return P2QSTRING(messageEvent->getStanza()->getFrom().toString()); + } + std::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(event_); + if (subscriptionRequestEvent) { + return P2QSTRING(subscriptionRequestEvent->getJID().toBare().toString()); + } + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(event_); + if (errorEvent) { + return P2QSTRING(errorEvent->getJID().toBare().toString()); + } + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(event_); + if (mucInviteEvent) { + return P2QSTRING(mucInviteEvent->getInviter().toString()); + } + std::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(event_); + if (incomingFTEvent) { + return P2QSTRING(incomingFTEvent->getSender().toString()); + } + return ""; } QString QtEvent::text() { - boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event_); - if (messageEvent) { - return P2QSTRING(messageEvent->getStanza()->getBody().get_value_or("")); - } - boost::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event_); - if (subscriptionRequestEvent) { - std::string reason = subscriptionRequestEvent->getReason(); - QString message; - if (reason.empty()) { - message = QString(QObject::tr("%1 would like to add you to their contact list.")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()); - } - else { - message = QString(QObject::tr("%1 would like to add you to their contact list, saying '%2'")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()).arg(reason.c_str()); - } - return message; - } - boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event_); - if (errorEvent) { - return P2QSTRING(errorEvent->getText()); - } - boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event_); - if (mucInviteEvent) { - 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())); - return message; - } - boost::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(event_); - if (incomingFTEvent) { - QString message = QString(QObject::tr("%1 would like to send a file to you.")).arg(P2QSTRING(incomingFTEvent->getSender().toBare().toString())); - return message; - } - return ""; + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(event_); + if (messageEvent) { + return P2QSTRING(messageEvent->getStanza()->getBody().get_value_or("")); + } + std::shared_ptr<SubscriptionRequestEvent> subscriptionRequestEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(event_); + if (subscriptionRequestEvent) { + std::string reason = subscriptionRequestEvent->getReason(); + QString message; + if (reason.empty()) { + message = QString(QObject::tr("%1 would like to add you to their contact list.")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()); + } + else { + message = QString(QObject::tr("%1 would like to add you to their contact list, saying '%2'")).arg(subscriptionRequestEvent->getJID().toBare().toString().c_str()).arg(reason.c_str()); + } + return message; + } + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(event_); + if (errorEvent) { + return P2QSTRING(errorEvent->getText()); + } + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(event_); + if (mucInviteEvent) { + 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())); + return message; + } + std::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(event_); + if (incomingFTEvent) { + QString message = QString(QObject::tr("%1 would like to send a file to you.")).arg(P2QSTRING(incomingFTEvent->getSender().toBare().toString())); + return message; + } + return ""; } } diff --git a/Swift/QtUI/EventViewer/QtEvent.h b/Swift/QtUI/EventViewer/QtEvent.h index 8959452..cb78b00 100644 --- a/Swift/QtUI/EventViewer/QtEvent.h +++ b/Swift/QtUI/EventViewer/QtEvent.h @@ -1,32 +1,32 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <QVariant> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class QtEvent { - public: - QtEvent(boost::shared_ptr<StanzaEvent> event, bool active); - QVariant data(int role); - boost::shared_ptr<StanzaEvent> getEvent() { return event_; } - enum EventRoles { - SenderRole = Qt::UserRole + class QtEvent { + public: + QtEvent(std::shared_ptr<StanzaEvent> event, bool active); + QVariant data(int role); + std::shared_ptr<StanzaEvent> getEvent() { return event_; } + enum EventRoles { + SenderRole = Qt::UserRole - }; + }; - private: - QString text(); - QString sender(); - boost::shared_ptr<StanzaEvent> event_; - bool active_; - }; + private: + QString text(); + QString sender(); + std::shared_ptr<StanzaEvent> event_; + bool active_; + }; } diff --git a/Swift/QtUI/EventViewer/QtEventWindow.cpp b/Swift/QtUI/EventViewer/QtEventWindow.cpp index f92cd07..c8d1f0c 100644 --- a/Swift/QtUI/EventViewer/QtEventWindow.cpp +++ b/Swift/QtUI/EventViewer/QtEventWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -9,12 +9,13 @@ #include <QBoxLayout> #include <QMessageBox> #include <QPushButton> -#include <QtDebug> +#include <QTreeView> #include <Swiften/Base/Platform.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/XMPPEvents/ErrorEvent.h> #include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h> #include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> @@ -26,97 +27,97 @@ 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); + 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); + 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&))); + 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 */ + delete model_; + delete delegate_; + /* Not view_ because this is the parent */ } void QtEventWindow::handleItemClicked(const QModelIndex&) { - readButton_->setEnabled(true); + readButton_->setEnabled(true); } void QtEventWindow::handleReadClicked() { - QModelIndex index = view_->currentIndex(); - if (!index.isValid()) { - return; - } - handleItemActivated(index); + 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<IncomingFileTransferEvent> incomingFTEvent = boost::dynamic_pointer_cast<IncomingFileTransferEvent>(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 (incomingFTEvent) { - eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(incomingFTEvent->getSender()))); - incomingFTEvent->conclude(); - } else { - if (errorEvent) { - errorEvent->conclude(); - } - QMessageBox msgBox; - msgBox.setText(model_->data(item, Qt::DisplayRole).toString()); - msgBox.exec(); - } + QtEvent* event = model_->getItem(item.row()); + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(event->getEvent()); + std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(event->getEvent()); + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(event->getEvent()); + std::shared_ptr<IncomingFileTransferEvent> incomingFTEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(event->getEvent()); + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(event->getEvent()); + + if (messageEvent) { + if (messageEvent->getStanza()->getType() == Message::Groupchat) { + eventStream_->send(std::make_shared<JoinMUCUIEvent>(messageEvent->getStanza()->getFrom().toBare(), messageEvent->getStanza()->getTo().getResource())); + } else { + eventStream_->send(std::make_shared<RequestChatUIEvent>(messageEvent->getStanza()->getFrom())); + } + } else if (subscriptionEvent) { + QtSubscriptionRequestWindow* window = QtSubscriptionRequestWindow::getWindow(subscriptionEvent, this); + window->show(); + } else if (mucInviteEvent) { + eventStream_->send(std::make_shared<RequestChatUIEvent>(mucInviteEvent->getInviter())); + mucInviteEvent->conclude(); + } else if (incomingFTEvent) { + eventStream_->send(std::make_shared<RequestChatUIEvent>(incomingFTEvent->getSender())); + incomingFTEvent->conclude(); + } else { + if (errorEvent) { + errorEvent->conclude(); + } + QMessageBox msgBox; + msgBox.setText(event->data(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()); - readButton_->setEnabled(model_->rowCount() > 0); +void QtEventWindow::addEvent(std::shared_ptr<StanzaEvent> event, bool active) { + view_->clearSelection(); + model_->addEvent(event, active); + emit onNewEventCountUpdated(model_->getNewEventCount()); + readButton_->setEnabled(model_->rowCount() > 0); } -void QtEventWindow::removeEvent(boost::shared_ptr<StanzaEvent> event) { - view_->clearSelection(); - model_->removeEvent(event); - emit onNewEventCountUpdated(model_->getNewEventCount()); - readButton_->setEnabled(model_->rowCount() > 0); +void QtEventWindow::removeEvent(std::shared_ptr<StanzaEvent> event) { + view_->clearSelection(); + model_->removeEvent(event); + emit onNewEventCountUpdated(model_->getNewEventCount()); + readButton_->setEnabled(model_->rowCount() > 0); } } diff --git a/Swift/QtUI/EventViewer/QtEventWindow.h b/Swift/QtUI/EventViewer/QtEventWindow.h index 68c3456..7ae33ec 100644 --- a/Swift/QtUI/EventViewer/QtEventWindow.h +++ b/Swift/QtUI/EventViewer/QtEventWindow.h @@ -1,44 +1,48 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> -#include <QTreeView> +#include <Swift/Controllers/UIInterfaces/EventWindow.h> -#include "Swift/Controllers/UIInterfaces/EventWindow.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/QtUI/EventViewer/EventView.h" -#include "Swift/QtUI/EventViewer/EventModel.h" -#include "Swift/QtUI/EventViewer/EventDelegate.h" +#include <Swift/QtUI/EventViewer/EventDelegate.h> +#include <Swift/QtUI/EventViewer/EventModel.h> +#include <Swift/QtUI/EventViewer/EventView.h> class QPushButton; +class QTreeView; namespace Swift { - class QtEventWindow : public QWidget, public EventWindow { - Q_OBJECT - public: - QtEventWindow(UIEventStream* eventStream); - ~QtEventWindow(); - void addEvent(boost::shared_ptr<StanzaEvent> event, bool active); - void removeEvent(boost::shared_ptr<StanzaEvent> event); - signals: - void onNewEventCountUpdated(int count); - private slots: - void handleItemActivated(const QModelIndex& item); - void handleItemClicked(const QModelIndex& item); - void handleReadClicked(); - private: - EventModel* model_; - EventDelegate* delegate_; - UIEventStream* eventStream_; - QTreeView* view_; - QPushButton* readButton_; - }; - + class UIEventStream; + + class QtEventWindow : public QWidget, public EventWindow { + Q_OBJECT + public: + QtEventWindow(UIEventStream* eventStream); + ~QtEventWindow(); + void addEvent(std::shared_ptr<StanzaEvent> event, bool active); + void removeEvent(std::shared_ptr<StanzaEvent> event); + + signals: + void onNewEventCountUpdated(int count); + + private slots: + void handleItemActivated(const QModelIndex& item); + void handleItemClicked(const QModelIndex& item); + void handleReadClicked(); + + private: + EventModel* model_; + EventDelegate* delegate_; + UIEventStream* eventStream_; + QTreeView* view_; + QPushButton* readButton_; + }; + } diff --git a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp index 662f5f8..5ba24ec 100644 --- a/Swift/QtUI/EventViewer/TwoLineDelegate.cpp +++ b/Swift/QtUI/EventViewer/TwoLineDelegate.cpp @@ -1,20 +1,25 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "TwoLineDelegate.h" +#include <Swift/QtUI/EventViewer/TwoLineDelegate.h> -#include <QPen> +#include <QColor> #include <QPainter> -#include <QDebug> +#include <QPen> namespace Swift { + +namespace { + const QColor secondLineColor = QColor(160,160,160); +} + TwoLineDelegate::TwoLineDelegate(int firstRole, int secondRole, bool wrap) { - firstRole_ = firstRole; - secondRole_ = secondRole; - wrap_ = wrap; + firstRole_ = firstRole; + secondRole_ = secondRole; + wrap_ = wrap; } TwoLineDelegate::~TwoLineDelegate() { @@ -22,41 +27,41 @@ TwoLineDelegate::~TwoLineDelegate() { } QSize TwoLineDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, QtEvent* /*event*/ ) const { - QFontMetrics nameMetrics(common_.nameFont); - QFontMetrics statusMetrics(common_.detailFont); - int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); - return QSize(150, sizeByText); + QFontMetrics nameMetrics(common_.nameFont); + QFontMetrics statusMetrics(common_.detailFont); + int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); + return QSize(150, sizeByText); } void TwoLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const { - painter->save(); - QRect fullRegion(option.rect); - if ( option.state & QStyle::State_Selected ) { - painter->fillRect(fullRegion, option.palette.highlight()); - painter->setPen(option.palette.highlightedText().color()); - } else { - QColor nameColor = event->data(Qt::TextColorRole).value<QColor>(); - painter->setPen(QPen(nameColor)); - } - - QFontMetrics nameMetrics(common_.nameFont); - painter->setFont(common_.nameFont); - int extraFontWidth = nameMetrics.width("H"); - int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; - QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); - - int nameHeight = nameMetrics.height() + common_.verticalMargin; - QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - - DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString()); - - painter->setFont(common_.detailFont); - painter->setPen(QPen(QColor(160,160,160))); - - QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString()); - - painter->restore(); + painter->save(); + QRect fullRegion(option.rect); + if ( option.state & QStyle::State_Selected ) { + painter->fillRect(fullRegion, option.palette.highlight()); + painter->setPen(option.palette.highlightedText().color()); + } else { + QColor nameColor = event->data(Qt::TextColorRole).value<QColor>(); + painter->setPen(QPen(nameColor)); + } + + QFontMetrics nameMetrics(common_.nameFont); + painter->setFont(common_.nameFont); + int extraFontWidth = nameMetrics.width("H"); + int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; + QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); + + int nameHeight = nameMetrics.height() + common_.verticalMargin; + QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); + + DelegateCommons::drawElidedText(painter, nameRegion, event->data(firstRole_).toString()); + + painter->setFont(common_.detailFont); + painter->setPen(QPen(secondLineColor)); + + QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); + DelegateCommons::drawElidedText(painter, detailRegion, event->data(secondRole_).toString()); + + painter->restore(); } } diff --git a/Swift/QtUI/EventViewer/TwoLineDelegate.h b/Swift/QtUI/EventViewer/TwoLineDelegate.h index e1e3c7a..089f97a 100644 --- a/Swift/QtUI/EventViewer/TwoLineDelegate.h +++ b/Swift/QtUI/EventViewer/TwoLineDelegate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,22 +8,22 @@ #include <QStyledItemDelegate> -#include "Swift/QtUI/Roster/DelegateCommons.h" -#include "QtEvent.h" +#include <Swift/QtUI/EventViewer/QtEvent.h> +#include <Swift/QtUI/Roster/DelegateCommons.h> namespace Swift { - class TwoLineDelegate { - public: - TwoLineDelegate(int firstRole, int secondRole, bool wrap); - ~TwoLineDelegate(); - QSize sizeHint(const QStyleOptionViewItem& option, QtEvent* event) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const; - private: - DelegateCommons common_; - int firstRole_; - int secondRole_; - bool wrap_; - }; + class TwoLineDelegate { + public: + TwoLineDelegate(int firstRole, int secondRole, bool wrap); + ~TwoLineDelegate(); + QSize sizeHint(const QStyleOptionViewItem& option, QtEvent* event) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, QtEvent* event) const; + private: + DelegateCommons common_; + int firstRole_; + int secondRole_; + bool wrap_; + }; } diff --git a/Swift/QtUI/EventViewer/main.cpp b/Swift/QtUI/EventViewer/main.cpp index 278dfa8..492599e 100644 --- a/Swift/QtUI/EventViewer/main.cpp +++ b/Swift/QtUI/EventViewer/main.cpp @@ -1,31 +1,33 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <QtGui> -#include "EventView.h" -#include "EventModel.h" -#include "QtEventWindow.h" -#include "Swiften/Events/MessageEvent.h" -#include "Swiften/Events/ErrorEvent.h" -#include "Swiften/JID/JID.h" +#include <EventModel.h> +#include <EventView.h> + +#include <Swiften/Events/ErrorEvent.h> +#include <Swiften/Events/MessageEvent.h> +#include <Swiften/JID/JID.h> + +#include <Swift/QtUI/EventViewer/QtEventWindow.h> int main(int argc, char *argv[]) { - QApplication app(argc, argv); - Swift::UIEventStream eventStream; - Swift::QtEventWindow* viewer = new Swift::QtEventWindow(&eventStream); - viewer->show(); - boost::shared_ptr<Swift::Message> message1(new Swift::Message()); - message1->setBody("Oooh, shiny"); - boost::shared_ptr<Swift::MessageEvent> event1(new Swift::MessageEvent(message1)); - viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), true); - for (int i = 0; i < 100; i++) { - viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(event1), false); - } - viewer->addEvent(boost::dynamic_pointer_cast<Swift::StanzaEvent>(boost::make_shared<Swift::ErrorEvent>(Swift::JID("me@example.com"), "Something bad did happen to you.")), true); - return app.exec(); + QApplication app(argc, argv); + Swift::UIEventStream eventStream; + Swift::QtEventWindow* viewer = new Swift::QtEventWindow(&eventStream); + viewer->show(); + std::shared_ptr<Swift::Message> message1(new Swift::Message()); + message1->setBody("Oooh, shiny"); + std::shared_ptr<Swift::MessageEvent> event1(new Swift::MessageEvent(message1)); + viewer->addEvent(std::dynamic_pointer_cast<Swift::StanzaEvent>(event1), true); + for (int i = 0; i < 100; i++) { + viewer->addEvent(std::dynamic_pointer_cast<Swift::StanzaEvent>(event1), false); + } + viewer->addEvent(std::dynamic_pointer_cast<Swift::StanzaEvent>(std::make_shared<Swift::ErrorEvent>(Swift::JID("me@example.com"), "Something bad did happen to you.")), true); + return app.exec(); } |