From 7adf012f9c910f4ae3656d02e7909f4fcd29a9c4 Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Mon, 22 Jul 2013 18:39:48 +0400 Subject: [PATCH 1/3] Enable edit/rename via F2 or double click in various places --- src/addnewtorrentdialog.cpp | 7 ++++++- src/addnewtorrentdialog.h | 2 ++ src/properties/propertieswidget.cpp | 10 +++++++++- src/properties/propertieswidget.h | 3 +++ src/properties/trackerlist.cpp | 3 +++ src/properties/trackerlist.h | 2 ++ src/transferlistwidget.cpp | 3 +++ src/transferlistwidget.h | 2 ++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index ab2c1e480..4b2e861e3 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -81,6 +81,9 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : loadState(); // Signal / slots connect(ui->adv_button, SIGNAL(clicked(bool)), SLOT(showAdvancedSettings(bool))); + editHotkey = new QShortcut(QKeySequence("F2"), ui->content_tree, 0, 0, Qt::WidgetShortcut); + connect(editHotkey, SIGNAL(activated()), SLOT(renameSelectedFile())); + connect(ui->content_tree, SIGNAL(doubleClicked(QModelIndex)), SLOT(renameSelectedFile())); } AddNewTorrentDialog::~AddNewTorrentDialog() @@ -89,6 +92,7 @@ AddNewTorrentDialog::~AddNewTorrentDialog() delete ui; if (m_contentModel) delete m_contentModel; + delete editHotkey; } void AddNewTorrentDialog::loadState() @@ -390,7 +394,8 @@ void AddNewTorrentDialog::relayout() void AddNewTorrentDialog::renameSelectedFile() { const QModelIndexList selectedIndexes = ui->content_tree->selectionModel()->selectedRows(0); - Q_ASSERT(selectedIndexes.size() == 1); + if (selectedIndexes.size() != 1) + return; const QModelIndex &index = selectedIndexes.first(); // Ask for new name bool ok; diff --git a/src/addnewtorrentdialog.h b/src/addnewtorrentdialog.h index f6d8b078d..60b095b94 100644 --- a/src/addnewtorrentdialog.h +++ b/src/addnewtorrentdialog.h @@ -31,6 +31,7 @@ #ifndef ADDNEWTORRENTDIALOG_H #define ADDNEWTORRENTDIALOG_H +#include #include #include #include @@ -86,6 +87,7 @@ private: boost::intrusive_ptr m_torrentInfo; QStringList m_filesPath; bool m_hasRenamedFile; + QShortcut *editHotkey; }; #endif // ADDNEWTORRENTDIALOG_H diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index 95554036c..05e9d7b93 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -119,6 +119,11 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra refreshTimer = new QTimer(this); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData())); refreshTimer->start(3000); // 3sec + editHotkeyFile = new QShortcut(QKeySequence("F2"), filesList, 0, 0, Qt::WidgetShortcut); + connect(editHotkeyFile, SIGNAL(activated()), SLOT(renameSelectedFile())); + editHotkeyWeb = new QShortcut(QKeySequence("F2"), listWebSeeds, 0, 0, Qt::WidgetShortcut); + connect(editHotkeyWeb, SIGNAL(activated()), SLOT(editWebSeed())); + connect(listWebSeeds, SIGNAL(doubleClicked(QModelIndex)), SLOT(editWebSeed())); } PropertiesWidget::~PropertiesWidget() { @@ -131,6 +136,8 @@ PropertiesWidget::~PropertiesWidget() { delete PropListModel; delete PropDelegate; delete m_tabBar; + delete editHotkeyFile; + delete editHotkeyWeb; qDebug() << Q_FUNC_INFO << "EXIT"; } @@ -519,7 +526,8 @@ void PropertiesWidget::displayWebSeedListMenu(const QPoint&) { void PropertiesWidget::renameSelectedFile() { const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); - Q_ASSERT(selectedIndexes.size() == 1); + if (selectedIndexes.size() != 1) + return; const QModelIndex index = selectedIndexes.first(); // Ask for new name bool ok; diff --git a/src/properties/propertieswidget.h b/src/properties/propertieswidget.h index 5ba610b6e..0ea4738d6 100644 --- a/src/properties/propertieswidget.h +++ b/src/properties/propertieswidget.h @@ -31,6 +31,7 @@ #ifndef PROPERTIESWIDGET_H #define PROPERTIESWIDGET_H +#include #include #include "ui_propertieswidget.h" #include "qtorrenthandle.h" @@ -112,6 +113,8 @@ private: PieceAvailabilityBar *pieces_availability; PropTabBar *m_tabBar; LineEdit *m_contentFilerLine; + QShortcut *editHotkeyFile; + QShortcut *editHotkeyWeb; }; #endif // PROPERTIESWIDGET_H diff --git a/src/properties/trackerlist.cpp b/src/properties/trackerlist.cpp index e9c1132b3..68fbf2cf4 100644 --- a/src/properties/trackerlist.cpp +++ b/src/properties/trackerlist.cpp @@ -75,11 +75,14 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie lsd_item = new QTreeWidgetItem(QStringList() << "" << "** [LSD] **"); insertTopLevelItem(2, lsd_item); setRowColor(2, QColor("grey")); + editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut); + connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker())); loadSettings(); } TrackerList::~TrackerList() { + delete editHotkey; saveSettings(); } diff --git a/src/properties/trackerlist.h b/src/properties/trackerlist.h index 19aee9ae0..e0c71ac6f 100644 --- a/src/properties/trackerlist.h +++ b/src/properties/trackerlist.h @@ -31,6 +31,7 @@ #ifndef TRACKERLIST_H #define TRACKERLIST_H +#include #include #include #include @@ -52,6 +53,7 @@ private: QTreeWidgetItem* dht_item; QTreeWidgetItem* pex_item; QTreeWidgetItem* lsd_item; + QShortcut *editHotkey; public: TrackerList(PropertiesWidget *properties); diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 9d30991c5..bb3a6a5ad 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -141,6 +141,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&))); header()->setContextMenuPolicy(Qt::CustomContextMenu); connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); + + editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut); } TransferListWidget::~TransferListWidget() { @@ -153,6 +155,7 @@ TransferListWidget::~TransferListWidget() { delete nameFilterModel; delete listModel; delete listDelegate; + delete editHotkey; qDebug() << Q_FUNC_INFO << "EXIT"; } diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index d8971c308..8a4dbd2cd 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -31,6 +31,7 @@ #ifndef TRANSFERLISTWIDGET_H #define TRANSFERLISTWIDGET_H +#include #include #include #include "qtorrenthandle.h" @@ -116,6 +117,7 @@ private: QSortFilterProxyModel *labelFilterModel; QBtSession* BTSession; MainWindow *main_window; + QShortcut *editHotkey; }; #endif // TRANSFERLISTWIDGET_H From 107906928a72f92ddc1a752af557758d38e75aba Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Mon, 22 Jul 2013 21:48:55 +0400 Subject: [PATCH 2/3] Enable delete hotkey in web seed and tracker list. Make delete hotkey in transfer list non-global. --- src/mainwindow.cpp | 5 ----- src/properties/propertieswidget.cpp | 7 ++++++- src/properties/propertieswidget.h | 1 + src/properties/trackerlist.cpp | 2 ++ src/properties/trackerlist.h | 1 + src/transferlistwidget.cpp | 2 ++ src/transferlistwidget.h | 1 + 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc1caaefc..ae1c81b74 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -557,11 +557,6 @@ void MainWindow::createKeyboardShortcuts() { connect(switchRSSShortcut, SIGNAL(activated()), this, SLOT(displayRSSTab())); actionDocumentation->setShortcut(QKeySequence("F1")); actionOptions->setShortcut(QKeySequence(QString::fromUtf8("Alt+O"))); -#ifdef Q_WS_MAC - actionDelete->setShortcut(QKeySequence("Ctrl+Backspace")); -#else - actionDelete->setShortcut(QKeySequence(QString::fromUtf8("Del"))); -#endif actionStart->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+S"))); actionStart_All->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+Shift+S"))); actionPause->setShortcut(QKeySequence(QString::fromUtf8("Ctrl+P"))); diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index 05e9d7b93..9e1840d21 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -124,6 +124,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra editHotkeyWeb = new QShortcut(QKeySequence("F2"), listWebSeeds, 0, 0, Qt::WidgetShortcut); connect(editHotkeyWeb, SIGNAL(activated()), SLOT(editWebSeed())); connect(listWebSeeds, SIGNAL(doubleClicked(QModelIndex)), SLOT(editWebSeed())); + deleteHotkeyWeb = new QShortcut(QKeySequence(QKeySequence::Delete), listWebSeeds, 0, 0, Qt::WidgetShortcut); + connect(deleteHotkeyWeb, SIGNAL(activated()), SLOT(deleteSelectedUrlSeeds())); } PropertiesWidget::~PropertiesWidget() { @@ -138,6 +140,7 @@ PropertiesWidget::~PropertiesWidget() { delete m_tabBar; delete editHotkeyFile; delete editHotkeyWeb; + delete deleteHotkeyWeb; qDebug() << Q_FUNC_INFO << "EXIT"; } @@ -663,6 +666,8 @@ void PropertiesWidget::askWebSeed() { void PropertiesWidget::deleteSelectedUrlSeeds() { const QList selectedItems = listWebSeeds->selectedItems(); + if (selectedItems.isEmpty()) + return; bool change = false; foreach (const QListWidgetItem *item, selectedItems) { QString url_seed = item->text(); @@ -691,7 +696,7 @@ void PropertiesWidget::copySelectedWebSeedsToClipboard() const { void PropertiesWidget::editWebSeed() { const QList selected_items = listWebSeeds->selectedItems(); - if (selected_items.isEmpty()) + if (selected_items.size() != 1) return; const QListWidgetItem *selected_item = selected_items.last(); diff --git a/src/properties/propertieswidget.h b/src/properties/propertieswidget.h index 0ea4738d6..65d3b41ea 100644 --- a/src/properties/propertieswidget.h +++ b/src/properties/propertieswidget.h @@ -115,6 +115,7 @@ private: LineEdit *m_contentFilerLine; QShortcut *editHotkeyFile; QShortcut *editHotkeyWeb; + QShortcut *deleteHotkeyWeb; }; #endif // PROPERTIESWIDGET_H diff --git a/src/properties/trackerlist.cpp b/src/properties/trackerlist.cpp index 68fbf2cf4..b4096fb5c 100644 --- a/src/properties/trackerlist.cpp +++ b/src/properties/trackerlist.cpp @@ -77,12 +77,14 @@ TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), propertie setRowColor(2, QColor("grey")); editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut); connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker())); + deleteHotkey = new QShortcut(QKeySequence(QKeySequence::Delete), this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut); loadSettings(); } TrackerList::~TrackerList() { delete editHotkey; + delete deleteHotkey; saveSettings(); } diff --git a/src/properties/trackerlist.h b/src/properties/trackerlist.h index e0c71ac6f..580aa3f38 100644 --- a/src/properties/trackerlist.h +++ b/src/properties/trackerlist.h @@ -54,6 +54,7 @@ private: QTreeWidgetItem* pex_item; QTreeWidgetItem* lsd_item; QShortcut *editHotkey; + QShortcut *deleteHotkey; public: TrackerList(PropertiesWidget *properties); diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index bb3a6a5ad..f8e4bca15 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -143,6 +143,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut); + deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTorrents()), 0, Qt::WidgetShortcut); } TransferListWidget::~TransferListWidget() { @@ -156,6 +157,7 @@ TransferListWidget::~TransferListWidget() { delete listModel; delete listDelegate; delete editHotkey; + delete deleteHotkey; qDebug() << Q_FUNC_INFO << "EXIT"; } diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 8a4dbd2cd..7b817ed17 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -118,6 +118,7 @@ private: QBtSession* BTSession; MainWindow *main_window; QShortcut *editHotkey; + QShortcut *deleteHotkey; }; #endif // TRANSFERLISTWIDGET_H From 42e81b9d190c39a7db88868e5a72888be53db8ee Mon Sep 17 00:00:00 2001 From: Nick Tiskov Date: Mon, 22 Jul 2013 22:38:57 +0400 Subject: [PATCH 3/3] 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; };