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 /Swift/QtUI
parent61620db053088fac637799b27f04efa44d0bcc6b (diff)
downloadswift-contrib-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.zip
swift-contrib-203ca1c122db89c4a9f9f01bff2cadb3b9daca04.tar.bz2
Cleaned up MUC code.
Diffstat (limited to 'Swift/QtUI')
-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
11 files changed, 44 insertions, 39 deletions
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_;
};
}