diff options
Diffstat (limited to 'Swift/Controllers/Roster')
-rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.cpp | 10 | ||||
-rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.h | 10 | ||||
-rw-r--r-- | Swift/Controllers/Roster/Roster.cpp | 27 | ||||
-rw-r--r-- | Swift/Controllers/Roster/Roster.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/Roster/RosterController.cpp | 31 | ||||
-rw-r--r-- | Swift/Controllers/Roster/RosterController.h | 15 | ||||
-rw-r--r-- | Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp | 6 |
7 files changed, 94 insertions, 7 deletions
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp index f301552..bf85167 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.cpp +++ b/Swift/Controllers/Roster/ContactRosterItem.cpp @@ -16,7 +16,7 @@ namespace Swift { -ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent) : RosterItem(name, parent), jid_(jid), displayJID_(displayJID) { +ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent) : RosterItem(name, parent), jid_(jid), displayJID_(displayJID), blockState_(BlockingNotSupported) { } ContactRosterItem::~ContactRosterItem() { @@ -134,6 +134,14 @@ bool ContactRosterItem::supportsFeature(const Feature feature) const { return features_.find(feature) != features_.end(); } +void ContactRosterItem::setBlockState(BlockState state) { + blockState_ = state; +} + +ContactRosterItem::BlockState ContactRosterItem::blockState() const { + return blockState_; +} + } diff --git a/Swift/Controllers/Roster/ContactRosterItem.h b/Swift/Controllers/Roster/ContactRosterItem.h index 247c606..fc65d6d 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.h +++ b/Swift/Controllers/Roster/ContactRosterItem.h @@ -28,6 +28,12 @@ class ContactRosterItem : public RosterItem { FileTransferFeature, WhiteboardFeature }; + + enum BlockState { + BlockingNotSupported, + IsBlocked, + IsUnblocked + }; public: ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent); @@ -53,6 +59,9 @@ class ContactRosterItem : public RosterItem { void setSupportedFeatures(const std::set<Feature>& features); bool supportsFeature(Feature feature) const; + void setBlockState(BlockState state); + BlockState blockState() const; + private: JID jid_; JID displayJID_; @@ -63,6 +72,7 @@ class ContactRosterItem : public RosterItem { boost::shared_ptr<Presence> shownPresence_; std::vector<std::string> groups_; std::set<Feature> features_; + BlockState blockState_; }; } diff --git a/Swift/Controllers/Roster/Roster.cpp b/Swift/Controllers/Roster/Roster.cpp index b5c5998..3d0ca2e 100644 --- a/Swift/Controllers/Roster/Roster.cpp +++ b/Swift/Controllers/Roster/Roster.cpp @@ -22,7 +22,7 @@ namespace Swift { -Roster::Roster(bool sortByStatus, bool fullJIDMapping) { +Roster::Roster(bool sortByStatus, bool fullJIDMapping) : blockingSupported_(false) { sortByStatus_ = sortByStatus; fullJIDMapping_ = fullJIDMapping; root_ = new GroupRosterItem("Dummy-Root", NULL, sortByStatus_); @@ -71,6 +71,28 @@ void Roster::setAvailableFeatures(const JID& jid, const std::set<ContactRosterIt } } +void Roster::setBlockedState(const std::vector<JID> &jids, ContactRosterItem::BlockState state) { + if (!blockingSupported_ ) { + foreach(ItemMap::value_type i, itemMap_) { + foreach(ContactRosterItem* item, i.second) { + item->setBlockState(ContactRosterItem::IsUnblocked); + } + } + } + + foreach(const JID& jid, jids) { + ItemMap::const_iterator i = itemMap_.find(fullJIDMapping_ ? jid : jid.toBare()); + if (i == itemMap_.end()) { + continue; + } + foreach(ContactRosterItem* item, i->second) { + item->setBlockState(state); + } + } + + blockingSupported_ = true; +} + void Roster::removeGroup(const std::string& group) { root_->removeGroupChild(group); } @@ -87,6 +109,9 @@ void Roster::addContact(const JID& jid, const JID& displayJID, const std::string GroupRosterItem* group(getGroup(groupName)); ContactRosterItem *item = new ContactRosterItem(jid, displayJID, name, group); item->setAvatarPath(avatarPath); + if (blockingSupported_) { + item->setBlockState(ContactRosterItem::IsUnblocked); + } group->addChild(item); ItemMap::iterator i = itemMap_.insert(std::make_pair(fullJIDMapping_ ? jid : jid.toBare(), std::vector<ContactRosterItem*>())).first; if (!i->second.empty()) { diff --git a/Swift/Controllers/Roster/Roster.h b/Swift/Controllers/Roster/Roster.h index 74547d6..91a152f 100644 --- a/Swift/Controllers/Roster/Roster.h +++ b/Swift/Controllers/Roster/Roster.h @@ -45,6 +45,7 @@ class Roster { boost::signal<void (RosterItem*)> onDataChanged; GroupRosterItem* getGroup(const std::string& groupName); void setAvailableFeatures(const JID& jid, const std::set<ContactRosterItem::Feature>& features); + void setBlockedState(const std::vector<JID>& jids, ContactRosterItem::BlockState state); private: void handleDataChanged(RosterItem* item); @@ -58,6 +59,7 @@ class Roster { ItemMap itemMap_; bool fullJIDMapping_; bool sortByStatus_; + bool blockingSupported_; }; } diff --git a/Swift/Controllers/Roster/RosterController.cpp b/Swift/Controllers/Roster/RosterController.cpp index ec52993..d09ef4c 100644 --- a/Swift/Controllers/Roster/RosterController.cpp +++ b/Swift/Controllers/Roster/RosterController.cpp @@ -44,14 +44,15 @@ #include <Swiften/Disco/EntityCapsManager.h> #include <Swiften/Jingle/JingleSessionManager.h> #include <Swift/Controllers/SettingConstants.h> +#include <Swiften/Client/ClientBlockListManager.h> namespace Swift { /** * 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) { +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, ClientBlockListManager* clientBlockListManager) + : 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), clientBlockListManager_(clientBlockListManager) { assert(fileTransferOverview); iqRouter_ = iqRouter; presenceOracle_ = presenceOracle; @@ -183,6 +184,20 @@ void RosterController::handleSettingChanged(const std::string& settingPath) { } } +void RosterController::handleBlockingStateChanged() { + if (clientBlockListManager_->getBlockList()->getState() == BlockList::Available) { + roster_->setBlockedState(clientBlockListManager_->getBlockList()->getItems(), ContactRosterItem::IsBlocked); + } +} + +void RosterController::handleBlockingItemAdded(const JID& jid) { + roster_->setBlockedState(std::vector<JID>(1, jid), ContactRosterItem::IsBlocked); +} + +void RosterController::handleBlockingItemRemoved(const JID& jid) { + roster_->setBlockedState(std::vector<JID>(1, jid), ContactRosterItem::IsUnblocked); +} + void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) { if (boost::shared_ptr<AddContactUIEvent> addContactEvent = boost::dynamic_pointer_cast<AddContactUIEvent>(event)) { RosterItemPayload item; @@ -256,6 +271,18 @@ void RosterController::updateItem(const XMPPRosterItem& item) { request->send(); } +void RosterController::initBlockingCommand() { + boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList(); + + blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&RosterController::handleBlockingStateChanged, this)); + blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&RosterController::handleBlockingItemAdded, this, _1)); + blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&RosterController::handleBlockingItemRemoved, this, _1)); + + if (blockList->getState() == BlockList::Available) { + roster_->setBlockedState(blockList->getItems(), ContactRosterItem::IsBlocked); + } +} + void RosterController::handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload) { if (!error) { return; diff --git a/Swift/Controllers/Roster/RosterController.h b/Swift/Controllers/Roster/RosterController.h index ec07574..06b551e 100644 --- a/Swift/Controllers/Roster/RosterController.h +++ b/Swift/Controllers/Roster/RosterController.h @@ -39,10 +39,11 @@ namespace Swift { class NickManager; class EntityCapsProvider; class FileTransferManager; - + class ClientBlockListManager; + class RosterController { public: - 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* entityCapsProvider, FileTransferOverview* fileTransferOverview); + 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* entityCapsProvider, FileTransferOverview* fileTransferOverview, ClientBlockListManager* clientBlockListManager); ~RosterController(); void showRosterWindow(); MainWindow* getWindow() {return mainWindow_;} @@ -57,6 +58,8 @@ namespace Swift { void setContactGroups(const JID& jid, const std::vector<std::string>& groups); void updateItem(const XMPPRosterItem&); + void initBlockingCommand(); + private: void handleOnJIDAdded(const JID &jid); void handleRosterCleared(); @@ -76,6 +79,10 @@ namespace Swift { void handleOnCapsChanged(const JID& jid); void handleSettingChanged(const std::string& settingPath); + void handleBlockingStateChanged(); + void handleBlockingItemAdded(const JID& jid); + void handleBlockingItemRemoved(const JID& jid); + JID myJID_; XMPPRoster* xmppRoster_; MainWindowFactory* mainWindowFactory_; @@ -94,7 +101,11 @@ namespace Swift { UIEventStream* uiEventStream_; EntityCapsProvider* entityCapsManager_; FileTransferOverview* ftOverview_; + ClientBlockListManager* clientBlockListManager_; + boost::bsignals::scoped_connection blockingOnStateChangedConnection_; + boost::bsignals::scoped_connection blockingOnItemAddedConnection_; + boost::bsignals::scoped_connection blockingOnItemRemovedConnection_; boost::bsignals::scoped_connection changeStatusConnection_; boost::bsignals::scoped_connection signOutConnection_; boost::bsignals::scoped_connection uiEventConnection_; diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp index e439c78..b0034e6 100644 --- a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp +++ b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp @@ -37,6 +37,7 @@ #include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h> #include <Swiften/Base/Algorithm.h> #include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/Client/ClientBlockListManager.h> using namespace Swift; @@ -82,12 +83,14 @@ class RosterControllerTest : public CppUnit::TestFixture { ftManager_ = new DummyFileTransferManager(); ftOverview_ = new FileTransferOverview(ftManager_); - rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_); + clientBlockListManager_ = new ClientBlockListManager(router_); + rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickManager_, nickResolver_, presenceOracle_, subscriptionManager_, eventController_, uiEventStream_, router_, settings_, entityCapsManager_, ftOverview_, clientBlockListManager_); mainWindow_ = mainWindowFactory_->last; } void tearDown() { delete rosterController_; + delete clientBlockListManager_; delete ftManager_; delete jingleSessionManager_; @@ -337,6 +340,7 @@ class RosterControllerTest : public CppUnit::TestFixture { JingleSessionManager* jingleSessionManager_; FileTransferManager* ftManager_; FileTransferOverview* ftOverview_; + ClientBlockListManager* clientBlockListManager_; }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterControllerTest); |