From e4590ef43193c7aad892a819a42eaf9d8ffe8a98 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 29 Oct 2006 10:17:53 +0000 Subject: [PATCH] - Added an action to delete downloads from download list and from hard drive too --- TODO | 1 - src/GUI.cpp | 107 +++++++++++++++++++++------------ src/GUI.h | 2 +- src/Icons/skin/delete_perm.png | Bin 0 -> 2665 bytes src/MainWindow.ui | 8 +-- src/icons.qrc | 1 + 6 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 src/Icons/skin/delete_perm.png diff --git a/TODO b/TODO index ba5e9592b..380c36467 100644 --- a/TODO +++ b/TODO @@ -33,5 +33,4 @@ - Add Report a bug in qBittorrent menu entry - Display remaining HD space (check it before adding a new torrent?) - Move novaUpdater to a Thread (probably use downloadThread) to prevent GUI freezing -- Add button : delete from list and Hard drive - Check if there is at least one file in selection (torrent properties) diff --git a/src/GUI.cpp b/src/GUI.cpp index b77bf74d6..cd3ded823 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -82,7 +82,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ connecStatusLblIcon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/skin/disconnected.png"))); connecStatusLblIcon->setToolTip(tr("Connection Status:
Offline
No peers found...")); toolBar->addWidget(connecStatusLblIcon); - actionDelete_All->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete_all.png"))); + actionDelete_Permanently->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete_perm.png"))); actionTorrent_Properties->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/properties.png"))); actionCreate_torrent->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/new.png"))); info_icon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/log.png"))); @@ -138,7 +138,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ // Connecting Actions to slots connect(actionExit, SIGNAL(triggered()), this, SLOT(close())); connect(actionOpen, SIGNAL(triggered()), this, SLOT(askForTorrents())); - connect(actionDelete_All, SIGNAL(triggered()), this, SLOT(deleteAll())); + connect(actionDelete_Permanently, SIGNAL(triggered()), this, SLOT(deletePermanently())); connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelection())); connect(actionOptions, SIGNAL(triggered()), this, SLOT(showOptions())); connect(actionDownload_from_URL, SIGNAL(triggered()), this, SLOT(askForTorrentUrl())); @@ -374,6 +374,7 @@ void GUI::displayDLListMenu(const QPoint& pos){ myDLLlistMenu.addAction(actionPause); } myDLLlistMenu.addAction(actionDelete); + myDLLlistMenu.addAction(actionDelete_Permanently); myDLLlistMenu.addAction(actionTorrent_Properties); if(!options->getPreviewProgram().isEmpty() && isFilePreviewPossible(h) && selectedIndexes.size()<=DLListModel->columnCount()){ myDLLlistMenu.addAction(actionPreview_file); @@ -392,7 +393,6 @@ void GUI::displayGUIMenu(const QPoint& pos){ myGUIMenu.addAction(actionDownload_from_URL); myGUIMenu.addAction(actionStart_All); myGUIMenu.addAction(actionPause_All); - myGUIMenu.addAction(actionDelete_All); myGUIMenu.addAction(actionExit); myGUIMenu.exec(mapToGlobal(pos)); } @@ -1182,49 +1182,76 @@ void GUI::saveFastResumeData() const{ qDebug("Fast resume data saved"); } -// delete All Downloads in the list -void GUI::deleteAll(){ +// delete from download list AND from hard drive +void GUI::deletePermanently(){ QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); - QStringList torrents; QString scan_dir = options->getScanDir(); bool isScanningDir = !scan_dir.isNull(); if(isScanningDir && scan_dir.at(scan_dir.length()-1) != QDir::separator()){ scan_dir += QDir::separator(); } - - if(QMessageBox::question( - this, - tr("Are you sure? -- qBittorrent"), - tr("Are you sure you want to delete all files in download list?"), - tr("&Yes"), tr("&No"), - QString(), 0, 1) == 0) { - // User clicked YES - // Remove torrents from BT session - foreach(torrent_handle h, handles){ - // remove it from scan dir or it will start again - if(isScanningDir){ - QFile::remove(scan_dir+QString(h.get_torrent_info().name().c_str())+".torrent"); - } - // remove it from session - s->remove_torrent(h); - } - // Clear handles - handles.clear(); - // Clear torrent backup directory - torrents = torrentBackup.entryList(); - QString torrent; - foreach(torrent, torrents){ - if(torrent.endsWith(".fastresume") || torrent.endsWith(".torrent") || torrent.endsWith(".pieces") || torrent.endsWith(".paused") || torrent.endsWith(".incremental") || torrent.endsWith(".savepath")){ - torrentBackup.remove(torrent); - } - } - // Clear Download list - DLListModel->removeRows(0, DLListModel->rowCount()); - nbTorrents = 0; - tabs->setTabText(0, tr("Transfers") +" (0)"); - //Update info Bar - setInfoBar(tr("Download list cleared.")); - } + QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); + if(!selectedIndexes.isEmpty()){ + if(QMessageBox::question( + this, + tr("Are you sure? -- qBittorrent"), + tr("Are you sure you want to delete the selected item(s) in download list and in hard drive?"), + tr("&Yes"), tr("&No"), + QString(), 0, 1) == 0) { + //User clicked YES + QModelIndex index; + QList > sortedIndexes; + // We have to remove items from the bottom + // to the top in order not to change indexes + // of files to delete. + foreach(index, selectedIndexes){ + if(index.column() == NAME){ + qDebug("row to delete: %d", index.row()); + misc::insertSort2(sortedIndexes, QPair(index.row(), index), Qt::DescendingOrder); + } + } + QPair sortedIndex; + foreach(sortedIndex, sortedIndexes){ + qDebug("deleting row: %d, %d, col: %d", sortedIndex.first, sortedIndex.second.row(), sortedIndex.second.column()); + // Get the file name + QString fileName = sortedIndex.second.data().toString(); + QString savePath; + // Delete item from download list + DLListModel->removeRow(sortedIndex.first); + // Get handle and remove the torrent + QMap::iterator it = handles.find(fileName); + if(it != handles.end() && it.key() == fileName) { + torrent_handle h = it.value(); + savePath = QString::fromUtf8(h.save_path().string().c_str()); + s->remove_torrent(h); + // Remove torrent from handles + handles.erase(it); + // remove it from scan dir or it will start again + if(isScanningDir){ + QFile::remove(scan_dir+fileName+".torrent"); + } + // Remove it from torrent backup directory + torrentBackup.remove(fileName+".torrent"); + torrentBackup.remove(fileName+".fastresume"); + torrentBackup.remove(fileName+".paused"); + torrentBackup.remove(fileName+".incremental"); + torrentBackup.remove(fileName+".pieces"); + torrentBackup.remove(fileName+".savepath"); + // Remove from Hard drive TODO + qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName)); + QDir downloadedDir(savePath+QDir::separator()+fileName); + downloadedDir.rmpath(savePath+QDir::separator()+fileName); + QFile::remove(savePath+QDir::separator()+fileName); + // Update info bar + setInfoBar("'" + fileName +"' "+tr("removed.", " removed.")); + --nbTorrents; + tabs->setTabText(0, tr("Transfers") +" ("+QString(misc::toString(nbTorrents).c_str())+")"); + }else{ + std::cerr << "Error: Could not find the torrent handle supposed to be removed\n"; + } + } + } + } } // delete selected items in the list diff --git a/src/GUI.h b/src/GUI.h index 5e236943f..be0e062e4 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -144,7 +144,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void pauseSelection(); void startSelection(); void askForTorrents(); - void deleteAll(); + void deletePermanently(); void deleteSelection(); void resumeUnfinished(); void saveFastResumeData() const; diff --git a/src/Icons/skin/delete_perm.png b/src/Icons/skin/delete_perm.png new file mode 100644 index 0000000000000000000000000000000000000000..a3442b9c5bb0e881a36bfb279463560909d3e1be GIT binary patch literal 2665 zcmV-v3YPVWP)n5A0|INk~E{YN3=6L}?q4_(9ZGMTvT-LJ-tS{nu8ajf#*e zA%Rpiz>i9_{{hiJTGU)%kpPifENqexUs<2)W7m6ncJ99Kw_evstw0_5^Ulukz0Z3+ z@3T@EhWIkaQzu_aM-=7WNJP0yjzn&UBn<*mXZ>!tj4+%De1F{cy%FE@F1>v6#Kf1` zSNb9VCw}+xVO7;1lNI$*$jX2$N9Zk??$DC9J;?inKEi;PmkB)gwCmb$y!4x=-u=G- zJbCiekfud{8qxG0OR~}>$r{;>AfzSBGBhbb1Oe<&q5q5|B*Ou~02qkx(swuOJNB!N zQ~T2^C!e1F(g4Wo2Q}UJg{10_$g&P8qCnMDbho#nqcx6>CKH{8kIqyJ%2gY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faY#&D4$Vhd@lP$9MVrg7k#KfpJ>_cP39bDL656X9mMZVVuXp%V>HPR&qVDX^;r z1hl6V`XhF2D_REt?yZ$yC5aI z@!ILXQ%lZ?G?>I6td65Z-KDC9^Or`baHmkKtP9U6?jKtlrRUhj=VbZjqA7tWtt77p zAN$b*{pr0wRHEkBJcmYzW)PVepx+DB)4F)2Qe4Bz+%y(uu3~j|0?ed|)(*6!y6G7W zMm&Kesh^g%b}qV)GB?Kma{i4!U!<2yo2$lhfsL!IqG-ivHPLFJ)!d)H{kGe`dg$Ty zuKs&Su*O2v+lgCMrm)JgBGeO8t50oJE#<|zrbk7u%Tx)JzUo?b_Jgr2!+)Ed7{5;Y z7MQ=7FnNyAvbINnLA26pr`6W@yzP#=@7^(V+a0Z)y@ML53RX<@AE))gYy2jtp9F$% z+?r+Omgi>{rmv4)AN}w{y2Aytw(T>|#zh3S|1y#!v2!CLiA_M=wED^ZS5iIwcQm!8 zdJ|2pP0@HFs+)0v#I`CVAIr6JF<&g@SLat2XGh8YKk3#it))$a - + @@ -784,7 +784,7 @@ - + @@ -848,9 +848,9 @@ Documentation - + - Delete All + Delete Permanently diff --git a/src/icons.qrc b/src/icons.qrc index 89e9ed9a6..de4751891 100644 --- a/src/icons.qrc +++ b/src/icons.qrc @@ -40,6 +40,7 @@ Icons/flags/bulgaria.png Icons/flags/greece.png Icons/flags/finland.png + Icons/skin/delete_perm.png Icons/skin/properties.png Icons/skin/play_all.png Icons/skin/remove.png