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 | |
| 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
| -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,5 +1,5 @@  /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited.   * All rights reserved.   * See the COPYING file for more information.   */ @@ -131,6 +131,18 @@ QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const {  	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;  } 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,5 +1,5 @@  /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited.   * All rights reserved.   * See the COPYING file for more information.   */ @@ -10,11 +10,14 @@  #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: @@ -33,6 +36,9 @@ namespace Swift {  			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_; 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,10 +1,10 @@  /* - * 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> @@ -20,6 +20,7 @@  #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> @@ -58,7 +59,6 @@ QtChatListWindow::~QtChatListWindow() {  	delete model_;  	delete delegate_;  	delete mucMenu_; -	delete mucRecentsMenu_;  	delete emptyMenu_;  } @@ -89,9 +89,6 @@ void QtChatListWindow::setupContextMenus() {  	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()));  } @@ -148,13 +145,13 @@ void QtChatListWindow::setOnline(bool 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()); @@ -170,7 +167,7 @@ void QtChatListWindow::handleAddBookmark() {  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(); @@ -209,7 +206,19 @@ void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {  	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;  		}  	} 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,5 +1,5 @@  /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited.   * All rights reserved.   * See the COPYING file for more information.   */ @@ -8,10 +8,11 @@  #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; @@ -54,8 +55,7 @@ namespace Swift {  			ChatListDelegate* delegate_;  			QMenu* mucMenu_;  			QMenu* emptyMenu_; -			QMenu* mucRecentsMenu_; -			ChatListItem* contextMenuItem_; +			const ChatListItem* contextMenuItem_;  			SettingsProvider* settings_;  			QList<QAction*> onlineOnlyActions_;  			bool isOnline_;  | 
 Swift