diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-02 16:23:59 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-02 16:23:59 (GMT) |
commit | 7520c7fed383d4f7631f5572ef40379022126264 (patch) | |
tree | ee87b26bb923d0289a670defce96e2012f3623e3 /Swift/Controllers | |
parent | e8ab1af885ff61715ab0350c3cb22ed6988a082a (diff) | |
download | swift-contrib-7520c7fed383d4f7631f5572ef40379022126264.zip swift-contrib-7520c7fed383d4f7631f5572ef40379022126264.tar.bz2 |
Added whiteboard controller with simple sharing
Whiteboard controller is handled in ChatController only for
testing purposes.
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 3 | ||||
-rw-r--r-- | Swift/Controllers/SConscript | 3 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/UIFactory.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindow.h | 24 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h | 17 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardController.cpp | 45 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardController.h | 31 |
9 files changed, 132 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 2fa4559..38f443b 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -29,6 +29,8 @@ #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> #include <Swift/Controllers/SettingConstants.h> +#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> +#include <Swift/Controllers/WhiteboardController.h> #include <Swiften/Base/Log.h> @@ -39,6 +41,8 @@ namespace Swift { */ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings) : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts), settings_(settings) { + WhiteboardWindowFactory* fac = dynamic_cast<WhiteboardWindowFactory*>(chatWindowFactory); + whiteboardController_ = new WhiteboardController(stanzaChannel, toJID_, fac); isInMUC_ = isInMUC; lastWasPresence_ = false; chatStateNotifier_ = new ChatStateNotifier(stanzaChannel, contact, entityCapsProvider); @@ -89,6 +93,7 @@ ChatController::~ChatController() { nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2)); delete chatStateNotifier_; delete chatStateTracker_; + delete whiteboardController_; } JID ChatController::getBaseJID() { @@ -138,6 +143,7 @@ bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) { } void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) { + whiteboardController_->handleIncomingMessage(messageEvent); if (messageEvent->isReadable()) { chatWindow_->flash(); lastWasPresence_ = false; diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index 7043231..a6a9efa 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -12,6 +12,7 @@ #include <string> #include <Swift/Controllers/UIInterfaces/ChatWindow.h> +#include "Swift/Controllers/WhiteboardController.h" namespace Swift { class AvatarManager; @@ -76,6 +77,7 @@ namespace Swift { bool userWantsReceipts_; std::map<std::string, FileTransferController*> ftControllers; SettingsProvider* settings_; + WhiteboardController* whiteboardController_; }; } diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index da96603..b9a5759 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -30,6 +30,7 @@ #include <Swiften/MUC/MUCManager.h> #include <Swiften/Elements/ChatState.h> #include <Swiften/Elements/MUCUserPayload.h> +#include <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> #include <Swiften/MUC/MUCBookmarkManager.h> @@ -610,7 +611,7 @@ void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) { if (isMediatedInvite) { jid = (*message->getPayload<MUCUserPayload>()->getInvite()).from; } - if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject()) { + if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject() && !message->getPayload<WhiteboardPayload>()) { return; } diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index 70085a6..1e18d65 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -70,7 +70,8 @@ if env["SCONS_STAGE"] == "build" : "Translator.cpp", "XMPPURIController.cpp", "ChatMessageSummarizer.cpp", - "SettingConstants.cpp" + "SettingConstants.cpp", + "WhiteboardController.cpp" ]) env.Append(UNITTEST_SOURCES = [ diff --git a/Swift/Controllers/UIInterfaces/UIFactory.h b/Swift/Controllers/UIInterfaces/UIFactory.h index cf89dab..b583bf0 100644 --- a/Swift/Controllers/UIInterfaces/UIFactory.h +++ b/Swift/Controllers/UIInterfaces/UIFactory.h @@ -19,6 +19,7 @@ #include <Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h> #include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h> #include <Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h> +#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> namespace Swift { class UIFactory : @@ -34,7 +35,8 @@ namespace Swift { public ProfileWindowFactory, public ContactEditWindowFactory, public AdHocCommandWindowFactory, - public FileTransferListWidgetFactory { + public FileTransferListWidgetFactory, + public WhiteboardWindowFactory { public: virtual ~UIFactory() {} }; diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h new file mode 100644 index 0000000..bedb057 --- /dev/null +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include "Swiften/Base/boost_bsignals.h" + +#include <string> + +namespace Swift { + + class WhiteboardWindow { + public: + virtual ~WhiteboardWindow() {} + + virtual void show() = 0; + virtual void addItem(const std::string& item) = 0; + + boost::signal<void (std::string)> onItemAdd; + }; +} diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h new file mode 100644 index 0000000..a16b083 --- /dev/null +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +namespace Swift { + class WhiteboardWindow; + class WhiteboardWindowFactory { + public : + virtual ~WhiteboardWindowFactory() {}; + + virtual WhiteboardWindow* createWhiteboardWindow() = 0; + }; +} diff --git a/Swift/Controllers/WhiteboardController.cpp b/Swift/Controllers/WhiteboardController.cpp new file mode 100644 index 0000000..9228901 --- /dev/null +++ b/Swift/Controllers/WhiteboardController.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <boost/bind.hpp> + +#include "Swift/Controllers/WhiteboardController.h" + +#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> +#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> + +#include <Swiften/Elements/WhiteboardPayload.h> + +#include <iostream> + +namespace Swift { + WhiteboardController::WhiteboardController(StanzaChannel* stanzaChannel, const JID& toJID, WhiteboardWindowFactory* whiteboardWindowFactory) : stanzaChannel_(stanzaChannel), toJID_(toJID) { + whiteboardWindow_ = whiteboardWindowFactory->createWhiteboardWindow(); + whiteboardWindow_->show(); + whiteboardWindow_->onItemAdd.connect(boost::bind(&WhiteboardController::handleItemChange, this, _1)); + } + + WhiteboardController::~WhiteboardController() { + delete whiteboardWindow_; + } + + void WhiteboardController::handleIncomingMessage(boost::shared_ptr<MessageEvent> message) { + boost::shared_ptr<WhiteboardPayload> wb = message->getStanza()->getPayload<WhiteboardPayload>(); + if(wb) { + whiteboardWindow_->addItem(wb->getData()); + } + } + + void WhiteboardController::handleItemChange(std::string item) { + boost::shared_ptr<Message> mes(new Message()); + mes->setTo(toJID_); + boost::shared_ptr<WhiteboardPayload> wbPayload(new WhiteboardPayload); + wbPayload->setData(item); +// mes->setType(Swift::Message::Chat); + mes->addPayload(wbPayload); + stanzaChannel_->sendMessage(mes); + } +} diff --git a/Swift/Controllers/WhiteboardController.h b/Swift/Controllers/WhiteboardController.h new file mode 100644 index 0000000..aa1ace3 --- /dev/null +++ b/Swift/Controllers/WhiteboardController.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/Client/StanzaChannel.h> +#include "Swiften/JID/JID.h" +#include "Swift/Controllers/XMPPEvents/MessageEvent.h" + +namespace Swift { + class WhiteboardWindow; + class WhiteboardWindowFactory; + + class WhiteboardController { + public: + WhiteboardController(StanzaChannel* stanzaChannel, const JID& toJID, WhiteboardWindowFactory* whiteboardWindowFactory); + ~WhiteboardController(); + void handleIncomingMessage(boost::shared_ptr<MessageEvent> message); + private: + void handleItemChange(std::string item); + WhiteboardWindow* whiteboardWindow_; + StanzaChannel* stanzaChannel_; + JID toJID_; + }; +} + |