summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-05-07 18:45:47 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-05-07 18:45:47 (GMT)
commit203ca1c122db89c4a9f9f01bff2cadb3b9daca04 (patch)
treee57d7f5997aad1832146d2806418b184e1dfe6bb /Swiften
parent61620db053088fac637799b27f04efa44d0bcc6b (diff)
downloadswift-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.zip
swift-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.tar.bz2
Cleaned up MUC code.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/MUC/MUCBookmark.h3
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp41
-rw-r--r--Swiften/MUC/MUCBookmarkManager.h24
3 files changed, 36 insertions, 32 deletions
diff --git a/Swiften/MUC/MUCBookmark.h b/Swiften/MUC/MUCBookmark.h
index 2b31f90..7afbe76 100644
--- a/Swiften/MUC/MUCBookmark.h
+++ b/Swiften/MUC/MUCBookmark.h
@@ -23,7 +23,8 @@ namespace Swift {
const boost::optional<String>& getPassword() const {return password_;};
const String& getName() const {return name_;};
const JID& getRoom() const {return room_;};
- bool operator==(const MUCBookmark& rhs) {return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ && rhs.password_ == password_ && rhs.autojoin_ == autojoin_;};
+
+ bool operator==(const MUCBookmark& rhs) const {return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ && rhs.password_ == password_ && rhs.autojoin_ == autojoin_;};
private:
JID room_;
String name_;
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index f503754..400eb2b 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -25,22 +25,22 @@ void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payl
if (error) {
return;
}
- std::vector<boost::shared_ptr<MUCBookmark> > receivedBookmarks;
+ std::vector<MUCBookmark> receivedBookmarks;
foreach (Storage::Conference conference, payload->getConferences()) {
String name = (!conference.name.isEmpty()) ? conference.name : conference.jid.getNode();
- boost::shared_ptr<MUCBookmark> bookmark(new MUCBookmark(conference.jid, name));
- bookmark->setAutojoin(conference.autoJoin);
+ MUCBookmark bookmark(conference.jid, name);
+ bookmark.setAutojoin(conference.autoJoin);
if (!conference.nick.isEmpty()) {
- bookmark->setNick(conference.nick);
+ bookmark.setNick(conference.nick);
}
if (!conference.password.isEmpty()) {
- bookmark->setPassword(conference.password);
+ bookmark.setPassword(conference.password);
}
receivedBookmarks.push_back(bookmark);
}
- std::vector<boost::shared_ptr<MUCBookmark> > newBookmarks;
- foreach (boost::shared_ptr<MUCBookmark> oldBookmark, bookmarks_) {
+ std::vector<MUCBookmark> newBookmarks;
+ foreach (const MUCBookmark& oldBookmark, bookmarks_) {
if (containsEquivalent(receivedBookmarks, oldBookmark)) {
newBookmarks.push_back(oldBookmark);
} else {
@@ -48,7 +48,7 @@ void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payl
}
}
- foreach (boost::shared_ptr<MUCBookmark> newBookmark, receivedBookmarks) {
+ foreach (const MUCBookmark& newBookmark, receivedBookmarks) {
if (!containsEquivalent(bookmarks_, newBookmark)) {
newBookmarks.push_back(newBookmark);
onBookmarkAdded(newBookmark);
@@ -57,19 +57,13 @@ void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payl
bookmarks_ = newBookmarks;
}
-bool MUCBookmarkManager::containsEquivalent(std::vector<boost::shared_ptr<MUCBookmark> > list, boost::shared_ptr<MUCBookmark> bookmark) {
- foreach (boost::shared_ptr<MUCBookmark> listBookmark, list) {
- if (*listBookmark == *bookmark) {
- return true;
- }
- }
- return false;
+bool MUCBookmarkManager::containsEquivalent(const std::vector<MUCBookmark>& list, const MUCBookmark& bookmark) {
+ return std::find(list.begin(), list.end(), bookmark) != list.end();
}
-void MUCBookmarkManager::replaceBookmark(boost::shared_ptr<MUCBookmark> oldBookmark, boost::shared_ptr<MUCBookmark> newBookmark) {
+void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) {
for (size_t i = 0; i < bookmarks_.size(); i++) {
- boost::shared_ptr<MUCBookmark> bookmark(bookmarks_[i]);
- if (bookmark.get() == oldBookmark.get()) {
+ if (bookmarks_[i] == oldBookmark) {
bookmarks_[i] = newBookmark;
flush();
onBookmarkRemoved(oldBookmark);
@@ -79,17 +73,18 @@ void MUCBookmarkManager::replaceBookmark(boost::shared_ptr<MUCBookmark> oldBookm
}
}
-void MUCBookmarkManager::addBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+void MUCBookmarkManager::addBookmark(const MUCBookmark& bookmark) {
bookmarks_.push_back(bookmark);
onBookmarkAdded(bookmark);
flush();
}
-void MUCBookmarkManager::removeBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
- std::vector<boost::shared_ptr<MUCBookmark> >::iterator it;
+void MUCBookmarkManager::removeBookmark(const MUCBookmark& bookmark) {
+ // FIXME: Clean this up using proper STL
+ std::vector<MUCBookmark>::iterator it;
for (it = bookmarks_.begin(); it != bookmarks_.end(); it++) {
- if ((*it).get() == bookmark.get()) {
+ if ((*it) == bookmark) {
bookmarks_.erase(it);
onBookmarkRemoved(bookmark);
break;
@@ -102,7 +97,7 @@ void MUCBookmarkManager::flush() {
//FIXME: some code may be useful
}
-const std::vector<boost::shared_ptr<MUCBookmark> >& MUCBookmarkManager::getBookmarks() {
+const std::vector<MUCBookmark>& MUCBookmarkManager::getBookmarks() const {
return bookmarks_;
}
diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h
index 79b6167..ffa903f 100644
--- a/Swiften/MUC/MUCBookmarkManager.h
+++ b/Swiften/MUC/MUCBookmarkManager.h
@@ -18,20 +18,28 @@
namespace Swift {
class IQRouter;
+
class MUCBookmarkManager {
public:
MUCBookmarkManager(IQRouter* iqRouter);
- void addBookmark(boost::shared_ptr<MUCBookmark> bookmark);
- void removeBookmark(boost::shared_ptr<MUCBookmark> bookmark);
- void replaceBookmark(boost::shared_ptr<MUCBookmark> oldBookmark, boost::shared_ptr<MUCBookmark> newBookmark);
- const std::vector<boost::shared_ptr<MUCBookmark> >& getBookmarks();
- boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkAdded;
- boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkRemoved;
+
+ void addBookmark(const MUCBookmark& bookmark);
+ void removeBookmark(const MUCBookmark& bookmark);
+ void replaceBookmark(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark);
+
+ const std::vector<MUCBookmark>& getBookmarks() const;
+
+ public:
+ boost::signal<void (const MUCBookmark&)> onBookmarkAdded;
+ boost::signal<void (const MUCBookmark&)> onBookmarkRemoved;
+
private:
- bool containsEquivalent(std::vector<boost::shared_ptr<MUCBookmark> > list, boost::shared_ptr<MUCBookmark> bookmark);
+ bool containsEquivalent(const std::vector<MUCBookmark>& list, const MUCBookmark& bookmark);
void handleBookmarksReceived(boost::shared_ptr<Storage> payload, const boost::optional<ErrorPayload>& error);
void flush();
- std::vector<boost::shared_ptr<MUCBookmark> > bookmarks_;
+
+ private:
+ std::vector<MUCBookmark> bookmarks_;
IQRouter* iqRouter_;
};
}