diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-05-07 18:45:47 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-05-07 18:45:47 (GMT) |
commit | 203ca1c122db89c4a9f9f01bff2cadb3b9daca04 (patch) | |
tree | e57d7f5997aad1832146d2806418b184e1dfe6bb /Swift | |
parent | 61620db053088fac637799b27f04efa44d0bcc6b (diff) | |
download | swift-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.zip swift-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.tar.bz2 |
Cleaned up MUC code.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 10 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.h | 4 | ||||
-rw-r--r-- | Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h | 12 | ||||
-rw-r--r-- | Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/ChatListWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListMUCItem.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListMUCItem.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.cpp | 4 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtAddBookmarkWindow.cpp | 9 | ||||
-rw-r--r-- | Swift/QtUI/QtBookmarkDetailWindow.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/QtBookmarkDetailWindow.h | 5 | ||||
-rw-r--r-- | Swift/QtUI/QtEditBookmarkWindow.cpp | 20 | ||||
-rw-r--r-- | Swift/QtUI/QtEditBookmarkWindow.h | 4 |
17 files changed, 68 insertions, 59 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_; }; } |