diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-05-06 13:08:57 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-05-29 16:18:23 (GMT) |
| commit | b70a50f11da1ea57a0e89ff14882eed03944eb2a (patch) | |
| tree | bbe3d3f28104dcba7d276a7016da283665b8f326 /Swift/QtUI | |
| parent | ab612d0f18ff545b4ebcb2bf2bb400996e751181 (diff) | |
| download | swift-contrib-b70a50f11da1ea57a0e89ff14882eed03944eb2a.zip swift-contrib-b70a50f11da1ea57a0e89ff14882eed03944eb2a.tar.bz2 | |
Right-click MUC in Recents to bookmark.
Change-Id: Idfb5907adf9bf53f0ac1f417dd57d49ecc897bb0
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 39 | ||||
| -rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 3 |
2 files changed, 34 insertions, 8 deletions
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index 7455fb5..210124b 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -36,154 +36,177 @@ QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvide model_ = new ChatListModel(); setModel(model_); delegate_ = new ChatListDelegate(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); #endif expandAll(); setAnimated(true); setIndentation(0); setDragEnabled(true); setRootIsDecorated(true); setupContextMenus(); connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&))); settings_->onSettingChanged.connect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1)); } QtChatListWindow::~QtChatListWindow() { settings_->onSettingChanged.disconnect(boost::bind(&QtChatListWindow::handleSettingChanged, this, _1)); delete model_; delete delegate_; delete mucMenu_; delete emptyMenu_; } void QtChatListWindow::handleSettingChanged(const std::string& setting) { if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) { delegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); repaint(); } } +void QtChatListWindow::handleClearRecentsRequested() { + onClearRecentsRequested(); +} + void QtChatListWindow::setBookmarksEnabled(bool enabled) { bookmarksEnabled_ = enabled; } void QtChatListWindow::handleClicked(const QModelIndex& index) { ChatListGroupItem* item = dynamic_cast<ChatListGroupItem*>(static_cast<ChatListItem*>(index.internalPointer())); if (item) { setExpanded(index, !isExpanded(index)); } } void QtChatListWindow::setupContextMenus() { mucMenu_ = new QMenu(); mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark())); mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark())); mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark())); + mucRecentsMenu_ = new QMenu(); + mucRecentsMenu_->addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents())); + mucRecentsMenu_->addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested())); emptyMenu_ = new QMenu(); emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark())); - } void QtChatListWindow::handleItemActivated(const QModelIndex& index) { ChatListItem* item = model_->getItemForIndex(index); if (ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(item)) { if (bookmarksEnabled_) { onMUCBookmarkActivated(mucItem->getBookmark()); } } else if (ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(item)) { if (!recentItem->getChat().isMUC || bookmarksEnabled_) { onRecentActivated(recentItem->getChat()); } } else if (ChatListWhiteboardItem* whiteboardItem = dynamic_cast<ChatListWhiteboardItem*>(item)) { if (!whiteboardItem->getChat().isMUC || bookmarksEnabled_) { eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(whiteboardItem->getChat().jid)); } } } void QtChatListWindow::clearBookmarks() { model_->clearBookmarks(); } void QtChatListWindow::addMUCBookmark(const MUCBookmark& bookmark) { model_->addMUCBookmark(bookmark); } void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) { model_->removeMUCBookmark(bookmark); } void QtChatListWindow::addWhiteboardSession(const ChatListWindow::Chat& chat) { model_->addWhiteboardSession(chat); } void QtChatListWindow::removeWhiteboardSession(const JID& jid) { model_->removeWhiteboardSession(jid); } void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents) { model_->setRecents(recents); } void QtChatListWindow::setUnreadCount(int unread) { emit onCountUpdated(unread); } void QtChatListWindow::handleRemoveBookmark() { ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark()))); } +void QtChatListWindow::handleAddBookmarkFromRecents() { + ChatListRecentItem* item = dynamic_cast<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))); + } +} + void QtChatListWindow::handleAddBookmark() { (new QtAddBookmarkWindow(eventStream_))->show(); } void QtChatListWindow::handleEditBookmark() { ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; QtEditBookmarkWindow* window = new QtEditBookmarkWindow(eventStream_, mucItem->getBookmark()); window->show(); } void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) { event->acceptProposedAction(); } } void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL; contextMenuItem_ = baseItem; if (!baseItem) { emptyMenu_->exec(QCursor::pos()); return; } + ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem); if (mucItem) { if (!bookmarksEnabled_) { return; } mucMenu_->exec(QCursor::pos()); + return; } - else { - QMenu menu; - QAction* clearRecents = menu.addAction(tr("Clear recents")); - menu.addAction(clearRecents); - QAction* result = menu.exec(event->globalPos()); - if (result == clearRecents) { - onClearRecentsRequested(); + + ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem); + if (recentItem) { + const ChatListWindow::Chat& chat = recentItem->getChat(); + if (chat.isMUC) { + mucRecentsMenu_->exec(QCursor::pos()); + return; } } + + QMenu menu; + menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested())); + menu.exec(event->globalPos()); } } diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index e218266..1cba3a4 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -4,55 +4,58 @@ * See Documentation/Licenses/GPLv3.txt 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" namespace Swift { class SettingsProvider; class QtChatListWindow : public QTreeView, public ChatListWindow { Q_OBJECT public: QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent = NULL); virtual ~QtChatListWindow(); void addMUCBookmark(const MUCBookmark& bookmark); void removeMUCBookmark(const MUCBookmark& bookmark); void addWhiteboardSession(const ChatListWindow::Chat& chat); void removeWhiteboardSession(const JID& jid); void setBookmarksEnabled(bool enabled); void setRecents(const std::list<ChatListWindow::Chat>& recents); void setUnreadCount(int unread); void clearBookmarks(); signals: void onCountUpdated(int count); private slots: void handleItemActivated(const QModelIndex&); void handleAddBookmark(); void handleEditBookmark(); void handleRemoveBookmark(); + void handleAddBookmarkFromRecents(); void handleClicked(const QModelIndex& index); void handleSettingChanged(const std::string& setting); + void handleClearRecentsRequested(); protected: void dragEnterEvent(QDragEnterEvent* event); void contextMenuEvent(QContextMenuEvent* event); private: void setupContextMenus(); bool bookmarksEnabled_; UIEventStream* eventStream_; ChatListModel* model_; ChatListDelegate* delegate_; QMenu* mucMenu_; QMenu* emptyMenu_; + QMenu* mucRecentsMenu_; ChatListItem* contextMenuItem_; SettingsProvider* settings_; }; } |
Swift