summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-03-20 00:05:55 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-03-20 19:13:43 (GMT)
commit3d6694b0c698fff63d11f8bb4aa995c1df882315 (patch)
treea46ccace647f23a65100cf69c951345aa6dea7ab /Swiften/MUC/MUCBookmarkManager.cpp
parent3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (diff)
downloadswift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.zip
swift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.tar.bz2
boost::shared_ptr<?>(new ?(...)) -> boost::make_shared<?>(...) transformation where possible.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/MUC/MUCBookmarkManager.cpp')
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index 643a8c4..8a63745 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -1,44 +1,45 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "MUCBookmarkManager.h"
#include <boost/bind.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <iostream>
#include <Swiften/Base/foreach.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Queries/Requests/GetPrivateStorageRequest.h>
#include <Swiften/Queries/Requests/SetPrivateStorageRequest.h>
namespace Swift {
MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) {
iqRouter_ = iqRouter;
ready_ = false;
GetPrivateStorageRequest<Storage>::ref request = GetPrivateStorageRequest<Storage>::create(iqRouter_);
request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksReceived, this, _1, _2));
request->send();
}
void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payload, ErrorPayload::ref error) {
if (error) {
return;
}
ready_ = true;
onBookmarksReady();
storage = payload;
std::vector<MUCBookmark> receivedBookmarks;
foreach (Storage::Room room, payload->getRooms()) {
receivedBookmarks.push_back(MUCBookmark(room));
}
std::vector<MUCBookmark> newBookmarks;
foreach (const MUCBookmark& oldBookmark, bookmarks_) {
@@ -66,55 +67,55 @@ void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const M
if (!ready_) return;
for (size_t i = 0; i < bookmarks_.size(); i++) {
if (bookmarks_[i] == oldBookmark) {
bookmarks_[i] = newBookmark;
flush();
onBookmarkRemoved(oldBookmark);
onBookmarkAdded(newBookmark);
return;
}
}
}
void MUCBookmarkManager::addBookmark(const MUCBookmark& bookmark) {
if (!ready_) return;
bookmarks_.push_back(bookmark);
onBookmarkAdded(bookmark);
flush();
}
void MUCBookmarkManager::removeBookmark(const MUCBookmark& bookmark) {
if (!ready_) return;
std::vector<MUCBookmark>::iterator it;
for (it = bookmarks_.begin(); it != bookmarks_.end(); ++it) {
if ((*it) == bookmark) {
bookmarks_.erase(it);
onBookmarkRemoved(bookmark);
break;
}
}
flush();
}
void MUCBookmarkManager::flush() {
if (!storage) {
- storage = boost::shared_ptr<Storage>(new Storage());
+ storage = boost::make_shared<Storage>();
}
// Update the storage element
storage->clearRooms();
foreach(const MUCBookmark& bookmark, bookmarks_) {
storage->addRoom(bookmark.toStorage());
}
// Send an iq to save the storage element
SetPrivateStorageRequest<Storage>::ref request = SetPrivateStorageRequest<Storage>::create(storage, iqRouter_);
// FIXME: We should care about the result
//request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksSet, this, _1, _2));
request->send();
}
const std::vector<MUCBookmark>& MUCBookmarkManager::getBookmarks() const {
return bookmarks_;
}
}