diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/FileStoragesFactory.h | 24 | ||||
-rw-r--r-- | Swift/Controllers/MainController.cpp | 46 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 22 | ||||
-rw-r--r-- | Swift/Controllers/StoragesFactory.h | 18 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.cpp | 14 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.h | 11 |
6 files changed, 68 insertions, 67 deletions
diff --git a/Swift/Controllers/FileStoragesFactory.h b/Swift/Controllers/FileStoragesFactory.h new file mode 100644 index 0000000..bd7cdfb --- /dev/null +++ b/Swift/Controllers/FileStoragesFactory.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swift/Controllers/StoragesFactory.h" +#include "Swiften/Client/FileStorages.h" + +namespace Swift { + class FileStoragesFactory : public StoragesFactory { + public: + FileStoragesFactory(const boost::filesystem::path& basePath) : basePath(basePath) {} + + virtual Storages* createStorages(const JID& profile) const { + return new FileStorages(basePath, profile); + } + + private: + boost::filesystem::path basePath; + }; +} diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index c5b55bf..a2d8331 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -16,9 +16,9 @@ #include "Swiften/Network/BoostIOServiceThread.h" #include "Swiften/Network/MainBoostIOServiceThread.h" #include "Swift/Controllers/BuildVersion.h" -#include "Swiften/VCards/VCardStorageFactory.h" +#include "Swift/Controllers/StoragesFactory.h" +#include "Swiften/Client/Storages.h" #include "Swiften/VCards/VCardManager.h" -#include "Swiften/VCards/VCardStorage.h" #include "Swift/Controllers/Chat/MUCSearchController.h" #include "Swift/Controllers/Chat/ChatsManager.h" #include "Swift/Controllers/XMPPEvents/EventController.h" @@ -53,9 +53,7 @@ #include "Swiften/Disco/CapsInfoGenerator.h" #include "Swiften/Disco/GetDiscoInfoRequest.h" #include "Swiften/VCards/GetVCardRequest.h" -#include "Swiften/Avatars/AvatarStorage.h" #include "Swiften/Avatars/AvatarManagerImpl.h" -#include "Swiften/Disco/CapsFileStorage.h" #include "Swiften/Disco/CapsManager.h" #include "Swiften/Disco/EntityCapsManager.h" #include "Swiften/StringCodecs/SHA1.h" @@ -83,25 +81,23 @@ MainController::MainController( XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory, MUCSearchWindowFactory* mucSearchWindowFactory, - AvatarStorage* avatarStorage, - CapsStorage* capsStorage, - VCardStorageFactory* vcardStorageFactory, + StoragesFactory* storagesFactory, Dock* dock, Notifier* notifier, bool useDelayForLatency) : timerFactory_(&boostIOServiceThread_.getIOService()), idleDetector_(&idleQuerier_, &timerFactory_, 100), + storagesFactory_(storagesFactory), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), settings_(settings), - vcardStorageFactory_(vcardStorageFactory), loginWindow_(NULL) , useDelayForLatency_(useDelayForLatency) { + storages_ = NULL; statusTracker_ = NULL; client_ = NULL; - vcardManager_ = NULL; avatarManager_ = NULL; capsManager_ = NULL; entityCapsManager_ = NULL; @@ -122,8 +118,6 @@ MainController::MainController( chatListWindowFactory_ = chatListWindowFactory; uiEventStream_ = new UIEventStream(); - avatarStorage_ = avatarStorage; - capsStorage_ = capsStorage; notifier_ = new TogglableNotifier(notifier); eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); @@ -180,9 +174,6 @@ MainController::~MainController() { resetClient(); delete eventController_; delete notifier_; - for(VCardStorageMap::iterator i = vcardStorages_.begin(); i != vcardStorages_.end(); ++i) { - delete i->second; - } } void MainController::resetClient() { @@ -213,10 +204,10 @@ void MainController::resetClient() { avatarManager_ = NULL; delete nickResolver_; nickResolver_ = NULL; - delete vcardManager_; - vcardManager_ = NULL; delete client_; client_ = NULL; + delete storages_; + storages_ = NULL; delete statusTracker_; statusTracker_ = NULL; delete profileSettings_; @@ -288,7 +279,7 @@ void MainController::handleConnected() { discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2)); discoInfoRequest->send(); - vcardManager_->requestOwnVCard(); + client_->getVCardManager()->requestOwnVCard(); rosterController_->setEnabled(true); /* Send presence later to catch all the incoming presences. */ @@ -390,7 +381,8 @@ void MainController::performLoginFromCachedCredentials() { statusTracker_ = new StatusTracker(); } if (!client_) { - client_ = new Swift::Client(jid_, password_); + storages_ = storagesFactory_->createStorages(jid_); + client_ = new Swift::Client(jid_, password_, storages_); client_->onDataRead.connect(boost::bind(&XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); client_->onDataWritten.connect(boost::bind(&XMLConsoleController::handleDataWritten, xmlConsoleController_, _1)); client_->onError.connect(boost::bind(&MainController::handleError, this, _1)); @@ -398,11 +390,10 @@ void MainController::performLoginFromCachedCredentials() { client_->setSoftwareVersion(CLIENT_NAME, buildVersion); - vcardManager_ = new VCardManager(jid_, client_->getIQRouter(), getVCardStorageForProfile(jid_)); - vcardManager_->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2)); - nickResolver_ = new NickResolver(this->jid_.toBare(), client_->getRoster(), vcardManager_, client_->getMUCRegistry()); - avatarManager_ = new AvatarManagerImpl(vcardManager_, client_->getStanzaChannel(), avatarStorage_, client_->getMUCRegistry()); - capsManager_ = new CapsManager(capsStorage_, client_->getStanzaChannel(), client_->getIQRouter()); + client_->getVCardManager()->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2)); + nickResolver_ = new NickResolver(this->jid_.toBare(), client_->getRoster(), client_->getVCardManager(), client_->getMUCRegistry()); + avatarManager_ = new AvatarManagerImpl(client_->getVCardManager(), client_->getStanzaChannel(), storages_->getAvatarStorage(), client_->getMUCRegistry()); + capsManager_ = new CapsManager(storages_->getCapsStorage(), client_->getStanzaChannel(), client_->getIQRouter()); entityCapsManager_ = new EntityCapsManager(capsManager_, client_->getStanzaChannel()); presenceNotifier_ = new PresenceNotifier(client_->getStanzaChannel(), notifier_, client_->getMUCRegistry(), avatarManager_, nickResolver_, client_->getPresenceOracle(), &timerFactory_); presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); @@ -541,14 +532,5 @@ void MainController::handleNotificationClicked(const JID& jid) { uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(jid))); } -VCardStorage* MainController::getVCardStorageForProfile(const JID& jid) { - String profile = jid.toBare().toString(); - std::pair<VCardStorageMap::iterator, bool> r = vcardStorages_.insert(std::make_pair<String, VCardStorage*>(profile, NULL)); - if (r.second) { - r.first->second = vcardStorageFactory_->createVCardStorage(profile); - } - return r.first->second; -} - } diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index e04123c..0a14993 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -28,10 +28,6 @@ #include "Swift/Controllers/UIEvents/UIEvent.h" namespace Swift { - class AvatarStorage; - class CapsStorage; - class VCardStorage; - class VCardManager; class Application; class Client; class ChatWindowFactory; @@ -67,8 +63,9 @@ namespace Swift { class MUCSearchController; class MUCSearchWindowFactory; class StatusTracker; - class VCardStorageFactory; class Dock; + class Storages; + class StoragesFactory; class MainController { public: @@ -83,9 +80,7 @@ namespace Swift { XMLConsoleWidgetFactory* xmlConsoleWidgetFactory, ChatListWindowFactory* chatListWindowFactory_, MUCSearchWindowFactory* mucSearchWindowFactory, - AvatarStorage* avatarStorage, - CapsStorage* capsStorage, - VCardStorageFactory* vcardStorageFactory, + StoragesFactory* storagesFactory, Dock* dock, Notifier* notifier, bool useDelayForLatency); @@ -116,13 +111,13 @@ namespace Swift { void setManagersOffline(); void handleNotificationClicked(const JID& jid); - VCardStorage* getVCardStorageForProfile(const JID& jid); - private: BoostIOServiceThread boostIOServiceThread_; BoostTimerFactory timerFactory_; PlatformIdleQuerier idleQuerier_; ActualIdleDetector idleDetector_; + StoragesFactory* storagesFactory_; + Storages* storages_; Client* client_; ChatWindowFactory* chatWindowFactory_; MainWindowFactory* mainWindowFactory_; @@ -130,10 +125,6 @@ namespace Swift { EventWindowFactory* eventWindowFactory_; SettingsProvider *settings_; ProfileSettingsProvider* profileSettings_; - AvatarStorage* avatarStorage_; - CapsStorage* capsStorage_; - VCardStorageFactory* vcardStorageFactory_; - VCardManager* vcardManager_; Dock* dock_; TogglableNotifier* notifier_; PresenceNotifier* presenceNotifier_; @@ -167,8 +158,5 @@ namespace Swift { Timer::ref reconnectTimer_; StatusTracker* statusTracker_; bool myStatusLooksOnline_; - - typedef std::map<String, VCardStorage*> VCardStorageMap; - VCardStorageMap vcardStorages_; }; } diff --git a/Swift/Controllers/StoragesFactory.h b/Swift/Controllers/StoragesFactory.h new file mode 100644 index 0000000..441a4e9 --- /dev/null +++ b/Swift/Controllers/StoragesFactory.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + class Storages; + + class StoragesFactory { + public: + virtual ~StoragesFactory() {} + + virtual Storages* createStorages(const JID& profile) const = 0; + }; +} diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index d9879a2..d61f94c 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -26,9 +26,9 @@ #include "SwifTools/Application/PlatformApplicationPathProvider.h" #include "Swiften/Avatars/AvatarFileStorage.h" #include "Swiften/Disco/CapsFileStorage.h" -#include "Swiften/VCards/VCardFileStorageFactory.h" #include "Swiften/Base/String.h" #include "Swiften/Base/Platform.h" +#include "Swift/Controllers/FileStoragesFactory.h" #include "Swiften/Elements/Presence.h" #include "Swiften/Client/Client.h" #include "Swift/Controllers/MainController.h" @@ -95,9 +95,7 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) { tabs_ = options.count("no-tabs") && !(splitter_ > 0) ? NULL : new QtChatTabs(); settings_ = new QtSettingsProvider(); applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME); - avatarStorage_ = new AvatarFileStorage(applicationPathProvider_->getAvatarDir()); - vcardStorageFactory_ = new VCardFileStorageFactory(applicationPathProvider_->getDataDir()); - capsStorage_ = new CapsFileStorage(applicationPathProvider_->getDataDir() / "caps"); + storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir()); chatWindowFactory_ = new QtChatWindowFactory(splitter_, settings_, tabs_, ""); soundPlayer_ = new QtSoundPlayer(applicationPathProvider_); #if defined(HAVE_GROWL) @@ -147,9 +145,7 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) { xmlConsoleWidgetFactory, chatListWindowFactory, mucSearchWindowFactory, - avatarStorage_, - capsStorage_, - vcardStorageFactory_, + storagesFactory_, dock_, notifier_, options.count("latency-debug") > 0); @@ -197,9 +193,7 @@ QtSwift::~QtSwift() { foreach (QtChatListWindowFactory* factory, chatListWindowFactories_) { delete factory; } - delete capsStorage_; - delete avatarStorage_; - delete vcardStorageFactory_; + delete storagesFactory_; } } diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h index d72faaa..59fa746 100644 --- a/Swift/QtUI/QtSwift.h +++ b/Swift/QtUI/QtSwift.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFT_QtSwift_H -#define SWIFT_QtSwift_H +#pragma once #include <boost/program_options/variables_map.hpp> #include <boost/program_options/options_description.hpp> @@ -31,7 +30,7 @@ class QSplitter; namespace Swift { class Dock; class Notifier; - class VCardStorageFactory; + class StoragesFactory; class AutoUpdater; class ApplicationPathProvider; class AvatarStorage; @@ -70,9 +69,7 @@ namespace Swift { Dock* dock_; QtChatTabs* tabs_; ApplicationPathProvider* applicationPathProvider_; - AvatarStorage* avatarStorage_; - CapsStorage* capsStorage_; - VCardStorageFactory* vcardStorageFactory_; + StoragesFactory* storagesFactory_; AutoUpdater* autoUpdater_; Notifier* notifier_; #if defined(SWIFTEN_PLATFORM_MACOSX) @@ -83,5 +80,3 @@ namespace Swift { #endif }; } - -#endif |