From ad2b02aba3130b06d69bb6ffd803a4a167f39e69 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 21 Feb 2016 10:59:35 +0100 Subject: [PATCH] Fixed #162. --- resources/text/CHANGELOG | 1 + src/gui/dialogs/formmain.cpp | 21 +++++++++------------ src/services/abstract/recyclebin.cpp | 21 ++++++++++++++++++++- src/services/abstract/recyclebin.h | 3 +++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 622e7e707..4a61e7f46 100755 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -9,6 +9,7 @@ http://goo.gl/forms/GcvPYgS2a8 Added: +▪ Recycle bins now have context menu. (issue #162) ▪ User is now able to delete TT-RSS feeds. (issue #151) ▪ Added ability to stop running batch feed update. (issue #157) diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index a638f7ed2..deb3dc9b9 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -239,6 +239,7 @@ void FormMain::updateRecycleBinMenu() { root_menu->setToolTip(activated_root->description()); RecycleBin *bin = activated_root->recycleBin(); + QList context_menu; if (bin == NULL) { QAction *no_action = new QAction(qApp->icons()->fromTheme(QSL("dialog-error")), @@ -247,19 +248,15 @@ void FormMain::updateRecycleBinMenu() { no_action->setEnabled(false); root_menu->addAction(no_action); } + else if ((context_menu = bin->contextMenu()).isEmpty()) { + QAction *no_action = new QAction(qApp->icons()->fromTheme(QSL("dialog-error")), + tr("No actions possible"), + m_ui->m_menuRecycleBin); + no_action->setEnabled(false); + root_menu->addAction(no_action); + } else { - QAction *restore_action = new QAction(qApp->icons()->fromTheme(QSL("recycle-bin-restore-all")), - tr("Restore recycle bin"), - m_ui->m_menuRecycleBin); - QAction *empty_action = new QAction(qApp->icons()->fromTheme(QSL("recycle-bin-empty")), - tr("Empty recycle bin"), - m_ui->m_menuRecycleBin); - - connect(restore_action, SIGNAL(triggered()), bin, SLOT(restore())); - connect(empty_action, SIGNAL(triggered()), bin, SLOT(empty())); - - root_menu->addAction(restore_action); - root_menu->addAction(empty_action); + root_menu->addActions(context_menu); } m_ui->m_menuRecycleBin->addMenu(root_menu); diff --git a/src/services/abstract/recyclebin.cpp b/src/services/abstract/recyclebin.cpp index 820687305..e898fd8a1 100755 --- a/src/services/abstract/recyclebin.cpp +++ b/src/services/abstract/recyclebin.cpp @@ -25,7 +25,7 @@ #include -RecycleBin::RecycleBin(RootItem *parent_item) : RootItem(parent_item) { +RecycleBin::RecycleBin(RootItem *parent_item) : RootItem(parent_item), m_contextMenu(QList()) { setKind(RootItemKind::Bin); setId(ID_RECYCLE_BIN); setIcon(qApp->icons()->fromTheme(QSL("folder-recycle-bin"))); @@ -87,6 +87,25 @@ QVariant RecycleBin::data(int column, int role) const { } } +QList RecycleBin::contextMenu() { + if (m_contextMenu.isEmpty()) { + QAction *restore_action = new QAction(qApp->icons()->fromTheme(QSL("recycle-bin-restore-all")), + tr("Restore recycle bin"), + this); + QAction *empty_action = new QAction(qApp->icons()->fromTheme(QSL("recycle-bin-empty")), + tr("Empty recycle bin"), + this); + + connect(restore_action, SIGNAL(triggered()), this, SLOT(restore())); + connect(empty_action, SIGNAL(triggered()), this, SLOT(empty())); + + m_contextMenu.append(restore_action); + m_contextMenu.append(empty_action); + } + + return m_contextMenu; +} + QList RecycleBin::undeletedMessages() const { QList messages; const int account_id = getParentServiceRoot()->accountId(); diff --git a/src/services/abstract/recyclebin.h b/src/services/abstract/recyclebin.h index 6e66ca48a..3023617c9 100755 --- a/src/services/abstract/recyclebin.h +++ b/src/services/abstract/recyclebin.h @@ -30,6 +30,7 @@ class RecycleBin : public RootItem { QVariant data(int column, int role) const; + QList contextMenu(); QList undeletedMessages() const; bool markAsReadUnread(ReadStatus status); @@ -60,6 +61,8 @@ class RecycleBin : public RootItem { private: int m_totalCount; int m_unreadCount; + + QList m_contextMenu; }; #endif // RECYCLEBIN_H