diff options
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.cpp | 14 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/ChatListModel.h | 8 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 29 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 14 |
4 files changed, 46 insertions, 19 deletions
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp index b7ce239..2447aa1 100644 --- a/Swift/QtUI/ChatList/ChatListModel.cpp +++ b/Swift/QtUI/ChatList/ChatListModel.cpp @@ -1,8 +1,8 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/QtUI/ChatList/ChatListModel.h> @@ -128,12 +128,24 @@ QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const { } data->setData(mimeType, itemData); return data; } +const ChatListMUCItem* ChatListModel::getChatListMUCItem(const JID& roomJID) const { + const ChatListMUCItem* mucItem = NULL; + for (int i = 0; i < mucBookmarks_->rowCount(); i++) { + ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i)); + if (item->getBookmark().getRoom() == roomJID) { + mucItem = item; + break; + } + } + return mucItem; +} + int ChatListModel::columnCount(const QModelIndex& /*parent*/) const { return 1; } ChatListItem* ChatListModel::getItemForIndex(const QModelIndex& index) const { return index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL; diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h index fc0ae32..ea85efb 100644 --- a/Swift/QtUI/ChatList/ChatListModel.h +++ b/Swift/QtUI/ChatList/ChatListModel.h @@ -1,23 +1,26 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include <QAbstractItemModel> #include <QPersistentModelIndex> #include <Swiften/MUC/MUCBookmark.h> + #include <Swift/Controllers/UIInterfaces/ChatListWindow.h> #include <Swift/QtUI/ChatList/ChatListGroupItem.h> namespace Swift { + class ChatListMUCItem; + class ChatListModel : public QAbstractItemModel { Q_OBJECT public: ChatListModel(); Qt::ItemFlags flags(const QModelIndex& index) const; void addMUCBookmark(const MUCBookmark& bookmark); @@ -30,12 +33,15 @@ namespace Swift { QModelIndex parent(const QModelIndex& index) const; int rowCount(const QModelIndex& parent = QModelIndex()) const; ChatListItem* getItemForIndex(const QModelIndex& index) const; void clearBookmarks(); void setRecents(const std::list<ChatListWindow::Chat>& recents); QMimeData* mimeData(const QModelIndexList& indexes) const; + + const ChatListMUCItem* getChatListMUCItem(const JID& roomJID) const; + private: ChatListGroupItem* mucBookmarks_; ChatListGroupItem* recents_; ChatListGroupItem* whiteboards_; ChatListGroupItem* root_; diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index 71d4f1b..7b40f9c 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -1,13 +1,13 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Swift/QtUI/ChatList/QtChatListWindow.h" +#include <Swift/QtUI/ChatList/QtChatListWindow.h> #include <boost/bind.hpp> #include <QContextMenuEvent> #include <QMenu> #include <QMimeData> @@ -17,12 +17,13 @@ #include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h> #include <Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> #include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h> + #include <Swift/QtUI/ChatList/ChatListMUCItem.h> #include <Swift/QtUI/ChatList/ChatListRecentItem.h> #include <Swift/QtUI/ChatList/ChatListWhiteboardItem.h> #include <Swift/QtUI/QtAddBookmarkWindow.h> #include <Swift/QtUI/QtEditBookmarkWindow.h> #include <Swift/QtUI/QtUISettingConstants.h> @@ -55,13 +56,12 @@ QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvide QtChatListWindow::~QtChatListWindow() { settings_->onSettingChanged.disconnect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1)); delete model_; delete delegate_; delete mucMenu_; - delete mucRecentsMenu_; delete emptyMenu_; } void QtChatListWindow::handleSettingChanged(const std::string& setting) { if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) { delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); @@ -86,15 +86,12 @@ void QtChatListWindow::handleClicked(const QModelIndex& index) { void QtChatListWindow::setupContextMenus() { mucMenu_ = new QMenu(); onlineOnlyActions_ << mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark())); onlineOnlyActions_ << mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark())); onlineOnlyActions_ << mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark())); - mucRecentsMenu_ = new QMenu(); - onlineOnlyActions_ << mucRecentsMenu_->addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents())); - mucRecentsMenu_->addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested())); emptyMenu_ = new QMenu(); onlineOnlyActions_ << emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark())); } void QtChatListWindow::handleItemActivated(const QModelIndex& index) { ChatListItem* item = model_->getItemForIndex(index); @@ -145,19 +142,19 @@ void QtChatListWindow::setUnreadCount(int unread) { void QtChatListWindow::setOnline(bool isOnline) { isOnline_ = isOnline; } void QtChatListWindow::handleRemoveBookmark() { - ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); + const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark()))); } void QtChatListWindow::handleAddBookmarkFromRecents() { - ChatListRecentItem* item = dynamic_cast<ChatListRecentItem*>(contextMenuItem_); + const ChatListRecentItem* item = dynamic_cast<const ChatListRecentItem*>(contextMenuItem_); if (item) { const ChatListWindow::Chat& chat = item->getChat(); MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString()); bookmark.setNick(chat.nick); bookmark.setPassword(chat.password); eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark))); @@ -167,13 +164,13 @@ void QtChatListWindow::handleAddBookmarkFromRecents() { void QtChatListWindow::handleAddBookmark() { (new QtAddBookmarkWindow(eventStream_))->show(); } void QtChatListWindow::handleEditBookmark() { - ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); + const ChatListMUCItem* mucItem = dynamic_cast<const ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark()); window->show(); } void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) { @@ -206,13 +203,25 @@ void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) { } ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem); if (recentItem) { const ChatListWindow::Chat& chat = recentItem->getChat(); if (chat.isMUC) { - mucRecentsMenu_->exec(QCursor::pos()); + QMenu mucRecentsMenu; + QAction* bookmarkAction = NULL; + const ChatListMUCItem* mucItem = model_->getChatListMUCItem(chat.jid); + if (mucItem) { + contextMenuItem_ = mucItem; + bookmarkAction = mucRecentsMenu.addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark())); + } + else { + bookmarkAction = mucRecentsMenu.addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents())); + } + bookmarkAction->setEnabled(isOnline_); + mucRecentsMenu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested())); + mucRecentsMenu.exec(QCursor::pos()); return; } } QMenu menu; menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested())); diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index 9738413..627dcd4 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -1,20 +1,21 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include <QTreeView> -#include "Swift/Controllers/UIInterfaces/ChatListWindow.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/QtUI/ChatList/ChatListModel.h" -#include "Swift/QtUI/ChatList/ChatListDelegate.h" +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIInterfaces/ChatListWindow.h> + +#include <Swift/QtUI/ChatList/ChatListDelegate.h> +#include <Swift/QtUI/ChatList/ChatListModel.h> namespace Swift { class SettingsProvider; class QtChatListWindow : public QTreeView, public ChatListWindow { Q_OBJECT public: @@ -51,14 +52,13 @@ namespace Swift { bool bookmarksEnabled_; UIEventStream* eventStream_; ChatListModel* model_; ChatListDelegate* delegate_; QMenu* mucMenu_; QMenu* emptyMenu_; - QMenu* mucRecentsMenu_; - ChatListItem* contextMenuItem_; + const ChatListItem* contextMenuItem_; SettingsProvider* settings_; QList<QAction*> onlineOnlyActions_; bool isOnline_; }; } |