Browse Source

- FEATURE: Labeled torrent can be downloaded corresponding subfolders

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
1fd57b5d63
  1. 1
      Changelog
  2. 64
      src/bittorrent.cpp
  3. 3
      src/bittorrent.h
  4. 6
      src/options_imp.cpp
  5. 10
      src/preferences.h
  6. 188
      src/ui/options.ui

1
Changelog

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - 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

64
src/bittorrent.cpp

@ -102,6 +102,7 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit @@ -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() { @@ -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) { @@ -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<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::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,15 +1706,32 @@ QString Bittorrent::getSavePath(QString hash) { @@ -1672,15 +1706,32 @@ 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);
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());
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());
}
// Checking if savePath Dir exists
// create it if it is not
@ -1688,8 +1739,7 @@ QString Bittorrent::getSavePath(QString hash) { @@ -1688,8 +1739,7 @@ QString Bittorrent::getSavePath(QString hash) {
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;

3
src/bittorrent.h

@ -109,6 +109,7 @@ private: @@ -109,6 +109,7 @@ private:
bool DHTEnabled;
bool PeXEnabled;
bool queueingEnabled;
bool appendLabelToSavePath;
QString defaultSavePath;
QString defaultTempPath;
// GeoIP
@ -199,6 +200,8 @@ public slots: @@ -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);

6
src/options_imp.cpp

@ -148,6 +148,8 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -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(){ @@ -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(){ @@ -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());

10
src/preferences.h

@ -133,6 +133,16 @@ public: @@ -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();

188
src/ui/options.ui

@ -639,7 +639,7 @@ @@ -639,7 +639,7 @@
<x>0</x>
<y>0</y>
<width>642</width>
<height>472</height>
<height>515</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
@ -655,29 +655,26 @@ @@ -655,29 +655,26 @@
<string>File system</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
<widget class="QGroupBox" name="groupBox_3">
<property name="styleSheet">
<string>QGroupBox::title {
font-weight: normal;
margin-left: -3px;
}
QGroupBox {
border-width: 0;
}</string>
</property>
<property name="margin">
<number>0</number>
<property name="title">
<string>Destination Folder:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_26">
<item>
<widget class="QLabel" name="lblSavePath">
<property name="text">
<string>Download folder:</string>
</property>
</widget>
</item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLineEdit" name="textSavePath">
<property name="text">
@ -710,22 +707,35 @@ @@ -710,22 +707,35 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkAppendLabel">
<property name="text">
<string>Append the torrent's label</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QCheckBox" name="checkTempFolder">
<property name="text">
<string>Temp folder:</string>
<string>Use a different folder for incomplete downloads:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLineEdit" name="textTempPath">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>QLineEdit {
margin-left: 23px;
}</string>
</property>
</widget>
</item>
<item>
@ -759,6 +769,65 @@ @@ -759,6 +769,65 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkScanDir">
<property name="text">
<string>Automatically load .torrent files from:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="textScanDir">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string>QLineEdit {
margin-left: 23px;
}</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="browseScanDirButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>25</width>
<height>27</height>
</size>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/browse.png</normaloff>:/Icons/oxygen/browse.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkAppendqB">
<property name="text">
<string>Append .!qB extension to incomplete files</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkPreallocateAll">
<property name="text">
@ -813,68 +882,6 @@ @@ -813,68 +882,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="dirScanBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string comment="qBittorrent will watch a directory and automatically download torrents present in it">Folder watching</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QCheckBox" name="checkScanDir">
<property name="text">
<string>Automatically download torrents present in this folder:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="textScanDir">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="browseScanDirButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>25</width>
<height>27</height>
</size>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/browse.png</normaloff>:/Icons/oxygen/browse.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
@ -1125,7 +1132,7 @@ @@ -1125,7 +1132,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>602</width>
<width>451</width>
<height>513</height>
</rect>
</property>
@ -1546,8 +1553,8 @@ @@ -1546,8 +1553,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>490</height>
<width>468</width>
<height>376</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_19">
@ -2454,8 +2461,8 @@ @@ -2454,8 +2461,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>220</height>
<width>620</width>
<height>490</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
@ -2618,8 +2625,8 @@ @@ -2618,8 +2625,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>451</width>
<height>195</height>
<width>620</width>
<height>490</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_24">
@ -2834,7 +2841,6 @@ @@ -2834,7 +2841,6 @@
<tabstop>checkPreallocateAll</tabstop>
<tabstop>checkAdditionDialog</tabstop>
<tabstop>checkStartPaused</tabstop>
<tabstop>checkScanDir</tabstop>
<tabstop>browseScanDirButton</tabstop>
<tabstop>spinPort</tabstop>
<tabstop>checkUPnP</tabstop>

Loading…
Cancel
Save