Browse Source

Add torrent and files deletion with Shift+Delete hotkey

adaptive-webui-19844
pieniacy 8 years ago
parent
commit
5f4114ae76
  1. 10
      src/gui/deletionconfirmationdlg.h
  2. 2
      src/gui/mainwindow.cpp
  3. 26
      src/gui/transferlistwidget.cpp
  4. 5
      src/gui/transferlistwidget.h

10
src/gui/deletionconfirmationdlg.h

@ -42,7 +42,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
Q_OBJECT Q_OBJECT
public: public:
DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name): QDialog(parent) { DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) {
setupUi(this); setupUi(this);
if (size == 1) if (size == 1)
label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name)); label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name));
@ -54,7 +54,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
rememberBtn->setIcon(GuiIconProvider::instance()->getIcon("object-locked")); rememberBtn->setIcon(GuiIconProvider::instance()->getIcon("object-locked"));
move(Utils::Misc::screenCenter(this)); move(Utils::Misc::screenCenter(this));
checkPermDelete->setChecked(Preferences::instance()->deleteTorrentFilesAsDefault()); checkPermDelete->setChecked(defaultDeleteFiles || Preferences::instance()->deleteTorrentFilesAsDefault());
connect(checkPermDelete, SIGNAL(clicked()), this, SLOT(updateRememberButtonState())); connect(checkPermDelete, SIGNAL(clicked()), this, SLOT(updateRememberButtonState()));
buttonBox->button(QDialogButtonBox::Cancel)->setFocus(); buttonBox->button(QDialogButtonBox::Cancel)->setFocus();
} }
@ -63,10 +63,10 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
return checkPermDelete->isChecked(); return checkPermDelete->isChecked();
} }
static bool askForDeletionConfirmation(bool& delete_local_files, const int& size, const QString& name) { static bool askForDeletionConfirmation(bool& deleteLocalFiles, const int& size, const QString& name) {
DeletionConfirmationDlg dlg(NULL, size, name); DeletionConfirmationDlg dlg(NULL, size, name, deleteLocalFiles);
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
delete_local_files = dlg.shouldDeleteLocalFiles(); deleteLocalFiles = dlg.shouldDeleteLocalFiles();
return true; return true;
} }
return false; return false;

2
src/gui/mainwindow.cpp

@ -248,7 +248,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_ui->actionStartAll, SIGNAL(triggered()), m_transferListWidget, SLOT(resumeAllTorrents())); connect(m_ui->actionStartAll, SIGNAL(triggered()), m_transferListWidget, SLOT(resumeAllTorrents()));
connect(m_ui->actionPause, SIGNAL(triggered()), m_transferListWidget, SLOT(pauseSelectedTorrents())); connect(m_ui->actionPause, SIGNAL(triggered()), m_transferListWidget, SLOT(pauseSelectedTorrents()));
connect(m_ui->actionPauseAll, SIGNAL(triggered()), m_transferListWidget, SLOT(pauseAllTorrents())); connect(m_ui->actionPauseAll, SIGNAL(triggered()), m_transferListWidget, SLOT(pauseAllTorrents()));
connect(m_ui->actionDelete, SIGNAL(triggered()), m_transferListWidget, SLOT(deleteSelectedTorrents())); connect(m_ui->actionDelete, SIGNAL(triggered()), m_transferListWidget, SLOT(softDeleteSelectedTorrents()));
connect(m_ui->actionTopPriority, SIGNAL(triggered()), m_transferListWidget, SLOT(topPrioSelectedTorrents())); connect(m_ui->actionTopPriority, SIGNAL(triggered()), m_transferListWidget, SLOT(topPrioSelectedTorrents()));
connect(m_ui->actionIncreasePriority, SIGNAL(triggered()), m_transferListWidget, SLOT(increasePrioSelectedTorrents())); connect(m_ui->actionIncreasePriority, SIGNAL(triggered()), m_transferListWidget, SLOT(increasePrioSelectedTorrents()));
connect(m_ui->actionDecreasePriority, SIGNAL(triggered()), m_transferListWidget, SLOT(decreasePrioSelectedTorrents())); connect(m_ui->actionDecreasePriority, SIGNAL(triggered()), m_transferListWidget, SLOT(decreasePrioSelectedTorrents()));

26
src/gui/transferlistwidget.cpp

@ -155,7 +155,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window)
connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings())); connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings()));
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut); editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(renameSelectedTorrent()), 0, Qt::WidgetShortcut);
deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTorrents()), 0, Qt::WidgetShortcut); deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(softDeleteSelectedTorrents()), 0, Qt::WidgetShortcut);
permDeleteHotkey = new QShortcut(QKeySequence("Shift+Delete"), this, SLOT(permDeleteSelectedTorrents()), 0, Qt::WidgetShortcut);
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
// This hack fixes reordering of first column with Qt5. // This hack fixes reordering of first column with Qt5.
@ -309,19 +310,28 @@ void TransferListWidget::pauseVisibleTorrents()
} }
} }
void TransferListWidget::deleteSelectedTorrents() void TransferListWidget::softDeleteSelectedTorrents()
{
deleteSelectedTorrents(false);
}
void TransferListWidget::permDeleteSelectedTorrents()
{
deleteSelectedTorrents(true);
}
void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles)
{ {
if (main_window->currentTabWidget() != this) return; if (main_window->currentTabWidget() != this) return;
const QList<BitTorrent::TorrentHandle *> torrents = getSelectedTorrents(); const QList<BitTorrent::TorrentHandle *> torrents = getSelectedTorrents();
if (torrents.empty()) return; if (torrents.empty()) return;
bool delete_local_files = false;
if (Preferences::instance()->confirmTorrentDeletion() && if (Preferences::instance()->confirmTorrentDeletion() &&
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, torrents.size(), torrents[0]->name())) !DeletionConfirmationDlg::askForDeletionConfirmation(deleteLocalFiles, torrents.size(), torrents[0]->name()))
return; return;
foreach (BitTorrent::TorrentHandle *const torrent, torrents) foreach (BitTorrent::TorrentHandle *const torrent, torrents)
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), delete_local_files); BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
} }
void TransferListWidget::deleteVisibleTorrents() void TransferListWidget::deleteVisibleTorrents()
@ -332,12 +342,12 @@ void TransferListWidget::deleteVisibleTorrents()
for (int i = 0; i < nameFilterModel->rowCount(); ++i) for (int i = 0; i < nameFilterModel->rowCount(); ++i)
torrents << listModel->torrentHandle(mapToSource(nameFilterModel->index(i, 0))); torrents << listModel->torrentHandle(mapToSource(nameFilterModel->index(i, 0)));
bool delete_local_files = false; bool deleteLocalFiles = false;
if (Preferences::instance()->confirmTorrentDeletion() && if (Preferences::instance()->confirmTorrentDeletion() &&
!DeletionConfirmationDlg::askForDeletionConfirmation(delete_local_files, torrents.size(), torrents[0]->name())) !DeletionConfirmationDlg::askForDeletionConfirmation(deleteLocalFiles, torrents.size(), torrents[0]->name()))
return; return;
foreach (BitTorrent::TorrentHandle *const torrent, torrents) foreach (BitTorrent::TorrentHandle *const torrent, torrents)
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), delete_local_files); BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
} }
void TransferListWidget::increasePrioSelectedTorrents() void TransferListWidget::increasePrioSelectedTorrents()

5
src/gui/transferlistwidget.h

@ -68,7 +68,9 @@ public slots:
void startVisibleTorrents(); void startVisibleTorrents();
void pauseSelectedTorrents(); void pauseSelectedTorrents();
void pauseVisibleTorrents(); void pauseVisibleTorrents();
void deleteSelectedTorrents(); void softDeleteSelectedTorrents();
void permDeleteSelectedTorrents();
void deleteSelectedTorrents(bool deleteLocalFiles);
void deleteVisibleTorrents(); void deleteVisibleTorrents();
void increasePrioSelectedTorrents(); void increasePrioSelectedTorrents();
void decreasePrioSelectedTorrents(); void decreasePrioSelectedTorrents();
@ -119,6 +121,7 @@ private:
MainWindow *main_window; MainWindow *main_window;
QShortcut *editHotkey; QShortcut *editHotkey;
QShortcut *deleteHotkey; QShortcut *deleteHotkey;
QShortcut *permDeleteHotkey;
}; };
#endif // TRANSFERLISTWIDGET_H #endif // TRANSFERLISTWIDGET_H

Loading…
Cancel
Save