diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-08-08 08:47:51 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-08-08 08:47:51 (GMT) |
commit | b4bdfea96ac0e0971109df94b3b71f79adefefe9 (patch) | |
tree | 1ff771011d94fe8a89d17d3e15c34971247b25e5 /Swift | |
parent | ed00df1501e2da74b0287999d4d1c7185005e3f6 (diff) | |
download | swift-contrib-b4bdfea96ac0e0971109df94b3b71f79adefefe9.zip swift-contrib-b4bdfea96ac0e0971109df94b3b71f79adefefe9.tar.bz2 |
wb session manager responsible only for creating and storing sessions
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 14 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | 11 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.cpp | 75 | ||||
-rw-r--r-- | Swift/Controllers/WhiteboardManager.h | 15 |
6 files changed, 91 insertions, 35 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 4705246..bfcc15a 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -42,7 +42,7 @@ #include <Swift/Controllers/Settings/SettingsProvider.h> #include <Swift/Controllers/SettingConstants.h> #include <Swiften/Client/StanzaChannel.h> -#include <Swiften/Whiteboard/WhiteboardSessionManager.h> +#include <Swift/Controllers/WhiteboardManager.h> namespace Swift { @@ -73,7 +73,7 @@ ChatsManager::ChatsManager( XMPPRoster* roster, bool eagleMode, SettingsProvider* settings, - WhiteboardSessionManager* whiteboardSessionManager) : + WhiteboardManager* whiteboardManager) : jid_(jid), joinMUCWindowFactory_(joinMUCWindowFactory), useDelayForLatency_(useDelayForLatency), @@ -84,7 +84,7 @@ ChatsManager::ChatsManager( roster_(roster), eagleMode_(eagleMode), settings_(settings), - whiteboardSessionManager_(whiteboardSessionManager) { + whiteboardManager_(whiteboardManager) { timerFactory_ = timerFactory; eventController_ = eventController; stanzaChannel_ = stanzaChannel; @@ -110,10 +110,10 @@ ChatsManager::ChatsManager( mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, profileSettings_); mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1)); ftOverview_->onNewFileTransferController.connect(boost::bind(&ChatsManager::handleNewFileTransferController, this, _1)); - whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&ChatsManager::handleWhiteboardSessionRequest, this, _1, _2)); - whiteboardSessionManager_->onRequestAccepted.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardAccepted)); - whiteboardSessionManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardCanceled)); - whiteboardSessionManager_->onRequestRejected.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardRejected)); + whiteboardManager_->onSessionRequest.connect(boost::bind(&ChatsManager::handleWhiteboardSessionRequest, this, _1, _2)); + whiteboardManager_->onRequestAccepted.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardAccepted)); + whiteboardManager_->onSessionTerminate.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardCanceled)); + whiteboardManager_->onRequestRejected.connect(boost::bind(&ChatsManager::handleWhiteboardStateChange, this, _1, ChatWindow::WhiteboardRejected)); roster_->onJIDAdded.connect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1)); roster_->onJIDRemoved.connect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1)); roster_->onJIDUpdated.connect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1)); diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 69cf1bd..97f0937 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -48,11 +48,11 @@ namespace Swift { class FileTransferController; class XMPPRoster; class SettingsProvider; - class WhiteboardSessionManager; + class WhiteboardManager; class ChatsManager { public: - ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, ProfileSettingsProvider* profileSettings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode, SettingsProvider* settings, WhiteboardSessionManager* whiteboardSessionManager); + ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRouter, EventController* eventController, ChatWindowFactory* chatWindowFactory, JoinMUCWindowFactory* joinMUCWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, ProfileSettingsProvider* profileSettings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode, SettingsProvider* settings, WhiteboardManager* whiteboardManager); virtual ~ChatsManager(); void setAvatarManager(AvatarManager* avatarManager); void setOnline(bool enabled); @@ -133,6 +133,6 @@ namespace Swift { bool eagleMode_; bool userWantsReceipts_; SettingsProvider* settings_; - WhiteboardSessionManager* whiteboardSessionManager_; + WhiteboardManager* whiteboardManager_; }; } diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index fe57d95..53fee18 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -17,6 +17,7 @@ #include "Swift/Controllers/Settings/DummySettingsProvider.h" #include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h" #include "Swift/Controllers/UIInterfaces/ChatListWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h" #include "Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h" #include "Swift/Controllers/UIInterfaces/MUCSearchWindowFactory.h" #include "Swiften/Client/Client.h" @@ -49,6 +50,7 @@ #include "Swiften/Elements/DeliveryReceipt.h" #include <Swiften/Base/Algorithm.h> #include <Swift/Controllers/SettingConstants.h> +#include <Swift/Controllers/WhiteboardManager.h> #include <Swiften/Whiteboard/WhiteboardSessionManager.h> using namespace Swift; @@ -101,12 +103,13 @@ public: chatListWindow_ = new MockChatListWindow(); ftManager_ = new DummyFileTransferManager(); ftOverview_ = new FileTransferOverview(ftManager_); + avatarManager_ = new NullAvatarManager(); wbSessionManager_ = new WhiteboardSessionManager(iqRouter_, presenceOracle_, entityCapsManager_); + wbManager_ = new WhiteboardManager(whiteboardWindowFactory_, chatListWindowFactory_, uiEventStream_, nickResolver_, avatarManager_, wbSessionManager_); mocks_->ExpectCall(chatListWindowFactory_, ChatListWindowFactory::createChatListWindow).With(uiEventStream_).Return(chatListWindow_); - manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsManager_, mucManager_, mucSearchWindowFactory_, profileSettings_, ftOverview_, xmppRoster_, false, settings_, wbSessionManager_); + manager_ = new ChatsManager(jid_, stanzaChannel_, iqRouter_, eventController_, chatWindowFactory_, joinMUCWindowFactory_, nickResolver_, presenceOracle_, directedPresenceSender_, uiEventStream_, chatListWindowFactory_, true, NULL, mucRegistry_, entityCapsManager_, mucManager_, mucSearchWindowFactory_, profileSettings_, ftOverview_, xmppRoster_, false, settings_, wbManager_); - avatarManager_ = new NullAvatarManager(); manager_->setAvatarManager(avatarManager_); }; @@ -117,6 +120,8 @@ public: delete manager_; delete ftOverview_; delete ftManager_; + delete wbSessionManager_; + delete wbManager_; delete directedPresenceSender_; delete presenceSender_; delete presenceOracle_; @@ -462,6 +467,7 @@ private: MockRepository* mocks_; UIEventStream* uiEventStream_; ChatListWindowFactory* chatListWindowFactory_; + WhiteboardWindowFactory* whiteboardWindowFactory_; MUCSearchWindowFactory* mucSearchWindowFactory_; MUCRegistry* mucRegistry_; DirectedPresenceSender* directedPresenceSender_; @@ -474,6 +480,7 @@ private: FileTransferOverview* ftOverview_; FileTransferManager* ftManager_; WhiteboardSessionManager* wbSessionManager_; + WhiteboardManager* wbManager_; }; CPPUNIT_TEST_SUITE_REGISTRATION(ChatsManagerTest); diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index c9c4773..8b3d1a7 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -292,8 +292,9 @@ void MainController::handleConnected() { rosterController_->getWindow()->onShowCertificateRequest.connect(boost::bind(&MainController::handleShowCertificateRequest, this)); contactEditController_ = new ContactEditController(rosterController_, client_->getVCardManager(), uiFactory_, uiEventStream_); + whiteboardManager_ = new WhiteboardManager(uiFactory_, uiFactory_, uiEventStream_, client_->getNickResolver(), client_->getAvatarManager(), client_->getWhiteboardSessionManager()); - chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, client_->getWhiteboardSessionManager()); + chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, whiteboardManager_); client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); @@ -321,7 +322,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_, uiFactory_, uiEventStream_, client_->getNickResolver(), client_->getAvatarManager(), client_->getWhiteboardSessionManager()); + } loginWindow_->setIsLoggingIn(false); diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp index bb73ae3..8ac7ba2 100644 --- a/Swift/Controllers/WhiteboardManager.cpp +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -25,8 +25,7 @@ namespace Swift { WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, ChatListWindowFactory* chatListWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, AvatarManager* avatarManager, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), avatarManager_(avatarManager), whiteboardSessionManager_(whiteboardSessionManager) { chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_); chatListWindow_->onWhiteboardActivated.connect(boost::bind(&WhiteboardManager::activateWindow, this, _1)); - whiteboardSessionManager_->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccepted, this, _1)); - whiteboardSessionManager_->onSessionTerminate.connect(boost::bind(&WhiteboardManager::handleSessionTerminated, this, _1)); + whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1)); uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); } @@ -53,14 +52,7 @@ namespace Swift { void WhiteboardManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { boost::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = boost::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event); if (requestWhiteboardEvent) { - JID contact = requestWhiteboardEvent->getContact(); - WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact); - WhiteboardWindow* window = findWhiteboardWindow(contact); - if (window == NULL) { - createNewWhiteboardWindow(contact, session); - } else { - window->setSession(session); - } + requestSession(requestWhiteboardEvent->getContact()); } boost::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = boost::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event); if (sessionAcceptEvent) { @@ -78,18 +70,29 @@ namespace Swift { void WhiteboardManager::acceptSession(const JID& from) { IncomingWhiteboardSession::ref session = boost::dynamic_pointer_cast<IncomingWhiteboardSession>(whiteboardSessionManager_->getSession(from)); - if (session) { + WhiteboardWindow* window = findWhiteboardWindow(from); + if (session && window) { session->accept(); - WhiteboardWindow* window = findWhiteboardWindow(from); - if (window == NULL) { - window = createNewWhiteboardWindow(from, session); - } else { - window->setSession(session); - } window->show(); } } + void WhiteboardManager::requestSession(const JID& contact) { + WhiteboardSession::ref session = whiteboardSessionManager_->requestSession(contact); + session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); + session->onSessionCancelled.connect(boost::bind(&WhiteboardManager::handleSessionCancel, this, _1)); + session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); + session->onRequestRejected.connect(boost::bind(&WhiteboardManager::handleRequestReject, this, _1)); + + WhiteboardWindow* window = findWhiteboardWindow(contact); + if (window == NULL) { + createNewWhiteboardWindow(contact, session); + } else { + window->setSession(session); + } + onSessionRequest(session->getTo(), true); + } + void WhiteboardManager::cancelSession(const JID& from) { WhiteboardSession::ref session = whiteboardSessionManager_->getSession(from); if (session) { @@ -97,7 +100,22 @@ namespace Swift { } } - void WhiteboardManager::handleSessionAccepted(const JID& from) { + void WhiteboardManager::handleIncomingSession(IncomingWhiteboardSession::ref session) { + session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardManager::handleSessionTerminate, this, _1)); + session->onSessionCancelled.connect(boost::bind(&WhiteboardManager::handleSessionCancel, this, _1)); + session->onRequestAccepted.connect(boost::bind(&WhiteboardManager::handleSessionAccept, this, _1)); + + WhiteboardWindow* window = findWhiteboardWindow(session->getTo()); + if (window == NULL) { + createNewWhiteboardWindow(session->getTo(), session); + } else { + window->setSession(session); + } + + onSessionRequest(session->getTo(), false); + } + +/* void WhiteboardManager::handleSessionAccepted(const JID& from) { boost::filesystem::path path; JID bareJID = from.toBare(); if (avatarManager_) { @@ -109,7 +127,7 @@ namespace Swift { void WhiteboardManager::handleSessionTerminated(const JID& from) { chatListWindow_->removeWhiteboardSession(from.toBare()); - } + }*/ void WhiteboardManager::activateWindow(const JID& jid) { WhiteboardWindow* window = findWhiteboardWindow(jid); @@ -117,4 +135,23 @@ namespace Swift { window->activateWindow(); } } + + void WhiteboardManager::handleSessionTerminate(const JID& contact) { + onSessionTerminate(contact); + } + + void WhiteboardManager::handleSessionCancel(const JID& contact) { + onSessionTerminate(contact); + } + + void WhiteboardManager::handleSessionAccept(const JID& contact) { + WhiteboardWindow* window = findWhiteboardWindow(contact); + window->show(); + onRequestAccepted(contact); + } + + void WhiteboardManager::handleRequestReject(const JID& contact) { + onRequestRejected(contact); + } + } diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h index 98ee1cd..78938e1 100644 --- a/Swift/Controllers/WhiteboardManager.h +++ b/Swift/Controllers/WhiteboardManager.h @@ -17,6 +17,7 @@ #include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h> #include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> #include <Swiften/Whiteboard/WhiteboardSession.h> +#include <Swiften/Whiteboard/IncomingWhiteboardSession.h> namespace Swift { class WhiteboardSessionManager; @@ -32,11 +33,21 @@ namespace Swift { WhiteboardWindow* createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session); + public: + boost::signal< void (const JID&, bool senderIsSelf)> onSessionRequest; + boost::signal< void (const JID&)> onSessionTerminate; + boost::signal< void (const JID&)> onRequestAccepted; + boost::signal< void (const JID&)> onRequestRejected; + private: void handleUIEvent(boost::shared_ptr<UIEvent> event); - void handleSessionAccepted(const JID& from); - void handleSessionTerminated(const JID& from); + void handleSessionTerminate(const JID& contact); + void handleSessionCancel(const JID& contact); + void handleSessionAccept(const JID& contact); + void handleRequestReject(const JID& contact); + void handleIncomingSession(IncomingWhiteboardSession::ref session); void acceptSession(const JID& from); + void requestSession(const JID& contact); void cancelSession(const JID& from); WhiteboardWindow* findWhiteboardWindow(const JID& contact); void activateWindow(const JID& jid); |