Support edit/delete/double click hotkeys in rss feed list and rule list.

This commit is contained in:
Nick Tiskov 2013-07-22 22:38:57 +04:00
parent 107906928a
commit 42e81b9d19
4 changed files with 38 additions and 4 deletions

View file

@ -95,6 +95,14 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& m
Q_ASSERT(ok); Q_ASSERT(ok);
ok = connect(this, SIGNAL(finished(int)), SLOT(on_finished(int))); ok = connect(this, SIGNAL(finished(int)), SLOT(on_finished(int)));
Q_ASSERT(ok); 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(); updateRuleDefinitionBox();
updateFeedList(); updateFeedList();
} }
@ -102,6 +110,8 @@ AutomatedRssDownloader::AutomatedRssDownloader(const QWeakPointer<RssManager>& m
AutomatedRssDownloader::~AutomatedRssDownloader() AutomatedRssDownloader::~AutomatedRssDownloader()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
delete editHotkey;
delete deleteHotkey;
delete ui; delete ui;
delete m_editableRuleList; delete m_editableRuleList;
} }
@ -421,8 +431,11 @@ void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
void AutomatedRssDownloader::renameSelectedRule() void AutomatedRssDownloader::renameSelectedRule()
{ {
QListWidgetItem *item = ui->listRules->currentItem(); const QList<QListWidgetItem*> selection = ui->listRules->selectedItems();
if (!item) return; if (selection.isEmpty())
return;
QListWidgetItem *item = selection.first();
forever { forever {
QString new_name = QInputDialog::getText(this, tr("Rule renaming"), tr("Please type the new rule name"), QLineEdit::Normal, item->text()); 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(); new_name = new_name.trimmed();

View file

@ -33,6 +33,7 @@
#include <QDialog> #include <QDialog>
#include <QWeakPointer> #include <QWeakPointer>
#include <QShortcut>
#include "rssdownloadrule.h" #include "rssdownloadrule.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -93,6 +94,8 @@ private:
QListWidgetItem* m_editedRule; QListWidgetItem* m_editedRule;
RssDownloadRuleList *m_ruleList; RssDownloadRuleList *m_ruleList;
RssDownloadRuleList *m_editableRuleList; RssDownloadRuleList *m_editableRuleList;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
}; };
#endif // AUTOMATEDRSSDOWNLOADER_H #endif // AUTOMATEDRSSDOWNLOADER_H

View file

@ -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?"), 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"), tr("&Yes"), tr("&No"),
QString(), 0, 1); 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?"), 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"), tr("&Yes"), tr("&No"),
QString(), 0, 1); QString(), 0, 1);
}
if (ret) if (ret)
return; return;
@ -250,6 +253,8 @@ void RSSImp::deleteSelectedItems()
m_currentArticle = 0; m_currentArticle = 0;
listArticles->clear(); listArticles->clear();
} }
if (item == m_feedList->stickyUnreadItem())
continue;
RssFilePtr rss_item = m_feedList->getRSSItem(item); RssFilePtr rss_item = m_feedList->getRSSItem(item);
QTreeWidgetItem* parent = item->parent(); QTreeWidgetItem* parent = item->parent();
// Notify TreeWidget // Notify TreeWidget
@ -366,8 +371,11 @@ void RSSImp::openSelectedArticlesUrls()
void RSSImp::renameSelectedRssFile() void RSSImp::renameSelectedRssFile()
{ {
QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = m_feedList->selectedItems();
Q_ASSERT(selectedItems.size() == 1); if (selectedItems.size() != 1)
return;
QTreeWidgetItem* item = selectedItems.first(); QTreeWidgetItem* item = selectedItems.first();
if (item == m_feedList->stickyUnreadItem())
return;
RssFilePtr rss_item = m_feedList->getRSSItem(item); RssFilePtr rss_item = m_feedList->getRSSItem(item);
bool ok; bool ok;
QString newName; QString newName;
@ -681,6 +689,11 @@ RSSImp::RSSImp(QWidget *parent) :
splitter_h->insertWidget(0, m_feedList); splitter_h->insertWidget(0, m_feedList);
listArticles->setSelectionBehavior(QAbstractItemView::SelectItems); listArticles->setSelectionBehavior(QAbstractItemView::SelectItems);
listArticles->setSelectionMode(QAbstractItemView::SingleSelection); 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(); m_rssManager->loadStreamList();
fillFeedsList(); fillFeedsList();
@ -729,6 +742,8 @@ RSSImp::~RSSImp()
{ {
qDebug("Deleting RSSImp..."); qDebug("Deleting RSSImp...");
saveFoldersOpenState(); saveFoldersOpenState();
delete editHotkey;
delete deleteHotkey;
delete m_feedList; delete m_feedList;
qDebug("RSSImp deleted"); qDebug("RSSImp deleted");
} }

View file

@ -33,6 +33,7 @@
#define REFRESH_MAX_LATENCY 600000 #define REFRESH_MAX_LATENCY 600000
#include <QPointer> #include <QPointer>
#include <QShortcut>
#include "ui_rss.h" #include "ui_rss.h"
#include "rssfolder.h" #include "rssfolder.h"
@ -91,6 +92,8 @@ private:
RssManagerPtr m_rssManager; RssManagerPtr m_rssManager;
FeedListWidget *m_feedList; FeedListWidget *m_feedList;
QListWidgetItem* m_currentArticle; QListWidgetItem* m_currentArticle;
QShortcut *editHotkey;
QShortcut *deleteHotkey;
}; };