Browse Source

- FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0)

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
862d24ac48
  1. 1
      Changelog
  2. 2
      TODO
  3. 35
      src/GUI.cpp
  4. 1
      src/GUI.h
  5. 34
      src/bittorrent.cpp
  6. 5
      src/bittorrent.h

1
Changelog

@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
- FEATURE: Added an option to add torrents in paused state
- FEATURE: Added an option to set the max number of connections per torrent
- FEATURE: Added an option to set the max number of uploads per torrent
- FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0)
- I18N: Added Hungarian translation
- I18N: Added Brazilian translation
- BUGFIX: Progress of paused torrents is now correct on restart

2
TODO

@ -63,6 +63,7 @@ @@ -63,6 +63,7 @@
* beta 7
- Add "Mark all as read" feature for RSS
- update doc for plugins (and add screenies)
- update doc for options
- Redesign options (fully)
- Review torrent content selection
* check the one in ktorrent
@ -102,6 +103,7 @@ beta6->beta7 changelog: @@ -102,6 +103,7 @@ beta6->beta7 changelog:
- FEATURE: Allow to disable UPnP/NAT-PMP/LSD
- FEATURE: Added an option to set the max number of connections per torrent
- FEATURE: Added an option to set the max number of uploads per torrent
- FEATURE: Added an option to automatically delete torrents when they reach a given ratio (>= 1.0)
- BUGFIX: In torrent content, it is now easier to filter all torrents using right click menu
- BUGFIX: Updated man page / README / INSTALL
- BUGFIX: Paused torrents could be displayed as connected for a sec after checking

35
src/GUI.cpp

@ -112,6 +112,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for @@ -112,6 +112,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), for
connect(BTSession, SIGNAL(scanDirFoundTorrents(const QStringList&)), this, SLOT(processScannedFiles(const QStringList&)));
connect(BTSession, SIGNAL(newDownloadedTorrent(QString, QString)), this, SLOT(processDownloadedFiles(QString, QString)));
connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(BTSession, SIGNAL(torrent_deleted(QString, QString, bool)), this, SLOT(deleteTorrent(QString, QString, bool)));
qDebug("create tabWidget");
tabs = new QTabWidget();
// Download torrents tab
@ -661,6 +662,16 @@ void GUI::on_actionDelete_Permanently_triggered() { @@ -661,6 +662,16 @@ void GUI::on_actionDelete_Permanently_triggered() {
}
}
void GUI::deleteTorrent(QString hash, QString fileName, bool finished) {
if(finished) {
finishedTorrentTab->deleteTorrent(hash);
} else {
downloadingTorrentTab->deleteTorrent(hash);
}
// Update info bar
downloadingTorrentTab->setInfoBar(tr("'%1' was removed because its ratio reached the maximum value you set.", "%1 is a file name").arg(fileName));
}
// delete selected items in the list
void GUI::on_actionDelete_triggered() {
QStringList hashes;
@ -778,8 +789,16 @@ void GUI::processDownloadedFiles(QString path, QString url) { @@ -778,8 +789,16 @@ void GUI::processDownloadedFiles(QString path, QString url) {
void GUI::configureSession(bool deleteOptions) {
qDebug("Configuring session");
// Downloads
// Save path
BTSession->setDefaultSavePath(options->getSavePath());
BTSession->preAllocateAllFiles(options->preAllocateAllFiles());
BTSession->startTorrentsInPause(options->addTorrentsInPause());
// * Scan dir
if(options->getScanDir().isNull()) {
BTSession->disableDirectoryScanning();
}else{
BTSession->enableDirectoryScanning(options->getScanDir());
}
// Connection
// * Ports binding
unsigned short old_listenPort = BTSession->getListenPort();
@ -906,12 +925,11 @@ void GUI::configureSession(bool deleteOptions) { @@ -906,12 +925,11 @@ void GUI::configureSession(bool deleteOptions) {
downloadingTorrentTab->setInfoBar(tr("Encryption support [OFF]"), QString::fromUtf8("blue"));
}
BTSession->applyEncryptionSettings(encryptionSettings);
// IP Filter
// Configure session regarding options
BTSession->setDefaultSavePath(options->getSavePath());
// Apply ratio (0 if disabled)
// * Desired ratio
BTSession->setGlobalRatio(options->getDesiredRatio());
// Apply filtering settings
// * Maximum ratio
BTSession->setDeleteRatio(options->getDeleteRatio());
// Ip Filter
if(options->isFilteringEnabled()) {
BTSession->enableIPFilter(options->getFilter());
downloadingTorrentTab->setBottomTabEnabled(1, true);
@ -919,12 +937,7 @@ void GUI::configureSession(bool deleteOptions) { @@ -919,12 +937,7 @@ void GUI::configureSession(bool deleteOptions) {
BTSession->disableIPFilter();
downloadingTorrentTab->setBottomTabEnabled(1, false);
}
// Scan dir stuff
if(options->getScanDir().isNull()) {
BTSession->disableDirectoryScanning();
}else{
BTSession->enableDirectoryScanning(options->getScanDir());
}
// Clean up
if(deleteOptions) {
delete options;
}

1
src/GUI.h

@ -132,6 +132,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -132,6 +132,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void processScannedFiles(const QStringList& params);
void processDownloadedFiles(QString path, QString url);
void downloadFromURLList(const QStringList& urls);
void deleteTorrent(QString hash, QString fileName, bool finished);
void finishedTorrent(QTorrentHandle& h) const;
void torrentChecked(QString hash) const;
void updateLists();

34
src/bittorrent.cpp

@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
#define MAX_TRACKER_ERRORS 2
// Main constructor
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4) {
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1) {
// To avoid some exceptions
fs::path::default_name_check(fs::no_check);
// Creating bittorrent session
@ -100,6 +100,26 @@ void bittorrent::preAllocateAllFiles(bool b) { @@ -100,6 +100,26 @@ void bittorrent::preAllocateAllFiles(bool b) {
}
}
void bittorrent::deleteBigRatios() {
if(max_ratio == -1) return;
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
for(unsigned int i=0; i<nbHandles; ++i) {
QTorrentHandle h = handles[i];
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
continue;
}
QString hash = h.hash();
if(getRealRatio(hash) > max_ratio) {
bool finished = finishedTorrents.contains(hash);
QString fileName = h.name();
deleteTorrent(hash);
emit torrent_deleted(hash, fileName, finished);
}
}
}
void bittorrent::setDownloadLimit(QString hash, long val) {
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid())
@ -149,6 +169,9 @@ void bittorrent::updateETAs() { @@ -149,6 +169,9 @@ void bittorrent::updateETAs() {
}
}
}
// Delete big ratios
if(max_ratio != -1)
deleteBigRatios();
}
long bittorrent::getETA(QString hash) const{
@ -929,6 +952,7 @@ void bittorrent::setUploadRateLimit(long rate) { @@ -929,6 +952,7 @@ void bittorrent::setUploadRateLimit(long rate) {
// libtorrent allow to adjust ratio for each torrent
// This function will apply to same ratio to all torrents
void bittorrent::setGlobalRatio(float ratio) {
if(ratio != -1 && ratio < 1.) ratio = 1.;
std::vector<torrent_handle> handles = s->get_torrents();
unsigned int nbHandles = handles.size();
for(unsigned int i=0; i<nbHandles; ++i) {
@ -941,6 +965,14 @@ void bittorrent::setGlobalRatio(float ratio) { @@ -941,6 +965,14 @@ void bittorrent::setGlobalRatio(float ratio) {
}
}
// Torrents will a ratio superior to the given value will
// be automatically deleted
void bittorrent::setDeleteRatio(float ratio) {
if(ratio != -1 && ratio < 1.) ratio = 1.;
max_ratio = ratio;
deleteBigRatios();
}
bool bittorrent::loadTrackerFile(QString hash) {
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QFile tracker_file(torrentBackup.path()+QDir::separator()+ hash + ".trackers");

5
src/bittorrent.h

@ -61,6 +61,7 @@ class bittorrent : public QObject{ @@ -61,6 +61,7 @@ class bittorrent : public QObject{
bool addInPause;
int maxConnecsPerTorrent;
int maxUploadsPerTorrent;
float max_ratio;
protected:
QString getSavePath(QString hash);
@ -119,6 +120,7 @@ class bittorrent : public QObject{ @@ -119,6 +120,7 @@ class bittorrent : public QObject{
void setDownloadRateLimit(long rate);
void setUploadRateLimit(long rate);
void setGlobalRatio(float ratio);
void setDeleteRatio(float ratio);
void setDHTPort(int dht_port);
void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true);
void setSessionSettings(session_settings sessionSettings);
@ -142,6 +144,7 @@ class bittorrent : public QObject{ @@ -142,6 +144,7 @@ class bittorrent : public QObject{
bool loadTrackerFile(QString hash);
void saveTrackerFile(QString hash);
void reloadTorrent(const QTorrentHandle &h); // This is protected now, call pauseAndReloadTorrent() instead
void deleteBigRatios();
signals:
void invalidTorrent(QString path);
@ -161,7 +164,7 @@ class bittorrent : public QObject{ @@ -161,7 +164,7 @@ class bittorrent : public QObject{
void fastResumeDataRejected(QString name);
void urlSeedProblem(QString url, QString msg);
void torrentFinishedChecking(QString hash);
void torrent_deleted(QString hash, QString fileName, bool finished);
};
#endif

Loading…
Cancel
Save