From 21e358a55e6eee1036fe95993c5715382d08c0c8 Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Tue, 5 Jun 2012 15:49:26 +0200 Subject: Moved whiteboard handling to WhiteboardManager 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 + +#include + +#include +#include + +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 event) { + boost::shared_ptr whiteboardEvent = boost::dynamic_pointer_cast(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 + +#include + +#include + +#include +#include +#include + +namespace Swift { + class StanzaChannel; + + class WhiteboardManager { + public: + WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel); + ~WhiteboardManager(); + + private: + void handleUIEvent(boost::shared_ptr event); + + private: + std::map 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 #include +#include 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 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 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(contact->getJID())); @@ -79,6 +81,9 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { } } #endif + else if (result == startWhiteboardChat) { + eventStream_->send(boost::make_shared(contact->getJID())); + } } else if (GroupRosterItem* group = dynamic_cast(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 +#include + +#include + +#include +#include 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) { + boost::shared_ptr wb = message->getPayload(); + 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 mes(new Message()); + mes->setTo(jid_); + boost::shared_ptr 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 +#include +#include "Swiften/JID/JID.h" #include #include @@ -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); void addItem(const std::string& item); void show(); @@ -67,5 +72,8 @@ namespace Swift { QToolButton* textButton; QToolButton* polygonButton; QToolButton* selectButton; + + StanzaChannel* stanzaChannel_; + JID jid_; }; } -- cgit v0.10.2-6-g49f6