summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/AdHocManager.cpp5
-rw-r--r--Swift/Controllers/AdHocManager.h5
-rw-r--r--Swift/Controllers/BlockListController.cpp9
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp32
-rw-r--r--Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp14
-rw-r--r--Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp10
-rw-r--r--Swift/Controllers/Chat/UserSearchController.cpp16
-rw-r--r--Swift/Controllers/ChatMessageSummarizer.cpp3
-rw-r--r--Swift/Controllers/ContactSuggester.cpp3
-rw-r--r--Swift/Controllers/ContactsFromXMPPRoster.cpp3
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferOverview.cpp5
-rw-r--r--Swift/Controllers/HighlightManager.cpp2
-rw-r--r--Swift/Controllers/HighlightRule.cpp11
-rw-r--r--Swift/Controllers/Highlighter.cpp2
-rw-r--r--Swift/Controllers/HistoryViewController.cpp21
-rw-r--r--Swift/Controllers/PreviousStatusStore.cpp4
-rw-r--r--Swift/Controllers/PreviousStatusStore.h1
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.cpp4
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.h10
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp1
-rw-r--r--Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp3
-rw-r--r--Swift/Controllers/Roster/TableRoster.cpp5
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.cpp14
-rw-r--r--Swift/Controllers/ShowProfileController.cpp4
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.cpp1
-rw-r--r--Swift/Controllers/Storages/CertificateMemoryStorage.cpp6
-rw-r--r--Swift/Controllers/Storages/VCardFileStorage.cpp1
-rw-r--r--Swift/Controllers/UIInterfaces/ChatListWindow.h12
-rw-r--r--Swift/Controllers/UnitTest/ContactSuggesterTest.cpp22
-rw-r--r--Swift/Controllers/WhiteboardManager.cpp5
-rw-r--r--Swift/Controllers/XMPPEvents/EventController.cpp6
31 files changed, 106 insertions, 134 deletions
diff --git a/Swift/Controllers/AdHocManager.cpp b/Swift/Controllers/AdHocManager.cpp
index 81f80e2..717f083 100644
--- a/Swift/Controllers/AdHocManager.cpp
+++ b/Swift/Controllers/AdHocManager.cpp
@@ -1,95 +1,94 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/AdHocManager.h>
#include <memory>
#include <boost/bind.hpp>
#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h>
#include <Swift/Controllers/UIInterfaces/MainWindow.h>
namespace Swift {
AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow) : jid_(jid) {
iqRouter_ = iqRouter;
uiEventStream_ = uiEventStream;
mainWindow_ = mainWindow;
factory_ = factory;
uiEventStream_->onUIEvent.connect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
}
AdHocManager::~AdHocManager() {
uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
for (auto& controller : controllers_) {
controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));
}
}
void AdHocManager::removeController(std::shared_ptr<AdHocController> controller) {
controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));
controllers_.erase(std::find(controllers_.begin(), controllers_.end(), controller));
}
void AdHocManager::setServerDiscoInfo(std::shared_ptr<DiscoInfo> info) {
if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::CommandsFeature)) {
if (discoItemsRequest_) {
discoItemsRequest_->onResponse.disconnect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
discoItemsRequest_.reset();
}
discoItemsRequest_ = GetDiscoItemsRequest::create(JID(jid_.getDomain()), DiscoInfo::CommandsFeature, iqRouter_);
discoItemsRequest_->onResponse.connect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2));
discoItemsRequest_->send();
} else {
mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
}
}
void AdHocManager::setOnline(bool online) {
- foreach (std::shared_ptr<AdHocController> controller, controllers_) {
+ for (auto&& controller : controllers_) {
controller->setOnline(online);
}
}
void AdHocManager::handleServerDiscoItemsResponse(std::shared_ptr<DiscoItems> items, ErrorPayload::ref error) {
std::vector<DiscoItems::Item> commands;
if (!error) {
- foreach (DiscoItems::Item item, items->getItems()) {
+ for (const auto& item : items->getItems()) {
if (item.getNode() != "http://isode.com/xmpp/commands#test") {
commands.push_back(item);
}
}
}
mainWindow_->setAvailableAdHocCommands(commands);
}
void AdHocManager::handleUIEvent(std::shared_ptr<UIEvent> event) {
std::shared_ptr<RequestAdHocUIEvent> adHocEvent = std::dynamic_pointer_cast<RequestAdHocUIEvent>(event);
if (adHocEvent) {
std::shared_ptr<OutgoingAdHocCommandSession> command = std::make_shared<OutgoingAdHocCommandSession>(adHocEvent->getCommand().getJID(), adHocEvent->getCommand().getNode(), iqRouter_);
std::shared_ptr<AdHocController> controller = std::make_shared<AdHocController>(factory_, command);
controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
controllers_.push_back(controller);
}
std::shared_ptr<RequestAdHocWithJIDUIEvent> adHocJIDEvent = std::dynamic_pointer_cast<RequestAdHocWithJIDUIEvent>(event);
if (!!adHocJIDEvent) {
std::shared_ptr<OutgoingAdHocCommandSession> command = std::make_shared<OutgoingAdHocCommandSession>(adHocJIDEvent->getJID(), adHocJIDEvent->getNode(), iqRouter_);
std::shared_ptr<AdHocController> controller = std::make_shared<AdHocController>(factory_, command);
controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
controllers_.push_back(controller);
}
}
}
diff --git a/Swift/Controllers/AdHocManager.h b/Swift/Controllers/AdHocManager.h
index 20e5db7..0786370 100644
--- a/Swift/Controllers/AdHocManager.h
+++ b/Swift/Controllers/AdHocManager.h
@@ -1,48 +1,51 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <vector>
#include <boost/signals2.hpp>
-#include <Swiften/Client/Client.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
#include <Swiften/Elements/DiscoInfo.h>
#include <Swiften/Elements/DiscoItems.h>
#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/JID/JID.h>
#include <Swift/Controllers/AdHocController.h>
#include <Swift/Controllers/UIEvents/UIEvent.h>
namespace Swift {
class IQRouter;
class MainWindow;
class UIEventStream;
class AdHocCommandWindowFactory;
+
class AdHocManager {
public:
AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow);
~AdHocManager();
void removeController(std::shared_ptr<AdHocController> contoller);
void setServerDiscoInfo(std::shared_ptr<DiscoInfo> info);
void setOnline(bool online);
+
private:
void handleServerDiscoItemsResponse(std::shared_ptr<DiscoItems>, ErrorPayload::ref error);
void handleUIEvent(std::shared_ptr<UIEvent> event);
boost::signals2::signal<void (const AdHocController&)> onControllerComplete;
+
+private:
JID jid_;
IQRouter* iqRouter_;
UIEventStream* uiEventStream_;
MainWindow* mainWindow_;
AdHocCommandWindowFactory* factory_;
GetDiscoItemsRequest::ref discoItemsRequest_;
std::vector<std::shared_ptr<AdHocController> > controllers_;
};
}
diff --git a/Swift/Controllers/BlockListController.cpp b/Swift/Controllers/BlockListController.cpp
index 560a3f3..37c536b 100644
--- a/Swift/Controllers/BlockListController.cpp
+++ b/Swift/Controllers/BlockListController.cpp
@@ -1,79 +1,78 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/BlockListController.h>
#include <boost/bind.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Base/format.h>
#include <Swiften/Client/ClientBlockListManager.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/UIEvents/RequestBlockListDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h>
#include <Swift/Controllers/UIInterfaces/BlockListEditorWidget.h>
#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
#include <Swift/Controllers/XMPPEvents/EventController.h>
namespace Swift {
BlockListController::BlockListController(ClientBlockListManager* blockListManager, UIEventStream* uiEventStream, BlockListEditorWidgetFactory* blockListEditorWidgetFactory, EventController* eventController) : blockListManager_(blockListManager), blockListEditorWidgetFactory_(blockListEditorWidgetFactory), blockListEditorWidget_(nullptr), eventController_(eventController), remainingRequests_(0), uiEventStream_(uiEventStream) {
uiEventStream->onUIEvent.connect(boost::bind(&BlockListController::handleUIEvent, this, _1));
blockListManager_->getBlockList()->onItemAdded.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
blockListManager_->getBlockList()->onItemRemoved.connect(boost::bind(&BlockListController::handleBlockListChanged, this));
}
BlockListController::~BlockListController() {
uiEventStream_->onUIEvent.disconnect(boost::bind(&BlockListController::handleUIEvent, this, _1));
blockListManager_->getBlockList()->onItemAdded.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
blockListManager_->getBlockList()->onItemRemoved.disconnect(boost::bind(&BlockListController::handleBlockListChanged, this));
}
void BlockListController::blockListDifferences(const std::vector<JID> &newBlockList, std::vector<JID> &jidsToUnblock, std::vector<JID> &jidsToBlock) const {
- foreach (const JID& jid, blockListBeforeEdit) {
+ for (const auto& jid : blockListBeforeEdit) {
if (std::find(newBlockList.begin(), newBlockList.end(), jid) == newBlockList.end()) {
jidsToUnblock.push_back(jid);
}
}
- foreach (const JID& jid, newBlockList) {
+ for (const auto& jid : newBlockList) {
if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
jidsToBlock.push_back(jid);
}
}
}
void BlockListController::handleUIEvent(std::shared_ptr<UIEvent> rawEvent) {
// handle UI dialog
std::shared_ptr<RequestBlockListDialogUIEvent> requestDialogEvent = std::dynamic_pointer_cast<RequestBlockListDialogUIEvent>(rawEvent);
if (requestDialogEvent != nullptr) {
if (blockListEditorWidget_ == nullptr) {
blockListEditorWidget_ = blockListEditorWidgetFactory_->createBlockListEditorWidget();
blockListEditorWidget_->onSetNewBlockList.connect(boost::bind(&BlockListController::handleSetNewBlockList, this, _1));
}
blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
blockListEditorWidget_->setError("");
blockListEditorWidget_->show();
return;
}
// handle block state change
std::shared_ptr<RequestChangeBlockStateUIEvent> changeStateEvent = std::dynamic_pointer_cast<RequestChangeBlockStateUIEvent>(rawEvent);
if (changeStateEvent != nullptr) {
if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Blocked) {
GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDRequest(changeStateEvent->getContact());
blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, std::vector<JID>(1, changeStateEvent->getContact()), false));
blockRequest->send();
} else if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Unblocked) {
GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDRequest(changeStateEvent->getContact());
@@ -142,45 +141,45 @@ void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlock
if (!jidsToBlock.empty()) {
remainingRequests_++;
GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDsRequest(jidsToBlock);
blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, jidsToBlock, true));
blockRequest->send();
}
if (!jidsToUnblock.empty()) {
remainingRequests_++;
GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDsRequest(jidsToUnblock);
unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, jidsToUnblock, true));
unblockRequest->send();
}
if (!jidsToBlock.empty() || !jidsToUnblock.empty()) {
assert(blockListEditorWidget_);
blockListEditorWidget_->setBusy(true);
blockListEditorWidget_->setError("");
} else {
blockListEditorWidget_->hide();
}
}
void BlockListController::handleBlockListChanged() {
if (blockListEditorWidget_) {
std::vector<JID> jidsToBlock;
std::vector<JID> jidsToUnblock;
blockListDifferences(blockListEditorWidget_->getCurrentBlockList(), jidsToUnblock, jidsToBlock);
blockListBeforeEdit = blockListManager_->getBlockList()->getItems();
- foreach (const JID& jid, jidsToBlock) {
+ for (const auto& jid : jidsToBlock) {
if (std::find(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid) == blockListBeforeEdit.end()) {
blockListBeforeEdit.push_back(jid);
}
}
- foreach (const JID& jid, jidsToUnblock) {
+ for (const auto& jid : jidsToUnblock) {
blockListBeforeEdit.erase(std::remove(blockListBeforeEdit.begin(), blockListBeforeEdit.end(), jid), blockListBeforeEdit.end());
}
blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit);
}
}
}
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 9ae3845..349bf8a 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -1,47 +1,47 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Chat/MUCController.h>
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>
+#include <boost/range/adaptor/reversed.hpp>
#include <Swiften/Avatars/AvatarManager.h>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Base/format.h>
#include <Swiften/Base/Tristate.h>
#include <Swiften/Client/BlockList.h>
#include <Swiften/Client/ClientBlockListManager.h>
#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Disco/EntityCapsProvider.h>
#include <Swiften/Elements/Delay.h>
#include <Swiften/Elements/Thread.h>
#include <Swiften/MUC/MUC.h>
#include <Swiften/MUC/MUCBookmark.h>
#include <Swiften/MUC/MUCBookmarkManager.h>
#include <Swiften/Network/Timer.h>
#include <Swiften/Network/TimerFactory.h>
#include <Swiften/Roster/XMPPRoster.h>
#include <SwifTools/TabComplete.h>
#include <Swift/Controllers/Chat/ChatMessageParser.h>
#include <Swift/Controllers/Highlighter.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/Roster/ContactRosterItem.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
#include <Swift/Controllers/Roster/ItemOperations/SetAvatar.h>
#include <Swift/Controllers/Roster/ItemOperations/SetMUC.h>
#include <Swift/Controllers/Roster/ItemOperations/SetPresence.h>
#include <Swift/Controllers/Roster/Roster.h>
#include <Swift/Controllers/Roster/RosterVCardProvider.h>
#include <Swift/Controllers/UIEvents/InviteToMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h>
@@ -211,129 +211,128 @@ void MUCController::handleWindowOccupantSelectionChanged(ContactRosterItem* item
// Add contact is available only if the real JID is also available
if (muc_->getOccupant(item->getJID().getResource()).getRealJID()) {
actions.push_back(ChatWindow::AddContact);
}
actions.push_back(ChatWindow::ShowProfile);
}
chatWindow_->setAvailableOccupantActions(actions);
}
void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction action, ContactRosterItem* item) {
JID mucJID = item->getJID();
MUCOccupant occupant = muc_->getOccupant(mucJID.getResource());
JID realJID;
if (occupant.getRealJID()) {
realJID = occupant.getRealJID().get();
}
switch (action) {
case ChatWindow::Kick: muc_->kickOccupant(mucJID);break;
case ChatWindow::Ban: muc_->changeAffiliation(realJID, MUCOccupant::Outcast);break;
case ChatWindow::MakeModerator: muc_->changeOccupantRole(mucJID, MUCOccupant::Moderator);break;
case ChatWindow::MakeParticipant: muc_->changeOccupantRole(mucJID, MUCOccupant::Participant);break;
case ChatWindow::MakeVisitor: muc_->changeOccupantRole(mucJID, MUCOccupant::Visitor);break;
case ChatWindow::AddContact: if (occupant.getRealJID()) events_->send(std::make_shared<RequestAddUserDialogUIEvent>(realJID, occupant.getNick()));break;
case ChatWindow::ShowProfile: events_->send(std::make_shared<ShowProfileForRosterItemUIEvent>(mucJID));break;
}
}
void MUCController::handleBareJIDCapsChanged(const JID& /*jid*/) {
Tristate support = Yes;
bool any = false;
- foreach (const std::string& nick, currentOccupants_) {
+ for (const auto& nick : currentOccupants_) {
DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick);
if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) {
any = true;
} else {
support = Maybe;
}
}
if (!any) {
support = No;
}
chatWindow_->setCorrectionEnabled(support);
}
/**
* Join the MUC if not already in it.
*/
void MUCController::rejoin() {
if (parting_) {
joined_ = false;
parting_ = false;
if (password_) {
muc_->setPassword(*password_);
}
//FIXME: check for received activity
#ifdef SWIFT_EXPERIMENTAL_HISTORY
if (lastActivity_ == boost::posix_time::not_a_date_time && historyController_) {
lastActivity_ = historyController_->getLastTimeStampFromMUC(selfJID_, toJID_);
}
#endif
if (lastActivity_ == boost::posix_time::not_a_date_time) {
muc_->joinAs(nick_);
}
else {
muc_->joinWithContextSince(nick_, lastActivity_);
}
}
}
bool MUCController::isJoined() {
return joined_;
}
const std::string& MUCController::getNick() {
return nick_;
}
const boost::optional<std::string> MUCController::getPassword() const {
return password_;
}
bool MUCController::isImpromptu() const {
return isImpromptu_;
}
std::map<std::string, JID> MUCController::getParticipantJIDs() const {
std::map<std::string, JID> participants;
- typedef std::pair<std::string, MUCOccupant> MUCOccupantPair;
std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
- foreach(const MUCOccupantPair& occupant, occupants) {
+ for (const auto& occupant : occupants) {
if (occupant.first != nick_) {
participants[occupant.first] = occupant.second.getRealJID().is_initialized() ? occupant.second.getRealJID().get().toBare() : JID();
}
}
return participants;
}
void MUCController::sendInvites(const std::vector<JID>& jids, const std::string& reason) const {
- foreach (const JID& jid, jids) {
+ for (const auto& jid : jids) {
muc_->invitePerson(jid, reason, isImpromptu_);
}
}
void MUCController::handleJoinTimeoutTick() {
receivedActivity();
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(str(format(QT_TRANSLATE_NOOP("", "Room %1% is not responding. This operation may never complete.")) % toJID_.toString())), ChatWindow::DefaultDirection);
}
void MUCController::receivedActivity() {
if (loginCheckTimer_) {
loginCheckTimer_->stop();
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch-enum"
void MUCController::handleJoinFailed(std::shared_ptr<ErrorPayload> error) {
receivedActivity();
std::string errorMessage = QT_TRANSLATE_NOOP("", "Unable to enter this room");
std::string rejoinNick;
if (error) {
switch (error->getCondition()) {
case ErrorPayload::Conflict:
rejoinNick = nick_ + "_";
errorMessage = str(format(QT_TRANSLATE_NOOP("", "Unable to enter this room as %1%, retrying as %2%")) % nick_ % rejoinNick);
break;
case ErrorPayload::JIDMalformed:
errorMessage += ": ";
@@ -832,61 +831,61 @@ void MUCController::appendToJoinParts(std::vector<NickJoinPart>& joinParts, cons
case JoinThenPart: break;
}
(*it).type = type;
break;
}
}
if (!matched) {
joinParts.push_back(newEvent);
}
}
std::string MUCController::concatenateListOfNames(const std::vector<NickJoinPart>& joinParts) {
std::string result;
for (size_t i = 0; i < joinParts.size(); i++) {
if (i > 0) {
if (i < joinParts.size() - 1) {
result += ", ";
} else {
result += QT_TRANSLATE_NOOP("", " and ");
}
}
NickJoinPart event = joinParts[i];
result += event.nick;
}
return result;
}
std::string MUCController::generateJoinPartString(const std::vector<NickJoinPart>& joinParts, bool isImpromptu) {
std::vector<NickJoinPart> sorted[4];
std::string eventStrings[4];
- foreach (NickJoinPart event, joinParts) {
+ for (const auto& event : joinParts) {
sorted[event.type].push_back(event);
}
std::string result;
std::vector<JoinPart> populatedEvents;
for (size_t i = 0; i < 4; i++) {
std::string names = concatenateListOfNames(sorted[i]);
if (!names.empty()) {
std::string eventString;
switch (i) {
case Join:
if (sorted[i].size() > 1) {
eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined the chat") : QT_TRANSLATE_NOOP("", "%1% have entered the room"));
}
else {
eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% has joined the chat") : QT_TRANSLATE_NOOP("", "%1% has entered the room"));
}
break;
case Part:
if (sorted[i].size() > 1) {
eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% have left the room"));
}
else {
eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have left the chat") : QT_TRANSLATE_NOOP("", "%1% has left the room"));
}
break;
case JoinThenPart:
if (sorted[i].size() > 1) {
eventString = (isImpromptu ? QT_TRANSLATE_NOOP("", "%1% have joined then left the chat") : QT_TRANSLATE_NOOP("", "%1% have entered then left the room"));
}
else {
@@ -910,61 +909,61 @@ std::string MUCController::generateJoinPartString(const std::vector<NickJoinPart
if (i > 0) {
if (i < populatedEvents.size() - 1) {
result += ", ";
} else {
result += QT_TRANSLATE_NOOP("", " and ");
}
}
result += eventStrings[populatedEvents[i]];
}
return result;
}
std::string MUCController::generateNicknameChangeString(const std::string& oldNickname, const std::string& newNickname) {
return str(boost::format(QT_TRANSLATE_NOOP("", "%1% is now known as %2%.")) % oldNickname % newNickname);
}
void MUCController::handleChangeSubjectRequest(const std::string& subject) {
muc_->changeSubject(subject);
}
void MUCController::handleBookmarkRequest() {
const JID jid = muc_->getJID();
// Prepare new bookmark for this room.
MUCBookmark roomBookmark(jid, jid.toBare().toString());
roomBookmark.setPassword(password_);
roomBookmark.setNick(nick_);
// Check for existing bookmark for this room and, if it exists, use it instead.
std::vector<MUCBookmark> bookmarks = mucBookmarkManager_->getBookmarks();
- foreach (const MUCBookmark& bookmark, bookmarks) {
+ for (const auto& bookmark : bookmarks) {
if (bookmark.getRoom() == jid.toBare()) {
roomBookmark = bookmark;
break;
}
}
chatWindow_->showBookmarkWindow(roomBookmark);
}
void MUCController::handleConfigureRequest(Form::ref form) {
if (form) {
muc_->configureRoom(form);
}
else {
muc_->requestConfigurationForm();
}
}
void MUCController::handleConfigurationFailed(ErrorPayload::ref error) {
std::string errorMessage = getErrorMessage(error);
errorMessage = str(format(QT_TRANSLATE_NOOP("", "Room configuration failed: %1%.")) % errorMessage);
chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
}
void MUCController::handleOccupantRoleChangeFailed(ErrorPayload::ref error, const JID&, MUCOccupant::Role) {
std::string errorMessage = getErrorMessage(error);
errorMessage = str(format(QT_TRANSLATE_NOOP("", "Occupant role change failed: %1%.")) % errorMessage);
chatWindow_->addErrorMessage(chatMessageParser_->parseMessageBody(errorMessage));
}
@@ -974,216 +973,213 @@ void MUCController::configureAsImpromptuRoom(Form::ref form) {
onImpromptuConfigCompleted();
}
void MUCController::handleConfigurationFormReceived(Form::ref form) {
if (isImpromptu_) {
if (!isImpromptuAlreadyConfigured_) {
configureAsImpromptuRoom(form);
}
} else {
chatWindow_->showRoomConfigurationForm(form);
}
}
void MUCController::handleConfigurationCancelled() {
muc_->cancelConfigureRoom();
}
void MUCController::handleDestroyRoomRequest() {
muc_->destroyRoom();
}
void MUCController::handleInvitePersonToThisMUCRequest(const std::vector<JID>& jidsToInvite) {
RequestInviteToMUCUIEvent::ImpromptuMode mode = isImpromptu_ ? RequestInviteToMUCUIEvent::Impromptu : RequestInviteToMUCUIEvent::NotImpromptu;
std::shared_ptr<UIEvent> event(new RequestInviteToMUCUIEvent(muc_->getJID(), jidsToInvite, mode));
eventStream_->send(event);
}
void MUCController::handleUIEvent(std::shared_ptr<UIEvent> event) {
std::shared_ptr<InviteToMUCUIEvent> inviteEvent = std::dynamic_pointer_cast<InviteToMUCUIEvent>(event);
if (inviteEvent && inviteEvent->getRoom() == muc_->getJID()) {
- foreach (const JID& jid, inviteEvent->getInvites()) {
+ for (const auto& jid : inviteEvent->getInvites()) {
muc_->invitePerson(jid, inviteEvent->getReason(), isImpromptu_);
}
}
}
void MUCController::handleGetAffiliationsRequest() {
muc_->requestAffiliationList(MUCOccupant::Owner);
muc_->requestAffiliationList(MUCOccupant::Admin);
muc_->requestAffiliationList(MUCOccupant::Member);
muc_->requestAffiliationList(MUCOccupant::Outcast);
}
-typedef std::pair<MUCOccupant::Affiliation, JID> AffiliationChangePair;
-
void MUCController::handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes) {
std::set<JID> addedJIDs;
- foreach (const AffiliationChangePair& change, changes) {
+ for (const auto& change : changes) {
if (change.first != MUCOccupant::NoAffiliation) {
addedJIDs.insert(change.second);
}
}
- foreach (const AffiliationChangePair& change, changes) {
+ for (const auto& change : changes) {
if (change.first != MUCOccupant::NoAffiliation || addedJIDs.find(change.second) == addedJIDs.end()) {
muc_->changeAffiliation(change.second, change.first);
}
}
}
void MUCController::handleUnblockUserRequest() {
eventStream_->send(std::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, muc_->getJID()));
}
void MUCController::handleBlockingStateChanged() {
std::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
if (blockList->getState() == BlockList::Available) {
if (blockList->isBlocked(toJID_)) {
if (!blockedContactAlert_) {
blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've blocked this room. To enter the room, first unblock it using the cog menu and try again"));
}
chatWindow_->setBlockingState(ChatWindow::IsBlocked);
} else {
if (blockedContactAlert_) {
chatWindow_->removeAlert(*blockedContactAlert_);
blockedContactAlert_.reset();
}
chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
}
}
}
void MUCController::handleAffiliationListReceived(MUCOccupant::Affiliation affiliation, const std::vector<JID>& jids) {
chatWindow_->setAffiliations(affiliation, jids);
}
void MUCController::logMessage(const std::string& message, const JID& fromJID, const JID& toJID, const boost::posix_time::ptime& timeStamp, bool isIncoming) {
// log only incoming messages
if (isIncoming && historyController_) {
historyController_->addMessage(message, fromJID, toJID, HistoryMessage::Groupchat, timeStamp);
}
}
void MUCController::addRecentLogs() {
if (!historyController_) {
return;
}
joinContext_ = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_);
- foreach (const HistoryMessage& message, joinContext_) {
+ for (const auto& message : joinContext_) {
bool senderIsSelf = nick_ == message.getFromJID().getResource();
// the chatWindow uses utc timestamps
addMessage(chatMessageParser_->parseMessageBody(message.getMessage()), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, std::make_shared<SecurityLabel>(), avatarManager_->getAvatarPath(message.getFromJID()), message.getTime() - boost::posix_time::hours(message.getOffset()));
}
}
void MUCController::checkDuplicates(std::shared_ptr<Message> newMessage) {
std::string body = newMessage->getBody().get_value_or("");
JID jid = newMessage->getFrom();
boost::optional<boost::posix_time::ptime> time = newMessage->getTimestamp();
- reverse_foreach (const HistoryMessage& message, joinContext_) {
+ for (const auto& message : boost::adaptors::reverse(joinContext_)) {
boost::posix_time::ptime messageTime = message.getTime() - boost::posix_time::hours(message.getOffset());
if (time && time < messageTime) {
break;
}
if (time && time != messageTime) {
continue;
}
if (message.getFromJID() != jid) {
continue;
}
if (message.getMessage() != body) {
continue;
}
// Mark the message as unreadable
newMessage->setBody("");
}
}
void MUCController::setNick(const std::string& nick) {
nick_ = nick;
highlighter_->setNick(nick_);
}
Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigurationForm) {
Form::ref result = std::make_shared<Form>(Form::SubmitType);
std::string impromptuConfigs[] = { "muc#roomconfig_enablelogging", "muc#roomconfig_persistentroom", "muc#roomconfig_publicroom", "muc#roomconfig_whois"};
std::set<std::string> impromptuConfigsMissing(impromptuConfigs, impromptuConfigs + 4);
- foreach (std::shared_ptr<FormField> field, roomConfigurationForm->getFields()) {
+ for (const auto& field : roomConfigurationForm->getFields()) {
std::shared_ptr<FormField> resultField;
if (field->getName() == "muc#roomconfig_enablelogging") {
resultField = std::make_shared<FormField>(FormField::BooleanType, "0");
}
if (field->getName() == "muc#roomconfig_persistentroom") {
resultField = std::make_shared<FormField>(FormField::BooleanType, "0");
}
if (field->getName() == "muc#roomconfig_publicroom") {
resultField = std::make_shared<FormField>(FormField::BooleanType, "0");
}
if (field->getName() == "muc#roomconfig_whois") {
resultField = std::make_shared<FormField>(FormField::ListSingleType, "anyone");
}
if (field->getName() == "FORM_TYPE") {
resultField = std::make_shared<FormField>(FormField::HiddenType, "http://jabber.org/protocol/muc#roomconfig");
}
if (resultField) {
impromptuConfigsMissing.erase(field->getName());
resultField->setName(field->getName());
result->addField(resultField);
}
}
- foreach (const std::string& config, impromptuConfigsMissing) {
+ for (const auto& config : impromptuConfigsMissing) {
if (config == "muc#roomconfig_publicroom") {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support hiding your chat from other users.")), ChatWindow::DefaultDirection);
} else if (config == "muc#roomconfig_whois") {
chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support sharing people's real identity in this chat.")), ChatWindow::DefaultDirection);
}
}
return result;
}
void MUCController::setImpromptuWindowTitle() {
std::string title;
- typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
std::map<std::string, MUCOccupant> occupants = muc_->getOccupants();
if (occupants.size() <= 1) {
title = QT_TRANSLATE_NOOP("", "Empty Chat");
} else {
- foreach (StringMUCOccupantPair pair, occupants) {
+ for (const auto& pair : occupants) {
if (pair.first != nick_) {
title += (title.empty() ? "" : ", ") + pair.first;
}
}
}
chatWindow_->setName(title);
}
void MUCController::handleRoomUnlocked() {
// Handle buggy MUC implementations where the joined room already exists and is unlocked.
// Configure the room again in this case.
if (!isImpromptuAlreadyConfigured_) {
if (isImpromptu_ && (muc_->getOccupant(nick_).getAffiliation() == MUCOccupant::Owner)) {
muc_->requestConfigurationForm();
} else if (isImpromptu_) {
onImpromptuConfigCompleted();
}
}
}
void MUCController::setAvailableServerFeatures(std::shared_ptr<DiscoInfo> info) {
ChatControllerBase::setAvailableServerFeatures(info);
if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::BlockingCommandFeature)) {
std::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&MUCController::handleBlockingStateChanged, this));
handleBlockingStateChanged();
diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
index 31c9be9..a5e68cf 100644
--- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp
@@ -62,61 +62,61 @@
#include <Swift/Controllers/UnitTest/MockChatWindow.h>
#include <Swift/Controllers/WhiteboardManager.h>
#include <Swift/Controllers/XMPPEvents/EventController.h>
using namespace Swift;
class ChatsManagerTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ChatsManagerTest);
CPPUNIT_TEST(testFirstOpenWindowIncoming);
CPPUNIT_TEST(testSecondOpenWindowIncoming);
CPPUNIT_TEST(testFirstOpenWindowOutgoing);
CPPUNIT_TEST(testFirstOpenWindowBareToFull);
CPPUNIT_TEST(testSecondWindow);
CPPUNIT_TEST(testUnbindRebind);
CPPUNIT_TEST(testNoDuplicateUnbind);
CPPUNIT_TEST(testThreeMUCWindows);
CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnRemoveFromRoster);
CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnAddToRoster);
CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth);
CPPUNIT_TEST(testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom);
CPPUNIT_TEST(testChatControllerFullJIDBindingOnMessageAndNotReceipt);
CPPUNIT_TEST(testChatControllerFullJIDBindingOnTypingAndNotActive);
CPPUNIT_TEST(testChatControllerPMPresenceHandling);
CPPUNIT_TEST(testLocalMUCServiceDiscoveryResetOnDisconnect);
CPPUNIT_TEST(testPresenceChangeDoesNotReplaceMUCInvite);
// Highlighting tests
CPPUNIT_TEST(testChatControllerHighlightingNotificationTesting);
CPPUNIT_TEST(testChatControllerHighlightingNotificationDeduplicateSounds);
CPPUNIT_TEST(testChatControllerMeMessageHandling);
- CPPUNIT_TEST(testRestartingMUCComponentCrash);
+ CPPUNIT_TEST(testRestartingMUCComponentCrash);
CPPUNIT_TEST(testChatControllerMeMessageHandlingInMUC);
// Carbons tests
CPPUNIT_TEST(testCarbonsForwardedIncomingMessageToSecondResource);
CPPUNIT_TEST(testCarbonsForwardedOutgoingMessageFromSecondResource);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
mocks_ = new MockRepository();
jid_ = JID("test@test.com/resource");
stanzaChannel_ = new DummyStanzaChannel();
iqRouter_ = new IQRouter(stanzaChannel_);
eventController_ = new EventController();
chatWindowFactory_ = mocks_->InterfaceMock<ChatWindowFactory>();
joinMUCWindowFactory_ = mocks_->InterfaceMock<JoinMUCWindowFactory>();
xmppRoster_ = new XMPPRosterImpl();
mucRegistry_ = new MUCRegistry();
nickResolver_ = new NickResolver(jid_.toBare(), xmppRoster_, nullptr, mucRegistry_);
presenceOracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
serverDiscoInfo_ = std::make_shared<DiscoInfo>();
presenceSender_ = new StanzaChannelPresenceSender(stanzaChannel_);
directedPresenceSender_ = new DirectedPresenceSender(presenceSender_);
mucManager_ = new MUCManager(stanzaChannel_, iqRouter_, directedPresenceSender_, mucRegistry_);
uiEventStream_ = new UIEventStream();
entityCapsProvider_ = new DummyEntityCapsProvider();
chatListWindowFactory_ = mocks_->InterfaceMock<ChatListWindowFactory>();
mucSearchWindowFactory_ = mocks_->InterfaceMock<MUCSearchWindowFactory>();
settings_ = new DummySettingsProvider();
@@ -428,103 +428,103 @@ public:
/**
* Test that ChatController sends receipts if requested after change from subscription state To to subscription state Both.
*/
void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToBoth() {
testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::Both);
}
/**
* Test that ChatController sends receipts if requested after change from subscription state To to subscription state From.
*/
void testChatControllerPresenceAccessUpdatedOnSubscriptionChangeToFrom() {
testhelperChatControllerPresenceAccessUpdatedOnSubscriptionChangeReceiptsAllowed(RosterItemPayload::To, RosterItemPayload::From);
}
void testChatControllerFullJIDBindingOnMessageAndNotReceipt() {
JID ownJID("test@test.com/resource");
JID sender("foo@test.com");
std::vector<JID> senderResource;
senderResource.push_back(sender.withResource("resourceA"));
senderResource.push_back(sender.withResource("resourceB"));
// We support delivery receipts.
settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
// Open chat window to a sender.
MockChatWindow* window = new MockChatWindow();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
uiEventStream_->send(std::make_shared<RequestChatUIEvent>(sender));
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
// The sender supports delivery receipts.
DiscoInfo::ref disco = std::make_shared<DiscoInfo>();
disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
entityCapsProvider_->caps[senderJID] = disco;
// The sender is online.
Presence::ref senderPresence = std::make_shared<Presence>();
senderPresence->setFrom(senderJID);
senderPresence->setTo(ownJID);
stanzaChannel_->onPresenceReceived(senderPresence);
entityCapsProvider_->onCapsChanged(senderJID);
}
// Send first message.
window->onSendMessageRequest("hello there", false);
// A bare message is send because no resources is bound.
CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
// Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
Message::ref receiptReply = std::make_shared<Message>();
receiptReply->setFrom(senderJID);
receiptReply->setTo(ownJID);
std::shared_ptr<DeliveryReceipt> receipt = std::make_shared<DeliveryReceipt>();
receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
receiptReply->addPayload(receipt);
manager_->handleIncomingMessage(receiptReply);
}
// Send second message.
window->onSendMessageRequest("how are you?", false);
// A bare message is send because no resources is bound.
CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
// Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
Message::ref receiptReply = std::make_shared<Message>();
receiptReply->setFrom(senderJID);
receiptReply->setTo(ownJID);
std::shared_ptr<DeliveryReceipt> receipt = std::make_shared<DeliveryReceipt>();
receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
receiptReply->addPayload(receipt);
manager_->handleIncomingMessage(receiptReply);
}
// Reply with a message including a body text.
Message::ref reply = std::make_shared<Message>();
reply->setFrom(senderResource[0]);
reply->setTo(ownJID);
reply->setBody("fine.");
manager_->handleIncomingMessage(reply);
// Send third message.
window->onSendMessageRequest("great to hear.", false);
// The chat session is bound to the full JID of the first resource.
CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(2)->getPayload<DeliveryReceiptRequest>());
// Receive random receipt from second sender resource.
reply = std::make_shared<Message>();
reply->setFrom(senderResource[1]);
reply->setTo(ownJID);
std::shared_ptr<DeliveryReceipt> receipt = std::make_shared<DeliveryReceipt>();
@@ -543,103 +543,103 @@ public:
reply = std::make_shared<Message>();
reply->setFrom(senderResource[1]);
reply->setTo(ownJID);
reply->setBody("nothing.");
manager_->handleIncomingMessage(reply);
// Send fifth message.
window->onSendMessageRequest("okay", false);
// The chat session is now bound to the full JID of the second resource.
CPPUNIT_ASSERT_EQUAL(senderResource[1], stanzaChannel_->getStanzaAtIndex<Message>(5)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(5)->getPayload<DeliveryReceiptRequest>());
}
void testChatControllerFullJIDBindingOnTypingAndNotActive() {
JID ownJID("test@test.com/resource");
JID sender("foo@test.com");
std::vector<JID> senderResource;
senderResource.push_back(sender.withResource("resourceA"));
senderResource.push_back(sender.withResource("resourceB"));
// We support delivery receipts.
settings_->storeSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS, true);
// Open chat window to a sender.
MockChatWindow* window = new MockChatWindow();
mocks_->ExpectCall(chatWindowFactory_, ChatWindowFactory::createChatWindow).With(sender, uiEventStream_).Return(window);
uiEventStream_->send(std::make_shared<RequestChatUIEvent>(sender));
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
// The sender supports delivery receipts.
DiscoInfo::ref disco = std::make_shared<DiscoInfo>();
disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature);
entityCapsProvider_->caps[senderJID] = disco;
// The sender is online.
Presence::ref senderPresence = std::make_shared<Presence>();
senderPresence->setFrom(senderJID);
senderPresence->setTo(ownJID);
stanzaChannel_->onPresenceReceived(senderPresence);
entityCapsProvider_->onCapsChanged(senderJID);
}
// Send first message.
window->onSendMessageRequest("hello there", false);
// A bare message is send because no resources is bound.
CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
// Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
Message::ref reply = std::make_shared<Message>();
reply->setFrom(senderJID);
reply->setTo(ownJID);
std::shared_ptr<ChatState> csn = std::make_shared<ChatState>();
csn->setChatState(ChatState::Active);
reply->addPayload(csn);
manager_->handleIncomingMessage(reply);
}
// Send second message.
window->onSendMessageRequest("how are you?", false);
// A bare message is send because no resources is bound.
CPPUNIT_ASSERT_EQUAL(sender, stanzaChannel_->getStanzaAtIndex<Message>(1)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>());
// Two resources respond with message receipts.
- foreach(const JID& senderJID, senderResource) {
+ for (const auto& senderJID : senderResource) {
Message::ref receiptReply = std::make_shared<Message>();
receiptReply->setFrom(senderJID);
receiptReply->setTo(ownJID);
std::shared_ptr<DeliveryReceipt> receipt = std::make_shared<DeliveryReceipt>();
receipt->setReceivedID(stanzaChannel_->getStanzaAtIndex<Message>(1)->getID());
receiptReply->addPayload(receipt);
manager_->handleIncomingMessage(receiptReply);
}
// Reply with a message including a CSN.
Message::ref reply = std::make_shared<Message>();
reply->setFrom(senderResource[0]);
reply->setTo(ownJID);
std::shared_ptr<ChatState> csn = std::make_shared<ChatState>();
csn->setChatState(ChatState::Composing);
reply->addPayload(csn);
manager_->handleIncomingMessage(reply);
// Send third message.
window->onSendMessageRequest("great to hear.", false);
// The chat session is now bound to the full JID of the first resource due to its recent composing message.
CPPUNIT_ASSERT_EQUAL(senderResource[0], stanzaChannel_->getStanzaAtIndex<Message>(3)->getTo());
CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(3)->getPayload<DeliveryReceiptRequest>());
// Reply with a message including a CSN from the other resource.
reply = std::make_shared<Message>();
reply->setFrom(senderResource[1]);
diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
index 1142c98..32639f6 100644
--- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
+++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp
@@ -1,44 +1,43 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <boost/algorithm/string.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <hippomocks.h>
#include <Swiften/Avatars/NullAvatarManager.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/ClientBlockListManager.h>
#include <Swiften/Client/DummyStanzaChannel.h>
#include <Swiften/Client/NickResolver.h>
#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/Crypto/PlatformCryptoProvider.h>
#include <Swiften/Disco/DummyEntityCapsProvider.h>
#include <Swiften/Elements/MUCUserPayload.h>
#include <Swiften/Elements/Thread.h>
#include <Swiften/MUC/MUCBookmarkManager.h>
#include <Swiften/MUC/UnitTest/MockMUC.h>
#include <Swiften/Network/TimerFactory.h>
#include <Swiften/Presence/DirectedPresenceSender.h>
#include <Swiften/Presence/PresenceOracle.h>
#include <Swiften/Presence/StanzaChannelPresenceSender.h>
#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Roster/XMPPRoster.h>
#include <Swiften/Roster/XMPPRosterImpl.h>
#include <Swiften/VCards/VCardManager.h>
#include <Swiften/VCards/VCardMemoryStorage.h>
#include <Swift/Controllers/Chat/ChatMessageParser.h>
#include <Swift/Controllers/Chat/MUCController.h>
#include <Swift/Controllers/Chat/UserSearchController.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
#include <Swift/Controllers/Roster/Roster.h>
#include <Swift/Controllers/Settings/DummySettingsProvider.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h>
#include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h>
@@ -344,77 +343,76 @@ public:
list.push_back(NickJoinPart("Ernie", Join));
CPPUNIT_ASSERT_EQUAL(std::string("Kev, Bert and Ernie have entered the room and Remko has left the room"), MUCController::generateJoinPartString(list, false));
}
void testJoinPartStringContructionMixed() {
std::vector<NickJoinPart> list;
list.push_back(NickJoinPart("Kev", JoinThenPart));
CPPUNIT_ASSERT_EQUAL(std::string("Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
list.push_back(NickJoinPart("Remko", Part));
CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room and Kev has entered then left the room"), MUCController::generateJoinPartString(list, false));
list.push_back(NickJoinPart("Bert", PartThenJoin));
CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev has entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
list.push_back(NickJoinPart("Ernie", JoinThenPart));
CPPUNIT_ASSERT_EQUAL(std::string("Remko has left the room, Kev and Ernie have entered then left the room and Bert has left then returned to the room"), MUCController::generateJoinPartString(list, false));
}
JID jidFromOccupant(const MUCOccupant& occupant) {
return JID(mucJID_.toString()+"/"+occupant.getNick());
}
void testRoleAffiliationStates() {
typedef std::map<std::string, MUCOccupant> occupant_map;
occupant_map occupants;
occupants.insert(occupant_map::value_type("Kev", MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Owner)));
occupants.insert(occupant_map::value_type("Remko", MUCOccupant("Remko", MUCOccupant::Participant, MUCOccupant::Owner)));
occupants.insert(occupant_map::value_type("Bert", MUCOccupant("Bert", MUCOccupant::Participant, MUCOccupant::Owner)));
occupants.insert(occupant_map::value_type("Ernie", MUCOccupant("Ernie", MUCOccupant::Participant, MUCOccupant::Owner)));
/* populate the MUC with fake users */
- typedef const std::pair<std::string,MUCOccupant> occupantIterator;
- foreach(occupantIterator &occupant, occupants) {
+ for (auto&& occupant : occupants) {
muc_->insertOccupant(occupant.second);
}
std::vector<MUCOccupant> alterations;
alterations.push_back(MUCOccupant("Kev", MUCOccupant::Visitor, MUCOccupant::Admin));
alterations.push_back(MUCOccupant("Remko", MUCOccupant::Moderator, MUCOccupant::Member));
alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::Outcast));
alterations.push_back(MUCOccupant("Ernie", MUCOccupant::NoRole, MUCOccupant::Member));
alterations.push_back(MUCOccupant("Bert", MUCOccupant::Moderator, MUCOccupant::Owner));
alterations.push_back(MUCOccupant("Kev", MUCOccupant::Participant, MUCOccupant::Outcast));
alterations.push_back(MUCOccupant("Bert", MUCOccupant::Visitor, MUCOccupant::NoAffiliation));
alterations.push_back(MUCOccupant("Remko", MUCOccupant::NoRole, MUCOccupant::NoAffiliation));
alterations.push_back(MUCOccupant("Ernie", MUCOccupant::Visitor, MUCOccupant::Outcast));
- foreach(const MUCOccupant& alteration, alterations) {
+ for (const auto& alteration : alterations) {
/* perform an alteration to a user's role and affiliation */
occupant_map::iterator occupant = occupants.find(alteration.getNick());
CPPUNIT_ASSERT(occupant != occupants.end());
const JID jid = jidFromOccupant(occupant->second);
/* change the affiliation, leave the role in place */
muc_->changeAffiliation(jid, alteration.getAffiliation());
occupant->second = MUCOccupant(occupant->first, occupant->second.getRole(), alteration.getAffiliation());
testRoleAffiliationStatesVerify(occupants);
/* change the role, leave the affiliation in place */
muc_->changeOccupantRole(jid, alteration.getRole());
occupant->second = MUCOccupant(occupant->first, alteration.getRole(), occupant->second.getAffiliation());
testRoleAffiliationStatesVerify(occupants);
}
}
void testSubjectChangeCorrect() {
std::string messageBody("test message");
window_->onSendMessageRequest(messageBody, false);
std::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
Message::ref message = std::dynamic_pointer_cast<Message>(rawStanza);
CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
CPPUNIT_ASSERT(message);
CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
{
Message::ref message = std::make_shared<Message>();
message->setType(Message::Groupchat);
message->setTo(self_);
message->setFrom(mucJID_.withResource("SomeNickname"));
message->setID(iqChannel_->getNewIQID());
@@ -479,64 +477,64 @@ public:
/*
* Test that message stanzas with subject element and empty body element do not cause a subject change.
*/
void testSubjectChangeIncorrectC() {
std::string messageBody("test message");
window_->onSendMessageRequest(messageBody, false);
std::shared_ptr<Stanza> rawStanza = stanzaChannel_->sentStanzas[stanzaChannel_->sentStanzas.size() - 1];
Message::ref message = std::dynamic_pointer_cast<Message>(rawStanza);
CPPUNIT_ASSERT(stanzaChannel_->isAvailable()); /* Otherwise will prevent sends. */
CPPUNIT_ASSERT(message);
CPPUNIT_ASSERT_EQUAL(messageBody, message->getBody().get_value_or(""));
{
Message::ref message = std::make_shared<Message>();
message->setType(Message::Groupchat);
message->setTo(self_);
message->setFrom(mucJID_.withResource("SomeNickname"));
message->setID(iqChannel_->getNewIQID());
message->setSubject("New Room Subject");
message->setBody("");
controller_->handleIncomingMessage(std::make_shared<MessageEvent>(message));
CPPUNIT_ASSERT_EQUAL(std::string("Trying to enter room teaparty@rooms.wonderland.lit"), std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(window_->lastAddedSystemMessage_.getParts()[0])->text);
}
}
void testRoleAffiliationStatesVerify(const std::map<std::string, MUCOccupant> &occupants) {
/* verify that the roster is in sync */
GroupRosterItem* group = window_->getRosterModel()->getRoot();
- foreach(RosterItem* rosterItem, group->getChildren()) {
+ for (auto rosterItem : group->getChildren()) {
GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(rosterItem);
CPPUNIT_ASSERT(child);
- foreach(RosterItem* childItem, child->getChildren()) {
+ for (auto childItem : child->getChildren()) {
ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(childItem);
CPPUNIT_ASSERT(item);
std::map<std::string, MUCOccupant>::const_iterator occupant = occupants.find(item->getJID().getResource());
CPPUNIT_ASSERT(occupant != occupants.end());
CPPUNIT_ASSERT(item->getMUCRole() == occupant->second.getRole());
CPPUNIT_ASSERT(item->getMUCAffiliation() == occupant->second.getAffiliation());
}
}
}
private:
JID self_;
JID mucJID_;
MockMUC::ref muc_;
std::string nick_;
DummyStanzaChannel* stanzaChannel_;
DummyIQChannel* iqChannel_;
IQRouter* iqRouter_;
EventController* eventController_;
ChatWindowFactory* chatWindowFactory_;
UserSearchWindowFactory* userSearchWindowFactory_;
MUCController* controller_;
// NickResolver* nickResolver_;
PresenceOracle* presenceOracle_;
AvatarManager* avatarManager_;
StanzaChannelPresenceSender* presenceSender_;
DirectedPresenceSender* directedPresenceSender_;
MockRepository* mocks_;
UIEventStream* uiEventStream_;
MockChatWindow* window_;
diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp
index 305049f..91e0dea 100644
--- a/Swift/Controllers/Chat/UserSearchController.cpp
+++ b/Swift/Controllers/Chat/UserSearchController.cpp
@@ -1,45 +1,44 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Chat/UserSearchController.h>
#include <memory>
#include <boost/bind.hpp>
#include <Swiften/Avatars/AvatarManager.h>
#include <Swiften/Base/String.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Disco/DiscoServiceWalker.h>
#include <Swiften/Disco/GetDiscoInfoRequest.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
#include <Swiften/Presence/PresenceOracle.h>
#include <Swiften/VCards/VCardManager.h>
#include <Swift/Controllers/ContactEditController.h>
#include <Swift/Controllers/ContactSuggester.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/ProfileSettingsProvider.h>
#include <Swift/Controllers/Roster/RosterController.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestInviteToMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
#include <Swift/Controllers/UIInterfaces/UserSearchWindowFactory.h>
namespace Swift {
static const std::string SEARCHED_DIRECTORIES = "searchedDirectories";
UserSearchController::UserSearchController(Type type, const JID& jid, UIEventStream* uiEventStream, VCardManager* vcardManager, UserSearchWindowFactory* factory, IQRouter* iqRouter, RosterController* rosterController, ContactSuggester* contactSuggester, AvatarManager* avatarManager, PresenceOracle* presenceOracle, ProfileSettingsProvider* settings) : type_(type), jid_(jid), uiEventStream_(uiEventStream), vcardManager_(vcardManager), factory_(factory), iqRouter_(iqRouter), rosterController_(rosterController), contactSuggester_(contactSuggester), avatarManager_(avatarManager), presenceOracle_(presenceOracle), settings_(settings) {
uiEventStream_->onUIEvent.connect(boost::bind(&UserSearchController::handleUIEvent, this, _1));
vcardManager_->onVCardChanged.connect(boost::bind(&UserSearchController::handleVCardChanged, this, _1, _2));
avatarManager_->onAvatarChanged.connect(boost::bind(&UserSearchController::handleAvatarChanged, this, _1));
presenceOracle_->onPresenceChange.connect(boost::bind(&UserSearchController::handlePresenceChanged, this, _1));
window_ = nullptr;
discoWalker_ = nullptr;
loadSavedDirectories();
@@ -116,201 +115,202 @@ void UserSearchController::handleUIEvent(std::shared_ptr<UIEvent> event) {
window_->setRoomJID(inviteToMUCRequest->getRoom());
}
return;
}
}
void UserSearchController::handleFormRequested(const JID& service) {
window_->setSearchError(false);
window_->setServerSupportsSearch(true);
//Abort a previous search if is active
endDiscoWalker();
delete discoWalker_;
discoWalker_ = new DiscoServiceWalker(service, iqRouter_);
discoWalker_->onServiceFound.connect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
discoWalker_->onWalkComplete.connect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
discoWalker_->beginWalk();
}
void UserSearchController::endDiscoWalker() {
if (discoWalker_) {
discoWalker_->endWalk();
discoWalker_->onServiceFound.disconnect(boost::bind(&UserSearchController::handleDiscoServiceFound, this, _1, _2));
discoWalker_->onWalkComplete.disconnect(boost::bind(&UserSearchController::handleDiscoWalkFinished, this));
}
}
void UserSearchController::handleDiscoServiceFound(const JID& jid, std::shared_ptr<DiscoInfo> info) {
//bool isUserDirectory = false;
bool supports55 = false;
- foreach (DiscoInfo::Identity identity, info->getIdentities()) {
+ // TODO: Cleanup code
+ for (const auto& identity : info->getIdentities()) {
if ((identity.getCategory() == "directory"
&& identity.getType() == "user")) {
//isUserDirectory = true;
}
}
std::vector<std::string> features = info->getFeatures();
supports55 = std::find(features.begin(), features.end(), DiscoInfo::JabberSearchFeature) != features.end();
if (/*isUserDirectory && */supports55) { //FIXME: once M-Link correctly advertises directoryness.
/* Abort further searches.*/
endDiscoWalker();
std::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Get, jid, std::make_shared<SearchPayload>(), iqRouter_));
searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleFormResponse, this, _1, _2));
searchRequest->send();
}
}
void UserSearchController::handleFormResponse(std::shared_ptr<SearchPayload> fields, ErrorPayload::ref error) {
if (error || !fields) {
window_->setServerSupportsSearch(false);
return;
}
window_->setSearchFields(fields);
}
void UserSearchController::handleSearch(std::shared_ptr<SearchPayload> fields, const JID& jid) {
addToSavedDirectories(jid);
std::shared_ptr<GenericRequest<SearchPayload> > searchRequest(new GenericRequest<SearchPayload>(IQ::Set, jid, fields, iqRouter_));
searchRequest->onResponse.connect(boost::bind(&UserSearchController::handleSearchResponse, this, _1, _2));
searchRequest->send();
}
void UserSearchController::handleSearchResponse(std::shared_ptr<SearchPayload> resultsPayload, ErrorPayload::ref error) {
if (error || !resultsPayload) {
window_->setSearchError(true);
return;
}
std::vector<UserSearchResult> results;
if (resultsPayload->getForm()) {
window_->setResultsForm(resultsPayload->getForm());
} else {
- foreach (SearchPayload::Item item, resultsPayload->getItems()) {
+ for (auto&& item : resultsPayload->getItems()) {
JID jid(item.jid);
std::map<std::string, std::string> fields;
fields["first"] = item.first;
fields["last"] = item.last;
fields["nick"] = item.nick;
fields["email"] = item.email;
UserSearchResult result(jid, fields);
results.push_back(result);
}
window_->setResults(results);
}
}
void UserSearchController::handleNameSuggestionRequest(const JID &jid) {
suggestionsJID_= jid;
VCard::ref vcard = vcardManager_->getVCardAndRequestWhenNeeded(jid);
if (vcard) {
handleVCardChanged(jid, vcard);
}
}
void UserSearchController::handleJIDEditingFinished(const JID& jid) {
if (jid.isValid()) {
if (rosterController_->getItem(jid)) {
window_->setWarning(QT_TRANSLATE_NOOP("", "This contact is already on your contact list."));
}
else if (jid.getNode().empty()) {
window_->setWarning(QT_TRANSLATE_NOOP("", "Part of the address you have entered is missing. An address has a structure of 'user@example.com'."));
}
else {
window_->setWarning(boost::optional<std::string>());
}
}
else {
window_->setWarning(QT_TRANSLATE_NOOP("", "The address you have entered is invalid."));
}
}
void UserSearchController::handleContactSuggestionsRequested(std::string text) {
const std::vector<JID> existingJIDs = window_->getJIDs();
std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text, false);
/* do not suggest contacts that have already been added to the chat list */
std::vector<Contact::ref>::iterator i = suggestions.begin();
while (i != suggestions.end()) {
bool found = false;
- foreach (const JID& jid, existingJIDs) {
+ for (const auto& jid : existingJIDs) {
if ((*i)->jid == jid) {
found = true;
break;
}
}
// remove contact suggestions which are already on the contact list in add-contact-mode
if (type_ == AddContact) {
if (!found && !!rosterController_->getItem((*i)->jid)) {
found = true;
}
}
if (found) {
i = suggestions.erase(i);
} else {
i++;
}
}
window_->setContactSuggestions(suggestions);
}
void UserSearchController::handleVCardChanged(const JID& jid, VCard::ref vcard) {
if (jid == suggestionsJID_) {
window_->setNameSuggestions(ContactEditController::nameSuggestionsFromVCard(vcard));
suggestionsJID_ = JID();
}
handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handleAvatarChanged(const JID& jid) {
handleJIDUpdateRequested(std::vector<JID>(1, jid));
}
void UserSearchController::handlePresenceChanged(Presence::ref presence) {
handleJIDUpdateRequested(std::vector<JID>(1, presence->getFrom().toBare()));
}
void UserSearchController::handleJIDUpdateRequested(const std::vector<JID>& jids) {
if (window_) {
std::vector<Contact::ref> updates;
- foreach(const JID& jid, jids) {
+ for (const auto& jid : jids) {
updates.push_back(convertJIDtoContact(jid));
}
window_->updateContacts(updates);
}
}
void UserSearchController::handleJIDAddRequested(const std::vector<JID>& jids) {
std::vector<Contact::ref> contacts;
- foreach(const JID& jid, jids) {
+ for (const auto& jid : jids) {
contacts.push_back(convertJIDtoContact(jid));
}
window_->addContacts(contacts);
}
Contact::ref UserSearchController::convertJIDtoContact(const JID& jid) {
Contact::ref contact = std::make_shared<Contact>();
contact->jid = jid;
// name lookup
boost::optional<XMPPRosterItem> rosterItem = rosterController_->getItem(jid);
if (rosterItem && !rosterItem->getName().empty()) {
contact->name = rosterItem->getName();
} else {
VCard::ref vcard = vcardManager_->getVCard(jid);
if (vcard && !vcard->getFullName().empty()) {
contact->name = vcard->getFullName();
} else {
contact->name = jid.toString();
}
}
// presence lookup
Presence::ref presence = presenceOracle_->getAccountPresence(jid);
if (presence) {
contact->statusType = presence->getShow();
} else {
contact->statusType = StatusShow::None;
}
@@ -331,62 +331,62 @@ void UserSearchController::initializeUserWindow() {
case AddContact:
windowType = UserSearchWindow::AddContact;
break;
case StartChat:
windowType = UserSearchWindow::ChatToContact;
break;
case InviteToChat:
windowType = UserSearchWindow::InviteToChat;
break;
}
window_ = factory_->createUserSearchWindow(windowType, uiEventStream_, rosterController_->getGroups());
if (!window_) {
// UI Doesn't support user search
return;
}
window_->onNameSuggestionRequested.connect(boost::bind(&UserSearchController::handleNameSuggestionRequest, this, _1));
window_->onFormRequested.connect(boost::bind(&UserSearchController::handleFormRequested, this, _1));
window_->onSearchRequested.connect(boost::bind(&UserSearchController::handleSearch, this, _1, _2));
window_->onContactSuggestionsRequested.connect(boost::bind(&UserSearchController::handleContactSuggestionsRequested, this, _1));
window_->onJIDUpdateRequested.connect(boost::bind(&UserSearchController::handleJIDUpdateRequested, this, _1));
window_->onJIDAddRequested.connect(boost::bind(&UserSearchController::handleJIDAddRequested, this, _1));
window_->onJIDEditFieldChanged.connect(boost::bind(&UserSearchController::handleJIDEditingFinished, this, _1));
window_->setSelectedService(JID(jid_.getDomain()));
window_->clear();
}
}
void UserSearchController::loadSavedDirectories() {
savedDirectories_.clear();
- foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
+ for (auto&& stringItem : String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) {
if(!stringItem.empty()) {
savedDirectories_.push_back(JID(stringItem));
}
}
}
void UserSearchController::addToSavedDirectories(const JID& jid) {
if (!jid.isValid()) {
return;
}
savedDirectories_.erase(std::remove(savedDirectories_.begin(), savedDirectories_.end(), jid), savedDirectories_.end());
savedDirectories_.insert(savedDirectories_.begin(), jid);
std::string collapsed;
int i = 0;
- foreach (JID jidItem, savedDirectories_) {
+ for (const auto& jidItem : savedDirectories_) {
if (i >= 15) {
break;
}
if (!collapsed.empty()) {
collapsed += "\n";
}
collapsed += jidItem.toString();
++i;
}
settings_->storeString(SEARCHED_DIRECTORIES, collapsed);
window_->addSavedServices(savedDirectories_);
}
}
diff --git a/Swift/Controllers/ChatMessageSummarizer.cpp b/Swift/Controllers/ChatMessageSummarizer.cpp
index 6b630e7..ac3d896 100644
--- a/Swift/Controllers/ChatMessageSummarizer.cpp
+++ b/Swift/Controllers/ChatMessageSummarizer.cpp
@@ -1,46 +1,45 @@
/*
* Copyright (c) 2011-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/ChatMessageSummarizer.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Base/format.h>
#include <Swift/Controllers/Intl.h>
using namespace Swift;
using namespace std;
string ChatMessageSummarizer::getSummary(const string& current, const vector<UnreadPair>& unreads) {
vector<UnreadPair> others;
int currentUnread = 0;
int otherCount = 0;
- foreach (UnreadPair unread, unreads) {
+ for (const auto& unread : unreads) {
if (unread.first == current) {
currentUnread += unread.second;
} else {
if (unread.second > 0) {
otherCount += unread.second;
others.push_back(unread);
}
}
}
string myString(current);
if (currentUnread > 0) {
string result(QT_TRANSLATE_NOOP("", "%1% (%2%)"));
myString = str(format(result) % current % currentUnread);
}
if (others.size() > 1) {
string result(QT_TRANSLATE_NOOP("", "%1% and %2% others (%3%)"));
myString = str(format(result) % myString % others.size() % otherCount);
} else if (!others.empty()) {
string result(QT_TRANSLATE_NOOP("", "%1%; %2% (%3%)"));
myString = str(format(result) % myString % others[0].first % otherCount);
}
return myString;
}
diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp
index 8a3a6fa..eb27ed4 100644
--- a/Swift/Controllers/ContactSuggester.cpp
+++ b/Swift/Controllers/ContactSuggester.cpp
@@ -1,87 +1,86 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/ContactSuggester.h>
#include <algorithm>
#include <set>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/find.hpp>
#include <boost/bind.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <Swiften/Base/Algorithm.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/JID/JID.h>
#include <Swift/Controllers/ContactProvider.h>
namespace lambda = boost::lambda;
namespace Swift {
ContactSuggester::ContactSuggester() {
}
ContactSuggester::~ContactSuggester() {
}
void ContactSuggester::addContactProvider(ContactProvider* provider) {
contactProviders_.push_back(provider);
}
bool ContactSuggester::matchContact(const std::string& search, const Contact::ref& c) {
if (fuzzyMatch(c->name, search)) {
return true;
}
else if (c->jid.isValid()) {
return fuzzyMatch(c->jid.toString(), search);
}
return false;
}
std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search, bool withMUCNicks) const {
std::vector<Contact::ref> results;
- foreach(ContactProvider* provider, contactProviders_) {
+ for (auto provider : contactProviders_) {
append(results, provider->getContacts(withMUCNicks));
}
std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate);
results.erase(std::unique(results.begin(), results.end(), Contact::equalityPredicate), results.end());
results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&matchContact, search, lambda::_1)),
results.end());
std::sort(results.begin(), results.end(), boost::bind(&Contact::sortPredicate, _1, _2, search));
return results;
}
bool ContactSuggester::fuzzyMatch(std::string text, std::string match) {
std::string lowerText = text;
boost::algorithm::to_lower(lowerText);
std::string lowerMatch = match;
boost::algorithm::to_lower(lowerMatch);
size_t lastMatch = 0;
for (char i : lowerMatch) {
size_t where = lowerText.find_first_of(i, lastMatch);
if (where == std::string::npos) {
return false;
}
lastMatch = where + 1;
}
return true;
}
}
diff --git a/Swift/Controllers/ContactsFromXMPPRoster.cpp b/Swift/Controllers/ContactsFromXMPPRoster.cpp
index e3c5d97..1d1ccd4 100644
--- a/Swift/Controllers/ContactsFromXMPPRoster.cpp
+++ b/Swift/Controllers/ContactsFromXMPPRoster.cpp
@@ -1,41 +1,40 @@
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/ContactsFromXMPPRoster.h>
#include <Swiften/Avatars/AvatarManager.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Presence/PresenceOracle.h>
#include <Swiften/Roster/XMPPRoster.h>
#include <Swiften/Roster/XMPPRosterItem.h>
namespace Swift {
ContactsFromXMPPRoster::ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle) : roster_(roster), avatarManager_(avatarManager), presenceOracle_(presenceOracle) {
}
ContactsFromXMPPRoster::~ContactsFromXMPPRoster() {
}
std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts(bool /*withMUCNicks*/) {
std::vector<Contact::ref> results;
std::vector<XMPPRosterItem> rosterItems = roster_->getItems();
- foreach(const XMPPRosterItem& rosterItem, rosterItems) {
+ for (const auto& rosterItem : rosterItems) {
Contact::ref contact = std::make_shared<Contact>(rosterItem.getName().empty() ? rosterItem.getJID().toString() : rosterItem.getName(), rosterItem.getJID(), StatusShow::None,"");
contact->statusType = presenceOracle_->getAccountPresence(contact->jid) ? presenceOracle_->getAccountPresence(contact->jid)->getShow() : StatusShow::None;
contact->avatarPath = avatarManager_->getAvatarPath(contact->jid);
results.push_back(contact);
}
return results;
}
}
diff --git a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
index af2831c..fcc35e4 100644
--- a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
@@ -1,92 +1,91 @@
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2015-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/FileTransfer/FileTransferOverview.h>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <boost/signals2.hpp>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/FileTransfer/FileTransferManager.h>
namespace Swift {
FileTransferOverview::FileTransferOverview(FileTransferManager* ftm) : fileTransferManager(ftm) {
fileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
onNewFileTransferController.connect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
}
FileTransferOverview::~FileTransferOverview() {
onNewFileTransferController.disconnect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
fileTransferManager->onIncomingFileTransfer.disconnect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
- foreach(FileTransferController* controller, fileTransfers) {
+ for (auto controller : fileTransfers) {
controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
}
}
void FileTransferOverview::sendFile(const JID& jid, const std::string& filename) {
if (boost::filesystem::exists(filename) && boost::filesystem::file_size(filename) > 0) {
FileTransferController* controller = new FileTransferController(jid, filename, fileTransferManager);
onNewFileTransferController(controller);
}
}
void FileTransferOverview::handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
FileTransferController* controller = new FileTransferController(transfer);
onNewFileTransferController(controller);
}
void FileTransferOverview::handleNewFileTransferController(FileTransferController* controller) {
fileTransfers.push_back(controller);
controller->onStateChanged.connect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
}
void FileTransferOverview::handleFileTransferStateChanged() {
onFileTransferListChanged();
}
const std::vector<FileTransferController*>& FileTransferOverview::getFileTransfers() const {
return fileTransfers;
}
void FileTransferOverview::clearFinished() {
for (std::vector<FileTransferController*>::iterator it = fileTransfers.begin(); it != fileTransfers.end(); ) {
if((*it)->getState().type == FileTransfer::State::Finished
|| (*it)->getState().type == FileTransfer::State::Failed
|| (*it)->getState().type == FileTransfer::State::Canceled) {
FileTransferController* controller = *it;
it = fileTransfers.erase(it);
controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
delete controller;
} else {
++it;
}
}
onFileTransferListChanged();
}
bool FileTransferOverview::isClearable() const {
bool isClearable = false;
- foreach (FileTransferController* controller, fileTransfers) {
+ for (auto controller : fileTransfers) {
if(controller->getState().type == FileTransfer::State::Finished
|| controller->getState().type == FileTransfer::State::Failed
|| controller->getState().type == FileTransfer::State::Canceled) {
isClearable = true;
break;
}
}
return isClearable;
}
}
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp
index 2afaf49..9176301 100644
--- a/Swift/Controllers/HighlightManager.cpp
+++ b/Swift/Controllers/HighlightManager.cpp
@@ -1,57 +1,55 @@
/*
* Copyright (c) 2012 Maciej Niedzielski
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/HighlightManager.h>
#include <cassert>
#include <sstream>
#include <boost/algorithm/string.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/bind.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/regex.hpp>
#include <boost/serialization/vector.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/Controllers/Highlighter.h>
#include <Swift/Controllers/SettingConstants.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
/* How does highlighting work?
*
* HighlightManager manages a list of if-then rules used to highlight messages.
* Rule is represented by HighlightRule. Action ("then" part) is HighlightAction.
*
*
* HighlightManager is also used as a factory for Highlighter objects.
* Each ChatControllerBase has its own Highlighter.
* Highligher may be customized by using setNick(), etc.
*
* ChatControllerBase passes incoming messages to Highlighter and gets HighlightAction in return
* (first matching rule is returned).
* If needed, HighlightAction is then passed back to Highlighter for further handling.
* This results in HighlightManager emiting onHighlight event,
* which is handled by SoundController to play sound notification
*/
namespace Swift {
HighlightManager::HighlightManager(SettingsProvider* settings)
: settings_(settings)
, storingSettings_(false) {
rules_ = std::make_shared<HighlightRulesList>();
loadSettings();
handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1));
}
diff --git a/Swift/Controllers/HighlightRule.cpp b/Swift/Controllers/HighlightRule.cpp
index 86ac5f7..a8cb7e4 100644
--- a/Swift/Controllers/HighlightRule.cpp
+++ b/Swift/Controllers/HighlightRule.cpp
@@ -1,121 +1,120 @@
/*
* Copyright (c) 2012 Maciej Niedzielski
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
- * Copyright (c) 2014-2015 Isode Limited.
+ * Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/HighlightRule.h>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <boost/lambda/lambda.hpp>
#include <Swiften/Base/Regex.h>
-#include <Swiften/Base/foreach.h>
namespace Swift {
HighlightRule::HighlightRule()
: nickIsKeyword_(false)
, matchCase_(false)
, matchWholeWords_(false)
, matchChat_(false)
, matchMUC_(false)
{
}
boost::regex HighlightRule::regexFromString(const std::string & s) const
{
std::string escaped = Regex::escape(s);
std::string word = matchWholeWords_ ? "\\b" : "";
boost::regex::flag_type flags = boost::regex::normal;
if (!matchCase_) {
flags |= boost::regex::icase;
}
return boost::regex(word + escaped + word, flags);
}
void HighlightRule::updateRegex() const
{
keywordRegex_.clear();
- foreach (const std::string & k, keywords_) {
+ for (const auto& k : keywords_) {
keywordRegex_.push_back(regexFromString(k));
}
senderRegex_.clear();
- foreach (const std::string & s, senders_) {
+ for (const auto& s : senders_) {
senderRegex_.push_back(regexFromString(s));
}
}
std::string HighlightRule::boolToString(bool b)
{
return b ? "1" : "0";
}
bool HighlightRule::boolFromString(const std::string& s)
{
return s == "1";
}
bool HighlightRule::isMatch(const std::string& body, const std::string& sender, const std::string& nick, MessageType messageType) const
{
if ((messageType == HighlightRule::ChatMessage && matchChat_) || (messageType == HighlightRule::MUCMessage && matchMUC_)) {
bool matchesKeyword = keywords_.empty() && (nick.empty() || !nickIsKeyword_);
bool matchesSender = senders_.empty();
if (!matchesKeyword) {
// check if the nickname matches
if (nickIsKeyword_ && !nick.empty() && boost::regex_search(body, regexFromString(nick))) {
matchesKeyword = true;
}
// check if a keyword matches
if (!matchesKeyword && !keywords_.empty()) {
- foreach (const boost::regex &keyword, keywordRegex_) {
+ for (const auto& keyword : keywordRegex_) {
if (boost::regex_search(body, keyword)) {
matchesKeyword = true;
break;
}
}
}
}
- foreach (const boost::regex & rx, senderRegex_) {
+ for (const auto& rx : senderRegex_) {
if (boost::regex_search(sender, rx)) {
matchesSender = true;
break;
}
}
if (matchesKeyword && matchesSender) {
return true;
}
}
return false;
}
void HighlightRule::setSenders(const std::vector<std::string>& senders)
{
senders_ = senders;
updateRegex();
}
void HighlightRule::setKeywords(const std::vector<std::string>& keywords)
{
keywords_ = keywords;
updateRegex();
}
std::vector<boost::regex> HighlightRule::getKeywordRegex(const std::string& nick) const {
if (nickIsKeyword_) {
std::vector<boost::regex> regex;
if (!nick.empty()) {
diff --git a/Swift/Controllers/Highlighter.cpp b/Swift/Controllers/Highlighter.cpp
index 3499217..cea077e 100644
--- a/Swift/Controllers/Highlighter.cpp
+++ b/Swift/Controllers/Highlighter.cpp
@@ -1,46 +1,44 @@
/*
* Copyright (c) 2012 Maciej Niedzielski
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Highlighter.h>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/Controllers/HighlightManager.h>
namespace Swift {
Highlighter::Highlighter(HighlightManager* manager)
: manager_(manager)
{
setMode(ChatMode);
}
void Highlighter::setMode(Mode mode)
{
mode_ = mode;
messageType_ = mode_ == ChatMode ? HighlightRule::ChatMessage : HighlightRule::MUCMessage;
}
HighlightAction Highlighter::findFirstFullMessageMatchAction(const std::string& body, const std::string& sender) const
{
HighlightAction match;
HighlightRulesListPtr rules = manager_->getRules();
for (size_t i = 0; i < rules->getSize(); ++i) {
const HighlightRule& rule = rules->getRule(i);
if (rule.isMatch(body, sender, nick_, messageType_) && rule.getAction().highlightWholeMessage()) {
match = rule.getAction();
break;
}
}
return match;
}
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index d66b2b2..669b002 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -1,47 +1,48 @@
/*
* Copyright (c) 2012 Catalin Badea
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2013-2016 Isode Limited.
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/HistoryViewController.h>
+#include <boost/range/adaptor/reversed.hpp>
+
#include <Swiften/Avatars/AvatarManager.h>
#include <Swiften/Base/Path.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/NickResolver.h>
#include <Swiften/History/HistoryMessage.h>
#include <Swift/Controllers/HistoryController.h>
#include <Swift/Controllers/Roster/ItemOperations/SetAvatar.h>
#include <Swift/Controllers/Roster/ItemOperations/SetPresence.h>
#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
#include <Swift/Controllers/UIInterfaces/HistoryWindowFactory.h>
namespace Swift {
static const std::string category[] = { "Contacts", "MUC", "Contacts" };
HistoryViewController::HistoryViewController(
const JID& selfJID,
UIEventStream* uiEventStream,
HistoryController* historyController,
NickResolver* nickResolver,
AvatarManager* avatarManager,
PresenceOracle* presenceOracle,
HistoryWindowFactory* historyWindowFactory) :
selfJID_(selfJID),
uiEventStream_(uiEventStream),
historyController_(historyController),
nickResolver_(nickResolver),
avatarManager_(avatarManager),
presenceOracle_(presenceOracle),
historyWindowFactory_(historyWindowFactory),
historyWindow_(nullptr),
selectedItem_(nullptr),
currentResultDate_(boost::gregorian::not_a_date_time) {
@@ -97,61 +98,61 @@ void HistoryViewController::handleUIEvent(std::shared_ptr<UIEvent> rawEvent) {
}
}
void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) {
// FIXME: signal is triggerd twice.
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(newContact);
if (contact && selectedItem_ != contact) {
selectedItem_ = contact;
historyWindow_->resetConversationView();
}
else {
return;
}
JID contactJID = contact->getJID();
std::vector<HistoryMessage> messages;
for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
if (contacts_[type].count(contactJID)) {
currentResultDate_ = *contacts_[type][contactJID].rbegin();
selectedItemType_ = type;
messages = historyController_->getMessagesFromDate(selfJID_, contactJID, type, currentResultDate_);
}
}
historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, false);
}
}
void HistoryViewController::handleNewMessage(const HistoryMessage& message) {
JID contactJID = message.getFromJID().toBare() == selfJID_ ? message.getToJID() : message.getFromJID();
JID displayJID;
if (message.getType() == HistoryMessage::PrivateMessage) {
displayJID = contactJID;
}
else {
displayJID = contactJID.toBare();
}
// check current conversation
if (selectedItem_ && selectedItem_->getJID() == displayJID) {
if (historyWindow_->getLastVisibleDate() == message.getTime().date()) {
addNewMessage(message, false);
}
}
// check if the new message matches the query
if (message.getMessage().find(historyWindow_->getSearchBoxText()) == std::string::npos) {
return;
}
// update contacts
if (!contacts_[message.getType()].count(displayJID)) {
roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), category[message.getType()], avatarManager_->getAvatarPath(displayJID));
@@ -176,184 +177,184 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) {
contacts_[type] = historyController_->getContacts(selfJID_, type, keyword);
for (ContactsMap::const_iterator contact = contacts_[type].begin(); contact != contacts_[type].end(); contact++) {
const JID& jid = contact->first;
std::string nick;
if (type == HistoryMessage::PrivateMessage) {
nick = jid.toString();
}
else {
nick = nickResolver_->jidToNick(jid);
}
roster_->addContact(jid, jid, nick, category[type], avatarManager_->getAvatarPath(jid));
Presence::ref presence = getPresence(jid, type == HistoryMessage::Groupchat);
if (presence.get()) {
roster_->applyOnItem(SetPresence(presence, JID::WithoutResource), jid);
}
}
}
}
void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date& date) {
if (!selectedItem_) {
return;
}
std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, true);
}
historyWindow_->resetConversationViewTopInsertPoint();
}
void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::date& date) {
if (!selectedItem_) {
return;
}
std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, false);
}
}
void HistoryViewController::handleNextButtonClicked() {
if (!selectedItem_) {
return;
}
std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
if (*date == *contacts_[selectedItemType_][selectedItem_->getJID()].rbegin()) {
return;
}
historyWindow_->resetConversationView();
currentResultDate_ = *(++date);
std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, false);
}
}
void HistoryViewController::handlePreviousButtonClicked() {
if (!selectedItem_) {
return;
}
std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
if (date == contacts_[selectedItemType_][selectedItem_->getJID()].begin()) {
return;
}
historyWindow_->resetConversationView();
currentResultDate_ = *(--date);
std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, false);
}
}
void HistoryViewController::reset() {
roster_->removeAll();
contacts_.clear();
selectedItem_ = nullptr;
historyWindow_->resetConversationView();
}
void HistoryViewController::handleCalendarClicked(const boost::gregorian::date& date) {
if (!selectedItem_) {
return;
}
boost::gregorian::date newDate;
if (contacts_[selectedItemType_][selectedItem_->getJID()].count(date)) {
newDate = date;
}
else if (date < currentResultDate_) {
- foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
+ for (const auto& current : contacts_[selectedItemType_][selectedItem_->getJID()]) {
if (current > date) {
newDate = current;
break;
}
}
}
else {
- reverse_foreach(const boost::gregorian::date& current, contacts_[selectedItemType_][selectedItem_->getJID()]) {
+ for (const auto& current : boost::adaptors::reverse(contacts_[selectedItemType_][selectedItem_->getJID()])) {
if (current < date) {
newDate = current;
break;
}
}
}
historyWindow_->setDate(newDate);
if (newDate == currentResultDate_) {
return;
}
currentResultDate_ = newDate;
historyWindow_->resetConversationView();
std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
historyWindow_->setDate(currentResultDate_);
- foreach (const HistoryMessage& message, messages) {
+ for (const auto& message : messages) {
addNewMessage(message, false);
}
}
void HistoryViewController::handlePresenceChanged(Presence::ref presence) {
JID jid = presence->getFrom();
if (contacts_[HistoryMessage::Chat].count(jid.toBare())) {
roster_->applyOnItems(SetPresence(presence, JID::WithoutResource));
return;
}
if (contacts_[HistoryMessage::Groupchat].count(jid.toBare())) {
Presence::ref availablePresence = std::make_shared<Presence>(Presence());
availablePresence->setFrom(jid.toBare());
roster_->applyOnItems(SetPresence(availablePresence, JID::WithResource));
}
if (contacts_[HistoryMessage::PrivateMessage].count(jid)) {
roster_->applyOnItems(SetPresence(presence, JID::WithResource));
}
}
void HistoryViewController::handleAvatarChanged(const JID& jid) {
roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid)));
}
Presence::ref HistoryViewController::getPresence(const JID& jid, bool isMUC) {
if (jid.isBare() && !isMUC) {
return presenceOracle_->getHighestPriorityPresence(jid);
}
std::vector<Presence::ref> mucPresence = presenceOracle_->getAllPresence(jid.toBare());
if (isMUC && !mucPresence.empty()) {
Presence::ref presence = std::make_shared<Presence>(Presence());
presence->setFrom(jid);
return presence;
}
- foreach (Presence::ref presence, mucPresence) {
+ for (auto&& presence : mucPresence) {
if (presence.get() && presence->getFrom() == jid) {
return presence;
}
}
return Presence::create();
}
}
diff --git a/Swift/Controllers/PreviousStatusStore.cpp b/Swift/Controllers/PreviousStatusStore.cpp
index 4806f9c..0b2d437 100644
--- a/Swift/Controllers/PreviousStatusStore.cpp
+++ b/Swift/Controllers/PreviousStatusStore.cpp
@@ -1,53 +1,51 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/PreviousStatusStore.h>
-#include <Swiften/Base/foreach.h>
-
namespace Swift {
PreviousStatusStore::PreviousStatusStore() {
}
PreviousStatusStore::~PreviousStatusStore() {
}
void PreviousStatusStore::addStatus(StatusShow::Type status, const std::string& message) {
//FIXME: remove old entries
store_.push_back(TypeStringPair(status, message));
}
std::vector<TypeStringPair> PreviousStatusStore::exactMatchSuggestions(StatusShow::Type status, const std::string& message) {
std::vector<TypeStringPair> suggestions;
suggestions.push_back(TypeStringPair(status, message));
return suggestions;
}
std::vector<TypeStringPair> PreviousStatusStore::getSuggestions(const std::string& message) {
std::vector<TypeStringPair> suggestions;
- foreach (TypeStringPair status, store_) {
+ for (auto&& status : store_) {
if (status.second == message) {
suggestions.clear();
suggestions.push_back(status);
break;
} else if (status.second.find(message) != std::string::npos) {
suggestions.push_back(status);
}
}
if (suggestions.empty()) {
TypeStringPair suggestion(StatusShow::Online, message);
suggestions.push_back(suggestion);
}
if (suggestions.size() == 1) {
suggestions = exactMatchSuggestions(suggestions[0].first, suggestions[0].second);
}
return suggestions;
}
}
diff --git a/Swift/Controllers/PreviousStatusStore.h b/Swift/Controllers/PreviousStatusStore.h
index eb1fb59..b106445 100644
--- a/Swift/Controllers/PreviousStatusStore.h
+++ b/Swift/Controllers/PreviousStatusStore.h
@@ -1,28 +1,29 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <string>
#include <utility> /* std::pair */
#include <vector>
#include <Swiften/Elements/StatusShow.h>
namespace Swift {
typedef std::pair<StatusShow::Type, std::string> TypeStringPair;
+
class PreviousStatusStore {
public:
PreviousStatusStore();
~PreviousStatusStore();
void addStatus(StatusShow::Type status, const std::string& message);
std::vector<TypeStringPair> getSuggestions(const std::string& message);
private:
std::vector<TypeStringPair> exactMatchSuggestions(StatusShow::Type status, const std::string& message);
std::vector<TypeStringPair> store_;
};
}
diff --git a/Swift/Controllers/ProfileSettingsProvider.cpp b/Swift/Controllers/ProfileSettingsProvider.cpp
index bb186fc..b979555 100644
--- a/Swift/Controllers/ProfileSettingsProvider.cpp
+++ b/Swift/Controllers/ProfileSettingsProvider.cpp
@@ -1,45 +1,47 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/ProfileSettingsProvider.h>
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+
namespace Swift {
ProfileSettingsProvider::ProfileSettingsProvider(const std::string& profile, SettingsProvider* provider) :
profile_(profile) {
provider_ = provider;
bool found = false;
- foreach (std::string existingProfile, provider->getAvailableProfiles()) {
+ for (const auto& 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);
diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h
index f3c3156..e309c11 100644
--- a/Swift/Controllers/ProfileSettingsProvider.h
+++ b/Swift/Controllers/ProfileSettingsProvider.h
@@ -1,34 +1,36 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
-#include <Swiften/Base/foreach.h>
-
-#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <string>
namespace Swift {
+class SettingsProvider;
+
class ProfileSettingsProvider {
public:
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 \ref SettingsProvider::getIsSettingFinal for discussion of what this means.*/
virtual bool getIsSettingFinal(const std::string& settingPath);
private:
std::string profileSettingPath(const std::string &settingPath);
+
+ private:
SettingsProvider* provider_;
std::string profile_;
};
}
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp
index 71c5f8e..8fdf183 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.cpp
+++ b/Swift/Controllers/Roster/ContactRosterItem.cpp
@@ -1,42 +1,41 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Roster/ContactRosterItem.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <Swiften/Base/DateTime.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/Idle.h>
#include <Swiften/Elements/Presence.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
namespace Swift {
ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, const std::string& name, GroupRosterItem* parent)
: RosterItem(name, parent), jid_(jid), displayJID_(displayJID.toBare()), mucRole_(MUCOccupant::NoRole), mucAffiliation_(MUCOccupant::NoAffiliation), blockState_(BlockingNotSupported)
{
}
ContactRosterItem::~ContactRosterItem() {
}
StatusShow::Type ContactRosterItem::getStatusShow() const {
return presence_ ? presence_->getShow() : StatusShow::None;
}
StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
switch (presence_ ? presence_->getShow() : StatusShow::None) {
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;
}
diff --git a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
index af89b54..0f07c0b 100644
--- a/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
+++ b/Swift/Controllers/Roster/RosterGroupExpandinessPersister.cpp
@@ -1,65 +1,64 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Roster/RosterGroupExpandinessPersister.h>
#include <vector>
#include <boost/bind.hpp>
#include <Swiften/Base/String.h>
-#include <Swiften/Base/foreach.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) {
if (collapsed_.find(group->getDisplayName()) != collapsed_.end()) {
group->setExpanded(false);
} else {
group->setExpanded(true);
}
group->onExpandedChanged.connect(boost::bind(&RosterGroupExpandinessPersister::handleExpandedChanged, this, group, _1));
}
void RosterGroupExpandinessPersister::handleExpandedChanged(GroupRosterItem* group, bool expanded) {
if (expanded) {
std::string displayName = group->getDisplayName();
//collapsed_.erase(std::remove(collapsed_.begin(), collapsed_.end(), displayName), collapsed_.end());
collapsed_.erase(displayName);
} else {
collapsed_.insert(group->getDisplayName());
}
save();
}
void RosterGroupExpandinessPersister::save() {
std::string setting;
- foreach (const std::string& group, collapsed_) {
+ for (const auto& group : collapsed_) {
if (!setting.empty()) {
setting += "\n";
}
setting += group;
}
settings_->storeSetting(SettingConstants::EXPANDED_ROSTER_GROUPS, setting);
}
void RosterGroupExpandinessPersister::load() {
std::string saved = settings_->getSetting(SettingConstants::EXPANDED_ROSTER_GROUPS);
std::vector<std::string> collapsed = String::split(saved, '\n');
collapsed_.insert(collapsed.begin(), collapsed.end());
}
}
diff --git a/Swift/Controllers/Roster/TableRoster.cpp b/Swift/Controllers/Roster/TableRoster.cpp
index f164a4d..713f390 100644
--- a/Swift/Controllers/Roster/TableRoster.cpp
+++ b/Swift/Controllers/Roster/TableRoster.cpp
@@ -1,45 +1,44 @@
/*
* Copyright (c) 2011-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Roster/TableRoster.h>
#include <algorithm>
#include <cassert>
#include <boost/cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Network/Timer.h>
#include <Swiften/Network/TimerFactory.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
#include <Swift/Controllers/Roster/LeastCommonSubsequence.h>
#include <Swift/Controllers/Roster/Roster.h>
namespace Swift {
struct SectionNameEquals {
bool operator()(const TableRoster::Section& s1, const TableRoster::Section& s2) const {
return s1.name == s2.name;
}
};
template<typename T>
struct True {
bool operator()(const T&, const T&) const {
return true;
}
};
struct ItemEquals {
bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
return i1.jid == i2.jid;
}
};
struct ItemNeedsUpdate {
bool operator()(const TableRoster::Item& i1, const TableRoster::Item& i2) const {
@@ -77,65 +76,65 @@ TableRoster::~TableRoster() {
if (model) {
model->onDataChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
model->onGroupAdded.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
model->onChildrenChanged.disconnect(boost::bind(&TableRoster::scheduleUpdate, this));
}
}
size_t TableRoster::getNumberOfSections() const {
return sections.size();
}
const std::string& TableRoster::getSectionTitle(size_t section) {
return sections[section].name;
}
size_t TableRoster::getNumberOfRowsInSection(size_t section) const {
return sections[section].items.size();
}
const TableRoster::Item& TableRoster::getItem(const Index& index) const {
return sections[index.section].items[index.row];
}
void TableRoster::handleUpdateTimerTick() {
updateTimer->stop();
updatePending = false;
// Get a model for the new roster
std::vector<Section> newSections;
if (model) {
- foreach(RosterItem* item, model->getRoot()->getDisplayedChildren()) {
+ for (auto item : model->getRoot()->getDisplayedChildren()) {
if (GroupRosterItem* groupItem = boost::polymorphic_downcast<GroupRosterItem*>(item)) {
//std::cerr << "* " << groupItem->getDisplayName() << std::endl;
Section section(groupItem->getDisplayName());
- foreach(RosterItem* groupChildItem, groupItem->getDisplayedChildren()) {
+ for (auto groupChildItem : groupItem->getDisplayedChildren()) {
if (ContactRosterItem* contact = boost::polymorphic_downcast<ContactRosterItem*>(groupChildItem)) {
//std::cerr << " - " << contact->getDisplayJID() << std::endl;
section.items.push_back(Item(contact->getDisplayName(), contact->getStatusText(), contact->getDisplayJID(), contact->getStatusShow(), contact->getAvatarPath()));
}
}
newSections.push_back(section);
}
}
}
// Do a diff with the previous roster
Update update;
std::vector<size_t> sectionUpdates;
std::vector<size_t> sectionPostUpdates;
computeIndexDiff<Section,SectionNameEquals,True<Section> >(sections, newSections, sectionUpdates, sectionPostUpdates, update.deletedSections, update.insertedSections);
assert(sectionUpdates.size() == sectionPostUpdates.size());
for (size_t i = 0; i < sectionUpdates.size(); ++i) {
assert(sectionUpdates[i] < sections.size());
assert(sectionPostUpdates[i] < newSections.size());
std::vector<size_t> itemUpdates;
std::vector<size_t> itemPostUpdates;
std::vector<size_t> itemRemoves;
std::vector<size_t> itemInserts;
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() + 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() + boost::numeric_cast<long long>(end), CreateIndexForSection(sectionUpdates[i]));
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
index 5156d14..a05fabc 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
@@ -1,116 +1,116 @@
/*
- * Copyright (c) 2012 Isode Limited.
+ * Copyright (c) 2012-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Base/Log.h>
+
namespace Swift {
SettingsProviderHierachy::~SettingsProviderHierachy() {
}
bool SettingsProviderHierachy::hasSetting(const std::string& key) {
- foreach (SettingsProvider* provider, providers_) {
+ for (auto provider : providers_) {
if (provider->hasSetting(key)) {
return true;
}
}
return false;
}
std::string SettingsProviderHierachy::getSetting(const Setting<std::string>& setting) {
std::string value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
+ for (auto provider : providers_) {
std::string providerSetting = provider->getSetting(setting);
if (provider->hasSetting(setting.getKey())) {
value = providerSetting;
}
if (provider->getIsSettingFinal(setting.getKey())) {
return value;
}
}
return value;
}
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) {
bool value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
+ for (auto provider : providers_) {
bool providerSetting = provider->getSetting(setting);
if (provider->hasSetting(setting.getKey())) {
value = providerSetting;
if (provider->getIsSettingFinal(setting.getKey())) {
return providerSetting;
}
}
}
return value;
}
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) {
int value = setting.getDefaultValue();
- foreach (SettingsProvider* provider, providers_) {
+ for (auto provider : providers_) {
int providerSetting = provider->getSetting(setting);
if (provider->hasSetting(setting.getKey())) {
value = providerSetting;
if (provider->getIsSettingFinal(setting.getKey())) {
return providerSetting;
}
}
}
return value;
}
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_) {
+ for (auto 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/ShowProfileController.cpp b/Swift/Controllers/ShowProfileController.cpp
index add6e73..b379141 100644
--- a/Swift/Controllers/ShowProfileController.cpp
+++ b/Swift/Controllers/ShowProfileController.cpp
@@ -1,64 +1,62 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/ShowProfileController.h>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/VCards/VCardManager.h>
#include <Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h>
#include <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swift/Controllers/UIInterfaces/ProfileWindowFactory.h>
namespace Swift {
ShowProfileController::ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream) : vcardManager(vcardManager), profileWindowFactory(profileWindowFactory), uiEventStream(uiEventStream) {
uiEventStream->onUIEvent.connect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
vcardManager->onVCardChanged.connect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
}
ShowProfileController::~ShowProfileController() {
- typedef std::pair<JID, ProfileWindow*> JIDProfileWindowPair;
- foreach(const JIDProfileWindowPair& jidWndPair, openedProfileWindows) {
+ for (const auto& jidWndPair : openedProfileWindows) {
jidWndPair.second->onWindowAboutToBeClosed.disconnect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
delete jidWndPair.second;
}
vcardManager->onVCardChanged.disconnect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2));
uiEventStream->onUIEvent.disconnect(boost::bind(&ShowProfileController::handleUIEvent, this, _1));
}
void ShowProfileController::handleUIEvent(UIEvent::ref event) {
ShowProfileForRosterItemUIEvent::ref showProfileEvent = std::dynamic_pointer_cast<ShowProfileForRosterItemUIEvent>(event);
if (!showProfileEvent) {
return;
}
if (openedProfileWindows.find(showProfileEvent->getJID()) == openedProfileWindows.end()) {
ProfileWindow* newProfileWindow = profileWindowFactory->createProfileWindow();
newProfileWindow->setJID(showProfileEvent->getJID());
newProfileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1));
openedProfileWindows[showProfileEvent->getJID()] = newProfileWindow;
VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(showProfileEvent->getJID(), boost::posix_time::minutes(5));
if (vcard) {
newProfileWindow->setVCard(vcard);
} else {
newProfileWindow->setProcessing(true);
}
newProfileWindow->show();
} else {
openedProfileWindows[showProfileEvent->getJID()]->show();
}
}
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp
index cded945..a103920 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.cpp
+++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp
@@ -1,45 +1,44 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Storages/AvatarFileStorage.h>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <Swiften/Base/String.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/StringCodecs/Hexify.h>
namespace Swift {
AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto) : avatarsDir(avatarsDir), avatarsFile(avatarsFile), crypto(crypto) {
if (boost::filesystem::exists(avatarsFile)) {
try {
boost::filesystem::ifstream file(avatarsFile);
std::string line;
if (file.is_open()) {
while (!file.eof()) {
getline(file, line);
std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
JID jid(r.second);
if (jid.isValid()) {
jidAvatars.insert(std::make_pair(jid, r.first));
}
else if (!r.first.empty() || !r.second.empty()) {
std::cerr << "Invalid entry in avatars file: " << r.second << std::endl;
}
}
}
}
catch (...) {
std::cerr << "Error reading avatars file" << std::endl;
}
}
}
diff --git a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
index 08c6ee7..545ca65 100644
--- a/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
+++ b/Swift/Controllers/Storages/CertificateMemoryStorage.cpp
@@ -1,27 +1,25 @@
/*
- * Copyright (c) 2011 Isode Limited.
+ * Copyright (c) 2011-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Storages/CertificateMemoryStorage.h>
-#include <Swiften/Base/foreach.h>
-
using namespace Swift;
CertificateMemoryStorage::CertificateMemoryStorage() {
}
bool CertificateMemoryStorage::hasCertificate(Certificate::ref certificate) const {
- foreach(Certificate::ref storedCert, certificates) {
+ for (auto&& storedCert : certificates) {
if (storedCert->toDER() == certificate->toDER()) {
return true;
}
}
return false;
}
void CertificateMemoryStorage::addCertificate(Certificate::ref certificate) {
certificates.push_back(certificate);
}
diff --git a/Swift/Controllers/Storages/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp
index dbb6799..2fdadf6 100644
--- a/Swift/Controllers/Storages/VCardFileStorage.cpp
+++ b/Swift/Controllers/Storages/VCardFileStorage.cpp
@@ -1,46 +1,45 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/Storages/VCardFileStorage.h>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <Swiften/Base/Path.h>
#include <Swiften/Base/String.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/Elements/VCard.h>
#include <Swiften/Entity/GenericPayloadPersister.h>
#include <Swiften/JID/JID.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h>
#include <Swiften/Parser/PayloadParsers/VCardParser.h>
#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h>
#include <Swiften/StringCodecs/Hexify.h>
using namespace Swift;
typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister;
VCardFileStorage::VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto) : VCardStorage(crypto), vcardsPath(dir), crypto(crypto) {
cacheFile = vcardsPath / "phashes";
if (boost::filesystem::exists(cacheFile)) {
try {
boost::filesystem::ifstream file(cacheFile);
std::string line;
if (file.is_open()) {
while (!file.eof()) {
getline(file, line);
std::pair<std::string, std::string> r = String::getSplittedAtFirst(line, ' ');
JID jid(r.second);
if (jid.isValid()) {
photoHashes.insert(std::make_pair(jid, r.first));
}
else if (!r.first.empty() || !r.second.empty()) {
std::cerr << "Invalid entry in phashes file" << std::endl;
}
diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h
index c84d130..dde596e 100644
--- a/Swift/Controllers/UIInterfaces/ChatListWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h
@@ -1,93 +1,91 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <list>
#include <map>
#include <memory>
#include <set>
#include <boost/filesystem/path.hpp>
#include <boost/signals2.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/StatusShow.h>
#include <Swiften/MUC/MUCBookmark.h>
namespace Swift {
class ChatListWindow {
public:
class Chat {
public:
Chat() : statusType(StatusShow::None), isMUC(false), unreadCount(0), isPrivateMessage(false) {}
Chat(const JID& jid, const std::string& chatName, const std::string& activity, int unreadCount, StatusShow::Type statusType, const boost::filesystem::path& avatarPath, bool isMUC, bool isPrivateMessage = false, const std::string& nick = "", const boost::optional<std::string> password = boost::optional<std::string>())
: jid(jid), chatName(chatName), activity(activity), statusType(statusType), isMUC(isMUC), nick(nick), password(password), unreadCount(unreadCount), avatarPath(avatarPath), isPrivateMessage(isPrivateMessage) {}
/** Assume that nicks and other transient features aren't important for equality */
bool operator==(const Chat& other) const {
if (impromptuJIDs.empty()) {
return jid.toBare() == other.jid.toBare()
&& isMUC == other.isMUC;
- } else { /* compare the chat occupant lists */
- typedef std::map<std::string, JID> JIDMap;
- foreach (const JIDMap::value_type& jid, impromptuJIDs) {
+ }
+ else { /* compare the chat occupant lists */
+ for (const auto& jid : impromptuJIDs) {
bool found = false;
- foreach (const JIDMap::value_type& otherJID, other.impromptuJIDs) {
+ for (const auto& otherJID : other.impromptuJIDs) {
if (jid.second.toBare() == otherJID.second.toBare()) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
}
void setUnreadCount(int unread) {
unreadCount = unread;
}
void setStatusType(StatusShow::Type type) {
statusType = type;
}
void setAvatarPath(const boost::filesystem::path& path) {
avatarPath = path;
}
std::string getImpromptuTitle() const {
- typedef std::pair<std::string, JID> StringJIDPair;
std::string title;
- foreach(StringJIDPair pair, impromptuJIDs) {
+ for (auto& pair : impromptuJIDs) {
if (title.empty()) {
title += pair.first;
} else {
title += ", " + pair.first;
}
}
return title;
}
JID jid;
std::string chatName;
std::string activity;
StatusShow::Type statusType;
bool isMUC;
std::string nick;
boost::optional<std::string> password;
int unreadCount;
boost::filesystem::path avatarPath;
std::map<std::string, JID> impromptuJIDs;
bool isPrivateMessage;
};
virtual ~ChatListWindow();
virtual void setBookmarksEnabled(bool enabled) = 0;
virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0;
virtual void addWhiteboardSession(const ChatListWindow::Chat& chat) = 0;
virtual void removeWhiteboardSession(const JID& jid) = 0;
virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
virtual void setRecents(const std::list<Chat>& recents) = 0;
virtual void setUnreadCount(int unread) = 0;
virtual void clearBookmarks() = 0;
diff --git a/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp b/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
index 217a2f0..6ac51b2 100644
--- a/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
+++ b/Swift/Controllers/UnitTest/ContactSuggesterTest.cpp
@@ -1,130 +1,128 @@
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <memory>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/Controllers/ContactSuggester.h>
using namespace Swift;
class ContactSuggesterTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ContactSuggesterTest);
CPPUNIT_TEST(equalityTest);
CPPUNIT_TEST(lexicographicalSortTest);
CPPUNIT_TEST(sortTest);
CPPUNIT_TEST_SUITE_END();
public:
std::vector<std::string> wordList() {
const std::string words[] = {
"abc",
"ab",
"bc",
"d"
};
return std::vector<std::string>(words, words+sizeof(words)/sizeof(*words));
}
std::vector<StatusShow::Type> statusList() {
StatusShow::Type types[] = {
StatusShow::Online,
StatusShow::Away,
StatusShow::FFC,
StatusShow::XA,
StatusShow::DND,
StatusShow::None
};
return std::vector<StatusShow::Type>(types, types+sizeof(types)/sizeof(*types));
}
std::vector<Contact::ref> contactList() {
std::vector<Contact::ref> contacts;
std::vector<std::string> words = wordList();
std::vector<StatusShow::Type> statuses = statusList();
- foreach (const std::string& name, words) {
- foreach (const std::string& jid, words) {
- foreach (const StatusShow::Type& status, statuses) {
+ for (const auto& name : words) {
+ for (const auto& jid : words) {
+ for (const auto& status : statuses) {
contacts.push_back(std::make_shared<Contact>(name, jid, status, ""));
}
}
}
return contacts;
}
/* a = a */
bool isReflexive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
+ for (const auto& a : contacts) {
if (!comparitor(a, a)) {
return false;
}
}
return true;
}
/* a = b -> b = a */
bool isSymmetric(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
- foreach (const Contact::ref& b, contacts) {
+ for (const auto& a : contacts) {
+ for (const auto& b : contacts) {
if (comparitor(a, b)) {
if (!comparitor(b, a)) {
return false;
}
}
}
}
return true;
}
/* a = b && b = c -> a = c */
bool isTransitive(const boost::function<bool (const Contact::ref&, const Contact::ref&)>& comparitor) {
std::vector<Contact::ref> contacts = contactList();
- foreach (const Contact::ref& a, contacts) {
- foreach (const Contact::ref& b, contacts) {
- foreach (const Contact::ref& c, contacts) {
+ for (const auto& a : contacts) {
+ for (const auto& b : contacts) {
+ for (const auto& c : contacts) {
if (comparitor(a, b) && comparitor(b, c)) {
if (!comparitor(a, c)) {
return false;
}
}
}
}
}
return true;
}
void equalityTest() {
CPPUNIT_ASSERT(isReflexive(Contact::equalityPredicate));
CPPUNIT_ASSERT(isSymmetric(Contact::equalityPredicate));
CPPUNIT_ASSERT(isTransitive(Contact::equalityPredicate));
}
void lexicographicalSortTest() {
CPPUNIT_ASSERT(isTransitive(Contact::lexicographicalSortPredicate));
}
void sortTest() {
std::vector<std::string> words = wordList();
- foreach (const std::string& word, words) {
+ for (const auto& word : words) {
CPPUNIT_ASSERT(isTransitive(boost::bind(Contact::sortPredicate, _1, _2, word)));
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(ContactSuggesterTest);
diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp
index fab5380..37fe8e3 100644
--- a/Swift/Controllers/WhiteboardManager.cpp
+++ b/Swift/Controllers/WhiteboardManager.cpp
@@ -1,69 +1,66 @@
/*
* Copyright (c) 2012 Mateusz Piękos
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/WhiteboardManager.h>
#include <boost/bind.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Client/NickResolver.h>
#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Whiteboard/WhiteboardSessionManager.h>
#include <Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h>
#include <Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h>
#include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h>
namespace Swift {
- typedef std::pair<JID, WhiteboardWindow*> JIDWhiteboardWindowPair;
-
WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, NickResolver* nickResolver, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), nickResolver_(nickResolver), whiteboardSessionManager_(whiteboardSessionManager) {
#ifdef SWIFT_EXPERIMENTAL_WB
whiteboardSessionManager_->onSessionRequest.connect(boost::bind(&WhiteboardManager::handleIncomingSession, this, _1));
#endif
uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1));
}
WhiteboardManager::~WhiteboardManager() {
- foreach (JIDWhiteboardWindowPair whiteboardWindowPair, whiteboardWindows_) {
+ for (auto&& whiteboardWindowPair : whiteboardWindows_) {
delete whiteboardWindowPair.second;
}
}
WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact, WhiteboardSession::ref session) {
WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session);
window->setName(nickResolver_->jidToNick(contact));
whiteboardWindows_[contact.toBare()] = window;
return window;
}
WhiteboardWindow* WhiteboardManager::findWhiteboardWindow(const JID& contact) {
if (whiteboardWindows_.find(contact.toBare()) == whiteboardWindows_.end()) {
return nullptr;
}
return whiteboardWindows_[contact.toBare()];
}
void WhiteboardManager::handleUIEvent(std::shared_ptr<UIEvent> event) {
std::shared_ptr<RequestWhiteboardUIEvent> requestWhiteboardEvent = std::dynamic_pointer_cast<RequestWhiteboardUIEvent>(event);
if (requestWhiteboardEvent) {
requestSession(requestWhiteboardEvent->getContact());
}
std::shared_ptr<AcceptWhiteboardSessionUIEvent> sessionAcceptEvent = std::dynamic_pointer_cast<AcceptWhiteboardSessionUIEvent>(event);
if (sessionAcceptEvent) {
acceptSession(sessionAcceptEvent->getContact());
}
std::shared_ptr<CancelWhiteboardSessionUIEvent> sessionCancelEvent = std::dynamic_pointer_cast<CancelWhiteboardSessionUIEvent>(event);
if (sessionCancelEvent) {
cancelSession(sessionCancelEvent->getContact());
diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp
index f0debb9..f8fb192 100644
--- a/Swift/Controllers/XMPPEvents/EventController.cpp
+++ b/Swift/Controllers/XMPPEvents/EventController.cpp
@@ -1,73 +1,71 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swift/Controllers/XMPPEvents/EventController.h>
#include <algorithm>
#include <boost/bind.hpp>
#include <boost/numeric/conversion/cast.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Swift/Controllers/XMPPEvents/ErrorEvent.h>
#include <Swift/Controllers/XMPPEvents/IncomingFileTransferEvent.h>
#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h>
#include <Swift/Controllers/XMPPEvents/MessageEvent.h>
#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h>
namespace Swift {
EventController::EventController() {
}
EventController::~EventController() {
- foreach(std::shared_ptr<StanzaEvent> event, events_) {
+ for (auto&& event : events_) {
event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
}
}
void EventController::handleIncomingEvent(std::shared_ptr<StanzaEvent> sourceEvent) {
std::shared_ptr<MessageEvent> messageEvent = std::dynamic_pointer_cast<MessageEvent>(sourceEvent);
std::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent);
std::shared_ptr<ErrorEvent> errorEvent = std::dynamic_pointer_cast<ErrorEvent>(sourceEvent);
std::shared_ptr<MUCInviteEvent> mucInviteEvent = std::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent);
std::shared_ptr<IncomingFileTransferEvent> incomingFileTransferEvent = std::dynamic_pointer_cast<IncomingFileTransferEvent>(sourceEvent);
/* If it's a duplicate subscription request, remove the previous request first */
if (subscriptionEvent) {
EventList existingEvents(events_);
- foreach(std::shared_ptr<StanzaEvent> existingEvent, existingEvents) {
+ for (auto&& existingEvent : existingEvents) {
std::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = std::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent);
if (existingSubscriptionEvent) {
if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) {
existingEvent->conclude();
}
}
}
}
if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent || incomingFileTransferEvent) {
events_.push_back(sourceEvent);
sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent));
onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
onEventQueueEventAdded(sourceEvent);
if (sourceEvent->getConcluded()) {
handleEventConcluded(sourceEvent);
}
}
}
void EventController::handleEventConcluded(std::shared_ptr<StanzaEvent> event) {
event->onConclusion.disconnect(boost::bind(&EventController::handleEventConcluded, this, event));
events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end());
onEventQueueLengthChange(boost::numeric_cast<int>(events_.size()));
}
void EventController::disconnectAll() {
onEventQueueLengthChange.disconnect_all_slots();
onEventQueueEventAdded.disconnect_all_slots();
}