diff options
author | Tobias Markmann <tm@ayena.de> | 2015-04-28 12:28:02 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-04-28 19:26:00 (GMT) |
commit | 68263f7cb360ae52915017df202775665c4eeeb6 (patch) | |
tree | 59dd2f8cece17d46e585fb00111fbc026fc1e9ce /Swift/QtUI/ChatList/QtChatListWindow.cpp | |
parent | 4ac05ebaf6c913b4bfcc7c4e7abeb6ace9efe5c8 (diff) | |
download | swift-68263f7cb360ae52915017df202775665c4eeeb6.zip swift-68263f7cb360ae52915017df202775665c4eeeb6.tar.bz2 |
Allow editing bookmarks of MUC chats in the "Recent Chats"
Test-Information:
Tested with online and offline account. Tested with not bookmarked
and already bookmarked chats. Works as expected.
Change-Id: Ib8851a70a7a82a198ee5b7a207816f03ad9df61e
Diffstat (limited to 'Swift/QtUI/ChatList/QtChatListWindow.cpp')
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
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())); |