diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-05 13:49:26 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-05 13:49:26 (GMT) |
commit | 21e358a55e6eee1036fe95993c5715382d08c0c8 (patch) | |
tree | c512cb0b6640c1fee942cf55fa76954a8100568c /Swift | |
parent | dfeab948530982d10a7754a93a37cd8422888378 (diff) | |
download | swift-contrib-21e358a55e6eee1036fe95993c5715382d08c0c8.zip swift-contrib-21e358a55e6eee1036fe95993c5715382d08c0c8.tar.bz2 |
Moved whiteboard handling to WhiteboardManager
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/MainController.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/SConscript | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h | 21 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.cpp | 29 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.h | 38 | ||||
-rw-r--r-- | Swift/QtUI/QtUIFactory.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtUIFactory.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtRosterWidget.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 27 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.h | 10 |
12 files changed, 143 insertions, 9 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index cb43057..d9bb249 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -42,6 +42,7 @@ #include "Swift/Controllers/PresenceNotifier.h" #include "Swift/Controllers/EventNotifier.h" #include "Swift/Controllers/Storages/StoragesFactory.h" +#include "Swift/Controllers/WhiteboardManager.h" #include "SwifTools/Dock/Dock.h" #include "SwifTools/Notifier/TogglableNotifier.h" #include "Swiften/Base/foreach.h" @@ -240,6 +241,8 @@ void MainController::resetClient() { userSearchControllerAdd_ = NULL; delete adHocManager_; adHocManager_ = NULL; + delete whiteboardManager_; + whiteboardManager_ = NULL; clientInitialized_ = false; } @@ -317,6 +320,7 @@ void MainController::handleConnected() { userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow()); + whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getStanzaChannel()); } loginWindow_->setIsLoggingIn(false); diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index eeba9f3..4395c67 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -68,6 +68,7 @@ namespace Swift { class AdHocManager; class AdHocCommandWindowFactory; class FileTransferOverview; + class WhiteboardManager; class MainController { public: @@ -167,5 +168,6 @@ namespace Swift { bool offlineRequested_; static const int SecondsToWaitBeforeForceQuitting; FileTransferOverview* ftOverview_; + WhiteboardManager* whiteboardManager_; }; } diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index 1e18d65..91a8949 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -71,7 +71,7 @@ if env["SCONS_STAGE"] == "build" : "XMPPURIController.cpp", "ChatMessageSummarizer.cpp", "SettingConstants.cpp", - "WhiteboardController.cpp" + "WhiteboardManager.cpp" ]) env.Append(UNITTEST_SOURCES = [ diff --git a/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h new file mode 100644 index 0000000..679bdc2 --- /dev/null +++ b/Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h @@ -0,0 +1,21 @@ +/* + * 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/JID/JID.h" + +#include "Swift/Controllers/UIEvents/UIEvent.h" + +namespace Swift { + class RequestWhiteboardUIEvent : public UIEvent { + public: + RequestWhiteboardUIEvent(const JID& contact) : contact_(contact) {}; + JID getContact() {return contact_;} + private: + JID contact_; + }; +} diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h index a16b083..8b52ee1 100644 --- a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h @@ -6,12 +6,16 @@ #pragma once +#include "Swiften/JID/JID.h" + namespace Swift { class WhiteboardWindow; + class StanzaChannel; + class WhiteboardWindowFactory { public : virtual ~WhiteboardWindowFactory() {}; - virtual WhiteboardWindow* createWhiteboardWindow() = 0; + virtual WhiteboardWindow* createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) = 0; }; } diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp new file mode 100644 index 0000000..3a87387 --- /dev/null +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swift/Controllers/WhiteboardManager.h> + +#include <boost/bind.hpp> + +#include <Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h> +#include <Swiften/Client/StanzaChannel.h> + +namespace Swift { + WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), stanzaChannel_(stanzaChannel) { + uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); + } + + WhiteboardManager::~WhiteboardManager() { + } + + void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { + boost::shared_ptr<RequestWhiteboardUIEvent> whiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); + if(whiteboardEvent) { + WhiteboardWindow* window = whiteboardWindowFactory_->createWhiteboardWindow(stanzaChannel_, whiteboardEvent->getContact()); + window->show(); + } + } +} diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h new file mode 100644 index 0000000..5876adf --- /dev/null +++ b/Swift/Controllers/WhiteboardManager.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#pragma once + +#include <map> + +#include <boost/shared_ptr.hpp> + +#include <Swiften/JID/JID.h> + +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> +#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> + +namespace Swift { + class StanzaChannel; + + class WhiteboardManager { + public: + WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel); + ~WhiteboardManager(); + + private: + void handleUIEvent(boost::shared_ptr<UIEvent> event); + + private: + std::map<JID, WhiteboardWindow*> whiteboardWindows_; + UIEventStream* uiEventStream_; + WhiteboardWindowFactory* whiteboardWindowFactory_; + boost::bsignals::scoped_connection uiEventConnection_; + StanzaChannel* stanzaChannel_; + }; +} diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index 28c8c7c..d127791 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -28,6 +28,7 @@ #include "Whiteboard/QtWhiteboardWindow.h" #include <Swift/Controllers/Settings/SettingsProviderHierachy.h> #include <Swift/QtUI/QtUISettingConstants.h> +#include <Swiften/Client/StanzaChannel.h> namespace Swift { @@ -135,8 +136,8 @@ ContactEditWindow* QtUIFactory::createContactEditWindow() { return new QtContactEditWindow(); } -WhiteboardWindow* QtUIFactory::createWhiteboardWindow() { - return new QtWhiteboardWindow(); +WhiteboardWindow* QtUIFactory::createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) { + return new QtWhiteboardWindow(stanzaChannel, jid); } void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) { diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h index e52c663..0c337f4 100644 --- a/Swift/QtUI/QtUIFactory.h +++ b/Swift/QtUI/QtUIFactory.h @@ -24,6 +24,7 @@ namespace Swift { class QtChatWindowFactory; class QtChatWindow; class TimerFactory; + class StanzaChannel; class QtUIFactory : public QObject, public UIFactory { Q_OBJECT @@ -42,7 +43,7 @@ namespace Swift { virtual ProfileWindow* createProfileWindow(); virtual ContactEditWindow* createContactEditWindow(); virtual FileTransferListWidget* createFileTransferListWidget(); - virtual WhiteboardWindow* createWhiteboardWindow(); + virtual WhiteboardWindow* createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid); virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); private slots: diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp index 2fe7f33..a7767fe 100644 --- a/Swift/QtUI/Roster/QtRosterWidget.cpp +++ b/Swift/QtUI/Roster/QtRosterWidget.cpp @@ -15,6 +15,7 @@ #include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" #include "Swift/Controllers/UIEvents/SendFileUIEvent.h" +#include "Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h" #include "QtContactEditWindow.h" #include "Swift/Controllers/Roster/ContactRosterItem.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" @@ -62,6 +63,7 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { sendFile = contextMenu.addAction(tr("Send File")); } #endif + QAction* startWhiteboardChat = contextMenu.addAction(tr("Start Whiteboard Chat")); QAction* result = contextMenu.exec(event->globalPos()); if (result == editContact) { eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID())); @@ -79,6 +81,9 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { } } #endif + else if (result == startWhiteboardChat) { + eventStream_->send(boost::make_shared<RequestWhiteboardUIEvent>(contact->getJID())); + } } else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 19d64ae..b991e52 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -6,12 +6,17 @@ #include "QtWhiteboardWindow.h" -#include<iostream> +#include <iostream> + +#include <boost/bind.hpp> + +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/WhiteboardPayload.h> using namespace std; namespace Swift { - QtWhiteboardWindow::QtWhiteboardWindow() : QWidget() { + QtWhiteboardWindow::QtWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) : QWidget(), stanzaChannel_(stanzaChannel), jid_(jid) { layout = new QVBoxLayout(this); hLayout = new QHBoxLayout; sidebarLayout = new QVBoxLayout; @@ -115,6 +120,15 @@ namespace Swift { hLayout->addLayout(sidebarLayout); layout->addLayout(hLayout); this->setLayout(layout); + + stanzaChannel_->onMessageReceived.connect(boost::bind(&QtWhiteboardWindow::handleIncommingMessage, this, _1)); + } + + void QtWhiteboardWindow::handleIncommingMessage(boost::shared_ptr<Message> message) { + boost::shared_ptr<WhiteboardPayload> wb = message->getPayload<WhiteboardPayload>(); + if(wb) { + addItem(wb->getData()); + } } void QtWhiteboardWindow::addItem(const std::string& item) { @@ -245,7 +259,14 @@ namespace Swift { } if (!serialized.empty()) { cout << "serialized: " << serialized << endl; - onItemAdd(serialized); + boost::shared_ptr<Message> mes(new Message()); + mes->setTo(jid_); + boost::shared_ptr<WhiteboardPayload> wbPayload(new WhiteboardPayload); + wbPayload->setData(serialized); +// mes->setType(Swift::Message::Chat); + mes->addPayload(wbPayload); + stanzaChannel_->sendMessage(mes); } + } } diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h index f472629..9ced322 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h @@ -7,6 +7,8 @@ #pragma once #include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> +#include <Swiften/Elements/Message.h> +#include "Swiften/JID/JID.h" #include <QWidget> #include <QGraphicsView> @@ -23,11 +25,14 @@ #include "GView.h" namespace Swift { + class StanzaChannel; + class QtWhiteboardWindow : public QWidget, public WhiteboardWindow { Q_OBJECT; public: - QtWhiteboardWindow(); + QtWhiteboardWindow(StanzaChannel *stanzaChannel, const JID& jid); + void handleIncommingMessage(boost::shared_ptr<Message> message); void addItem(const std::string& item); void show(); @@ -67,5 +72,8 @@ namespace Swift { QToolButton* textButton; QToolButton* polygonButton; QToolButton* selectButton; + + StanzaChannel* stanzaChannel_; + JID jid_; }; } |