diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/ChatController.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/ChatController.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/ChatControllerBase.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/ChatControllerBase.h | 20 | ||||
-rw-r--r-- | Swift/Controllers/ChatWindow.h | 5 | ||||
-rw-r--r-- | Swift/Controllers/MUCController.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/MUCController.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 16 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 4 |
9 files changed, 49 insertions, 22 deletions
diff --git a/Swift/Controllers/ChatController.cpp b/Swift/Controllers/ChatController.cpp index 8c0b8bb..39e9144 100644 --- a/Swift/Controllers/ChatController.cpp +++ b/Swift/Controllers/ChatController.cpp @@ -9,8 +9,8 @@ namespace Swift { /** * The controller does not gain ownership of the stanzaChannel, nor the factory. */ -ChatController::ChatController(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle) - : ChatControllerBase(stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle) { +ChatController::ChatController(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager) + : ChatControllerBase(stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager) { nickResolver_ = nickResolver; } @@ -28,7 +28,7 @@ void ChatController::preHandleIncomingMessage(boost::shared_ptr<Message> message } void ChatController::postSendMessage(const String& body) { - chatWindow_->addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>()); + chatWindow_->addMessage(body, "me", true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel() : boost::optional<SecurityLabel>(), ""); } String ChatController::senderDisplayNameFromMessage(JID from) { diff --git a/Swift/Controllers/ChatController.h b/Swift/Controllers/ChatController.h index 98e66bc..265bc91 100644 --- a/Swift/Controllers/ChatController.h +++ b/Swift/Controllers/ChatController.h @@ -4,17 +4,20 @@ #include "Swift/Controllers/ChatControllerBase.h" namespace Swift { + class AvatarManager; class NickResolver; class ChatController : public ChatControllerBase { public: - ChatController(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle); - ~ChatController() {}; + ChatController(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager*); + //boost::signal<void (const JID&, const JID&)> onJIDChanged; + protected: bool isIncomingMessageFromMe(boost::shared_ptr<Message> message); void postSendMessage(const String &body); void preHandleIncomingMessage(boost::shared_ptr<Message> message); String senderDisplayNameFromMessage(JID from); + private: NickResolver* nickResolver_; JID contact_; diff --git a/Swift/Controllers/ChatControllerBase.cpp b/Swift/Controllers/ChatControllerBase.cpp index 0d22571..e84ee04 100644 --- a/Swift/Controllers/ChatControllerBase.cpp +++ b/Swift/Controllers/ChatControllerBase.cpp @@ -3,6 +3,7 @@ #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> +#include "Swiften/Avatars/AvatarManager.h" #include "Swiften/Client/StanzaChannel.h" #include "Swiften/Base/foreach.h" #include "Swift/Controllers/ChatWindow.h" @@ -11,7 +12,7 @@ namespace Swift { -ChatControllerBase::ChatControllerBase(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle) : stanzaChannel_(stanzaChannel), iqRouter_(iqRouter), chatWindowFactory_(chatWindowFactory), toJID_(toJID), labelsEnabled_(false), presenceOracle_(presenceOracle) { +ChatControllerBase::ChatControllerBase(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager) : stanzaChannel_(stanzaChannel), iqRouter_(iqRouter), chatWindowFactory_(chatWindowFactory), toJID_(toJID), labelsEnabled_(false), presenceOracle_(presenceOracle), avatarManager_(avatarManager) { chatWindow_ = chatWindowFactory_->createChatWindow(toJID); chatWindow_->onAllMessagesRead.connect(boost::bind(&ChatControllerBase::handleAllMessagesRead, this)); chatWindow_->onSendMessageRequest.connect(boost::bind(&ChatControllerBase::handleSendMessageRequest, this, _1)); @@ -130,7 +131,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m boost::shared_ptr<SecurityLabel> label = message->getPayload<SecurityLabel>(); boost::optional<SecurityLabel> maybeLabel = label ? boost::optional<SecurityLabel>(*label) : boost::optional<SecurityLabel>(); JID from = message->getFrom(); - chatWindow_->addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel); + chatWindow_->addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), maybeLabel, String(avatarManager_->getAvatarPath(from).string())); } } diff --git a/Swift/Controllers/ChatControllerBase.h b/Swift/Controllers/ChatControllerBase.h index 1967977..58d3a1d 100644 --- a/Swift/Controllers/ChatControllerBase.h +++ b/Swift/Controllers/ChatControllerBase.h @@ -19,6 +19,7 @@ namespace Swift { class StanzaChannel; class ChatWindow; class ChatWindowFactory; + class AvatarManager; class ChatControllerBase { public: @@ -28,7 +29,8 @@ namespace Swift { void handleIncomingMessage(boost::shared_ptr<MessageEvent> message); protected: - ChatControllerBase(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle); + ChatControllerBase(StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &toJID, PresenceOracle* presenceOracle, AvatarManager* avatarManager); + virtual void postSendMessage(const String&) {}; virtual String senderDisplayNameFromMessage(JID from); void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> previousPresence); @@ -36,6 +38,14 @@ namespace Swift { virtual void preHandleIncomingMessage(boost::shared_ptr<Message>) {}; virtual void preSendMessageRequest(boost::shared_ptr<Message>) {}; + private: + void handleSendMessageRequest(const String &body); + String getStatusChangeString(boost::shared_ptr<Presence> presence); + void handleAllMessagesRead(); + void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, const boost::optional<Error>& error); + String getErrorMessage(boost::shared_ptr<Error>); + + protected: std::vector<boost::shared_ptr<MessageEvent> > unreadMessages_; StanzaChannel* stanzaChannel_; IQRouter* iqRouter_; @@ -44,13 +54,7 @@ namespace Swift { JID toJID_; bool labelsEnabled_; PresenceOracle* presenceOracle_; - - private: - void handleSendMessageRequest(const String &body); - String getStatusChangeString(boost::shared_ptr<Presence> presence); - void handleAllMessagesRead(); - void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, const boost::optional<Error>& error); - String getErrorMessage(boost::shared_ptr<Error>); + AvatarManager* avatarManager_; }; } diff --git a/Swift/Controllers/ChatWindow.h b/Swift/Controllers/ChatWindow.h index 04d0007..dd71bf9 100644 --- a/Swift/Controllers/ChatWindow.h +++ b/Swift/Controllers/ChatWindow.h @@ -10,12 +10,15 @@ #include "Swiften/Elements/SecurityLabel.h" namespace Swift { + class AvatarManager; class TreeWidget; + class ChatWindow { public: + ChatWindow() {} virtual ~ChatWindow() {}; - virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label) = 0; + virtual void addMessage(const String& message, const String& senderName, bool senderIsSelf, const boost::optional<SecurityLabel>& label, const String& avatarPath) = 0; virtual void addSystemMessage(const String& message) = 0; virtual void addErrorMessage(const String& message) = 0; diff --git a/Swift/Controllers/MUCController.cpp b/Swift/Controllers/MUCController.cpp index 93880c4..27ddcb8 100644 --- a/Swift/Controllers/MUCController.cpp +++ b/Swift/Controllers/MUCController.cpp @@ -23,8 +23,9 @@ MUCController::MUCController ( IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory *treeWidgetFactory, - PresenceOracle* presenceOracle) : - ChatControllerBase(stanzaChannel, iqRouter, chatWindowFactory, muc, presenceOracle), + PresenceOracle* presenceOracle, + AvatarManager* avatarManager) : + ChatControllerBase(stanzaChannel, iqRouter, chatWindowFactory, muc, presenceOracle, avatarManager), muc_(new MUC(stanzaChannel, muc)), nick_(nick), treeWidgetFactory_(treeWidgetFactory) { diff --git a/Swift/Controllers/MUCController.h b/Swift/Controllers/MUCController.h index c87695e..b2f396c 100644 --- a/Swift/Controllers/MUCController.h +++ b/Swift/Controllers/MUCController.h @@ -18,10 +18,11 @@ namespace Swift { class ChatWindowFactory; class Roster; class TreeWidgetFactory; + class AvatarManager; class MUCController : public ChatControllerBase { public: - MUCController(const JID &muc, const String &nick, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory *treeWidgetFactory, PresenceOracle* presenceOracle); + MUCController(const JID &muc, const String &nick, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory *treeWidgetFactory, PresenceOracle* presenceOracle, AvatarManager* avatarManager); ~MUCController(); protected: diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index e9177f8..20dfaa1 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -32,6 +32,8 @@ #include "Swiften/Queries/Responders/DiscoInfoResponder.h" #include "Swiften/Disco/CapsInfoGenerator.h" #include "Swiften/Queries/Requests/GetDiscoInfoRequest.h" +#include "Swiften/Avatars/AvatarFileStorage.h" +#include "Swiften/Avatars/AvatarManager.h" namespace Swift { @@ -45,8 +47,11 @@ typedef std::pair<JID, MUCController*> JIDMUCControllerPair; MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray) : client_(NULL), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), treeWidgetFactory_(treeWidgetFactory), settings_(settings), xmppRosterController_(NULL), rosterController_(NULL), loginWindow_(NULL), clientVersionResponder_(NULL), nickResolver_(NULL), discoResponder_(NULL), - serverDiscoInfo_(new DiscoInfo()), presenceOracle_(NULL) { + serverDiscoInfo_(new DiscoInfo()), presenceOracle_(NULL), avatarManager_(NULL) { application_ = application; + + avatarStorage_ = new AvatarFileStorage(application_->getAvatarDir()); + eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); systemTrayController_ = new SystemTrayController(eventController_, systemTray); @@ -55,6 +60,7 @@ MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowF } MainController::~MainController() { + delete avatarManager_; delete discoResponder_; delete clientVersionResponder_; delete xmppRosterController_; @@ -69,6 +75,7 @@ MainController::~MainController() { delete nickResolver_; delete client_; delete systemTrayController_; + delete avatarStorage_; } void MainController::handleConnected() { @@ -97,6 +104,9 @@ void MainController::handleConnected() { clientVersionResponder_ = new SoftwareVersionResponder(CLIENT_NAME, CLIENT_VERSION, client_); loginWindow_->morphInto(rosterController_->getWindow()); + delete avatarManager_; + avatarManager_ = new AvatarManager(client_, client_, avatarStorage_); + DiscoInfo discoInfo; discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc")); capsInfo_ = boost::shared_ptr<CapsInfo>(new CapsInfo(CapsInfoGenerator(CLIENT_NODE).generateCapsInfo(discoInfo))); @@ -206,7 +216,7 @@ ChatController* MainController::getChatController(const JID &contact) { lookupContact = JID(contact.toBare()); } if (chatControllers_.find(lookupContact) == chatControllers_.end()) { - chatControllers_[contact] = new ChatController(client_, client_, chatWindowFactory_, contact, nickResolver_, presenceOracle_); + chatControllers_[contact] = new ChatController(client_, client_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_); chatControllers_[contact]->setAvailableServerFeatures(serverDiscoInfo_); lookupContact = contact; } @@ -219,7 +229,7 @@ void MainController::handleChatControllerJIDChanged(const JID& from, const JID& } void MainController::handleJoinMUCRequest(const JID &muc, const String &nick) { - mucControllers_[muc] = new MUCController(muc, nick, client_, client_, chatWindowFactory_, treeWidgetFactory_, presenceOracle_); + mucControllers_[muc] = new MUCController(muc, nick, client_, client_, chatWindowFactory_, treeWidgetFactory_, presenceOracle_, avatarManager_); mucControllers_[muc]->setAvailableServerFeatures(serverDiscoInfo_); } diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index 8b3a702..aa6a85b 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -19,6 +19,7 @@ #include <vector> namespace Swift { + class AvatarStorage; class Application; class Client; class ChatWindowFactory; @@ -30,6 +31,7 @@ namespace Swift { class RosterController; class XMPPRosterController; class DiscoInfoResponder; + class AvatarManager; class LoginWindow; class EventLoop; class SoftwareVersionResponder; @@ -68,6 +70,7 @@ namespace Swift { TreeWidgetFactory* treeWidgetFactory_; SettingsProvider *settings_; Application* application_; + AvatarStorage* avatarStorage_; ChatController* chatController_; XMPPRosterController* xmppRosterController_; RosterController* rosterController_; @@ -82,6 +85,7 @@ namespace Swift { boost::shared_ptr<DiscoInfo> serverDiscoInfo_; PresenceOracle* presenceOracle_; SystemTrayController* systemTrayController_; + AvatarManager* avatarManager_; }; } #endif |