From 42e81b9d190c39a7db88868e5a72888be53db8ee Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Mon, 22 Jul 2013 22:38:57 +0400 Subject: [PATCH] Support edit/delete/double click hotkeys in rss feed list and rule list. --- src/rss/automatedrssdownloader.cpp | 17 +++++++++++++++-- src/rss/automatedrssdownloader.h | 3 +++ src/rss/rss_imp.cpp | 19 +++++++++++++++++-- src/rss/rss_imp.h | 3 +++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/rss/automatedrssdownloader.cpp b/src/rss/automatedrssdownloader.cpp index f34c1d7a6..a7aad87a5 100644 --- a/src/rss/automatedrssdownloader.cpp +++ b/src/rss/automatedrssdownloader.cpp @@ -95,6 +95,14 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer& m Q_ASSERT(ok); ok = connect(this, SIGNAL(finished(int)), SLOT(on_finished(int))); Q_ASSERT(ok); + editHotkey = new QShortcut(QKeySequence("F2"), ui->listRules, 0, 0, Qt::WidgetShortcut); + ok = connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedRule())); + Q_ASSERT(ok); + ok = connect(ui->listRules, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedRule())); + Q_ASSERT(ok); + deleteHotkey = new QShortcut(QKeySequence(QKeySequence::Delete), ui->listRules, 0, 0, Qt::WidgetShortcut); + ok = connect(deleteHotkey, SIGNAL(activated()), SLOT(on_removeRuleBtn_clicked())); + Q_ASSERT(ok); updateRuleDefinitionBox(); updateFeedList(); } @@ -102,6 +110,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer& m AutomatedRssDownloader::~AutomatedRssDownloader() { qDebug() << Q_FUNC_INFO; + delete editHotkey; + delete deleteHotkey; delete ui; delete m_editableRuleList; } @@ -421,8 +431,11 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos) void AutomatedRssDownloader::renameSelectedRule() { - QListWidgetItem *item = ui->listRules->currentItem(); - if (!item) return; + const QList selection = ui->listRules->selectedItems(); + if (selection.isEmpty()) + return; + + QListWidgetItem *item = selection.first(); forever { QString new_name = QInputDialog::getText(this, tr("Rule renaming"), tr("Please type the new rule name"), QLineEdit::Normal, item->text()); new_name = new_name.trimmed(); diff --git a/src/rss/automatedrssdownloader.h b/src/rss/automatedrssdownloader.h index 630052112..1373478d3 100644 --- a/src/rss/automatedrssdownloader.h +++ b/src/rss/automatedrssdownloader.h @@ -33,6 +33,7 @@ #include #include +#include #include "rssdownloadrule.h" QT_BEGIN_NAMESPACE @@ -93,6 +94,8 @@ private: QListWidgetItem* m_editedRule; RssDownloadRuleList *m_ruleList; RssDownloadRuleList *m_editableRuleList; + QShortcut *editHotkey; + QShortcut *deleteHotkey; }; #endif // AUTOMATEDRSSDOWNLOADER_H diff --git a/src/rss/rss_imp.cpp b/src/rss/rss_imp.cpp index 0c0982915..b8a7742e6 100644 --- a/src/rss/rss_imp.cpp +++ b/src/rss/rss_imp.cpp @@ -237,10 +237,13 @@ void RSSImp::deleteSelectedItems() ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete these elements from the list?"), tr("&Yes"), tr("&No"), QString(), 0, 1); - else + else { + if (selectedItems.first() == m_feedList->stickyUnreadItem()) + return; ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to delete this element from the list?"), tr("&Yes"), tr("&No"), QString(), 0, 1); + } if (ret) return; @@ -250,6 +253,8 @@ void RSSImp::deleteSelectedItems() m_currentArticle = 0; listArticles->clear(); } + if (item == m_feedList->stickyUnreadItem()) + continue; RssFilePtr rss_item = m_feedList->getRSSItem(item); QTreeWidgetItem* parent = item->parent(); // Notify TreeWidget @@ -366,8 +371,11 @@ void RSSImp::openSelectedArticlesUrls() void RSSImp::renameSelectedRssFile() { QList selectedItems = m_feedList->selectedItems(); - Q_ASSERT(selectedItems.size() == 1); + if (selectedItems.size() != 1) + return; QTreeWidgetItem* item = selectedItems.first(); + if (item == m_feedList->stickyUnreadItem()) + return; RssFilePtr rss_item = m_feedList->getRSSItem(item); bool ok; QString newName; @@ -681,6 +689,11 @@ RSSImp::RSSImp(QWidget *parent) : splitter_h->insertWidget(0, m_feedList); listArticles->setSelectionBehavior(QAbstractItemView::SelectItems); listArticles->setSelectionMode(QAbstractItemView::SingleSelection); + editHotkey = new QShortcut(QKeySequence("F2"), m_feedList, 0, 0, Qt::WidgetShortcut); + connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedRssFile())); + connect(m_feedList, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedRssFile())); + deleteHotkey = new QShortcut(QKeySequence(QKeySequence::Delete), m_feedList, 0, 0, Qt::WidgetShortcut); + connect(deleteHotkey, SIGNAL(activated()), SLOT(deleteSelectedItems())); m_rssManager->loadStreamList(); fillFeedsList(); @@ -729,6 +742,8 @@ RSSImp::~RSSImp() { qDebug("Deleting RSSImp..."); saveFoldersOpenState(); + delete editHotkey; + delete deleteHotkey; delete m_feedList; qDebug("RSSImp deleted"); } diff --git a/src/rss/rss_imp.h b/src/rss/rss_imp.h index ec8b747c4..ccc284fa5 100644 --- a/src/rss/rss_imp.h +++ b/src/rss/rss_imp.h @@ -33,6 +33,7 @@ #define REFRESH_MAX_LATENCY 600000 #include +#include #include "ui_rss.h" #include "rssfolder.h" @@ -91,6 +92,8 @@ private: RssManagerPtr m_rssManager; FeedListWidget *m_feedList; QListWidgetItem* m_currentArticle; + QShortcut *editHotkey; + QShortcut *deleteHotkey; };