diff options
author | Tobias Markmann <tm@ayena.de> | 2014-09-29 08:07:05 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2014-10-17 20:11:30 (GMT) |
commit | 38b0cb785fea8eae5e48fae56440695fdfd10ee1 (patch) | |
tree | 78bb8ce9a6bcbc397805bcd433b96b3b23994f09 /Swift/QtUI/ChatList | |
parent | 1722d220533a78e8b2acbcd571631960656e78f8 (diff) | |
download | swift-38b0cb785fea8eae5e48fae56440695fdfd10ee1.zip swift-38b0cb785fea8eae5e48fae56440695fdfd10ee1.tar.bz2 |
Disable online only actions when offline.
Disabling action, menu items and drag 'n' drop which require an online
connection when the user is offline.
Test-Information:
Checked by going offline and checking the relevant actions and menu items.
Change-Id: Iacfa2c9f815d3b9bbad9ca4c2d0d04f95ce9a9e4
Diffstat (limited to 'Swift/QtUI/ChatList')
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.cpp | 21 | ||||
-rw-r--r-- | Swift/QtUI/ChatList/QtChatListWindow.h | 3 |
2 files changed, 18 insertions, 6 deletions
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index 8e75f34..ea65dd6 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -26,13 +26,13 @@ #include <Swift/QtUI/QtAddBookmarkWindow.h> #include <Swift/QtUI/QtEditBookmarkWindow.h> #include <Swift/QtUI/QtUISettingConstants.h> namespace Swift { -QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent) { +QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent), isOnline_(false) { eventStream_ = uiEventStream; settings_ = settings; bookmarksEnabled_ = false; model_ = new ChatListModel(); setModel(model_); delegate_ = new ChatListDelegate(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); @@ -83,20 +83,20 @@ void QtChatListWindow::handleClicked(const QModelIndex& index) { 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())); + 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(); - mucRecentsMenu_->addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents())); + onlineOnlyActions_ << 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())); + onlineOnlyActions_ << 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_) { @@ -140,12 +140,16 @@ void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents } void QtChatListWindow::setUnreadCount(int unread) { emit onCountUpdated(unread); } +void QtChatListWindow::setOnline(bool isOnline) { + isOnline_ = isOnline; +} + void QtChatListWindow::handleRemoveBookmark() { ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_); if (!mucItem) return; eventStream_->send(boost::shared_ptr<UIEvent>(new RemoveMUCBookmarkUIEvent(mucItem->getBookmark()))); } @@ -179,12 +183,17 @@ void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) { } void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) { QModelIndex index = indexAt(event->pos()); ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL; contextMenuItem_ = baseItem; + + foreach(QAction* action, onlineOnlyActions_) { + action->setEnabled(isOnline_); + } + if (!baseItem) { emptyMenu_->exec(QCursor::pos()); return; } ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem); diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h index 1cba3a4..823e6dc 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.h +++ b/Swift/QtUI/ChatList/QtChatListWindow.h @@ -25,12 +25,13 @@ namespace Swift { 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(); + virtual void setOnline(bool isOnline); signals: void onCountUpdated(int count); private slots: void handleItemActivated(const QModelIndex&); void handleAddBookmark(); @@ -53,9 +54,11 @@ namespace Swift { ChatListDelegate* delegate_; QMenu* mucMenu_; QMenu* emptyMenu_; QMenu* mucRecentsMenu_; ChatListItem* contextMenuItem_; SettingsProvider* settings_; + QList<QAction*> onlineOnlyActions_; + bool isOnline_; }; } |