diff options
Diffstat (limited to 'Swift/Controllers')
28 files changed, 671 insertions, 256 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 9a56300..ea0e8ea 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Swift/Controllers/Chat/ChatController.h" #include <boost/bind.hpp> #include <stdio.h> @@ -21,29 +21,29 @@ #include <Swift/Controllers/XMPPEvents/EventController.h> #include <Swift/Controllers/FileTransfer/FileTransferController.h> #include <Swift/Controllers/StatusUtil.h> #include <Swiften/Disco/EntityCapsProvider.h> #include <Swiften/Base/foreach.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/SendFileUIEvent.h> #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> -#include <Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h> +#include <Swift/Controllers/SettingConstants.h> #include <Swiften/Base/Log.h> namespace Swift { /** * The controller does not gain ownership of the stanzaChannel, nor the factory. */ -ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts) - : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts) { +ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings) + : ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts), settings_(settings) { isInMUC_ = isInMUC; lastWasPresence_ = false; chatStateNotifier_ = new ChatStateNotifier(stanzaChannel, contact, entityCapsProvider); chatStateTracker_ = new ChatStateTracker(); nickResolver_ = nickResolver; presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1)); chatStateTracker_->onChatStateChange.connect(boost::bind(&ChatWindow::setContactChatState, chatWindow_, _1)); stanzaChannel_->onStanzaAcked.connect(boost::bind(&ChatController::handleStanzaAcked, this, _1)); nickResolver_->onNickChanged.connect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2)); @@ -67,29 +67,30 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ startMessage += "."; chatWindow_->addSystemMessage(startMessage); chatWindow_->onUserTyping.connect(boost::bind(&ChatStateNotifier::setUserIsTyping, chatStateNotifier_)); chatWindow_->onUserCancelsTyping.connect(boost::bind(&ChatStateNotifier::userCancelledNewMessage, chatStateNotifier_)); chatWindow_->onFileTransferStart.connect(boost::bind(&ChatController::handleFileTransferStart, this, _1, _2)); chatWindow_->onFileTransferAccept.connect(boost::bind(&ChatController::handleFileTransferAccept, this, _1, _2)); chatWindow_->onFileTransferCancel.connect(boost::bind(&ChatController::handleFileTransferCancel, this, _1)); chatWindow_->onSendFileRequest.connect(boost::bind(&ChatController::handleSendFileRequest, this, _1)); handleBareJIDCapsChanged(toJID_); - eventStream_->onUIEvent.connect(boost::bind(&ChatController::handleUIEvent, this, _1)); + + settings_->onSettingChanged.connect(boost::bind(&ChatController::handleSettingChanged, this, _1)); } void ChatController::handleContactNickChanged(const JID& jid, const std::string& /*oldNick*/) { if (jid.toBare() == toJID_.toBare()) { chatWindow_->setName(nickResolver_->jidToNick(jid)); } } ChatController::~ChatController() { - eventStream_->onUIEvent.disconnect(boost::bind(&ChatController::handleUIEvent, this, _1)); + settings_->onSettingChanged.disconnect(boost::bind(&ChatController::handleSettingChanged, this, _1)); nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2)); delete chatStateNotifier_; delete chatStateTracker_; } void ChatController::handleBareJIDCapsChanged(const JID& /*jid*/) { DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_); if (disco) { if (disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) { @@ -168,21 +169,21 @@ void ChatController::preSendMessageRequest(boost::shared_ptr<Message> message) { if (userWantsReceipts_ && (contactSupportsReceipts_ != ChatWindow::No) && message) { message->addPayload(boost::make_shared<DeliveryReceiptRequest>()); } } void ChatController::setContactIsReceivingPresence(bool isReceivingPresence) { receivingPresenceFromUs_ = isReceivingPresence; } -void ChatController::handleUIEvent(boost::shared_ptr<UIEvent> event) { - if (boost::shared_ptr<ToggleRequestDeliveryReceiptsUIEvent> toggleAllowReceipts = boost::dynamic_pointer_cast<ToggleRequestDeliveryReceiptsUIEvent>(event)) { - userWantsReceipts_ = toggleAllowReceipts->getEnabled(); +void ChatController::handleSettingChanged(const std::string& settingPath) { + if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) { + userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS); checkForDisplayingDisplayReceiptsAlert(); } } void ChatController::checkForDisplayingDisplayReceiptsAlert() { if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::No)) { chatWindow_->setAlert("This chat doesn't support delivery receipts."); } else if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::Maybe)) { chatWindow_->setAlert("This chat may not support delivery receipts. You might not receive delivery receipts for the messages you sent."); diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index 9c01923..2a66772 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -1,36 +1,36 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include "Swift/Controllers/Chat/ChatControllerBase.h" +#include <Swift/Controllers/Chat/ChatControllerBase.h> #include <map> #include <string> #include <Swift/Controllers/UIInterfaces/ChatWindow.h> namespace Swift { class AvatarManager; class ChatStateNotifier; class ChatStateTracker; class NickResolver; class EntityCapsProvider; class FileTransferController; - class UIEvent; + class SettingsProvider; class ChatController : public ChatControllerBase { public: - ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts); + ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings); virtual ~ChatController(); virtual void setToJID(const JID& jid); virtual void setOnline(bool online); virtual void handleNewFileTransferController(FileTransferController* ftc); virtual void setContactIsReceivingPresence(bool /*isReceivingPresence*/); private: void handlePresenceChange(boost::shared_ptr<Presence> newPresence); std::string getStatusChangeString(boost::shared_ptr<Presence> presence); @@ -45,19 +45,19 @@ namespace Swift { void dayTicked() {lastWasPresence_ = false;} void handleContactNickChanged(const JID& jid, const std::string& /*oldNick*/); void handleBareJIDCapsChanged(const JID& jid); void handleFileTransferCancel(std::string /* id */); void handleFileTransferStart(std::string /* id */, std::string /* description */); void handleFileTransferAccept(std::string /* id */, std::string /* filename */); void handleSendFileRequest(std::string filename); - void handleUIEvent(boost::shared_ptr<UIEvent> event); + void handleSettingChanged(const std::string& settingPath); void checkForDisplayingDisplayReceiptsAlert(); private: NickResolver* nickResolver_; ChatStateNotifier* chatStateNotifier_; ChatStateTracker* chatStateTracker_; std::string myLastMessageUIID_; bool isInMUC_; bool lastWasPresence_; @@ -65,12 +65,13 @@ namespace Swift { std::map<boost::shared_ptr<Stanza>, std::string> unackedStanzas_; std::map<std::string, std::string> requestedReceipts_; StatusShow::Type lastShownStatus_; UIEventStream* eventStream_; ChatWindow::Tristate contactSupportsReceipts_; bool receivingPresenceFromUs_; bool userWantsReceipts_; std::map<std::string, FileTransferController*> ftControllers; + SettingsProvider* settings_; }; } diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index c19c524..a2b286f 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -15,36 +15,37 @@ #include <Swift/Controllers/Chat/MUCSearchController.h> #include <Swift/Controllers/XMPPEvents/EventController.h> #include <Swift/Controllers/Chat/MUCController.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h> #include <Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h> #include <Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h> -#include <Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h> #include <Swift/Controllers/UIInterfaces/ChatListWindowFactory.h> #include <Swift/Controllers/UIInterfaces/JoinMUCWindow.h> #include <Swift/Controllers/UIInterfaces/JoinMUCWindowFactory.h> #include <Swiften/Presence/PresenceSender.h> #include <Swiften/Client/NickResolver.h> #include <Swiften/MUC/MUCManager.h> #include <Swiften/Elements/ChatState.h> #include <Swiften/Elements/MUCUserPayload.h> #include <Swiften/Elements/DeliveryReceipt.h> #include <Swiften/Elements/DeliveryReceiptRequest.h> #include <Swiften/MUC/MUCBookmarkManager.h> #include <Swift/Controllers/FileTransfer/FileTransferController.h> #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> #include <Swift/Controllers/ProfileSettingsProvider.h> #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Elements/MUCInvitationPayload.h> #include <Swiften/Roster/XMPPRoster.h> +#include <Swift/Controllers/Settings/SettingsProvider.h> +#include <Swift/Controllers/SettingConstants.h> namespace Swift { typedef std::pair<JID, ChatController*> JIDChatControllerPair; typedef std::pair<JID, MUCController*> JIDMUCControllerPair; #define RECENT_CHATS "recent_chats" ChatsManager::ChatsManager( @@ -58,65 +59,71 @@ ChatsManager::ChatsManager( PresenceSender* presenceSender, UIEventStream* uiEventStream, ChatListWindowFactory* chatListWindowFactory, bool useDelayForLatency, TimerFactory* timerFactory, MUCRegistry* mucRegistry, EntityCapsProvider* entityCapsProvider, MUCManager* mucManager, MUCSearchWindowFactory* mucSearchWindowFactory, - ProfileSettingsProvider* settings, + ProfileSettingsProvider* profileSettings, FileTransferOverview* ftOverview, XMPPRoster* roster, - bool eagleMode) : + bool eagleMode, + SettingsProvider* settings) : jid_(jid), joinMUCWindowFactory_(joinMUCWindowFactory), useDelayForLatency_(useDelayForLatency), mucRegistry_(mucRegistry), entityCapsProvider_(entityCapsProvider), mucManager(mucManager), ftOverview_(ftOverview), roster_(roster), - eagleMode_(eagleMode) { + eagleMode_(eagleMode), + settings_(settings) { timerFactory_ = timerFactory; eventController_ = eventController; stanzaChannel_ = stanzaChannel; iqRouter_ = iqRouter; chatWindowFactory_ = chatWindowFactory; nickResolver_ = nickResolver; presenceOracle_ = presenceOracle; avatarManager_ = NULL; serverDiscoInfo_ = boost::shared_ptr<DiscoInfo>(new DiscoInfo()); presenceSender_ = presenceSender; uiEventStream_ = uiEventStream; mucBookmarkManager_ = NULL; - profileSettings_ = settings; + profileSettings_ = profileSettings; presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1)); uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1)); chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_); chatListWindow_->onMUCBookmarkActivated.connect(boost::bind(&ChatsManager::handleMUCBookmarkActivated, this, _1)); chatListWindow_->onRecentActivated.connect(boost::bind(&ChatsManager::handleRecentActivated, this, _1)); chatListWindow_->onClearRecentsRequested.connect(boost::bind(&ChatsManager::handleClearRecentsRequested, this)); joinMUCWindow_ = NULL; - mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, settings); + 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)); 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)); roster_->onRosterCleared.connect(boost::bind(&ChatsManager::handleRosterCleared, this)); + + settings_->onSettingChanged.connect(boost::bind(&ChatsManager::handleSettingChanged, this, _1)); + setupBookmarks(); loadRecents(); } ChatsManager::~ChatsManager() { + settings_->onSettingChanged.disconnect(boost::bind(&ChatsManager::handleSettingChanged, this, _1)); roster_->onJIDAdded.disconnect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1)); roster_->onJIDRemoved.disconnect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1)); roster_->onJIDUpdated.disconnect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1)); roster_->onRosterCleared.disconnect(boost::bind(&ChatsManager::handleRosterCleared, this)); delete joinMUCWindow_; foreach (JIDChatControllerPair controllerPair, chatControllers_) { delete controllerPair.second; } foreach (JIDMUCControllerPair controllerPair, mucControllers_) { @@ -342,39 +349,42 @@ void ChatsManager::handleUserLeftMUC(MUCController* mucController) { } } mucControllers_.erase(it); delete mucController; return; } } } +void ChatsManager::handleSettingChanged(const std::string& settingPath) { + if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) { + userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS); + return; + } +} + void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> event) { boost::shared_ptr<RequestChatUIEvent> chatEvent = boost::dynamic_pointer_cast<RequestChatUIEvent>(event); if (chatEvent) { handleChatRequest(chatEvent->getContact()); return; } boost::shared_ptr<RemoveMUCBookmarkUIEvent> removeMUCBookmarkEvent = boost::dynamic_pointer_cast<RemoveMUCBookmarkUIEvent>(event); if (removeMUCBookmarkEvent) { mucBookmarkManager_->removeBookmark(removeMUCBookmarkEvent->getBookmark()); return; } boost::shared_ptr<AddMUCBookmarkUIEvent> addMUCBookmarkEvent = boost::dynamic_pointer_cast<AddMUCBookmarkUIEvent>(event); if (addMUCBookmarkEvent) { mucBookmarkManager_->addBookmark(addMUCBookmarkEvent->getBookmark()); return; } - boost::shared_ptr<ToggleRequestDeliveryReceiptsUIEvent> toggleRequestDeliveryReceiptsEvent = boost::dynamic_pointer_cast<ToggleRequestDeliveryReceiptsUIEvent>(event); - if (toggleRequestDeliveryReceiptsEvent) { - userWantsReceipts_ = toggleRequestDeliveryReceiptsEvent->getEnabled(); - return; - } + boost::shared_ptr<EditMUCBookmarkUIEvent> editMUCBookmarkEvent = boost::dynamic_pointer_cast<EditMUCBookmarkUIEvent>(event); if (editMUCBookmarkEvent) { mucBookmarkManager_->replaceBookmark(editMUCBookmarkEvent->getOldBookmark(), editMUCBookmarkEvent->getNewBookmark()); } else if (JoinMUCUIEvent::ref joinEvent = boost::dynamic_pointer_cast<JoinMUCUIEvent>(event)) { handleJoinMUCRequest(joinEvent->getJID(), joinEvent->getPassword(), joinEvent->getNick(), joinEvent->getShouldJoinAutomatically(), joinEvent->getCreateAsReservedRoomIfNew()); mucControllers_[joinEvent->getJID()]->activateChatWindow(); } @@ -483,19 +493,19 @@ ChatController* ChatsManager::getChatControllerOrFindAnother(const JID &contact) break; } } } return controller ? controller : createNewChatController(contact); } ChatController* ChatsManager::createNewChatController(const JID& contact) { assert(chatControllers_.find(contact) == chatControllers_.end()); - ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_, mucRegistry_->isMUC(contact.toBare()), useDelayForLatency_, uiEventStream_, eventController_, timerFactory_, entityCapsProvider_, userWantsReceipts_); + ChatController* controller = new ChatController(jid_, stanzaChannel_, iqRouter_, chatWindowFactory_, contact, nickResolver_, presenceOracle_, avatarManager_, mucRegistry_->isMUC(contact.toBare()), useDelayForLatency_, uiEventStream_, eventController_, timerFactory_, entityCapsProvider_, userWantsReceipts_, settings_); chatControllers_[contact] = controller; controller->setAvailableServerFeatures(serverDiscoInfo_); controller->onActivity.connect(boost::bind(&ChatsManager::handleChatActivity, this, contact, _1, false)); controller->onUnreadCountChanged.connect(boost::bind(&ChatsManager::handleUnreadCountChanged, this, controller)); updatePresenceReceivingStateOnChatController(contact); return controller; } ChatController* ChatsManager::getChatControllerOrCreate(const JID &contact) { diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 0c7f492..4d1fc14 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -40,22 +40,23 @@ namespace Swift { class TimerFactory; class EntityCapsProvider; class DirectedPresenceSender; class MUCSearchWindowFactory; class ProfileSettingsProvider; class MUCSearchController; class FileTransferOverview; class FileTransferController; class XMPPRoster; + class SettingsProvider; 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* settings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode); + 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* settings, FileTransferOverview* ftOverview, XMPPRoster* roster, bool eagleMode, SettingsProvider* settings); virtual ~ChatsManager(); void setAvatarManager(AvatarManager* avatarManager); void setOnline(bool enabled); void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info); void handleIncomingMessage(boost::shared_ptr<Message> message); private: ChatListWindow::Chat createChatListChatItem(const JID& jid, const std::string& activity); void handleChatRequest(const std::string& contact); @@ -80,18 +81,19 @@ namespace Swift { void handleMUCBookmarkActivated(const MUCBookmark&); void handleRecentActivated(const ChatListWindow::Chat&); void handleUnreadCountChanged(ChatControllerBase* controller); void handleAvatarChanged(const JID& jid); void handleClearRecentsRequested(); void handleJIDAddedToRoster(const JID&); void handleJIDRemovedFromRoster(const JID&); void handleJIDUpdatedInRoster(const JID&); void handleRosterCleared(); + void handleSettingChanged(const std::string& settingPath); void updatePresenceReceivingStateOnChatController(const JID&); ChatController* getChatControllerOrFindAnother(const JID &contact); ChatController* createNewChatController(const JID &contact); ChatController* getChatControllerOrCreate(const JID &contact); ChatController* getChatControllerIfExists(const JID &contact, bool rebindIfNeeded = true); private: @@ -119,11 +121,12 @@ namespace Swift { EntityCapsProvider* entityCapsProvider_; MUCManager* mucManager; MUCSearchController* mucSearchController_; std::list<ChatListWindow::Chat> recentChats_; ProfileSettingsProvider* profileSettings_; FileTransferOverview* ftOverview_; XMPPRoster* roster_; bool eagleMode_; bool userWantsReceipts_; + SettingsProvider* settings_; }; } diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 8162bec..cd868e6 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010-2011 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include "3rdParty/hippomocks.h" #include <boost/bind.hpp> @@ -37,24 +37,24 @@ #include "Swift/Controllers/UnitTest/MockChatWindow.h" #include "Swiften/Client/DummyStanzaChannel.h" #include "Swiften/Queries/DummyIQChannel.h" #include "Swiften/Presence/PresenceOracle.h" #include "Swiften/Jingle/JingleSessionManager.h" #include "Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h" #include <Swift/Controllers/ProfileSettingsProvider.h> #include "Swift/Controllers/FileTransfer/FileTransferOverview.h" #include "Swiften/Elements/DeliveryReceiptRequest.h" #include "Swiften/Elements/DeliveryReceipt.h" #include <Swiften/Base/Algorithm.h> +#include <Swift/Controllers/SettingConstants.h> using namespace Swift; class DummyCapsProvider : public CapsProvider { DiscoInfo::ref getCaps(const std::string&) const {return DiscoInfo::ref(new DiscoInfo());} }; class ChatsManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ChatsManagerTest); @@ -96,27 +96,26 @@ public: chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>(); mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>(); settings_ = new DummySettingsProvider(); profileSettings_ = new ProfileSettingsProvider("a", settings_); chatListWindow_ = new MockChatListWindow(); ftManager_ = new DummyFileTransferManager(); ftOverview_ = new FileTransferOverview(ftManager_); 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); + 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_); avatarManager_ = new NullAvatarManager(); manager_->setAvatarManager(avatarManager_); }; void tearDown() { //delete chatListWindowFactory - delete settings_; delete profileSettings_; delete avatarManager_; delete manager_; delete ftOverview_; delete ftManager_; delete directedPresenceSender_; delete presenceSender_; delete presenceOracle_; delete nickResolver_; @@ -126,18 +125,19 @@ public: delete iqRouter_; delete iqChannel_; delete uiEventStream_; delete mucManager_; delete xmppRoster_; delete entityCapsManager_; delete capsProvider_; delete chatListWindow_; delete mocks_; + delete settings_; } void testFirstOpenWindowIncoming() { JID messageJID("testling@test.com/resource1"); MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>(); mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window); boost::shared_ptr<Message> message(new Message()); @@ -347,19 +347,19 @@ public: /** * Test that ChatController doesn't send receipts anymore after removal of the contact from the roster. */ void testChatControllerPresenceAccessUpdatedOnRemoveFromRoster() { JID messageJID("testling@test.com/resource1"); xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both); MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>(); mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window); - uiEventStream_->send(boost::shared_ptr<UIEvent>(new ToggleRequestDeliveryReceiptsUIEvent(true))); + settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true); boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1"); manager_->handleIncomingMessage(message); Stanza::ref stanzaContactOnRoster = stanzaChannel_->getStanzaAtIndex<Stanza>(0); CPPUNIT_ASSERT_EQUAL(st(1), stanzaChannel_->sentStanzas.size()); CPPUNIT_ASSERT(stanzaContactOnRoster->getPayload<DeliveryReceipt>() != 0); xmppRoster_->removeContact(messageJID); @@ -370,19 +370,19 @@ public: /** * Test that ChatController sends receipts after the contact has been added to the roster. */ void testChatControllerPresenceAccessUpdatedOnAddToRoster() { JID messageJID("testling@test.com/resource1"); MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>(); mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window); - uiEventStream_->send(boost::shared_ptr<UIEvent>(new ToggleRequestDeliveryReceiptsUIEvent(true))); + settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true); boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1"); manager_->handleIncomingMessage(message); CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size()); xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), RosterItemPayload::Both); message->setID("2"); manager_->handleIncomingMessage(message); @@ -406,19 +406,19 @@ public: testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::From); } void testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::Subscription from, RosterItemPayload::Subscription to) { JID messageJID("testling@test.com/resource1"); xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), from); MockChatWindow* window = new MockChatWindow();//mocks_->InterfaceMock<ChatWindow>(); mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(messageJID, uiEventStream_).Return(window); - uiEventStream_->send(boost::shared_ptr<UIEvent>(new ToggleRequestDeliveryReceiptsUIEvent(true))); + settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true); boost::shared_ptr<Message> message = makeDeliveryReceiptTestMessage(messageJID, "1"); manager_->handleIncomingMessage(message); CPPUNIT_ASSERT_EQUAL(st(0), stanzaChannel_->sentStanzas.size()); xmppRoster_->addContact(messageJID, "foo", std::vector<std::string>(), to); message->setID("2"); manager_->handleIncomingMessage(message); diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 6f93dd3..06f8c3a 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010-2011 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swift/Controllers/MainController.h> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> #include <boost/shared_ptr.hpp> @@ -53,67 +53,62 @@ #include "Swift/Controllers/Settings/SettingsProvider.h" #include "Swiften/Elements/DiscoInfo.h" #include "Swiften/Disco/CapsInfoGenerator.h" #include "Swiften/Disco/GetDiscoInfoRequest.h" #include "Swiften/Disco/ClientDiscoManager.h" #include "Swiften/VCards/GetVCardRequest.h" #include "Swiften/StringCodecs/SHA1.h" #include "Swiften/StringCodecs/Hexify.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h" -#include "Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" #include "Swift/Controllers/Storages/CertificateStorageFactory.h" #include "Swift/Controllers/Storages/CertificateStorageTrustChecker.h" #include "Swiften/Network/NetworkFactories.h" #include <Swift/Controllers/ProfileController.h> #include <Swift/Controllers/ContactEditController.h> #include <Swift/Controllers/XMPPURIController.h> #include "Swift/Controllers/AdHocManager.h" #include <SwifTools/Idle/IdleDetector.h> #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> #include <Swiften/FileTransfer/FileTransferManager.h> #include <Swiften/Client/ClientXMLTracer.h> +#include <Swift/Controllers/SettingConstants.h> namespace Swift { static const std::string CLIENT_NAME = "Swift"; static const std::string CLIENT_NODE = "http://swift.im"; -static const std::string SHOW_NOTIFICATIONS = "showNotifications"; -static const std::string REQUEST_DELIVERYRECEIPTS = "requestDeliveryReceipts"; MainController::MainController( EventLoop* eventLoop, NetworkFactories* networkFactories, UIFactory* uiFactories, - SettingsProvider *settings, + SettingsProvider* settings, SystemTray* systemTray, SoundPlayer* soundPlayer, StoragesFactory* storagesFactory, CertificateStorageFactory* certificateStorageFactory, Dock* dock, Notifier* notifier, URIHandler* uriHandler, IdleDetector* idleDetector, - bool useDelayForLatency, - bool eagleMode) : + bool useDelayForLatency) : eventLoop_(eventLoop), networkFactories_(networkFactories), uiFactory_(uiFactories), storagesFactory_(storagesFactory), certificateStorageFactory_(certificateStorageFactory), settings_(settings), uriHandler_(uriHandler), idleDetector_(idleDetector), loginWindow_(NULL) , useDelayForLatency_(useDelayForLatency), - eagleMode_(eagleMode), ftOverview_(NULL) { storages_ = NULL; certificateStorage_ = NULL; statusTracker_ = NULL; presenceNotifier_ = NULL; eventNotifier_ = NULL; rosterController_ = NULL; chatsManager_ = NULL; eventWindowController_ = NULL; @@ -131,58 +126,57 @@ MainController::MainController( uiEventStream_ = new UIEventStream(); notifier_ = new TogglableNotifier(notifier); eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); systemTrayController_ = new SystemTrayController(eventController_, systemTray); loginWindow_ = uiFactory_->createLoginWindow(uiEventStream_); loginWindow_->setShowNotificationToggle(!notifier->isExternallyConfigured()); - soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings, uiEventStream_); + soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings); xmppURIController_ = new XMPPURIController(uriHandler_, uiEventStream_); - std::string selectedLoginJID = settings_->getStringSetting("lastLoginJID"); - bool loginAutomatically = settings_->getBoolSetting("loginAutomatically", false); + std::string selectedLoginJID = settings_->getSetting(SettingConstants::LAST_LOGIN_JID); + bool loginAutomatically = settings_->getSetting(SettingConstants::LOGIN_AUTOMATICALLY); std::string cachedPassword; std::string cachedCertificate; - if (!eagleMode_) { + bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS); + if (!eagle) { foreach (std::string profile, settings->getAvailableProfiles()) { ProfileSettingsProvider profileSettings(profile, settings); - std::string password = eagleMode ? "" : profileSettings.getStringSetting("pass"); + std::string password = profileSettings.getStringSetting("pass"); std::string certificate = profileSettings.getStringSetting("certificate"); std::string jid = profileSettings.getStringSetting("jid"); loginWindow_->addAvailableAccount(jid, password, certificate); if (jid == selectedLoginJID) { cachedPassword = password; cachedCertificate = certificate; } } loginWindow_->selectUser(selectedLoginJID); loginWindow_->setLoginAutomatically(loginAutomatically); } loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4, _5)); loginWindow_->onPurgeSavedLoginRequest.connect(boost::bind(&MainController::handlePurgeSavedLoginRequest, this, _1)); loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this)); loginWindow_->onQuitRequest.connect(boost::bind(&MainController::handleQuitRequest, this)); - idleDetector_->setIdleTimeSeconds(600); + idleDetector_->setIdleTimeSeconds(settings->getSetting(SettingConstants::IDLE_TIMEOUT)); idleDetector_->onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1)); xmlConsoleController_ = new XMLConsoleController(uiEventStream_, uiFactory_); fileTransferListController_ = new FileTransferListController(uiEventStream_, uiFactory_); - uiEventStream_->onUIEvent.connect(boost::bind(&MainController::handleUIEvent, this, _1)); - bool enabled = settings_->getBoolSetting(SHOW_NOTIFICATIONS, true); - uiEventStream_->send(boost::shared_ptr<ToggleNotificationsUIEvent>(new ToggleNotificationsUIEvent(enabled))); + settings_->onSettingChanged.connect(boost::bind(&MainController::handleSettingChanged, this, _1)); if (loginAutomatically) { profileSettings_ = new ProfileSettingsProvider(selectedLoginJID, settings_); handleLoginRequest(selectedLoginJID, cachedPassword, cachedCertificate, true, true); } else { profileSettings_ = NULL; } } @@ -240,30 +234,22 @@ void MainController::resetClient() { delete userSearchControllerChat_; userSearchControllerChat_ = NULL; delete userSearchControllerAdd_; userSearchControllerAdd_ = NULL; delete adHocManager_; adHocManager_ = NULL; clientInitialized_ = false; } -void MainController::handleUIEvent(boost::shared_ptr<UIEvent> event) { - boost::shared_ptr<ToggleNotificationsUIEvent> notificationsEvent = boost::dynamic_pointer_cast<ToggleNotificationsUIEvent>(event); - if (notificationsEvent) { - bool enabled = notificationsEvent->getEnabled(); - notifier_->setPersistentEnabled(enabled); - settings_->storeBool(SHOW_NOTIFICATIONS, enabled); +void MainController::handleSettingChanged(const std::string& settingPath) { + if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) { + notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS)); } - boost::shared_ptr<ToggleRequestDeliveryReceiptsUIEvent> deliveryReceiptEvent = boost::dynamic_pointer_cast<ToggleRequestDeliveryReceiptsUIEvent>(event); - if (deliveryReceiptEvent) { - settings_->storeBool(REQUEST_DELIVERYRECEIPTS, deliveryReceiptEvent->getEnabled()); - } - } void MainController::resetPendingReconnects() { timeBeforeNextReconnect_ = -1; if (reconnectTimer_) { reconnectTimer_->stop(); reconnectTimer_.reset(); } resetCurrentError(); @@ -275,38 +261,38 @@ void MainController::resetCurrentError() { lastDisconnectError_ = boost::shared_ptr<ErrorEvent>(); } } void MainController::handleConnected() { boundJID_ = client_->getJID(); resetCurrentError(); resetPendingReconnects(); - if (eagleMode_) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } bool freshLogin = rosterController_ == NULL; myStatusLooksOnline_ = true; if (freshLogin) { profileController_ = new ProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_); srand(time(NULL)); int randomPort = 10000 + rand() % 10000; client_->getFileTransferManager()->startListeningOnPort(randomPort); ftOverview_ = new FileTransferOverview(client_->getFileTransferManager()); fileTransferListController_->setFileTransferOverview(ftOverview_); rosterController_ = new RosterController(jid_, client_->getRoster(), client_->getAvatarManager(), uiFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_, client_->getEntityCapsProvider(), ftOverview_); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); contactEditController_ = new ContactEditController(rosterController_, uiFactory_, uiEventStream_); - 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(), eagleMode_); + 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_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); eventWindowController_ = new EventWindowController(eventController_, uiFactory_); loginWindow_->morphInto(rosterController_->getWindow()); DiscoInfo discoInfo; @@ -340,20 +326,18 @@ void MainController::handleConnected() { rosterController_->setEnabled(true); profileController_->setAvailable(true); contactEditController_->setAvailable(true); /* Send presence later to catch all the incoming presences. */ sendPresence(statusTracker_->getNextPresence()); /* Enable chats last of all, so rejoining MUCs has the right sent presence */ chatsManager_->setOnline(true); - // notify world about current delivey receipt request setting state. - uiEventStream_->send(boost::make_shared<ToggleRequestDeliveryReceiptsUIEvent>(settings_->getBoolSetting(REQUEST_DELIVERYRECEIPTS, false))); } void MainController::handleEventQueueLengthChange(int count) { dock_->setNumberOfPendingMessages(count); } void MainController::reconnectAfterError() { if (reconnectTimer_) { reconnectTimer_->stop(); @@ -402,64 +386,72 @@ void MainController::sendPresence(boost::shared_ptr<Presence> presence) { logout(); } } void MainController::handleInputIdleChanged(bool idle) { if (!statusTracker_) { //Haven't logged in yet. return; } - if (idle) { - if (statusTracker_->goAutoAway()) { - if (client_ && client_->isAvailable()) { - sendPresence(statusTracker_->getNextPresence()); - } + + if (settings_->getSetting(SettingConstants::IDLE_GOES_OFFLINE)) { + if (idle) { + logout(); } - } else { - if (statusTracker_->goAutoUnAway()) { - if (client_ && client_->isAvailable()) { - sendPresence(statusTracker_->getNextPresence()); + } + else { + if (idle) { + if (statusTracker_->goAutoAway()) { + if (client_ && client_->isAvailable()) { + sendPresence(statusTracker_->getNextPresence()); + } + } + } else { + if (statusTracker_->goAutoUnAway()) { + if (client_ && client_->isAvailable()) { + sendPresence(statusTracker_->getNextPresence()); + } } } } } void MainController::handleLoginRequest(const std::string &username, const std::string &password, const std::string& certificateFile, bool remember, bool loginAutomatically) { jid_ = JID(username); if (!jid_.isValid() || jid_.getNode().empty()) { loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'alice@wonderland.lit'")); loginWindow_->setIsLoggingIn(false); } else { loginWindow_->setMessage(""); loginWindow_->setIsLoggingIn(true); profileSettings_ = new ProfileSettingsProvider(username, settings_); - if (!eagleMode_) { + if (!settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { profileSettings_->storeString("jid", username); profileSettings_->storeString("certificate", certificateFile); profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : ""); - settings_->storeString("lastLoginJID", username); - settings_->storeBool("loginAutomatically", loginAutomatically); + settings_->storeSetting(SettingConstants::LAST_LOGIN_JID, username); + settings_->storeSetting(SettingConstants::LOGIN_AUTOMATICALLY, loginAutomatically); loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate")); } password_ = password; certificateFile_ = certificateFile; performLoginFromCachedCredentials(); } } void MainController::handlePurgeSavedLoginRequest(const std::string& username) { settings_->removeProfile(username); loginWindow_->removeAvailableAccount(username); } void MainController::performLoginFromCachedCredentials() { - if (eagleMode_ && password_.empty()) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS) && password_.empty()) { /* Then we can't try to login again. */ return; } /* If we logged in with a bare JID, and we have a full bound JID, re-login with the * bound JID to try and keep dynamically assigned resources */ JID clientJID = jid_; if (boundJID_.isValid() && jid_.isBare() && boundJID_.toBare() == jid_) { clientJID = boundJID_; } @@ -497,29 +489,30 @@ void MainController::performLoginFromCachedCredentials() { } else { /* In case we're in the middle of another login, make sure they don't overlap */ client_->disconnect(); } systemTrayController_->setConnecting(); if (rosterController_) { rosterController_->getWindow()->setConnecting(); } ClientOptions clientOptions; - clientOptions.forgetPassword = eagleMode_; - clientOptions.useTLS = eagleMode_ ? ClientOptions::RequireTLS : ClientOptions::UseTLSWhenAvailable; + bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS); + clientOptions.forgetPassword = eagle; + clientOptions.useTLS = eagle ? ClientOptions::RequireTLS : ClientOptions::UseTLSWhenAvailable; /*if (clientJID.getDomain() == "doomsong.co.uk") { clientOptions.boshURL = URL("https", "channels.doomsong.co.uk", 11443, "http-bind/"); clientOptions.boshHTTPConnectProxyURL = URL("http", "squidproxy.doomsong.co.uk", 8123, ""); }*/ client_->connect(clientOptions); } void MainController::handleDisconnected(const boost::optional<ClientError>& error) { - if (eagleMode_) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } if (quitRequested_) { resetClient(); loginWindow_->quit(); } else if (error) { std::string message; std::string certificateErrorMessage; @@ -569,19 +562,19 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro if (forceReconnectAfterCertificateTrust) { performLoginFromCachedCredentials(); } else if (!rosterController_) { //hasn't been logged in yet signOut(); loginWindow_->setMessage(message); loginWindow_->setIsLoggingIn(false); } else { logout(); - if (eagleMode_) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message); } else { if (!offlineRequested_) { setReconnectTimer(); } if (lastDisconnectError_) { message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_)); lastDisconnectError_->conclude(); } else { @@ -610,29 +603,29 @@ void MainController::setReconnectTimer() { reconnectTimer_->onTick.connect(boost::bind(&MainController::reconnectAfterError, this)); reconnectTimer_->start(); } void MainController::handleCancelLoginRequest() { signOut(); } void MainController::signOut() { - if (eagleMode_) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } eventController_->clear(); logout(); loginWindow_->loggedOut(); resetClient(); } void MainController::logout() { - if (eagleMode_) { + if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } systemTrayController_->setMyStatusType(StatusShow::None); if (clientInitialized_ /*&& client_->isAvailable()*/) { client_->disconnect(); } if (rosterController_ && myStatusLooksOnline_) { rosterController_->getWindow()->setMyStatusType(StatusShow::None); rosterController_->getWindow()->setMyStatusText(""); diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index 013f8bb..45e4ccf 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010-2011 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swiften/Base/boost_bsignals.h> #include <boost/shared_ptr.hpp> #include <vector> @@ -78,35 +78,34 @@ namespace Swift { SettingsProvider *settings, SystemTray* systemTray, SoundPlayer* soundPlayer, StoragesFactory* storagesFactory, CertificateStorageFactory* certificateStorageFactory, Dock* dock, Notifier* notifier, URIHandler* uriHandler, IdleDetector* idleDetector, - bool useDelayForLatency, - bool eagleMode); + bool useDelayForLatency); ~MainController(); private: void resetClient(); void handleConnected(); void handleLoginRequest(const std::string& username, const std::string& password, const std::string& certificateFile, bool remember, bool loginAutomatically); void handleCancelLoginRequest(); void handleQuitRequest(); void handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText); void handleDisconnected(const boost::optional<ClientError>& error); void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, ErrorPayload::ref); void handleEventQueueLengthChange(int count); void handleVCardReceived(const JID& j, VCard::ref vCard); - void handleUIEvent(boost::shared_ptr<UIEvent> event); + void handleSettingChanged(const std::string& settingPath); void handlePurgeSavedLoginRequest(const std::string& username); void sendPresence(boost::shared_ptr<Presence> presence); void handleInputIdleChanged(bool); void logout(); void signOut(); void setReconnectTimer(); void resetPendingReconnects(); void resetCurrentError(); @@ -160,13 +159,12 @@ namespace Swift { UserSearchController* userSearchControllerChat_; UserSearchController* userSearchControllerAdd_; int timeBeforeNextReconnect_; Timer::ref reconnectTimer_; StatusTracker* statusTracker_; bool myStatusLooksOnline_; bool quitRequested_; bool offlineRequested_; static const int SecondsToWaitBeforeForceQuitting; - bool eagleMode_; FileTransferOverview* ftOverview_; }; } diff --git a/Swift/Controllers/ProfileSettingsProvider.cpp b/Swift/Controllers/ProfileSettingsProvider.cpp new file mode 100644 index 0000000..c1b4b13 --- /dev/null +++ b/Swift/Controllers/ProfileSettingsProvider.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2010-2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swift/Controllers/ProfileSettingsProvider.h" + +namespace Swift { + +ProfileSettingsProvider::ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider) : + profile_(profile) { + provider_ = provider; + bool found = false; + foreach (std::string existingProfile, provider->getAvailableProfiles()) { + if (existingProfile == profile) { + found = true; + } + } + if (!found) { + provider_->createProfile(profile); + } +} + +ProfileSettingsProvider::~ProfileSettingsProvider() { +} + +std::string ProfileSettingsProvider::getStringSetting(const std::string &settingPath) { + //FIXME: Remove shim + SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), ""); + return provider_->getSetting(setting); +} + +void ProfileSettingsProvider::storeString(const std::string &settingPath, const std::string &settingValue) { + //FIXME: Remove shim + if (!getIsSettingFinal(settingPath)) { + SettingsProvider::Setting<std::string> setting(profileSettingPath(settingPath), ""); + provider_->storeSetting(setting, settingValue); + } +} + +int ProfileSettingsProvider::getIntSetting(const std::string& settingPath, int defaultValue) { + //FIXME: Remove shim + SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), defaultValue); + return provider_->getSetting(setting); +} +void ProfileSettingsProvider::storeInt(const std::string& settingPath, int settingValue) { + //FIXME: Remove shim + if (!getIsSettingFinal(settingPath)) { + SettingsProvider::Setting<int> setting(profileSettingPath(settingPath), 0); + provider_->storeSetting(setting, settingValue); + } +} + +bool ProfileSettingsProvider::getIsSettingFinal(const std::string& settingPath) { + //FIXME: Remove shim + SettingsProvider::Setting<int> setting(settingPath, 0); + return provider_->getIsSettingFinal(setting); +} + + +std::string ProfileSettingsProvider::profileSettingPath(const std::string &settingPath) { + return profile_ + ":" + settingPath; +} + + +} + diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h index 8ba250c..ebc515a 100644 --- a/Swift/Controllers/ProfileSettingsProvider.h +++ b/Swift/Controllers/ProfileSettingsProvider.h @@ -1,42 +1,33 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include "Swift/Controllers/Settings/SettingsProvider.h" +#include <Swift/Controllers/Settings/SettingsProvider.h> #include <Swiften/Base/foreach.h> namespace Swift { class ProfileSettingsProvider { public: - ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider) : profile_(profile) { - provider_ = provider; - bool found = false; - foreach (std::string existingProfile, provider->getAvailableProfiles()) { - if (existingProfile == profile) { - found = true; - } - } - if (!found) { - provider_->createProfile(profile); - } - }; - virtual ~ProfileSettingsProvider() {}; - virtual std::string getStringSetting(const std::string &settingPath) {return provider_->getStringSetting(profileSettingPath(settingPath));}; - virtual void storeString(const std::string &settingPath, const std::string &settingValue) {provider_->storeString(profileSettingPath(settingPath), settingValue);}; - virtual int getIntSetting(const std::string& settingPath, int defaultValue) {return provider_->getIntSetting(settingPath, defaultValue);} - virtual void storeInt(const std::string& settingPath, int settingValue) {provider_->storeInt(settingPath, settingValue);} + ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider); + virtual ~ProfileSettingsProvider(); + virtual std::string getStringSetting(const std::string &settingPath); + virtual void storeString(const std::string &settingPath, const std::string &settingValue); + virtual int getIntSetting(const std::string& settingPath, int defaultValue); + virtual void storeInt(const std::string& settingPath, int settingValue); + /** See @SettingsProvider::getIsSettingFinal for discussion of what this means.*/ + virtual bool getIsSettingFinal(const std::string& settingPath); private: - std::string profileSettingPath(const std::string &settingPath) {return profile_ + ":" + settingPath;}; + std::string profileSettingPath(const std::string &settingPath); SettingsProvider* provider_; std::string profile_; }; } diff --git a/Swift/Controllers/Roster/RosterController.cpp b/Swift/Controllers/Roster/RosterController.cpp index 66948c1..d3a00dd 100644 --- a/Swift/Controllers/Roster/RosterController.cpp +++ b/Swift/Controllers/Roster/RosterController.cpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Swift/Controllers/Roster/RosterController.h" #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> @@ -29,32 +29,30 @@ #include "Swift/Controllers/Roster/SetName.h" #include "Swift/Controllers/Roster/OfflineRosterFilter.h" #include "Swift/Controllers/Roster/GroupRosterItem.h" #include "Swiften/Roster/XMPPRoster.h" #include "Swiften/Roster/XMPPRosterItem.h" #include "Swift/Controllers/UIEvents/AddContactUIEvent.h" #include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h" -#include "Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h" #include "Swift/Controllers/UIEvents/SendFileUIEvent.h" #include <Swiften/FileTransfer/FileTransferManager.h> #include <Swiften/Client/NickManager.h> #include <Swift/Controllers/Intl.h> #include <Swiften/Base/format.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Disco/EntityCapsManager.h> #include <Swiften/Jingle/JingleSessionManager.h> +#include <Swift/Controllers/SettingConstants.h> namespace Swift { -static const std::string SHOW_OFFLINE = "showOffline"; - /** * The controller does not gain ownership of these parameters. */ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickManager* nickManager, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings, EntityCapsProvider* entityCapsManager, FileTransferOverview* fileTransferOverview) : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()), nickManager_(nickManager), nickResolver_(nickResolver), uiEventStream_(uiEventStream), entityCapsManager_(entityCapsManager), ftOverview_(fileTransferOverview) { assert(fileTransferOverview); iqRouter_ = iqRouter; presenceOracle_ = presenceOracle; subscriptionManager_ = subscriptionManager; @@ -77,24 +75,24 @@ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, Avata avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1)); mainWindow_->setMyAvatarPath(avatarManager_->getAvatarPath(myJID_).string()); nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); mainWindow_->setMyJID(jid); mainWindow_->setMyNick(nickManager_->getOwnNick()); entityCapsManager_->onCapsChanged.connect(boost::bind(&RosterController::handleOnCapsChanged, this, _1)); - if (settings->getBoolSetting(SHOW_OFFLINE, false)) { - uiEventStream->onUIEvent(boost::shared_ptr<UIEvent>(new ToggleShowOfflineUIEvent(true))); - } + settings_->onSettingChanged.connect(boost::bind(&RosterController::handleSettingChanged, this, _1)); + } RosterController::~RosterController() { + settings_->onSettingChanged.disconnect(boost::bind(&RosterController::handleSettingChanged, this, _1)); nickManager_->onOwnNickChanged.disconnect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); delete offlineFilter_; delete expandiness_; mainWindow_->setRosterModel(NULL); if (mainWindow_->canDelete()) { delete mainWindow_; } @@ -103,20 +101,20 @@ RosterController::~RosterController() { } void RosterController::setEnabled(bool enabled) { if (!enabled) { roster_->applyOnItems(AppearOffline()); } } void RosterController::handleShowOfflineToggled(bool state) { - if (state != settings_->getBoolSetting(SHOW_OFFLINE, false)) { - settings_->storeBool(SHOW_OFFLINE, state); + if (state != settings_->getSetting(SettingConstants::SHOW_OFFLINE)) { + settings_->storeSetting(SettingConstants::SHOW_OFFLINE, state); } if (state) { roster_->removeFilter(offlineFilter_); } else { roster_->addFilter(offlineFilter_); } } void RosterController::handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText) { @@ -175,23 +173,26 @@ void RosterController::handleOnJIDUpdated(const JID& jid, const std::string& old roster_->removeContactFromGroup(jid, group); if (roster_->getGroup(group)->getChildren().size() == 0) { roster_->removeGroup(group); } } } applyAllPresenceTo(jid); } -void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) { - if (boost::shared_ptr<ToggleShowOfflineUIEvent> showOfflineEvent = boost::dynamic_pointer_cast<ToggleShowOfflineUIEvent>(event)) { - handleShowOfflineToggled(showOfflineEvent->getShow()); +void RosterController::handleSettingChanged(const std::string& settingPath) { + if (settingPath == SettingConstants::SHOW_OFFLINE.getKey()) { + handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE)); } - else if (boost::shared_ptr<AddContactUIEvent> addContactEvent = boost::dynamic_pointer_cast<AddContactUIEvent>(event)) { +} + +void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) { + if (boost::shared_ptr<AddContactUIEvent> addContactEvent = boost::dynamic_pointer_cast<AddContactUIEvent>(event)) { RosterItemPayload item; item.setName(addContactEvent->getName()); item.setJID(addContactEvent->getJID()); item.setGroups(std::vector<std::string>(addContactEvent->getGroups().begin(), addContactEvent->getGroups().end())); boost::shared_ptr<RosterPayload> roster(new RosterPayload()); roster->addItem(item); SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_); request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster)); request->send(); diff --git a/Swift/Controllers/Roster/RosterController.h b/Swift/Controllers/Roster/RosterController.h index 66748ca..5e40124 100644 --- a/Swift/Controllers/Roster/RosterController.h +++ b/Swift/Controllers/Roster/RosterController.h @@ -68,18 +68,19 @@ namespace Swift { void handleIncomingPresence(boost::shared_ptr<Presence> newPresence); void handleSubscriptionRequest(const JID& jid, const std::string& message); void handleSubscriptionRequestAccepted(SubscriptionRequestEvent* event); void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event); void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload); void applyAllPresenceTo(const JID& jid); void handleEditProfileRequest(); void handleOnCapsChanged(const JID& jid); + void handleSettingChanged(const std::string& settingPath); JID myJID_; XMPPRoster* xmppRoster_; MainWindowFactory* mainWindowFactory_; MainWindow* mainWindow_; Roster* roster_; OfflineRosterFilter* offlineFilter_; AvatarManager* avatarManager_; NickManager* nickManager_; diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp index 0a242ae..81f0c12 100644 --- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp +++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp @@ -1,23 +1,24 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "RosterGroupExpandinessPersister.h" +#include <Swift/Controllers/Roster/RosterGroupExpandinessPersister.h> #include <boost/bind.hpp> #include <vector> #include <Swiften/Base/foreach.h> -#include "Swiften/Base/String.h" -#include "Swift/Controllers/Roster/GroupRosterItem.h" +#include <Swiften/Base/String.h> +#include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swift/Controllers/SettingConstants.h> namespace Swift { RosterGroupExpandinessPersister::RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings) : roster_(roster), settings_(settings) { load(); roster_->onGroupAdded.connect(boost::bind(&RosterGroupExpandinessPersister::handleGroupAdded, this, _1)); } void RosterGroupExpandinessPersister::handleGroupAdded(GroupRosterItem* group) { @@ -42,21 +43,21 @@ void RosterGroupExpandinessPersister::handleExpandedChanged(GroupRosterItem* gro void RosterGroupExpandinessPersister::save() { std::string setting; foreach (const std::string& group, collapsed_) { if (!setting.empty()) { setting += "\n"; } setting += group; } - settings_->storeString(SettingPath, setting); + settings_->storeSetting(SettingConstants::EXPANDED_ROSTER_GROUPS, setting); } void RosterGroupExpandinessPersister::load() { - std::string saved = settings_->getStringSetting(SettingPath); + std::string saved = settings_->getSetting(SettingConstants::EXPANDED_ROSTER_GROUPS); std::vector<std::string> collapsed = String::split(saved, '\n'); collapsed_.insert(collapsed.begin(), collapsed.end()); } -const std::string RosterGroupExpandinessPersister::SettingPath = "GroupExpandiness"; + } diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h index 63affe4..73c4f29 100644 --- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h +++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <set> #include "Swift/Controllers/Roster/Roster.h" #include "Swift/Controllers/Settings/SettingsProvider.h" @@ -16,12 +16,11 @@ namespace Swift { RosterGroupExpandinessPersister(Roster* roster, SettingsProvider* settings); private: void handleExpandedChanged(GroupRosterItem* group, bool expanded); void handleGroupAdded(GroupRosterItem* group); void load(); void save(); std::set<std::string> collapsed_; Roster* roster_; SettingsProvider* settings_; - static const std::string SettingPath; }; } diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index e48f382..02e212b 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -48,31 +48,35 @@ if env["SCONS_STAGE"] == "build" : "StatusTracker.cpp", "PresenceNotifier.cpp", "EventNotifier.cpp", "AdHocManager.cpp", "XMPPEvents/EventController.cpp", "UIEvents/UIEvent.cpp", "UIInterfaces/XMLConsoleWidget.cpp", "UIInterfaces/ChatListWindow.cpp", "PreviousStatusStore.cpp", + "ProfileSettingsProvider.cpp", + "Settings/SettingsProviderHierachy.cpp", + "Settings/XMLSettingsProvider.cpp", "Storages/CertificateStorageFactory.cpp", "Storages/CertificateStorage.cpp", "Storages/CertificateFileStorage.cpp", "Storages/CertificateMemoryStorage.cpp", "Storages/AvatarFileStorage.cpp", "Storages/FileStorages.cpp", "Storages/RosterFileStorage.cpp", "Storages/CapsFileStorage.cpp", "Storages/VCardFileStorage.cpp", "StatusUtil.cpp", "Translator.cpp", "XMPPURIController.cpp", "ChatMessageSummarizer.cpp", + "SettingConstants.cpp" ]) env.Append(UNITTEST_SOURCES = [ File("Roster/UnitTest/RosterControllerTest.cpp"), File("Roster/UnitTest/RosterTest.cpp"), File("Roster/UnitTest/LeastCommonSubsequenceTest.cpp"), File("Roster/UnitTest/TableRosterTest.cpp"), File("UnitTest/PreviousStatusStoreTest.cpp"), File("UnitTest/PresenceNotifierTest.cpp"), diff --git a/Swift/Controllers/SettingConstants.cpp b/Swift/Controllers/SettingConstants.cpp new file mode 100644 index 0000000..7ab4ac4 --- /dev/null +++ b/Swift/Controllers/SettingConstants.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/SettingConstants.h> + +namespace Swift { + +const SettingsProvider::Setting<bool> SettingConstants::IDLE_GOES_OFFLINE = SettingsProvider::Setting<bool>("idleGoesOffline", false); +const SettingsProvider::Setting<int> SettingConstants::IDLE_TIMEOUT = SettingsProvider::Setting<int>("idleTimeout", 600); +const SettingsProvider::Setting<bool> SettingConstants::SHOW_NOTIFICATIONS = SettingsProvider::Setting<bool>("showNotifications", true); +const SettingsProvider::Setting<bool> SettingConstants::REQUEST_DELIVERYRECEIPTS = SettingsProvider::Setting<bool>("requestDeliveryReceipts", false); +const SettingsProvider::Setting<bool> SettingConstants::FORGET_PASSWORDS = SettingsProvider::Setting<bool>("forgetPasswords", false); +const SettingsProvider::Setting<bool> SettingConstants::REMEMBER_RECENT_CHATS = SettingsProvider::Setting<bool>("rememberRecentChats", true); +const SettingsProvider::Setting<std::string> SettingConstants::LAST_LOGIN_JID = SettingsProvider::Setting<std::string>("lastLoginJID", ""); +const SettingsProvider::Setting<bool> SettingConstants::LOGIN_AUTOMATICALLY = SettingsProvider::Setting<bool>("loginAutomatically", false); +const SettingsProvider::Setting<bool> SettingConstants::SHOW_OFFLINE("showOffline", false); +const SettingsProvider::Setting<std::string> SettingConstants::EXPANDED_ROSTER_GROUPS("GroupExpandiness", ""); +const SettingsProvider::Setting<bool> SettingConstants::PLAY_SOUNDS("playSounds", true); +} diff --git a/Swift/Controllers/SettingConstants.h b/Swift/Controllers/SettingConstants.h new file mode 100644 index 0000000..ff1ed72 --- /dev/null +++ b/Swift/Controllers/SettingConstants.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/Settings/SettingsProvider.h> + +namespace Swift { + class SettingConstants { + public: + static const SettingsProvider::Setting<bool> IDLE_GOES_OFFLINE; + static const SettingsProvider::Setting<int> IDLE_TIMEOUT; + static const SettingsProvider::Setting<bool> SHOW_NOTIFICATIONS; + static const SettingsProvider::Setting<bool> REQUEST_DELIVERYRECEIPTS; + static const SettingsProvider::Setting<bool> FORGET_PASSWORDS; + static const SettingsProvider::Setting<bool> REMEMBER_RECENT_CHATS; + static const SettingsProvider::Setting<std::string> LAST_LOGIN_JID; + static const SettingsProvider::Setting<bool> LOGIN_AUTOMATICALLY; + static const SettingsProvider::Setting<bool> SHOW_OFFLINE; + static const SettingsProvider::Setting<std::string> EXPANDED_ROSTER_GROUPS; + static const SettingsProvider::Setting<bool> PLAY_SOUNDS; + }; +} diff --git a/Swift/Controllers/Settings/DummySettingsProvider.h b/Swift/Controllers/Settings/DummySettingsProvider.h index 90e1921..bb7d2e6 100644 --- a/Swift/Controllers/Settings/DummySettingsProvider.h +++ b/Swift/Controllers/Settings/DummySettingsProvider.h @@ -1,30 +1,52 @@ /* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once -#include "Swift/Controllers/Settings/SettingsProvider.h" +#include <Swift/Controllers/Settings/SettingsProvider.h> + +#include <map> namespace Swift { class DummySettingsProvider : public SettingsProvider { public: virtual ~DummySettingsProvider() {} - virtual std::string getStringSetting(const std::string&) {return "";} - virtual void storeString(const std::string &, const std::string &) {} - virtual bool getBoolSetting(const std::string &, bool ) {return true;} - virtual void storeBool(const std::string &, bool ) {} - virtual int getIntSetting(const std::string &, int ) {return 0;} - virtual void storeInt(const std::string &, int ) {} + virtual std::string getSetting(const Setting<std::string>& setting) { + return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue(); + }; + virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) { + stringValues[setting.getKey()] = value; + onSettingChanged(setting.getKey()); + }; + virtual bool getSetting(const Setting<bool>& setting) { + return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue(); + }; + virtual void storeSetting(const Setting<bool>& setting, const bool& value) { + boolValues[setting.getKey()] = value; + onSettingChanged(setting.getKey()); + }; + virtual int getSetting(const Setting<int>& setting) { + return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue(); + }; + virtual void storeSetting(const Setting<int>& setting, const int& value) { + intValues[setting.getKey()] = value; + onSettingChanged(setting.getKey()); + }; virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();} virtual void createProfile(const std::string& ) {} virtual void removeProfile(const std::string& ) {} + virtual bool getIsSettingFinal(const std::string& ) {return false;} + private: + std::map<std::string, std::string> stringValues; + std::map<std::string, int> intValues; + std::map<std::string, bool> boolValues; }; } diff --git a/Swift/Controllers/Settings/SettingsProvider.h b/Swift/Controllers/Settings/SettingsProvider.h index a5ff4eb..e884add 100644 --- a/Swift/Controllers/Settings/SettingsProvider.h +++ b/Swift/Controllers/Settings/SettingsProvider.h @@ -1,33 +1,73 @@ /* - * Copyright (c) 2010 Remko Tronçon + * Copyright (c) 2010-2012 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_SettingsProvider_H -#define SWIFTEN_SettingsProvider_H +#pragma once -#include <string> +#include <Swiften/Base/boost_bsignals.h> +#include <string> #include <vector> namespace Swift { class SettingsProvider { + + public: + template <typename T> + class Setting { + public: + Setting(const std::string& key, const T& defaultValue) : key(key), defaultValue(defaultValue) { + + } + + const std::string& getKey() const { + return key; + } + + const T& getDefaultValue() const { + return defaultValue; + } + + private: + std::string key; + T defaultValue; + }; + public: virtual ~SettingsProvider() {} - virtual std::string getStringSetting(const std::string &settingPath) = 0; - virtual void storeString(const std::string &settingPath, const std::string &settingValue) = 0; - virtual bool getBoolSetting(const std::string &settingPath, bool defaultValue) = 0; - virtual void storeBool(const std::string &settingPath, bool settingValue) = 0; - virtual int getIntSetting(const std::string &settingPath, int defaultValue) = 0; - virtual void storeInt(const std::string &settingPath, int settingValue) = 0; + virtual std::string getSetting(const Setting<std::string>& setting) = 0; + virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0; + virtual bool getSetting(const Setting<bool>& setting) = 0; + virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0; + virtual int getSetting(const Setting<int>& setting) = 0; + virtual void storeSetting(const Setting<int>& setting, const int& value) = 0; + virtual std::vector<std::string> getAvailableProfiles() = 0; virtual void createProfile(const std::string& profile) = 0; virtual void removeProfile(const std::string& profile) = 0; + /** A final setting is one that this settings provider says may not be overriden by lower priority profiles. + * e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user. + */ + template<typename T> + bool getIsSettingFinal(const Setting<T>& setting) { + return getIsSettingFinal(setting.getKey()); + } + + friend class SettingsProviderHierachy; + protected: + virtual bool getIsSettingFinal(const std::string& settingPath) = 0; + + public: + /** + * Emitted when a setting is changed. + */ + boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged; }; } -#endif + diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp new file mode 100644 index 0000000..3b7d13c --- /dev/null +++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/Settings/SettingsProviderHierachy.h> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Base/Log.h> +namespace Swift { + +SettingsProviderHierachy::~SettingsProviderHierachy() { +} + +std::string SettingsProviderHierachy::getSetting(const Setting<std::string>& setting) { + foreach (SettingsProvider* provider, providers_) { + std::string providerSetting = provider->getSetting(setting); + if (providerSetting != setting.getDefaultValue()) { + return providerSetting; + } + } + return setting.getDefaultValue(); +} + +void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) { + if (!getIsSettingFinal(setting.getKey())) { + getWritableProvider()->storeSetting(setting, settingValue); + } +} + +bool SettingsProviderHierachy::getSetting(const Setting<bool>& setting) { + foreach (SettingsProvider* provider, providers_) { + bool providerSetting = provider->getSetting(setting); + if (providerSetting != setting.getDefaultValue()) { + return providerSetting; + } + } + return setting.getDefaultValue(); +} + +void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const bool& settingValue) { + if (!getIsSettingFinal(setting.getKey())) { + getWritableProvider()->storeSetting(setting, settingValue); + } +} + +int SettingsProviderHierachy::getSetting(const Setting<int>& setting) { + foreach (SettingsProvider* provider, providers_) { + int providerSetting = provider->getSetting(setting); + if (providerSetting != setting.getDefaultValue()) { + return providerSetting; + } + } + return setting.getDefaultValue(); +} + +void SettingsProviderHierachy::storeSetting(const Setting<int>& setting, const int& settingValue) { + if (!getIsSettingFinal(setting.getKey())) { + getWritableProvider()->storeSetting(setting, settingValue); + } +} + +std::vector<std::string> SettingsProviderHierachy::getAvailableProfiles() { + /* Always pull profiles from the topmost */ + return getWritableProvider()->getAvailableProfiles(); +} + +void SettingsProviderHierachy::createProfile(const std::string& profile) { + return getWritableProvider()->createProfile(profile); +} + +void SettingsProviderHierachy::removeProfile(const std::string& profile) { + return getWritableProvider()->removeProfile(profile); +} + +bool SettingsProviderHierachy::getIsSettingFinal(const std::string& settingPath) { + bool isFinal = false; + foreach (SettingsProvider* provider, providers_) { + isFinal |= provider->getIsSettingFinal(settingPath); + } + return isFinal; +} + +SettingsProvider* SettingsProviderHierachy::getWritableProvider() { + return providers_.back(); +} + +void SettingsProviderHierachy::addProviderToTopOfStack(SettingsProvider* provider) { + providers_.push_back(provider); + provider->onSettingChanged.connect(onSettingChanged); +} + +} + diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.h b/Swift/Controllers/Settings/SettingsProviderHierachy.h new file mode 100644 index 0000000..b7f6961 --- /dev/null +++ b/Swift/Controllers/Settings/SettingsProviderHierachy.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/Settings/SettingsProvider.h> + +namespace Swift { + +class SettingsProviderHierachy : public SettingsProvider { + public: + virtual ~SettingsProviderHierachy(); + virtual std::string getSetting(const Setting<std::string>& setting); + virtual void storeSetting(const Setting<std::string>& setting, const std::string& value); + virtual bool getSetting(const Setting<bool>& setting); + virtual void storeSetting(const Setting<bool>& setting, const bool& value); + virtual int getSetting(const Setting<int>& setting); + virtual void storeSetting(const Setting<int>& setting, const int& value); + virtual std::vector<std::string> getAvailableProfiles(); + virtual void createProfile(const std::string& profile); + virtual void removeProfile(const std::string& profile); + protected: + virtual bool getIsSettingFinal(const std::string& settingPath); + + public: + /** + * Adds a provider less significant than any already added. + * This means that if an existing provider has a setting, this provider won't be asked. + * Any settings will be pushed into the topmost (least significant) provider. + * Does not take ownership of provider. + */ + void addProviderToTopOfStack(SettingsProvider* provider); + private: + SettingsProvider* getWritableProvider(); + private: + /* Start/Left is most significant (lowest), left overrides right.*/ + std::vector<SettingsProvider*> providers_; +}; + +} + + + diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.cpp b/Swift/Controllers/Settings/XMLSettingsProvider.cpp new file mode 100644 index 0000000..6ad3170 --- /dev/null +++ b/Swift/Controllers/Settings/XMLSettingsProvider.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/Controllers/Settings/XMLSettingsProvider.h> + +#include <boost/lexical_cast.hpp> +#include <boost/algorithm/string.hpp> + +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Parser/XMLParser.h> +#include <Swiften/Base/Log.h> + +namespace Swift { + +XMLSettingsProvider::XMLSettingsProvider(const std::string& xmlConfig) : level_(0) { + if (!xmlConfig.empty()) { + PlatformXMLParserFactory factory; + XMLParser* parser = factory.createXMLParser(this); + if (parser->parse(xmlConfig)) { + SWIFT_LOG(debug) << "Found and parsed system config" << std::endl; + } + else { + SWIFT_LOG(debug) << "Found invalid system config" << std::endl; + } + delete parser; + } + else { + SWIFT_LOG(debug) << "No system config found" << std::endl; + } +} + +XMLSettingsProvider::~XMLSettingsProvider() { + +} + +std::string XMLSettingsProvider::getSetting(const Setting<std::string>& setting) { + if (values_.find(setting.getKey()) != values_.end()) { + std::string value = values_[setting.getKey()]; + return value; + } + return setting.getDefaultValue(); +} + +void XMLSettingsProvider::storeSetting(const Setting<std::string>& /*settingPath*/, const std::string& /*settingValue*/) { + assert(false); +} + +bool XMLSettingsProvider::getSetting(const Setting<bool>& setting) { + if (values_.find(setting.getKey()) != values_.end()) { + std::string value = values_[setting.getKey()]; + return boost::iequals(value, "true") || value == "1"; + } + return setting.getDefaultValue(); +} + +void XMLSettingsProvider::storeSetting(const Setting<bool>& /*settingPath*/, const bool& /*settingValue*/) { + assert(false); +} + +int XMLSettingsProvider::getSetting(const Setting<int>& setting) { + if (values_.find(setting.getKey()) != values_.end()) { + std::string value = values_[setting.getKey()]; + try { + return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);; + } + catch(boost::bad_lexical_cast &) {} + } + return setting.getDefaultValue(); +} + +void XMLSettingsProvider::storeSetting(const Setting<int>& /*settingPath*/, const int& /*settingValue*/) { + assert(false); +} + +std::vector<std::string> XMLSettingsProvider::getAvailableProfiles() { + assert(false); +} + +void XMLSettingsProvider::createProfile(const std::string& /*profile*/) { + assert(false); +} + +void XMLSettingsProvider::removeProfile(const std::string& /*profile*/) { + assert(false); +} + +bool XMLSettingsProvider::getIsSettingFinal(const std::string& settingPath) { + return finals_.count(settingPath); +} + +void XMLSettingsProvider::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { + level_++; + if (level_ == SettingLevel) { + if (attributes.getBoolAttribute("final", false)) { + finals_.insert(element); + } + currentElement_ = element; + currentText_ = ""; + } +} + +void XMLSettingsProvider::handleEndElement(const std::string& /*element*/, const std::string& /*ns*/) { + if (level_ == SettingLevel) { + values_[currentElement_] = currentText_; + SWIFT_LOG(debug) << "Setting value of " << currentElement_ << " to " << currentText_ << std::endl; + } + level_--; +} + +void XMLSettingsProvider::handleCharacterData(const std::string& data) { + if (level_ >= SettingLevel) { + currentText_ += data; + } +} + + +} + + + + diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.h b/Swift/Controllers/Settings/XMLSettingsProvider.h new file mode 100644 index 0000000..61abd11 --- /dev/null +++ b/Swift/Controllers/Settings/XMLSettingsProvider.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swift/Controllers/Settings/SettingsProvider.h> +#include <Swiften/Parser/XMLParserClient.h> + +#include <map> +#include <set> + +namespace Swift { + +class XMLSettingsProvider : public SettingsProvider, public XMLParserClient { + public: + XMLSettingsProvider(const std::string& xmlConfig); + virtual ~XMLSettingsProvider(); + virtual std::string getSetting(const Setting<std::string>& setting); + virtual void storeSetting(const Setting<std::string>& setting, const std::string& value); + virtual bool getSetting(const Setting<bool>& setting); + virtual void storeSetting(const Setting<bool>& setting, const bool& value); + virtual int getSetting(const Setting<int>& setting); + virtual void storeSetting(const Setting<int>& setting, const int& value); + virtual std::vector<std::string> getAvailableProfiles(); + virtual void createProfile(const std::string& profile); + virtual void removeProfile(const std::string& profile); + + virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string& ns); + virtual void handleCharacterData(const std::string& data); + + protected: + virtual bool getIsSettingFinal(const std::string& settingPath); + private: + std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_; + /* Settings that are final*/ + std::set<std::string /*settingPath*/> finals_; + + enum Level { + TopLevel = 0, + SettingLevel = 2 + }; + + int level_; + std::string currentElement_; + std::string currentText_; +}; + +} + + + + diff --git a/Swift/Controllers/SoundEventController.cpp b/Swift/Controllers/SoundEventController.cpp index 26847ed..d056990 100644 --- a/Swift/Controllers/SoundEventController.cpp +++ b/Swift/Controllers/SoundEventController.cpp @@ -1,53 +1,45 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swift/Controllers/SoundEventController.h" +#include <Swift/Controllers/SoundEventController.h> #include <boost/bind.hpp> -#include "Swift/Controllers/XMPPEvents/EventController.h" -#include "Swift/Controllers/SoundPlayer.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h" +#include <Swift/Controllers/XMPPEvents/EventController.h> +#include <Swift/Controllers/SoundPlayer.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/SettingConstants.h> namespace Swift { -SoundEventController::SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, UIEventStream* uiEvents) { - uiEvents_ = uiEvents; +SoundEventController::SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings) { settings_ = settings; eventController_ = eventController; soundPlayer_ = soundPlayer; - uiEvents_->onUIEvent.connect(boost::bind(&SoundEventController::handleUIEvent, this, _1)); eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1)); + settings_->onSettingChanged.connect(boost::bind(&SoundEventController::handleSettingChanged, this, _1)); - bool playSounds = settings->getBoolSetting("playSounds", true); - playSounds_ = !playSounds; - setPlaySounds(playSounds); + playSounds_ = settings->getSetting(SettingConstants::PLAY_SOUNDS); } void SoundEventController::handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event) { if (playSounds_ && !event->getConcluded()) { soundPlayer_->playSound(SoundPlayer::MessageReceived); } } void SoundEventController::setPlaySounds(bool playSounds) { - bool transmit = playSounds != playSounds_; playSounds_ = playSounds; - settings_->storeBool("playSounds", playSounds); - if (transmit) { - uiEvents_->send(boost::shared_ptr<ToggleSoundsUIEvent>(new ToggleSoundsUIEvent(playSounds_))); - } + settings_->storeSetting(SettingConstants::PLAY_SOUNDS, playSounds); } -void SoundEventController::handleUIEvent(boost::shared_ptr<UIEvent> event) { - boost::shared_ptr<ToggleSoundsUIEvent> soundEvent = boost::dynamic_pointer_cast<ToggleSoundsUIEvent>(event); - if (soundEvent) { - setPlaySounds(soundEvent->getEnabled()); +void SoundEventController::handleSettingChanged(const std::string& settingPath) { + if (SettingConstants::PLAY_SOUNDS.getKey() == settingPath) { + playSounds_ = settings_->getSetting(SettingConstants::PLAY_SOUNDS); } } } diff --git a/Swift/Controllers/SoundEventController.h b/Swift/Controllers/SoundEventController.h index 5e00fc6..c6dec6f 100644 --- a/Swift/Controllers/SoundEventController.h +++ b/Swift/Controllers/SoundEventController.h @@ -1,33 +1,30 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> -#include "Swift/Controllers/XMPPEvents/StanzaEvent.h" -#include "Swift/Controllers/Settings/SettingsProvider.h" -#include "Swift/Controllers/UIEvents/UIEvent.h" +#include <Swift/Controllers/XMPPEvents/StanzaEvent.h> +#include <Swift/Controllers/Settings/SettingsProvider.h> namespace Swift { class EventController; class SoundPlayer; - class UIEventStream; class SoundEventController { public: - SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, UIEventStream* uiEvents); + SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings); void setPlaySounds(bool playSounds); bool getSoundEnabled() {return playSounds_;}; private: - void handleUIEvent(boost::shared_ptr<UIEvent> event); + void handleSettingChanged(const std::string& settingPath); void handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent> event); EventController* eventController_; SoundPlayer* soundPlayer_; bool playSounds_; - UIEventStream* uiEvents_; SettingsProvider* settings_; }; } diff --git a/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h b/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h deleted file mode 100644 index 0f7acc8..0000000 --- a/Swift/Controllers/UIEvents/ToggleNotificationsUIEvent.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swift/Controllers/UIEvents/UIEvent.h" - -namespace Swift { - class ToggleNotificationsUIEvent : public UIEvent { - public: - ToggleNotificationsUIEvent(bool enable) : enabled_(enable) {}; - bool getEnabled() {return enabled_;}; - private: - bool enabled_; - }; -} diff --git a/Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h b/Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h deleted file mode 100644 index 1ea2db5..0000000 --- a/Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2011 Tobias Markmann - * Licensed under the BSD license. - * See http://www.opensource.org/licenses/bsd-license.php for more information. - */ - -#pragma once - -#include "Swift/Controllers/UIEvents/UIEvent.h" - -namespace Swift { - class ToggleRequestDeliveryReceiptsUIEvent : public UIEvent { - public: - ToggleRequestDeliveryReceiptsUIEvent(bool enable) : enabled_(enable) {} - bool getEnabled() {return enabled_;} - private: - bool enabled_; - }; -} diff --git a/Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h b/Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h deleted file mode 100644 index b45eb83..0000000 --- a/Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swift/Controllers/UIEvents/UIEvent.h" - -namespace Swift { - class ToggleShowOfflineUIEvent : public UIEvent { - public: - ToggleShowOfflineUIEvent(bool show) : show_(show) {}; - bool getShow() {return show_;}; - private: - bool show_; - }; -} diff --git a/Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h b/Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h deleted file mode 100644 index 9e5cfc6..0000000 --- a/Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include "Swift/Controllers/UIEvents/UIEvent.h" - -namespace Swift { - class ToggleSoundsUIEvent : public UIEvent { - public: - ToggleSoundsUIEvent(bool enable) : enabled_(enable) {}; - bool getEnabled() {return enabled_;}; - private: - bool enabled_; - }; -} |