diff options
Diffstat (limited to 'Swift/Controllers/XMPPEvents')
-rw-r--r-- | Swift/Controllers/XMPPEvents/ErrorEvent.h | 39 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.cpp | 90 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.h | 58 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h | 30 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/MUCInviteEvent.h | 57 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/MessageEvent.h | 77 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/StanzaEvent.h | 40 | ||||
-rw-r--r-- | Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h | 69 |
8 files changed, 262 insertions, 198 deletions
diff --git a/Swift/Controllers/XMPPEvents/ErrorEvent.h b/Swift/Controllers/XMPPEvents/ErrorEvent.h index ac09de9..c0b5e52 100644 --- a/Swift/Controllers/XMPPEvents/ErrorEvent.h +++ b/Swift/Controllers/XMPPEvents/ErrorEvent.h @@ -1,31 +1,32 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <cassert> +#include <memory> +#include <string> -#include "Swiften/Base/boost_bsignals.h" -#include <boost/shared_ptr.hpp> +#include <boost/signals2.hpp> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class ErrorEvent : public StanzaEvent { - public: - ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){} - virtual ~ErrorEvent(){} - const JID& getJID() const {return jid_;} - const std::string& getText() const {return text_;} - - private: - JID jid_; - std::string text_; - }; + class ErrorEvent : public StanzaEvent { + public: + ErrorEvent(const JID& jid, const std::string& text) : jid_(jid), text_(text){} + virtual ~ErrorEvent(){} + const JID& getJID() const {return jid_;} + const std::string& getText() const {return text_;} + + private: + JID jid_; + std::string text_; + }; } diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp index 8cb259b..0e9429d 100644 --- a/Swift/Controllers/XMPPEvents/EventController.cpp +++ b/Swift/Controllers/XMPPEvents/EventController.cpp @@ -1,20 +1,21 @@ /* - * Copyright (c) 2010-2012 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #include <Swift/Controllers/XMPPEvents/EventController.h> +#include <algorithm> + #include <boost/bind.hpp> #include <boost/numeric/conversion/cast.hpp> -#include <algorithm> -#include <Swiften/Base/foreach.h> -#include <Swift/Controllers/XMPPEvents/MessageEvent.h> #include <Swift/Controllers/XMPPEvents/ErrorEvent.h> -#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h> +#include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h> #include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> +#include <Swift/Controllers/XMPPEvents/MessageEvent.h> +#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h> namespace Swift { @@ -22,55 +23,56 @@ EventController::EventController() { } EventController::~EventController() { - foreach(boost::shared_ptr<StanzaEvent> event, events_) { - event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); - } + for (auto&& event : events_) { + event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); + } } -void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent) { - boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent); - boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); - boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent); - boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); +void EventController::handleIncomingEvent(std::shared_ptr<StanzaEvent> sourceEvent) { + std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(sourceEvent); + std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); + std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(sourceEvent); + std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); + std::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent); - /* If it's a duplicate subscription request, remove the previous request first */ - if (subscriptionEvent) { - EventList existingEvents(events_); - foreach(boost::shared_ptr<StanzaEvent> existingEvent, existingEvents) { - boost::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent); - if (existingSubscriptionEvent) { - if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) { - existingEvent->conclude(); - } - } - } - } + /* If it's a duplicate subscription request, remove the previous request first */ + if (subscriptionEvent) { + EventList existingEvents(events_); + for (auto&& existingEvent : existingEvents) { + std::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent); + if (existingSubscriptionEvent) { + if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) { + existingEvent->conclude(); + } + } + } + } - if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent) { - events_.push_back(sourceEvent); - sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); - onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); - onEventQueueEventAdded(sourceEvent); - if (sourceEvent->getConcluded()) { - handleEventConcluded(sourceEvent); - } - } + if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) { + events_.push_back(sourceEvent); + sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); + onEventQueueLengthChange(events_.size()); + onEventQueueEventAdded(sourceEvent); + if (sourceEvent->getConcluded()) { + handleEventConcluded(sourceEvent); + } + } } -void EventController::handleEventConcluded(boost::shared_ptr<StanzaEvent> event) { - event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); - events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end()); - onEventQueueLengthChange(boost::numeric_cast<int>(events_.size())); +void EventController::handleEventConcluded(std::shared_ptr<StanzaEvent> event) { + event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event)); + events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end()); + onEventQueueLengthChange(events_.size()); } void EventController::disconnectAll() { - onEventQueueLengthChange.disconnect_all_slots(); - onEventQueueEventAdded.disconnect_all_slots(); + onEventQueueLengthChange.disconnect_all_slots(); + onEventQueueEventAdded.disconnect_all_slots(); } void EventController::clear() { - events_.clear(); - onEventQueueLengthChange(0); + events_.clear(); + onEventQueueLengthChange(0); } } diff --git a/Swift/Controllers/XMPPEvents/EventController.h b/Swift/Controllers/XMPPEvents/EventController.h index 827dce8..5b746e4 100644 --- a/Swift/Controllers/XMPPEvents/EventController.h +++ b/Swift/Controllers/XMPPEvents/EventController.h @@ -1,40 +1,36 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2018 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#ifndef SWIFTEN_EventController_H -#define SWIFTEN_EventController_H +#pragma once - -#include "Swiften/Base/boost_bsignals.h" -#include <boost/shared_ptr.hpp> +#include <cstddef> +#include <memory> #include <vector> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include "Swift/Controllers/XMPPEvents/MessageEvent.h" - -namespace Swift { - typedef std::vector<boost::shared_ptr<StanzaEvent> > EventList; - class EventController { - public: - - EventController(); - ~EventController(); +#include <boost/signals2.hpp> - void handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent); - boost::signal<void (int)> onEventQueueLengthChange; - boost::signal<void (boost::shared_ptr<StanzaEvent>)> onEventQueueEventAdded; - const EventList& getEvents() const {return events_;} - void disconnectAll(); - void clear(); +#include <Swift/Controllers/XMPPEvents/MessageEvent.h> +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> - private: - void handleEventConcluded(boost::shared_ptr<StanzaEvent> event); - EventList events_; - }; +namespace Swift { + typedef std::vector<std::shared_ptr<StanzaEvent> > EventList; + class EventController { + public: + EventController(); + ~EventController(); + + void handleIncomingEvent(std::shared_ptr<StanzaEvent> sourceEvent); + boost::signals2::signal<void (size_t)> onEventQueueLengthChange; + boost::signals2::signal<void (std::shared_ptr<StanzaEvent>)> onEventQueueEventAdded; + const EventList& getEvents() const {return events_;} + void disconnectAll(); + void clear(); + + private: + void handleEventConcluded(std::shared_ptr<StanzaEvent> event); + EventList events_; + }; } -#endif - - diff --git a/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h new file mode 100644 index 0000000..3d4303d --- /dev/null +++ b/Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> + +namespace Swift { + class IncomingFileTransferEvent : public StanzaEvent { + public: + typedef std::shared_ptr<IncomingFileTransferEvent> ref; + + IncomingFileTransferEvent(const JID& sender) : sender_(sender) {} + + const JID& getSender() const { + return sender_; + } + + private: + JID sender_; + }; +} + diff --git a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h index 65ecece..4cdbbff 100644 --- a/Swift/Controllers/XMPPEvents/MUCInviteEvent.h +++ b/Swift/Controllers/XMPPEvents/MUCInviteEvent.h @@ -4,30 +4,43 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once +#include <memory> +#include <string> + +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> + namespace Swift { - class MUCInviteEvent : public StanzaEvent { - public: - typedef boost::shared_ptr<MUCInviteEvent> ref; - - public: - MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {} - - const JID& getInviter() const { return inviter_; } - const JID& getRoomJID() const { return roomJID_; } - const std::string& getReason() const { return reason_; } - const std::string& getPassword() const { return password_; } - bool getDirect() const { return direct_; } - bool getImpromptu() const { return impromptu_; } - - private: - JID inviter_; - JID roomJID_; - std::string reason_; - std::string password_; - bool direct_; - bool impromptu_; - }; + class MUCInviteEvent : public StanzaEvent { + public: + typedef std::shared_ptr<MUCInviteEvent> ref; + + public: + MUCInviteEvent(const JID& inviter, const JID& roomJID, const std::string& reason, const std::string& password, bool direct, bool impromptu) : inviter_(inviter), roomJID_(roomJID), reason_(reason), password_(password), direct_(direct), impromptu_(impromptu) {} + + const JID& getInviter() const { return inviter_; } + const JID& getRoomJID() const { return roomJID_; } + const std::string& getReason() const { return reason_; } + const std::string& getPassword() const { return password_; } + bool getDirect() const { return direct_; } + bool getImpromptu() const { return impromptu_; } + + private: + JID inviter_; + JID roomJID_; + std::string reason_; + std::string password_; + bool direct_; + bool impromptu_; + }; } diff --git a/Swift/Controllers/XMPPEvents/MessageEvent.h b/Swift/Controllers/XMPPEvents/MessageEvent.h index a9214f5..12f4c48 100644 --- a/Swift/Controllers/XMPPEvents/MessageEvent.h +++ b/Swift/Controllers/XMPPEvents/MessageEvent.h @@ -1,46 +1,67 @@ /* - * Copyright (c) 2010-2012 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2017 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ -#pragma once +#pragma once + #include <cassert> +#include <memory> -#include <boost/shared_ptr.hpp> +#include <Swiften/Elements/Message.h> #include <Swift/Controllers/XMPPEvents/StanzaEvent.h> -#include <Swiften/Elements/Message.h> namespace Swift { - class MessageEvent : public StanzaEvent { - public: - typedef boost::shared_ptr<MessageEvent> ref; + class MessageEvent : public StanzaEvent { + public: + class SystemNotification { + public: + SystemNotification(const std::string& title, const std::string& message) : title(title), message(message) { + } + + public: + std::string title; + std::string message; + }; + + public: + typedef std::shared_ptr<MessageEvent> ref; + + MessageEvent(std::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {} + + std::shared_ptr<Message> getStanza() {return stanza_;} - MessageEvent(boost::shared_ptr<Message> stanza) : stanza_(stanza), targetsMe_(true) {} + bool isReadable() { + return getStanza()->isError() || !getStanza()->getBody().get_value_or("").empty(); + } - boost::shared_ptr<Message> getStanza() {return stanza_;} + void addNotification(const std::string& title, const std::string& message) { + systemNotifications_.push_back(SystemNotification(title, message)); + } - bool isReadable() { - return getStanza()->isError() || !getStanza()->getBody().empty(); - } + const std::vector<SystemNotification>& getNotifications() const { + return systemNotifications_; + } - void read() { - assert (isReadable()); - conclude(); - } + void read() { + assert (isReadable()); + conclude(); + } - void setTargetsMe(bool targetsMe) { - targetsMe_ = targetsMe; - } + void setTargetsMe(bool targetsMe) { + targetsMe_ = targetsMe; + } - bool targetsMe() const { - return targetsMe_; - } + bool targetsMe() const { + return targetsMe_; + } - private: - boost::shared_ptr<Message> stanza_; - bool targetsMe_; - }; + private: + std::shared_ptr<Message> stanza_; + std::vector<SystemNotification> systemNotifications_; + bool targetsMe_; + }; } diff --git a/Swift/Controllers/XMPPEvents/StanzaEvent.h b/Swift/Controllers/XMPPEvents/StanzaEvent.h index a15afc1..56c4ea3 100644 --- a/Swift/Controllers/XMPPEvents/StanzaEvent.h +++ b/Swift/Controllers/XMPPEvents/StanzaEvent.h @@ -1,29 +1,29 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> +#include <memory> -#include "Swiften/Base/boost_bsignals.h" +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/signals2.hpp> namespace Swift { - class StanzaEvent { - public: - StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;} - virtual ~StanzaEvent() {} - void conclude() {concluded_ = true; onConclusion();} - /** Do not call this directly from outside the class. - * If you connect to this signal, you *must* disconnect from it manually. */ - boost::signal<void()> onConclusion; - bool getConcluded() {return concluded_;} - boost::posix_time::ptime getTime() {return time_;} - private: - bool concluded_; - boost::posix_time::ptime time_; - }; + class StanzaEvent { + public: + StanzaEvent() : time_(boost::posix_time::microsec_clock::universal_time()) {concluded_ = false;} + virtual ~StanzaEvent() {} + void conclude() {concluded_ = true; onConclusion();} + /** Do not call this directly from outside the class. + * If you connect to this signal, you *must* disconnect from it manually. */ + boost::signals2::signal<void()> onConclusion; + bool getConcluded() {return concluded_;} + boost::posix_time::ptime getTime() {return time_;} + private: + bool concluded_; + boost::posix_time::ptime time_; + }; } diff --git a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h index fb7a05e..8e3fd32 100644 --- a/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h +++ b/Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h @@ -1,46 +1,47 @@ /* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. */ #pragma once #include <cassert> +#include <memory> +#include <string> -#include "Swiften/Base/boost_bsignals.h" -#include <boost/shared_ptr.hpp> +#include <boost/signals2.hpp> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include <string> -#include "Swiften/JID/JID.h" +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> namespace Swift { - class SubscriptionRequestEvent : public StanzaEvent { - public: - SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){} - virtual ~SubscriptionRequestEvent(){} - const JID& getJID() const {return jid_;} - const std::string& getReason() const {return reason_;} - boost::signal<void()> onAccept; - boost::signal<void()> onDecline; - void accept() { - onAccept(); - conclude(); - } - - void decline() { - onDecline(); - conclude(); - } - - void defer() { - conclude(); - } - - private: - JID jid_; - std::string reason_; - }; + class SubscriptionRequestEvent : public StanzaEvent { + public: + SubscriptionRequestEvent(const JID& jid, const std::string& reason) : jid_(jid), reason_(reason){} + virtual ~SubscriptionRequestEvent(){} + const JID& getJID() const {return jid_;} + const std::string& getReason() const {return reason_;} + boost::signals2::signal<void()> onAccept; + boost::signals2::signal<void()> onDecline; + void accept() { + onAccept(); + conclude(); + } + + void decline() { + onDecline(); + conclude(); + } + + void defer() { + conclude(); + } + + private: + JID jid_; + std::string reason_; + }; } |