diff --git a/Changelog b/Changelog index ddb949071..0867594c6 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,6 @@ * Unreleased - Christophe Dumez - v2.1.0 - FEATURE: Torrents can be labeled/categorized + - FEATURE: Labeled torrent can be downloaded corresponding subfolders - FEATURE: Disk cache size can be set from preferences - FEATURE: Peer Exchange (PeX) can be disabled from preferences diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 19c10c6ca..f4325d3e3 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -102,6 +102,7 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit downloader = new downloadThread(this); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); + appendLabelToSavePath = Preferences::appendTorrentLabel(); // Apply user settings to Bittorrent session configureSession(); qDebug("* BTSession constructed"); @@ -233,6 +234,7 @@ void Bittorrent::configureSession() { } else { setDefaultTempPath(QString::null); } + setAppendLabelToSavePath(Preferences::appendTorrentLabel()); preAllocateAllFiles(Preferences::preAllocateAllFiles()); startTorrentsInPause(Preferences::addTorrentsInPause()); // * Scan dir @@ -1279,6 +1281,38 @@ void Bittorrent::setDefaultTempPath(QString temppath) { defaultTempPath = temppath; } +void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) { + if(!h.is_valid()) return; + QString label = TorrentPersistentData::getLabel(h.hash()); + if(label.isEmpty()) return; + // Current save path + QString old_save_path = TorrentPersistentData::getSavePath(h.hash()); + QDir old_dir(old_save_path); + if(old_dir.dirName() != label) { + QString new_save_path = old_dir.absoluteFilePath(label); + TorrentPersistentData::saveSavePath(h.hash(), new_save_path); + if(old_dir == QDir(h.save_path())) { + // Move storage + h.move_storage(new_save_path); + } + } +} + +void Bittorrent::setAppendLabelToSavePath(bool append) { + if(appendLabelToSavePath != Preferences::appendTorrentLabel()) { + appendLabelToSavePath = !appendLabelToSavePath; + if(appendLabelToSavePath) { + // Move torrents storage to sub folder with label name + std::vector torrents = getTorrents(); + std::vector::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + appendLabelToTorrentSavePath(h); + } + } + } +} + // Enable directory scanning void Bittorrent::enableDirectoryScanning(QString scan_dir) { if(!scan_dir.isEmpty()) { @@ -1672,24 +1706,40 @@ QString Bittorrent::getSavePath(QString hash) { QString savePath; if(TorrentTempData::hasTempData(hash)) { savePath = TorrentTempData::getSavePath(hash); + if(savePath.isEmpty()) + savePath = defaultSavePath; + if(appendLabelToSavePath) { + QString label = TorrentTempData::getLabel(hash); + if(!label.isEmpty()) { + QDir save_dir(savePath); + if(save_dir.dirName() != label) { + savePath = save_dir.absoluteFilePath(label); + } + } + } qDebug("getSavePath, got save_path from temp data: %s", savePath.toLocal8Bit().data()); } else { savePath = TorrentPersistentData::getSavePath(hash); + if(savePath.isEmpty()) + savePath = defaultSavePath; + if(appendLabelToSavePath) { + QString label = TorrentPersistentData::getLabel(hash); + if(!label.isEmpty()) { + QDir save_dir(savePath); + if(save_dir.dirName() != label) { + savePath = save_dir.absoluteFilePath(label); + } + } + } qDebug("getSavePath, got save_path from persistent data: %s", savePath.toLocal8Bit().data()); } - if(savePath.isEmpty()) { - // use default save path if no other can be found - qDebug("Using default save path because none was set: %s", defaultSavePath.toLocal8Bit().data()); - savePath = defaultSavePath; - } // Checking if savePath Dir exists // create it if it is not QDir saveDir(savePath); if(!saveDir.exists()) { if(!saveDir.mkpath(saveDir.path())) { std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n"; - // XXX: handle this better - return QDir::homePath(); + // XXX: Do something else? } } return savePath; diff --git a/src/bittorrent.h b/src/bittorrent.h index b1e3ff2c5..4434c704b 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -109,6 +109,7 @@ private: bool DHTEnabled; bool PeXEnabled; bool queueingEnabled; + bool appendLabelToSavePath; QString defaultSavePath; QString defaultTempPath; // GeoIP @@ -199,6 +200,8 @@ public slots: void setSessionSettings(session_settings sessionSettings); void startTorrentsInPause(bool b); void setDefaultTempPath(QString temppath); + void setAppendLabelToSavePath(bool append); + void appendLabelToTorrentSavePath(QTorrentHandle h); void applyEncryptionSettings(pe_settings se); void setDownloadLimit(QString hash, long val); void setUploadLimit(QString hash, long val); diff --git a/src/options_imp.cpp b/src/options_imp.cpp index b5fe4af3e..a6e3769e9 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -148,6 +148,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ // Downloads tab connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableTempPathInput(bool))); connect(checkScanDir, SIGNAL(toggled(bool)), this, SLOT(enableDirScan(bool))); + connect(checkAppendLabel, SIGNAL(toggled(bool)), this, SLOT(enableDirScan(bool))); + connect(checkAppendqB, SIGNAL(toggled(bool)), this, SLOT(enableDirScan(bool))); connect(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -369,6 +371,8 @@ void options_imp::saveOptions(){ settings.setValue(QString::fromUtf8("SavePath"), getSavePath()); settings.setValue(QString::fromUtf8("TempPathEnabled"), isTempPathEnabled()); settings.setValue(QString::fromUtf8("TempPath"), getTempPath()); + settings.setValue(QString::fromUtf8("AppendLabel"), checkAppendLabel->isChecked()); + settings.setValue(QString::fromUtf8("UseIncompleteExtension"), checkAppendqB->isChecked()); settings.setValue(QString::fromUtf8("PreAllocation"), preAllocateAllFiles()); settings.setValue(QString::fromUtf8("DiskCache"), spinCache->value()); settings.setValue(QString::fromUtf8("AdditionDialog"), useAdditionDialog()); @@ -580,6 +584,8 @@ void options_imp::loadOptions(){ enableTempPathInput(checkTempFolder->isChecked()); } textTempPath->setText(Preferences::getTempPath()); + checkAppendLabel->setChecked(Preferences::appendTorrentLabel()); + checkAppendqB->setChecked(Preferences::useIncompleteFilesExtension()); checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles()); spinCache->setValue(Preferences::diskCacheSize()); checkAdditionDialog->setChecked(Preferences::useAdditionDialog()); diff --git a/src/preferences.h b/src/preferences.h index a85ff4efa..f5b5ac4a9 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -133,6 +133,16 @@ public: return settings.value(QString::fromUtf8("Preferences/Downloads/TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString(); } + static bool useIncompleteFilesExtension() { + QSettings settings("qBittorrent", "qBittorrent"); + return settings.value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool(); + } + + static bool appendTorrentLabel() { + QSettings settings("qBittorrent", "qBittorrent"); + return settings.value(QString::fromUtf8("Preferences/Downloads/AppendLabel"), false).toBool(); + } + static bool preAllocateAllFiles() { QSettings settings("qBittorrent", "qBittorrent"); return settings.value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool(); diff --git a/src/ui/options.ui b/src/ui/options.ui index c282cfaf9..f32f35eba 100644 --- a/src/ui/options.ui +++ b/src/ui/options.ui @@ -639,7 +639,7 @@ 0 0 642 - 472 + 515 @@ -655,77 +655,87 @@ File system + + 3 + - - - 6 + + + QGroupBox::title { +font-weight: normal; +margin-left: -3px; +} +QGroupBox { + border-width: 0; +} - - 0 + + Destination Folder: - - - - 6 - - - 0 - - - - - Download folder: - - - - - - - - - - - - - - true - - - - 22 - 22 - - - - - 25 - 27 - - - - - :/Icons/oxygen/browse.png:/Icons/oxygen/browse.png - - - - - - + + + + + + + + + + + + + + true + + + + 22 + 22 + + + + + 25 + 27 + + + + + :/Icons/oxygen/browse.png:/Icons/oxygen/browse.png + + + + + + + + + Append the torrent's label + + + + + + + + + + Use a different folder for incomplete downloads: + + - - - - Temp folder: - - - false + + QLineEdit { + margin-left: 23px; +} + @@ -759,6 +769,65 @@ + + + + Automatically load .torrent files from: + + + + + + + 6 + + + 0 + + + + + false + + + QLineEdit { + margin-left: 23px; +} + + + + + + + false + + + + 22 + 22 + + + + + 25 + 27 + + + + + :/Icons/oxygen/browse.png:/Icons/oxygen/browse.png + + + + + + + + + Append .!qB extension to incomplete files + + + @@ -813,68 +882,6 @@ - - - - - 0 - 0 - - - - Folder watching - - - - - - Automatically download torrents present in this folder: - - - - - - - 6 - - - 0 - - - - - false - - - - - - - false - - - - 22 - 22 - - - - - 25 - 27 - - - - - :/Icons/oxygen/browse.png:/Icons/oxygen/browse.png - - - - - - - - @@ -1125,7 +1132,7 @@ 0 0 - 602 + 451 513 @@ -1546,8 +1553,8 @@ 0 0 - 620 - 490 + 468 + 376 @@ -2454,8 +2461,8 @@ 0 0 - 218 - 220 + 620 + 490 @@ -2618,8 +2625,8 @@ 0 0 - 451 - 195 + 620 + 490 @@ -2834,7 +2841,6 @@ checkPreallocateAll checkAdditionDialog checkStartPaused - checkScanDir browseScanDirButton spinPort checkUPnP