summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp10
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h4
-rw-r--r--Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h7
-rw-r--r--Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h12
-rw-r--r--Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h7
-rw-r--r--Swift/Controllers/UIInterfaces/ChatListWindow.h4
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.cpp8
-rw-r--r--Swift/QtUI/ChatList/ChatListMUCItem.h6
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.cpp4
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.h4
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp6
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h4
-rw-r--r--Swift/QtUI/QtAddBookmarkWindow.cpp9
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.cpp13
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.h5
-rw-r--r--Swift/QtUI/QtEditBookmarkWindow.cpp20
-rw-r--r--Swift/QtUI/QtEditBookmarkWindow.h4
-rw-r--r--Swiften/MUC/MUCBookmark.h3
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp41
-rw-r--r--Swiften/MUC/MUCBookmarkManager.h24
20 files changed, 104 insertions, 91 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index a4ade48..69184ad 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -57,16 +57,16 @@ ChatsManager::~ChatsManager() {
delete mucBookmarkManager_;
}
-void ChatsManager::handleMUCBookmarkAdded(boost::shared_ptr<MUCBookmark> bookmark) {
- std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark->getRoom());
- if (it == mucControllers_.end() && bookmark->getAutojoin()) {
+void ChatsManager::handleMUCBookmarkAdded(const MUCBookmark& bookmark) {
+ std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark.getRoom());
+ if (it == mucControllers_.end() && bookmark.getAutojoin()) {
//FIXME: need vcard stuff here to get a nick
- handleJoinMUCRequest(bookmark->getRoom(), bookmark->getNick());
+ handleJoinMUCRequest(bookmark.getRoom(), bookmark.getNick());
}
chatListWindow_->addMUCBookmark(bookmark);
}
-void ChatsManager::handleMUCBookmarkRemoved(boost::shared_ptr<MUCBookmark> bookmark) {
+void ChatsManager::handleMUCBookmarkRemoved(const MUCBookmark& bookmark) {
chatListWindow_->removeMUCBookmark(bookmark);
}
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 59d4ec3..1f0f203 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -48,8 +48,8 @@ namespace Swift {
void rebindControllerJID(const JID& from, const JID& to);
void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> lastPresence);
void handleUIEvent(boost::shared_ptr<UIEvent> event);
- void handleMUCBookmarkAdded(boost::shared_ptr<MUCBookmark> bookmark);
- void handleMUCBookmarkRemoved(boost::shared_ptr<MUCBookmark> bookmark);
+ void handleMUCBookmarkAdded(const MUCBookmark& bookmark);
+ void handleMUCBookmarkRemoved(const MUCBookmark& bookmark);
void handleUserLeftMUC(MUCController* mucController);
ChatController* getChatControllerOrFindAnother(const JID &contact);
ChatController* createNewChatController(const JID &contact);
diff --git a/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
index 715798b..210da3e 100644
--- a/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h
@@ -14,9 +14,10 @@
namespace Swift {
class AddMUCBookmarkUIEvent : public UIEvent {
public:
- AddMUCBookmarkUIEvent(const boost::shared_ptr<MUCBookmark> bookmark) : bookmark_(bookmark) {};
- boost::shared_ptr<MUCBookmark> getBookmark() {return bookmark_;};
+ AddMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {};
+ const MUCBookmark& getBookmark() { return bookmark; }
+
private:
- boost::shared_ptr<MUCBookmark> bookmark_;
+ MUCBookmark bookmark;
};
}
diff --git a/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
index bcbcb76..2b10f09 100644
--- a/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h
@@ -14,11 +14,13 @@
namespace Swift {
class EditMUCBookmarkUIEvent : public UIEvent {
public:
- EditMUCBookmarkUIEvent(const boost::shared_ptr<MUCBookmark> oldBookmark, const boost::shared_ptr<MUCBookmark> newBookmark) : oldBookmark_(oldBookmark) , newBookmark_(newBookmark) {};
- boost::shared_ptr<MUCBookmark> getOldBookmark() {return oldBookmark_;};
- boost::shared_ptr<MUCBookmark> getNewBookmark() {return newBookmark_;};
+ EditMUCBookmarkUIEvent(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) : oldBookmark(oldBookmark) , newBookmark(newBookmark) {};
+
+ const MUCBookmark& getOldBookmark() {return oldBookmark;};
+ const MUCBookmark& getNewBookmark() {return newBookmark;};
+
private:
- boost::shared_ptr<MUCBookmark> oldBookmark_;
- boost::shared_ptr<MUCBookmark> newBookmark_;
+ MUCBookmark oldBookmark;
+ MUCBookmark newBookmark;
};
}
diff --git a/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h b/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
index 4a59b2c..ea2e609 100644
--- a/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
+++ b/Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h
@@ -14,9 +14,10 @@
namespace Swift {
class RemoveMUCBookmarkUIEvent : public UIEvent {
public:
- RemoveMUCBookmarkUIEvent(const boost::shared_ptr<MUCBookmark> bookmark) : bookmark_(bookmark) {};
- boost::shared_ptr<MUCBookmark> getBookmark() {return bookmark_;};
+ RemoveMUCBookmarkUIEvent(const MUCBookmark& bookmark) : bookmark(bookmark) {};
+ const MUCBookmark& getBookmark() { return bookmark; }
+
private:
- boost::shared_ptr<MUCBookmark> bookmark_;
+ MUCBookmark bookmark;
};
}
diff --git a/Swift/Controllers/UIInterfaces/ChatListWindow.h b/Swift/Controllers/UIInterfaces/ChatListWindow.h
index 6a0762b..fd176a6 100644
--- a/Swift/Controllers/UIInterfaces/ChatListWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatListWindow.h
@@ -15,7 +15,7 @@ namespace Swift {
public:
virtual ~ChatListWindow();
- virtual void addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) = 0;
- virtual void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) = 0;
+ virtual void addMUCBookmark(const MUCBookmark& bookmark) = 0;
+ virtual void removeMUCBookmark(const MUCBookmark& bookmark) = 0;
};
}
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.cpp b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
index ec643d1..370956e 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.cpp
@@ -9,18 +9,18 @@
#include "Swift/QtUI/QtSwiftUtil.h"
namespace Swift {
-ChatListMUCItem::ChatListMUCItem(boost::shared_ptr<MUCBookmark> bookmark, ChatListGroupItem* parent) : ChatListItem(parent), bookmark_(bookmark) {
+ChatListMUCItem::ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent) : ChatListItem(parent), bookmark_(bookmark) {
}
-boost::shared_ptr<MUCBookmark> ChatListMUCItem::getBookmark() {
+const MUCBookmark& ChatListMUCItem::getBookmark() {
return bookmark_;
}
QVariant ChatListMUCItem::data(int role) {
switch (role) {
- case Qt::DisplayRole: return P2QSTRING(bookmark_->getName());
- case DetailTextRole: return P2QSTRING(bookmark_->getRoom().toString());
+ case Qt::DisplayRole: return P2QSTRING(bookmark_.getName());
+ case DetailTextRole: return P2QSTRING(bookmark_.getRoom().toString());
/*case Qt::TextColorRole: return textColor_;
case Qt::BackgroundColorRole: return backgroundColor_;
case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
diff --git a/Swift/QtUI/ChatList/ChatListMUCItem.h b/Swift/QtUI/ChatList/ChatListMUCItem.h
index 4170c6f..f5e3242 100644
--- a/Swift/QtUI/ChatList/ChatListMUCItem.h
+++ b/Swift/QtUI/ChatList/ChatListMUCItem.h
@@ -23,11 +23,11 @@ namespace Swift {
};
class ChatListMUCItem : public ChatListItem {
public:
- ChatListMUCItem(boost::shared_ptr<MUCBookmark> bookmark, ChatListGroupItem* parent);
- boost::shared_ptr<MUCBookmark> getBookmark();
+ ChatListMUCItem(const MUCBookmark& bookmark, ChatListGroupItem* parent);
+ const MUCBookmark& getBookmark();
QVariant data(int role);
private:
- boost::shared_ptr<MUCBookmark> bookmark_;
+ MUCBookmark bookmark_;
QList<ChatListItem*> items_;
};
}
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp
index 0e4af55..50a6ad3 100644
--- a/Swift/QtUI/ChatList/ChatListModel.cpp
+++ b/Swift/QtUI/ChatList/ChatListModel.cpp
@@ -16,7 +16,7 @@ ChatListModel::ChatListModel() {
root_->addItem(mucBookmarks_);
}
-void ChatListModel::addMUCBookmark(boost::shared_ptr<Swift::MUCBookmark> bookmark) {
+void ChatListModel::addMUCBookmark(const Swift::MUCBookmark& bookmark) {
emit layoutAboutToBeChanged();
mucBookmarks_->addItem(new ChatListMUCItem(bookmark, mucBookmarks_));
emit layoutChanged();
@@ -25,7 +25,7 @@ void ChatListModel::addMUCBookmark(boost::shared_ptr<Swift::MUCBookmark> bookmar
//emit dataChanged(parent(index), parent(index));
}
-void ChatListModel::removeMUCBookmark(boost::shared_ptr<Swift::MUCBookmark> bookmark) {
+void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {
for (int i = 0; i < mucBookmarks_->rowCount(); i++) {
ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
if (item->getBookmark() == bookmark) {
diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h
index 71849cc..05fa60b 100644
--- a/Swift/QtUI/ChatList/ChatListModel.h
+++ b/Swift/QtUI/ChatList/ChatListModel.h
@@ -20,8 +20,8 @@ namespace Swift {
Q_OBJECT
public:
ChatListModel();
- void addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
- void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ void addMUCBookmark(const MUCBookmark& bookmark);
+ void removeMUCBookmark(const MUCBookmark& bookmark);
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index 9b70881..8dbb501 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -58,16 +58,16 @@ void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
ChatListItem* item = model_->getItemForIndex(index);
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item);
if (mucItem) {
- boost::shared_ptr<UIEvent> event(new JoinMUCUIEvent(mucItem->getBookmark()->getRoom(), mucItem->getBookmark()->getNick()));
+ boost::shared_ptr<UIEvent> event(new JoinMUCUIEvent(mucItem->getBookmark().getRoom(), mucItem->getBookmark().getNick()));
eventStream_->send(event);
}
}
-void QtChatListWindow::addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+void QtChatListWindow::addMUCBookmark(const MUCBookmark& bookmark) {
model_->addMUCBookmark(bookmark);
}
-void QtChatListWindow::removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) {
model_->removeMUCBookmark(bookmark);
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index 2055e6b..7d0dbb1 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -21,8 +21,8 @@ namespace Swift {
public:
QtChatListWindow(UIEventStream *uiEventStream, QWidget* parent = NULL);
virtual ~QtChatListWindow();
- void addMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
- void removeMUCBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ void addMUCBookmark(const MUCBookmark& bookmark);
+ void removeMUCBookmark(const MUCBookmark& bookmark);
private slots:
void handleItemActivated(const QModelIndex&);
void handleAddBookmark();
diff --git a/Swift/QtUI/QtAddBookmarkWindow.cpp b/Swift/QtUI/QtAddBookmarkWindow.cpp
index 2403eac..675ea03 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.cpp
+++ b/Swift/QtUI/QtAddBookmarkWindow.cpp
@@ -14,11 +14,14 @@ QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream) : eventStre
}
bool QtAddBookmarkWindow::commit() {
- boost::shared_ptr<MUCBookmark> bookmark(createBookmarkFromForm());
+ boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
if (bookmark) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
+ eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(*bookmark)));
+ return true;
+ }
+ else {
+ return false;
}
- return bookmark;
}
}
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.cpp b/Swift/QtUI/QtBookmarkDetailWindow.cpp
index b27ed7c..d83e2eb 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.cpp
+++ b/Swift/QtUI/QtBookmarkDetailWindow.cpp
@@ -23,30 +23,29 @@ void QtBookmarkDetailWindow::accept() {
}
}
-boost::shared_ptr<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
+boost::optional<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
//check room
//check bookmarkName
JID room(Q2PSTRING(room_->text()));
if (!room.isValid() || room.getNode().isEmpty() || !room.getResource().isEmpty()) {
QMessageBox::warning(this, "Bookmark not valid", "You must specify a valid room address (e.g. myroom@chats.example.com).");
- return boost::shared_ptr<MUCBookmark>();
+ return boost::optional<MUCBookmark>();
}
String name(Q2PSTRING(name_->text()));
if (name.isEmpty()) {
name = room.toString();
}
+ MUCBookmark bookmark(room, name);
String nick(Q2PSTRING(nick_->text()));
String password(Q2PSTRING(password_->text()));
- bool autojoin = autojoin_->isChecked();
- boost::shared_ptr<MUCBookmark> bookmark(new MUCBookmark(room, name));
+ bookmark.setAutojoin(autojoin_->isChecked());
if (!nick.isEmpty()) {
- bookmark->setNick(nick);
+ bookmark.setNick(nick);
}
if (!password.isEmpty()) {
- bookmark->setPassword(password);
+ bookmark.setPassword(password);
}
- bookmark->setAutojoin(autojoin);
return bookmark;
}
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.h b/Swift/QtUI/QtBookmarkDetailWindow.h
index dadd973..fd2b7b4 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.h
+++ b/Swift/QtUI/QtBookmarkDetailWindow.h
@@ -8,7 +8,7 @@
#include "ui_QtBookmarkDetailWindow.h"
-#include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
#include <QDialog>
@@ -20,7 +20,8 @@ namespace Swift {
public:
QtBookmarkDetailWindow(QWidget* parent = NULL);
virtual bool commit() = 0;
- boost::shared_ptr<MUCBookmark> createBookmarkFromForm();
+ boost::optional<MUCBookmark> createBookmarkFromForm();
+
public slots:
void accept();
};
diff --git a/Swift/QtUI/QtEditBookmarkWindow.cpp b/Swift/QtUI/QtEditBookmarkWindow.cpp
index 76a01f6..1d126cd 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.cpp
+++ b/Swift/QtUI/QtEditBookmarkWindow.cpp
@@ -9,18 +9,20 @@
#include "QtSwiftUtil.h"
namespace Swift {
-QtEditBookmarkWindow::QtEditBookmarkWindow(UIEventStream* eventStream, boost::shared_ptr<MUCBookmark> bookmark) : eventStream_(eventStream), bookmark_(bookmark) {
- name_->setText(P2QSTRING(bookmark->getName()));
- room_->setText(P2QSTRING(bookmark->getRoom().toString()));
- autojoin_->setChecked(bookmark->getAutojoin());
- nick_->setText(bookmark->getNick() ? P2QSTRING(bookmark->getNick().get()) : "");
- password_->setText(bookmark->getPassword() ? P2QSTRING(bookmark->getPassword().get()) : "");
+QtEditBookmarkWindow::QtEditBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark) : eventStream_(eventStream), bookmark_(bookmark) {
+ name_->setText(P2QSTRING(bookmark.getName()));
+ room_->setText(P2QSTRING(bookmark.getRoom().toString()));
+ autojoin_->setChecked(bookmark.getAutojoin());
+ nick_->setText(bookmark.getNick() ? P2QSTRING(bookmark.getNick().get()) : "");
+ password_->setText(bookmark.getPassword() ? P2QSTRING(bookmark.getPassword().get()) : "");
}
bool QtEditBookmarkWindow::commit() {
- boost::shared_ptr<MUCBookmark> bookmark = createBookmarkFromForm();
- if (!bookmark) return false;
- eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, bookmark)));
+ boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
+ if (!bookmark) {
+ return false;
+ }
+ eventStream_->send(boost::shared_ptr<UIEvent>(new EditMUCBookmarkUIEvent(bookmark_, *bookmark)));
return true;
}
diff --git a/Swift/QtUI/QtEditBookmarkWindow.h b/Swift/QtUI/QtEditBookmarkWindow.h
index 1ca5001..537a7a7 100644
--- a/Swift/QtUI/QtEditBookmarkWindow.h
+++ b/Swift/QtUI/QtEditBookmarkWindow.h
@@ -14,11 +14,11 @@ namespace Swift {
class QtEditBookmarkWindow : public QtBookmarkDetailWindow {
Q_OBJECT
public:
- QtEditBookmarkWindow(UIEventStream* eventStream, boost::shared_ptr<MUCBookmark> bookmark);
+ QtEditBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
bool commit();
private:
UIEventStream* eventStream_;
- boost::shared_ptr<MUCBookmark> bookmark_;
+ MUCBookmark bookmark_;
};
}
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_;
};
}