From f4502367f3cab5eb8bfbc362b1a20173f1fa93b9 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 8 Mar 2009 16:26:02 +0000 Subject: [PATCH] - Allow to define a temporary download folder --- Changelog | 3 ++- src/GUI.cpp | 5 +++++ src/bittorrent.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/bittorrent.h | 2 ++ src/options.ui | 2 +- src/options_imp.cpp | 4 +++- 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Changelog b/Changelog index 06f9c5004..a01f9f8c9 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ -* Unknown - Christophe Dumez - v1.3.3 +* Unknown - Christophe Dumez - v1.4.0 + - FEATURE: Allow to define temporary download folder - COSMETIC: Redesigned program preferences - COSMETIC: Updated icons set diff --git a/src/GUI.cpp b/src/GUI.cpp index 1dbc6e4c7..e67e4a3ce 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -945,6 +945,11 @@ void GUI::configureSession(bool deleteOptions) { // Downloads // * Save path BTSession->setDefaultSavePath(options->getSavePath()); + if(options->isTempPathEnabled()) { + BTSession->setDefaultTempPath(options->getTempPath()); + } else { + BTSession->setDefaultTempPath(QString::null); + } BTSession->preAllocateAllFiles(options->preAllocateAllFiles()); BTSession->startTorrentsInPause(options->addTorrentsInPause()); // * Scan dir diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index e96f1cf8d..82990afb3 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -439,7 +439,11 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr savepath_file.write(savePath.toUtf8()); savepath_file.close(); } - p.save_path = savePath.toUtf8().data(); + if(defaultTempPath.isEmpty()) { + p.save_path = savePath.toUtf8().data(); + } else { + p.save_path = defaultTempPath.toUtf8().data(); + } p.ti = t; // Preallocate all? if(preAllocateAll) @@ -895,6 +899,31 @@ void bittorrent::setDefaultSavePath(QString savepath) { defaultSavePath = savepath; } +void bittorrent::setDefaultTempPath(QString temppath) { + if(defaultTempPath == temppath) + return; + if(temppath.isEmpty()) { + // Disabling temp dir + // Moving all torrents to their destination folder + std::vector torrents = getTorrents(); + std::vector::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(!h.is_valid()) continue; + h.move_storage(getSavePath(h.hash())); + } + } else { + std::vector torrents = getTorrents(); + std::vector::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(!h.is_valid()) continue; + h.move_storage(temppath); + } + } + defaultTempPath = temppath; +} + // Enable directory scanning void bittorrent::enableDirectoryScanning(QString scan_dir) { if(!scan_dir.isEmpty()) { @@ -1111,6 +1140,15 @@ void bittorrent::readAlerts() { finished_file.open(QIODevice::WriteOnly | QIODevice::Text); finished_file.close(); h.save_resume_data(); + // Move to download directory if necessary + if(!defaultTempPath.isEmpty()) { + // Check if directory is different + QDir current_dir(h.save_path()); + QDir save_dir(getSavePath(h.hash())); + if(current_dir != save_dir) { + h.move_storage(save_dir.path()); + } + } qDebug("Received finished alert for %s", h.name().toUtf8().data()); } } diff --git a/src/bittorrent.h b/src/bittorrent.h index a03f92571..c1ce8fc74 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -51,6 +51,7 @@ class bittorrent : public QObject { bool DHTEnabled; QPointer downloader; QString defaultSavePath; + QString defaultTempPath; QHash > trackersErrors; QStringList consoleMessages; QStringList peerBanMessages; @@ -142,6 +143,7 @@ class bittorrent : public QObject { void setSessionSettings(session_settings sessionSettings); void startTorrentsInPause(bool b); void setDefaultSavePath(QString savepath); + void setDefaultTempPath(QString temppath); void applyEncryptionSettings(pe_settings se); void loadFilesPriorities(QTorrentHandle& h); void setDownloadLimit(QString hash, long val); diff --git a/src/options.ui b/src/options.ui index d26400af0..1ee77aa5f 100644 --- a/src/options.ui +++ b/src/options.ui @@ -200,7 +200,7 @@ - 1 + 0 diff --git a/src/options_imp.cpp b/src/options_imp.cpp index b382cb6bc..d050856d0 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -515,11 +515,13 @@ void options_imp::loadOptions(){ textSavePath->setText(settings.value(QString::fromUtf8("SavePath"), home+"qBT_dir").toString()); if(settings.value(QString::fromUtf8("TempPathEnabled"), false).toBool()) { // enable + checkTempFolder->setChecked(true); enableTempPathInput(2); } else { + checkTempFolder->setChecked(false); enableTempPathInput(0); } - textTempPath->setText(settings.value(QString::fromUtf8("TempPath"), home+"qBT_dir").toString()); + textTempPath->setText(settings.value(QString::fromUtf8("TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString()); checkPreallocateAll->setChecked(settings.value(QString::fromUtf8("PreAllocation"), false).toBool()); checkAdditionDialog->setChecked(settings.value(QString::fromUtf8("AdditionDialog"), true).toBool()); checkStartPaused->setChecked(settings.value(QString::fromUtf8("StartInPause"), false).toBool());