summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Roster')
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp39
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.h25
-rw-r--r--Swift/Controllers/Roster/LeastCommonSubsequence.h25
-rw-r--r--Swift/Controllers/Roster/Roster.cpp35
-rw-r--r--Swift/Controllers/Roster/Roster.h10
-rw-r--r--Swift/Controllers/Roster/RosterController.cpp46
-rw-r--r--Swift/Controllers/Roster/RosterController.h17
-rw-r--r--Swift/Controllers/Roster/RosterItemOperation.h8
-rw-r--r--Swift/Controllers/Roster/SetAvatar.h7
-rw-r--r--Swift/Controllers/Roster/TableRoster.cpp7
-rw-r--r--Swift/Controllers/Roster/TableRoster.h5
-rw-r--r--Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp26
-rw-r--r--Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp2
13 files changed, 182 insertions, 70 deletions
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp
index 8c388bf..70b4a1b 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.cpp
+++ b/Swift/Controllers/Roster/ContactRosterItem.cpp
@@ -8,11 +8,15 @@
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Elements/Idle.h>
+
+#include <boost/date_time/posix_time/posix_time.hpp>
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() {
@@ -24,12 +28,12 @@ StatusShow::Type ContactRosterItem::getStatusShow() const {
StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
switch (shownPresence_ ? shownPresence_->getShow() : StatusShow::None) {
- case StatusShow::Online: return StatusShow::Online; break;
- case StatusShow::Away: return StatusShow::Away; break;
- case StatusShow::XA: return StatusShow::Away; break;
- case StatusShow::FFC: return StatusShow::Online; break;
- case StatusShow::DND: return StatusShow::DND; break;
- case StatusShow::None: return StatusShow::None; break;
+ case StatusShow::Online: return StatusShow::Online;
+ case StatusShow::Away: return StatusShow::Away;
+ case StatusShow::XA: return StatusShow::Away;
+ case StatusShow::FFC: return StatusShow::Online;
+ case StatusShow::DND: return StatusShow::DND;
+ case StatusShow::None: return StatusShow::None;
}
assert(false);
return StatusShow::None;
@@ -39,11 +43,20 @@ std::string ContactRosterItem::getStatusText() const {
return shownPresence_ ? shownPresence_->getStatus() : "";
}
-void ContactRosterItem::setAvatarPath(const std::string& path) {
+std::string ContactRosterItem::getIdleText() const {
+ Idle::ref idle = shownPresence_ ? shownPresence_->getPayload<Idle>() : Idle::ref();
+ if (!idle || idle->getSince().is_not_a_date_time()) {
+ return "";
+ } else {
+ return dateTimeToLocalString(idle->getSince());
+ }
+}
+
+void ContactRosterItem::setAvatarPath(const boost::filesystem::path& path) {
avatarPath_ = path;
onDataChanged();
}
-const std::string& ContactRosterItem::getAvatarPath() const {
+const boost::filesystem::path& ContactRosterItem::getAvatarPath() const {
return avatarPath_;
}
@@ -121,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 8389a44..67a9722 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.h
+++ b/Swift/Controllers/Roster/ContactRosterItem.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -17,6 +17,8 @@
#include <boost/bind.hpp>
#include "Swiften/Base/boost_bsignals.h"
#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/ptime.hpp>
+#include <boost/filesystem/path.hpp>
namespace Swift {
@@ -25,7 +27,13 @@ class ContactRosterItem : public RosterItem {
public:
enum Feature {
FileTransferFeature,
- WhiteboardFeature,
+ WhiteboardFeature
+ };
+
+ enum BlockState {
+ BlockingNotSupported,
+ IsBlocked,
+ IsUnblocked
};
public:
@@ -35,8 +43,9 @@ class ContactRosterItem : public RosterItem {
StatusShow::Type getStatusShow() const;
StatusShow::Type getSimplifiedStatusShow() const;
std::string getStatusText() const;
- void setAvatarPath(const std::string& path);
- const std::string& getAvatarPath() const;
+ std::string getIdleText() const;
+ void setAvatarPath(const boost::filesystem::path& path);
+ const boost::filesystem::path& getAvatarPath() const;
const JID& getJID() const;
void setDisplayJID(const JID& jid);
const JID& getDisplayJID() const;
@@ -50,15 +59,21 @@ 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_;
- std::string avatarPath_;
+ boost::posix_time::ptime lastAvailableTime_;
+ boost::filesystem::path avatarPath_;
std::map<std::string, boost::shared_ptr<Presence> > presences_;
boost::shared_ptr<Presence> offlinePresence_;
boost::shared_ptr<Presence> shownPresence_;
std::vector<std::string> groups_;
std::set<Feature> features_;
+ BlockState blockState_;
};
}
diff --git a/Swift/Controllers/Roster/LeastCommonSubsequence.h b/Swift/Controllers/Roster/LeastCommonSubsequence.h
index dd3c95a..9d45679 100644
--- a/Swift/Controllers/Roster/LeastCommonSubsequence.h
+++ b/Swift/Controllers/Roster/LeastCommonSubsequence.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -7,6 +7,7 @@
#pragma once
#include <vector>
+#include <boost/numeric/conversion/cast.hpp>
namespace Swift {
using std::equal_to;
@@ -14,8 +15,8 @@ namespace Swift {
namespace Detail {
template<typename XIt, typename YIt, typename Length, typename Predicate>
void computeLeastCommonSubsequenceMatrix(XIt xBegin, XIt xEnd, YIt yBegin, YIt yEnd, std::vector<Length>& result) {
- size_t width = std::distance(xBegin, xEnd) + 1;
- size_t height = std::distance(yBegin, yEnd) + 1;
+ size_t width = static_cast<size_t>(std::distance(xBegin, xEnd) + 1);
+ size_t height = static_cast<size_t>(std::distance(yBegin, yEnd) + 1);
result.resize(width * height);
// Initialize first row & column
@@ -30,7 +31,7 @@ namespace Swift {
Predicate predicate;
for (size_t i = 1; i < width; ++i) {
for (size_t j = 1; j < height; ++j) {
- result[i + j*width] = (predicate(*(xBegin + i-1), *(yBegin + j-1)) ? result[(i-1) + (j-1)*width] + 1 : std::max(result[i + (j-1)*width], result[i-1 + (j*width)]));
+ result[i + j*width] = predicate(*(xBegin + boost::numeric_cast<long long>(i)-1), *(yBegin + boost::numeric_cast<long long >(j)-1)) ? result[(i-1) + (j-1)*width] + 1 : std::max(result[i + (j-1)*width], result[i-1 + (j*width)]);
}
}
}
@@ -46,29 +47,29 @@ namespace Swift {
typename std::vector<X>::const_iterator yBegin = y.begin();
while (xBegin < x.end() && yBegin < y.end() && insertRemovePredicate(*xBegin, *yBegin)) {
if (updatePredicate(*xBegin, *yBegin)) {
- updates.push_back(std::distance(x.begin(), xBegin));
- postUpdates.push_back(std::distance(y.begin(), yBegin));
+ updates.push_back(static_cast<size_t>(std::distance(x.begin(), xBegin)));
+ postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yBegin)));
}
++xBegin;
++yBegin;
}
- size_t prefixLength = std::distance(x.begin(), xBegin);
+ size_t prefixLength = static_cast<size_t>(std::distance(x.begin(), xBegin));
// Find & handle common suffix (Optimization to reduce LCS matrix size)
typename std::vector<X>::const_reverse_iterator xEnd = x.rbegin();
typename std::vector<X>::const_reverse_iterator yEnd = y.rbegin();
while (xEnd.base() > xBegin && yEnd.base() > yBegin && insertRemovePredicate(*xEnd, *yEnd)) {
if (updatePredicate(*xEnd, *yEnd)) {
- updates.push_back(std::distance(x.begin(), xEnd.base()) - 1);
- postUpdates.push_back(std::distance(y.begin(), yEnd.base()) - 1);
+ updates.push_back(static_cast<size_t>(std::distance(x.begin(), xEnd.base()) - 1));
+ postUpdates.push_back(static_cast<size_t>(std::distance(y.begin(), yEnd.base()) - 1));
}
++xEnd;
++yEnd;
}
// Compute lengths
- size_t xLength = std::distance(xBegin, xEnd.base());
- size_t yLength = std::distance(yBegin, yEnd.base());
+ size_t xLength = static_cast<size_t>(std::distance(xBegin, xEnd.base()));
+ size_t yLength = static_cast<size_t>(std::distance(yBegin, yEnd.base()));
// Compute LCS matrix
std::vector<unsigned int> lcs;
@@ -77,7 +78,7 @@ namespace Swift {
// Process LCS matrix
size_t i = xLength;
size_t j = yLength;
- const size_t width = xLength + 1;
+ size_t width = xLength + 1;
while (true) {
if (i > 0 && j > 0 && insertRemovePredicate(x[prefixLength + i-1], y[prefixLength + j-1])) {
// x[i-1] same
diff --git a/Swift/Controllers/Roster/Roster.cpp b/Swift/Controllers/Roster/Roster.cpp
index 65cf4d2..9b45b63 100644
--- a/Swift/Controllers/Roster/Roster.cpp
+++ b/Swift/Controllers/Roster/Roster.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -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);
}
@@ -83,10 +105,13 @@ void Roster::handleChildrenChanged(GroupRosterItem* item) {
onChildrenChanged(item);
}
-void Roster::addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& groupName, const std::string& avatarPath) {
+void Roster::addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& groupName, const boost::filesystem::path& avatarPath) {
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()) {
@@ -198,13 +223,13 @@ void Roster::removeFilter(RosterFilter *filter) {
}
void Roster::filterContact(ContactRosterItem* contact, GroupRosterItem* group) {
- int oldDisplayedSize = group->getDisplayedChildren().size();
+ size_t oldDisplayedSize = group->getDisplayedChildren().size();
bool hide = true;
foreach (RosterFilter *filter, filters_) {
hide &= (*filter)(contact);
}
group->setDisplayed(contact, filters_.empty() || !hide);
- int newDisplayedSize = group->getDisplayedChildren().size();
+ size_t newDisplayedSize = group->getDisplayedChildren().size();
if (oldDisplayedSize == 0 && newDisplayedSize > 0) {
onGroupAdded(group);
}
diff --git a/Swift/Controllers/Roster/Roster.h b/Swift/Controllers/Roster/Roster.h
index 2fcfba5..a4c8b99 100644
--- a/Swift/Controllers/Roster/Roster.h
+++ b/Swift/Controllers/Roster/Roster.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -28,7 +28,7 @@ class Roster {
Roster(bool sortByStatus = true, bool fullJIDMapping = false);
~Roster();
- void addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& group, const std::string& avatarPath);
+ void addContact(const JID& jid, const JID& displayJID, const std::string& name, const std::string& group, const boost::filesystem::path& avatarPath);
void removeContact(const JID& jid);
void removeContactFromGroup(const JID& jid, const std::string& group);
void removeGroup(const std::string& group);
@@ -36,15 +36,16 @@ class Roster {
void applyOnItems(const RosterItemOperation& operation);
void applyOnAllItems(const RosterItemOperation& operation);
void applyOnItem(const RosterItemOperation& operation, const JID& jid);
- void addFilter(RosterFilter *filter) {filters_.push_back(filter);filterAll();};
+ void addFilter(RosterFilter *filter) {filters_.push_back(filter);filterAll();}
void removeFilter(RosterFilter *filter);
GroupRosterItem* getRoot();
- std::vector<RosterFilter*> getFilters() {return filters_;};
+ std::vector<RosterFilter*> getFilters() {return filters_;}
boost::signal<void (GroupRosterItem*)> onChildrenChanged;
boost::signal<void (GroupRosterItem*)> onGroupAdded;
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..d277799 100644
--- a/Swift/Controllers/Roster/RosterController.cpp
+++ b/Swift/Controllers/Roster/RosterController.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -40,18 +40,20 @@
#include <Swiften/Client/NickManager.h>
#include <Swift/Controllers/Intl.h>
#include <Swiften/Base/format.h>
+#include <Swiften/Base/Path.h>
#include <Swiften/Elements/DiscoInfo.h>
#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;
@@ -72,7 +74,7 @@ RosterController::RosterController(const JID& jid, XMPPRoster* xmppRoster, Avata
uiEventConnection_ = uiEventStream->onUIEvent.connect(boost::bind(&RosterController::handleUIEvent, this, _1));
avatarManager_ = avatarManager;
avatarManager_->onAvatarChanged.connect(boost::bind(&RosterController::handleAvatarChanged, this, _1));
- mainWindow_->setMyAvatarPath(avatarManager_->getAvatarPath(myJID_).string());
+ mainWindow_->setMyAvatarPath(pathToString(avatarManager_->getAvatarPath(myJID_)));
nickManager_->onOwnNickChanged.connect(boost::bind(&MainWindow::setMyNick, mainWindow_, _1));
mainWindow_->setMyJID(jid);
@@ -124,11 +126,11 @@ void RosterController::handleOnJIDAdded(const JID& jid) {
std::string name = nickResolver_->jidToNick(jid);
if (!groups.empty()) {
foreach(const std::string& group, groups) {
- roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid).string());
+ roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
}
}
else {
- roster_->addContact(jid, jid, name, QT_TRANSLATE_NOOP("", "Contacts"), avatarManager_->getAvatarPath(jid).string());
+ roster_->addContact(jid, jid, name, QT_TRANSLATE_NOOP("", "Contacts"), avatarManager_->getAvatarPath(jid));
}
applyAllPresenceTo(jid);
}
@@ -163,7 +165,7 @@ void RosterController::handleOnJIDUpdated(const JID& jid, const std::string& old
}
foreach(const std::string& group, groups) {
if (std::find(oldGroups.begin(), oldGroups.end(), group) == oldGroups.end()) {
- roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid).string());
+ roster_->addContact(jid, jid, name, group, avatarManager_->getAvatarPath(jid));
}
}
foreach(const std::string& group, oldGroups) {
@@ -183,6 +185,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 +272,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;
@@ -299,10 +327,10 @@ void RosterController::handleSubscriptionRequestDeclined(SubscriptionRequestEven
}
void RosterController::handleAvatarChanged(const JID& jid) {
- std::string path = avatarManager_->getAvatarPath(jid).string();
+ boost::filesystem::path path = avatarManager_->getAvatarPath(jid);
roster_->applyOnItems(SetAvatar(jid, path));
if (jid.equals(myJID_, JID::WithoutResource)) {
- mainWindow_->setMyAvatarPath(path);
+ mainWindow_->setMyAvatarPath(pathToString(path));
}
}
diff --git a/Swift/Controllers/Roster/RosterController.h b/Swift/Controllers/Roster/RosterController.h
index 5e40124..06b551e 100644
--- a/Swift/Controllers/Roster/RosterController.h
+++ b/Swift/Controllers/Roster/RosterController.h
@@ -39,13 +39,14 @@ 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_;};
+ MainWindow* getWindow() {return mainWindow_;}
boost::signal<void (StatusShow::Type, const std::string&)> onChangeStatusRequest;
boost::signal<void ()> onSignOutRequest;
void handleAvatarChanged(const JID& jid);
@@ -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/RosterItemOperation.h b/Swift/Controllers/Roster/RosterItemOperation.h
index 691c8ef..f1dff8d 100644
--- a/Swift/Controllers/Roster/RosterItemOperation.h
+++ b/Swift/Controllers/Roster/RosterItemOperation.h
@@ -12,10 +12,10 @@ namespace Swift {
class RosterItemOperation {
public:
- RosterItemOperation(bool requiresLookup = false, const JID& lookupJID = JID()) : requiresLookup_(requiresLookup), lookupJID_(lookupJID) {};
- virtual ~RosterItemOperation() {};
- bool requiresLookup() const {return requiresLookup_;};
- const JID& lookupJID() const {return lookupJID_;};
+ RosterItemOperation(bool requiresLookup = false, const JID& lookupJID = JID()) : requiresLookup_(requiresLookup), lookupJID_(lookupJID) {}
+ virtual ~RosterItemOperation() {}
+ bool requiresLookup() const {return requiresLookup_;}
+ const JID& lookupJID() const {return lookupJID_;}
/**
* This is called when iterating over possible subjects, so must check it's
* applying to the right items - even if requiresLookup() is true an item
diff --git a/Swift/Controllers/Roster/SetAvatar.h b/Swift/Controllers/Roster/SetAvatar.h
index 241b741..424f0b3 100644
--- a/Swift/Controllers/Roster/SetAvatar.h
+++ b/Swift/Controllers/Roster/SetAvatar.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,6 +10,7 @@
#include "Swiften/JID/JID.h"
#include "Swift/Controllers/Roster/RosterItemOperation.h"
#include "Swift/Controllers/Roster/ContactRosterItem.h"
+#include <boost/filesystem/path.hpp>
namespace Swift {
@@ -17,7 +18,7 @@ class RosterItem;
class SetAvatar : public RosterItemOperation {
public:
- SetAvatar(const JID& jid, const std::string& path, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), path_(path), compareType_(compareType) {
+ SetAvatar(const JID& jid, const boost::filesystem::path& path, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, jid), jid_(jid), path_(path), compareType_(compareType) {
}
virtual void operator() (RosterItem* item) const {
@@ -29,7 +30,7 @@ class SetAvatar : public RosterItemOperation {
private:
JID jid_;
- std::string path_;
+ boost::filesystem::path path_;
JID::CompareType compareType_;
};
diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp
index c00bf4f..eb036db 100644
--- a/Swift/Controllers/Roster/TableRoster.cpp
+++ b/Swift/Controllers/Roster/TableRoster.cpp
@@ -9,6 +9,7 @@
#include <boost/cast.hpp>
#include <cassert>
#include <algorithm>
+#include <boost/numeric/conversion/cast.hpp>
#include <Swiften/Base/foreach.h>
#include <Swiften/Network/TimerFactory.h>
@@ -132,13 +133,13 @@ void TableRoster::handleUpdateTimerTick() {
computeIndexDiff<Item, ItemEquals, ItemNeedsUpdate >(sections[sectionUpdates[i]].items, newSections[sectionPostUpdates[i]].items, itemUpdates, itemPostUpdates, itemRemoves, itemInserts);
size_t end = update.insertedRows.size();
update.insertedRows.resize(update.insertedRows.size() + itemInserts.size());
- std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + end, CreateIndexForSection(sectionPostUpdates[i]));
+ std::transform(itemInserts.begin(), itemInserts.end(), update.insertedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
end = update.deletedRows.size();
update.deletedRows.resize(update.deletedRows.size() + itemRemoves.size());
- std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + end, CreateIndexForSection(sectionUpdates[i]));
+ std::transform(itemRemoves.begin(), itemRemoves.end(), update.deletedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i]));
end = update.updatedRows.size();
update.updatedRows.resize(update.updatedRows.size() + itemUpdates.size());
- std::transform(itemUpdates.begin(), itemUpdates.end(), update.updatedRows.begin() + end, CreateIndexForSection(sectionPostUpdates[i]));
+ std::transform(itemUpdates.begin(), itemUpdates.end(), update.updatedRows.begin() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionPostUpdates[i]));
}
// Switch the old model with the new
diff --git a/Swift/Controllers/Roster/TableRoster.h b/Swift/Controllers/Roster/TableRoster.h
index d4612ed..f447760 100644
--- a/Swift/Controllers/Roster/TableRoster.h
+++ b/Swift/Controllers/Roster/TableRoster.h
@@ -12,6 +12,7 @@
#include <Swiften/JID/JID.h>
#include <Swiften/Elements/StatusShow.h>
+#include <boost/filesystem/path.hpp>
namespace Swift {
class Roster;
@@ -21,13 +22,13 @@ namespace Swift {
class TableRoster {
public:
struct Item {
- Item(const std::string& name, const std::string& description, const JID& jid, StatusShow::Type status, const std::string& avatarPath) : name(name), description(description), jid(jid), status(status), avatarPath(avatarPath) {
+ Item(const std::string& name, const std::string& description, const JID& jid, StatusShow::Type status, const boost::filesystem::path& avatarPath) : name(name), description(description), jid(jid), status(status), avatarPath(avatarPath) {
}
std::string name;
std::string description;
JID jid;
StatusShow::Type status;
- std::string avatarPath;
+ boost::filesystem::path avatarPath;
};
struct Index {
diff --git a/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp b/Swift/Controllers/Roster/UnitTest/RosterControllerTest.cpp
index fbee894..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_;
@@ -105,7 +108,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
delete uiEventStream_;
delete settings_;
delete xmppRoster_;
- };
+ }
GroupRosterItem* groupChild(size_t i) {
return dynamic_cast<GroupRosterItem*>(CHILDREN[i]);
@@ -133,7 +136,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(item2);
CPPUNIT_ASSERT_EQUAL(presence->getStatus(), item2->getStatusText());
- };
+ }
void testHighestPresence() {
std::vector<std::string> groups;
@@ -153,7 +156,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
CPPUNIT_ASSERT(item);
CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- };
+ }
void testNotHighestPresence() {
std::vector<std::string> groups;
@@ -173,7 +176,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(dynamic_cast<GroupRosterItem*>(CHILDREN[0])->getChildren()[0]);
CPPUNIT_ASSERT(item);
CPPUNIT_ASSERT_EQUAL(highPresence->getStatus(), item->getStatusText());
- };
+ }
void testUnavailablePresence() {
std::vector<std::string> groups;
@@ -215,7 +218,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), high->getStatus());
CPPUNIT_ASSERT_EQUAL(StatusShow::None, item->getStatusShow());
CPPUNIT_ASSERT_EQUAL(lowPresenceOffline->getStatus(), item->getStatusText());
- };
+ }
void testAdd() {
std::vector<std::string> groups;
@@ -225,7 +228,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(CHILDREN.size()));
//CPPUNIT_ASSERT_EQUAL(std::string("Bob"), xmppRoster_->getNameForJID(JID("foo@bar.com")));
- };
+ }
void testAddSubscription() {
std::vector<std::string> groups;
@@ -242,7 +245,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
- };
+ }
void testReceiveRename() {
std::vector<std::string> groups;
@@ -256,7 +259,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(CHILDREN.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
CPPUNIT_ASSERT_EQUAL(std::string("NewName"), groupChild(0)->getChildren()[0]->getDisplayName());
- };
+ }
void testReceiveRegroup() {
std::vector<std::string> oldGroups;
@@ -282,7 +285,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(groupChild(0)->getChildren().size()));
CPPUNIT_ASSERT_EQUAL(std::string("new name"), groupChild(0)->getChildren()[0]->getDisplayName());
CPPUNIT_ASSERT_EQUAL(std::string("Best Group"), groupChild(0)->getDisplayName());
- };
+ }
void testSendRename() {
JID jid("testling@wonderland.lit");
@@ -337,6 +340,7 @@ class RosterControllerTest : public CppUnit::TestFixture {
JingleSessionManager* jingleSessionManager_;
FileTransferManager* ftManager_;
FileTransferOverview* ftOverview_;
+ ClientBlockListManager* clientBlockListManager_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(RosterControllerTest);
diff --git a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
index e433b50..db8a2fd 100644
--- a/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
+++ b/Swift/Controllers/Roster/UnitTest/TableRosterTest.cpp
@@ -6,6 +6,8 @@
#include <Swift/Controllers/Roster/TableRoster.h>
+std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i);
+
std::ostream& operator<<(std::ostream& os, const Swift::TableRoster::Index& i) {
os << "(" << i.section << ", " << i.row << ")";
return os;