summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/EventController.cpp17
-rw-r--r--Swift/Controllers/EventController.h10
-rw-r--r--Swift/Controllers/EventWindowController.cpp18
-rw-r--r--Swift/Controllers/EventWindowController.h21
-rw-r--r--Swift/Controllers/MainController.cpp24
-rw-r--r--Swift/Controllers/MainController.h6
-rw-r--r--Swift/Controllers/SConscript1
-rw-r--r--Swift/Controllers/SoundEventController.cpp4
-rw-r--r--Swift/Controllers/SoundEventController.h4
-rw-r--r--Swift/Controllers/SystemTrayController.cpp2
-rw-r--r--Swift/Controllers/SystemTrayController.h3
-rw-r--r--Swift/Controllers/UIInterfaces/EventWindow.h12
-rw-r--r--Swift/Controllers/UIInterfaces/EventWindowFactory.h17
13 files changed, 114 insertions, 25 deletions
diff --git a/Swift/Controllers/EventController.cpp b/Swift/Controllers/EventController.cpp
index 5141cc1..3849aa7 100644
--- a/Swift/Controllers/EventController.cpp
+++ b/Swift/Controllers/EventController.cpp
@@ -3,18 +3,23 @@
#include <boost/bind.hpp>
#include <algorithm>
+
namespace Swift {
-void EventController::handleIncomingEvent(boost::shared_ptr<MessageEvent> event) {
- if (event->isReadable()) {
- events_.push_back(event);
- event->onRead.connect(boost::bind(&EventController::handleEventRead, this, event));
+EventController::EventController() {
+}
+
+void EventController::handleIncomingEvent(boost::shared_ptr<Event> sourceEvent) {
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent);
+ if (messageEvent && messageEvent->isReadable()) {
+ events_.push_back(sourceEvent);
+ messageEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, messageEvent));
onEventQueueLengthChange(events_.size());
- onEventQueueEventAdded(event);
+ onEventQueueEventAdded(sourceEvent);
}
}
-void EventController::handleEventRead(boost::shared_ptr<MessageEvent> event) {
+void EventController::handleEventConcluded(boost::shared_ptr<Event> event) {
events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end());
onEventQueueLengthChange(events_.size());
}
diff --git a/Swift/Controllers/EventController.h b/Swift/Controllers/EventController.h
index c5c924b..482be58 100644
--- a/Swift/Controllers/EventController.h
+++ b/Swift/Controllers/EventController.h
@@ -6,18 +6,20 @@
#include <boost/shared_ptr.hpp>
#include <vector>
+#include "Swiften/Events/Event.h"
#include "Swiften/Events/MessageEvent.h"
namespace Swift {
class EventController {
public:
- void handleIncomingEvent(boost::shared_ptr<MessageEvent> event);
+ EventController();
+ void handleIncomingEvent(boost::shared_ptr<Event> sourceEvent);
boost::signal<void (int)> onEventQueueLengthChange;
- boost::signal<void (boost::shared_ptr<MessageEvent>)> onEventQueueEventAdded;
+ boost::signal<void (boost::shared_ptr<Event>)> onEventQueueEventAdded;
private:
- void handleEventRead(boost::shared_ptr<MessageEvent> event);
- std::vector<boost::shared_ptr<MessageEvent> > events_;
+ void handleEventConcluded(boost::shared_ptr<Event> event);
+ std::vector<boost::shared_ptr<Event> > events_;
};
}
#endif
diff --git a/Swift/Controllers/EventWindowController.cpp b/Swift/Controllers/EventWindowController.cpp
new file mode 100644
index 0000000..4bc5c22
--- /dev/null
+++ b/Swift/Controllers/EventWindowController.cpp
@@ -0,0 +1,18 @@
+#include "Swift/Controllers/EventWindowController.h"
+
+#include <boost/bind.hpp>
+
+namespace Swift {
+
+EventWindowController::EventWindowController(EventController* eventController, EventWindowFactory* windowFactory) {
+ eventController_ = eventController;
+ windowFactory_ = windowFactory;
+ window_ = windowFactory_->createEventWindow();
+ eventController_->onEventQueueEventAdded.connect(boost::bind(&EventWindowController::handleEventQueueEventAdded, this, _1));
+}
+
+void EventWindowController::handleEventQueueEventAdded(boost::shared_ptr<Event> event) {
+ window_->addEvent(event, true);
+}
+
+}
diff --git a/Swift/Controllers/EventWindowController.h b/Swift/Controllers/EventWindowController.h
new file mode 100644
index 0000000..0c06f49
--- /dev/null
+++ b/Swift/Controllers/EventWindowController.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "Swift/Controllers/UIInterfaces/EventWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/EventWindow.h"
+#include "Swift/Controllers/EventController.h"
+
+
+namespace Swift {
+
+ class EventWindowController {
+ public:
+ EventWindowController(EventController* eventController, EventWindowFactory* windowFactory);
+ private:
+ void handleEventQueueEventAdded(boost::shared_ptr<Event> event);
+
+ EventController* eventController_;
+ EventWindowFactory* windowFactory_;
+ EventWindow* window_;
+ };
+
+}
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index cbfb065..d013f5f 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -11,8 +11,10 @@
#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
#include "Swift/Controllers/Chat/ChatsManager.h"
#include "Swift/Controllers/EventController.h"
+#include "Swift/Controllers/EventWindowController.h"
#include "Swift/Controllers/UIInterfaces/LoginWindow.h"
#include "Swift/Controllers/UIInterfaces/LoginWindowFactory.h"
+#include "Swift/Controllers/UIInterfaces/EventWindowFactory.h"
#include "Swift/Controllers/MainWindow.h"
#include "Swift/Controllers/MainWindowFactory.h"
#include "Swift/Controllers/Chat/MUCController.h"
@@ -53,18 +55,20 @@ static const String CLIENT_VERSION = "0.3";
static const String CLIENT_NODE = "http://swift.im";
-MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory)
+MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory)
: timerFactory_(&boostIOServiceThread_.getIOService()), idleDetector_(&idleQuerier_, &timerFactory_, 100), client_(NULL), presenceSender_(NULL), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), treeWidgetFactory_(treeWidgetFactory), settings_(settings), xmppRosterController_(NULL), rosterController_(NULL), loginWindow_(NULL), clientVersionResponder_(NULL), nickResolver_(NULL), discoResponder_(NULL) {
application_ = application;
presenceOracle_ = NULL;
avatarManager_ = NULL;
chatsManager_ = NULL;
+ eventController_ = NULL;
+ eventWindowFactory_ = eventWindowFactory;
uiEventStream_ = new UIEventStream();
avatarStorage_ = new AvatarFileStorage(application_->getAvatarDir());
-
eventController_ = new EventController();
eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1));
+
systemTrayController_ = new SystemTrayController(eventController_, systemTray);
soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings->getBoolSetting("playSounds", true));
loginWindow_ = loginWindowFactory_->createLoginWindow(uiEventStream_);
@@ -89,6 +93,7 @@ MainController::~MainController() {
delete avatarStorage_;
delete xmlConsoleController_;
delete uiEventStream_;
+ delete eventController_;
resetClient();
}
@@ -103,6 +108,8 @@ void MainController::resetClient() {
nickResolver_ = NULL;
delete avatarManager_;
avatarManager_ = NULL;
+ delete eventWindowController_;
+ eventWindowController_ = NULL;
delete rosterController_;
rosterController_ = NULL;
delete xmppRosterController_;
@@ -126,26 +133,29 @@ void MainController::handleConnected() {
xmppRoster_ = boost::shared_ptr<XMPPRoster>(new XMPPRoster());
presenceOracle_ = new PresenceOracle(client_);
nickResolver_ = new NickResolver(xmppRoster_);
- chatsManager_ = new ChatsManager(jid_, client_, client_, eventController_, chatWindowFactory_, treeWidgetFactory_, nickResolver_, presenceOracle_, serverDiscoInfo_, presenceSender_);
-
lastSentPresence_ = boost::shared_ptr<Presence>();
client_->onPresenceReceived.connect(boost::bind(&MainController::handleIncomingPresence, this, _1));
+ chatsManager_ = new ChatsManager(jid_, client_, client_, eventController_, chatWindowFactory_, treeWidgetFactory_, nickResolver_, presenceOracle_, serverDiscoInfo_, presenceSender_);
+ client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1));
+
avatarManager_ = new AvatarManager(client_, client_, avatarStorage_, chatsManager_);
+
chatsManager_->setAvatarManager(avatarManager_);
- client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1));
rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, treeWidgetFactory_, nickResolver_);
- rosterController_->onStartChatRequest.connect(boost::bind(&ChatsManager::handleChatRequest, chatsManager_, _1));
- rosterController_->onJoinMUCRequest.connect(boost::bind(&ChatsManager::handleJoinMUCRequest, chatsManager_, _1, _2));
rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2));
rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this));
+ rosterController_->onStartChatRequest.connect(boost::bind(&ChatsManager::handleChatRequest, chatsManager_, _1));
+ rosterController_->onJoinMUCRequest.connect(boost::bind(&ChatsManager::handleJoinMUCRequest, chatsManager_, _1, _2));
xmppRosterController_ = new XMPPRosterController(client_, xmppRoster_);
xmppRosterController_->requestRoster();
+ eventWindowController_ = new EventWindowController(eventController_, eventWindowFactory_);
+
clientVersionResponder_ = new SoftwareVersionResponder(CLIENT_NAME, CLIENT_VERSION, client_);
loginWindow_->morphInto(rosterController_->getWindow());
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index b6a1254..63be284 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -49,10 +49,12 @@ namespace Swift {
class XMLConsoleController;
class UIEventStream;
class XMLConsoleWidgetFactory;
+ class EventWindowFactory;
+ class EventWindowController;
class MainController {
public:
- MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory);
+ MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, EventWindowFactory* eventWindowFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, XMLConsoleWidgetFactory* xmlConsoleWidgetFactory);
~MainController();
@@ -86,6 +88,7 @@ namespace Swift {
MainWindowFactory* mainWindowFactory_;
LoginWindowFactory* loginWindowFactory_;
TreeWidgetFactory* treeWidgetFactory_;
+ EventWindowFactory* eventWindowFactory_;
SettingsProvider *settings_;
Application* application_;
AvatarStorage* avatarStorage_;
@@ -93,6 +96,7 @@ namespace Swift {
XMPPRosterController* xmppRosterController_;
RosterController* rosterController_;
EventController* eventController_;
+ EventWindowController* eventWindowController_;
LoginWindow* loginWindow_;
SoftwareVersionResponder* clientVersionResponder_;
NickResolver* nickResolver_;
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index 6bd742b..bd2c16e 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -17,6 +17,7 @@ myenv.StaticLibrary("SwiftControllers", [
"XMPPRosterController.cpp",
"Chat/MUCController.cpp",
"EventController.cpp",
+ "EventWindowController.cpp",
"SoundEventController.cpp",
"SystemTrayController.cpp",
"XMLConsoleController.cpp",
diff --git a/Swift/Controllers/SoundEventController.cpp b/Swift/Controllers/SoundEventController.cpp
index d466842..392b4e9 100644
--- a/Swift/Controllers/SoundEventController.cpp
+++ b/Swift/Controllers/SoundEventController.cpp
@@ -9,12 +9,12 @@ namespace Swift {
SoundEventController::SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, bool playSounds) {
eventController_ = eventController;
+ eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1));
soundPlayer_ = soundPlayer;
playSounds_ = playSounds;
- eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1));
}
-void SoundEventController::handleEventQueueEventAdded(boost::shared_ptr<MessageEvent>) {
+void SoundEventController::handleEventQueueEventAdded(boost::shared_ptr<Event>) {
if (playSounds_) soundPlayer_->playSound(SoundPlayer::MessageReceived);
}
diff --git a/Swift/Controllers/SoundEventController.h b/Swift/Controllers/SoundEventController.h
index 9ac6f76..777e55f 100644
--- a/Swift/Controllers/SoundEventController.h
+++ b/Swift/Controllers/SoundEventController.h
@@ -2,7 +2,7 @@
#include <boost/shared_ptr.hpp>
-#include "Swiften/Events/MessageEvent.h"
+#include "Swiften/Events/Event.h"
namespace Swift {
class EventController;
@@ -12,7 +12,7 @@ namespace Swift {
SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, bool playSounds);
void setPlaySounds(bool playSounds);
private:
- void handleEventQueueEventAdded(boost::shared_ptr<MessageEvent> event);
+ void handleEventQueueEventAdded(boost::shared_ptr<Event> event);
EventController* eventController_;
SoundPlayer* soundPlayer_;
bool playSounds_;
diff --git a/Swift/Controllers/SystemTrayController.cpp b/Swift/Controllers/SystemTrayController.cpp
index 0fdd4b5..dfa10c6 100644
--- a/Swift/Controllers/SystemTrayController.cpp
+++ b/Swift/Controllers/SystemTrayController.cpp
@@ -8,8 +8,8 @@
namespace Swift {
SystemTrayController::SystemTrayController(EventController* eventController, SystemTray* systemTray) {
- eventController_ = eventController;
systemTray_ = systemTray;
+ eventController_ = eventController;
eventController_->onEventQueueLengthChange.connect(boost::bind(&SystemTrayController::handleEventQueueLengthChange, this, _1));
}
diff --git a/Swift/Controllers/SystemTrayController.h b/Swift/Controllers/SystemTrayController.h
index 6d2aa31..7eb2365 100644
--- a/Swift/Controllers/SystemTrayController.h
+++ b/Swift/Controllers/SystemTrayController.h
@@ -6,8 +6,7 @@ namespace Swift {
class SystemTrayController {
public:
- SystemTrayController(EventController* eventController, SystemTray* systemTray);
-
+ SystemTrayController(EventController* eventController, SystemTray* systemTray);
private:
void handleEventQueueLengthChange(int length);
diff --git a/Swift/Controllers/UIInterfaces/EventWindow.h b/Swift/Controllers/UIInterfaces/EventWindow.h
new file mode 100644
index 0000000..6cc5bbd
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/EventWindow.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "boost/shared_ptr.hpp"
+#include "Swiften/Events/Event.h"
+
+namespace Swift {
+ class EventWindow {
+ public:
+ virtual void addEvent(boost::shared_ptr<Event> event, bool active) = 0;
+ virtual void removeEvent(boost::shared_ptr<Event> event) = 0;
+ };
+}
diff --git a/Swift/Controllers/UIInterfaces/EventWindowFactory.h b/Swift/Controllers/UIInterfaces/EventWindowFactory.h
new file mode 100644
index 0000000..3dcc30a
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/EventWindowFactory.h
@@ -0,0 +1,17 @@
+#pragma once
+
+namespace Swift {
+ class EventWindow;
+
+ class EventWindowFactory {
+ public:
+ virtual ~EventWindowFactory() {};
+ /**
+ * Transfers ownership of result.
+ */
+ virtual EventWindow* createEventWindow() = 0;
+
+ };
+}
+
+