diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-12-12 12:29:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-12-12 16:00:53 (GMT) |
commit | 4315ccbd51f63e408d69d944f162d0ead4f9addd (patch) | |
tree | 046b3734d18c7c5e76040e8798a6f4af5e5045cb /Swift/Controllers | |
parent | aaf38fe2e6804bd87ea5e99a05ed57070cbe1c57 (diff) | |
download | swift-4315ccbd51f63e408d69d944f162d0ead4f9addd.zip swift-4315ccbd51f63e408d69d944f162d0ead4f9addd.tar.bz2 |
Refactored own nickname handling.
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/MainController.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.cpp | 28 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/MainWindow.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/MockMainWindow.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/RosterControllerTest.cpp | 6 |
6 files changed, 26 insertions, 23 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index c1d8682..f215dc6 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -230,7 +230,7 @@ void MainController::handleConnected() { bool freshLogin = rosterController_ == NULL; myStatusLooksOnline_ = true; if (freshLogin) { - rosterController_ = new RosterController(jid_, client_->getRoster(), client_->getAvatarManager(), mainWindowFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_); + rosterController_ = new RosterController(jid_, client_->getRoster(), client_->getAvatarManager(), mainWindowFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index cb044fb..1feeb58 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -32,6 +32,7 @@ #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h" +#include <Swiften/Client/NickManager.h> namespace Swift { @@ -40,8 +41,8 @@ static const String SHOW_OFFLINE = "showOffline"; /** * The controller does not gain ownership of these parameters. */ -RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter, SettingsProvider* settings) - : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()) { +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) + : myJID_(jid), xmppRoster_(xmppRoster), mainWindowFactory_(mainWindowFactory), mainWindow_(mainWindowFactory_->createMainWindow(uiEventStream)), roster_(new Roster()), offlineFilter_(new OfflineRosterFilter()), nickManager_(nickManager), nickResolver_(nickResolver) { iqRouter_ = iqRouter; presenceOracle_ = presenceOracle; subscriptionManager_ = subscriptionManager; @@ -63,13 +64,21 @@ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, Avata avatarManager_ = avatarManager; avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1)); mainWindow_->setMyAvatarPath(avatarManager_->getAvatarPath(myJID_).string()); - setNickResolver(nickResolver); + + nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); + mainWindow_->setMyJID(jid); + mainWindow_->setMyNick(nickManager_->getOwnNick()); + + mainWindow_->onChangeNickRequest.connect(boost::bind(&NickManager::setOwnNick, nickManager_, _1)); + if (settings->getBoolSetting(SHOW_OFFLINE, false)) { uiEventStream->onUIEvent(boost::shared_ptr<UIEvent>(new ToggleShowOfflineUIEvent(true))); } } RosterController::~RosterController() { + nickManager_->onOwnNickChanged.disconnect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1)); + delete offlineFilter_; delete expandiness_; mainWindow_->setRosterModel(NULL); @@ -79,19 +88,6 @@ RosterController::~RosterController() { delete roster_; } -void RosterController::setNickResolver(NickResolver* nickResolver) { - nickResolver_ = nickResolver; - if (nickResolver_ != NULL) { - handleOwnNickChanged(nickResolver_->jidToNick(myJID_)); - - nickResolver_->onOwnNickChanged.connect(boost::bind(&RosterController::handleOwnNickChanged, this, _1)); - } -} - -void RosterController::handleOwnNickChanged(const String& nick) { - mainWindow_->setMyName(nick); -} - void RosterController::setEnabled(bool enabled) { if (!enabled) { roster_->applyOnItems(AppearOffline()); diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index 2b1793e..79c14b9 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -33,14 +33,14 @@ namespace Swift { class UIEventStream; class IQRouter; class SettingsProvider; + class NickManager; class RosterController { public: - RosterController(const JID& jid, XMPPRoster* xmppRoster, AvatarManager* avatarManager, MainWindowFactory* mainWindowFactory, NickResolver* nickResolver, PresenceOracle* presenceOracle, SubscriptionManager* subscriptionManager, EventController* eventController, UIEventStream* uiEventStream, IQRouter* iqRouter_, SettingsProvider* settings); + 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); ~RosterController(); void showRosterWindow(); MainWindow* getWindow() {return mainWindow_;}; - void setNickResolver(NickResolver* nickResolver); boost::signal<void (StatusShow::Type, const String&)> onChangeStatusRequest; boost::signal<void ()> onSignOutRequest; void handleAvatarChanged(const JID& jid); @@ -59,7 +59,6 @@ namespace Swift { void handleSubscriptionRequestDeclined(SubscriptionRequestEvent* event); void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload); - void handleOwnNickChanged(const String& nick); void applyAllPresenceTo(const JID& jid); JID myJID_; XMPPRoster* xmppRoster_; @@ -68,6 +67,7 @@ namespace Swift { Roster* roster_; OfflineRosterFilter* offlineFilter_; AvatarManager* avatarManager_; + NickManager* nickManager_; NickResolver* nickResolver_; PresenceOracle* presenceOracle_; SubscriptionManager* subscriptionManager_; diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h index 0d33466..124d229 100644 --- a/Swift/Controllers/UIInterfaces/MainWindow.h +++ b/Swift/Controllers/UIInterfaces/MainWindow.h @@ -25,7 +25,8 @@ namespace Swift { return canDelete_; } - virtual void setMyName(const String& name) = 0; + virtual void setMyNick(const String& name) = 0; + virtual void setMyJID(const JID& jid) = 0; virtual void setMyAvatarPath(const String& path) = 0; virtual void setMyStatusText(const String& status) = 0; virtual void setMyStatusType(StatusShow::Type type) = 0; @@ -35,6 +36,7 @@ namespace Swift { boost::signal<void (StatusShow::Type, const String&)> onChangeStatusRequest; boost::signal<void ()> onSignOutRequest; + boost::signal<void (const String&)> onChangeNickRequest; private: bool canDelete_; diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h index 3d786d9..79c148a 100644 --- a/Swift/Controllers/UnitTest/MockMainWindow.h +++ b/Swift/Controllers/UnitTest/MockMainWindow.h @@ -15,7 +15,8 @@ namespace Swift { MockMainWindow() {}; virtual ~MockMainWindow() {}; virtual void setRosterModel(Roster* roster) {this->roster = roster;}; - virtual void setMyName(const String& /*name*/) {};; + virtual void setMyNick(const String& /*name*/) {};; + virtual void setMyJID(const JID& /*jid*/) {};; virtual void setMyAvatarPath(const String& /*path*/) {}; virtual void setMyStatusText(const String& /*status*/) {}; virtual void setMyStatusType(StatusShow::Type /*type*/) {}; diff --git a/Swift/Controllers/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/UnitTest/RosterControllerTest.cpp index 50419f9..df93ca5 100644 --- a/Swift/Controllers/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/UnitTest/RosterControllerTest.cpp @@ -30,6 +30,7 @@ #include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h" #include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h" #include "Swiften/MUC/MUCRegistry.h" +#include <Swiften/Client/DummyNickManager.h> using namespace Swift; @@ -67,12 +68,14 @@ class RosterControllerTest : public CppUnit::TestFixture eventController_ = new EventController(); uiEventStream_ = new UIEventStream(); settings_ = new DummySettingsProvider(); - rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_); + nickManager_ = new DummyNickManager(); + rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_); mainWindow_ = mainWindowFactory_->last; }; void tearDown() { delete rosterController_; + delete nickManager_; delete nickResolver_; delete mucRegistry_; delete mainWindowFactory_; @@ -304,6 +307,7 @@ class RosterControllerTest : public CppUnit::TestFixture MUCRegistry* mucRegistry_; AvatarManager* avatarManager_; MockMainWindowFactory* mainWindowFactory_; + NickManager* nickManager_; NickResolver* nickResolver_; RosterController* rosterController_; DummyIQChannel* channel_; |