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 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.1.0 * Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.1.0
- FEATURE: Torrents can be labeled/categorized - FEATURE: Torrents can be labeled/categorized
- FEATURE: Labeled torrent can be downloaded corresponding subfolders
- FEATURE: Disk cache size can be set from preferences - FEATURE: Disk cache size can be set from preferences
- FEATURE: Peer Exchange (PeX) can be disabled 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
downloader = new downloadThread(this); downloader = new downloadThread(this);
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
appendLabelToSavePath = Preferences::appendTorrentLabel();
// Apply user settings to Bittorrent session // Apply user settings to Bittorrent session
configureSession(); configureSession();
qDebug("* BTSession constructed"); qDebug("* BTSession constructed");
@ -233,6 +234,7 @@ void Bittorrent::configureSession() {
} else { } else {
setDefaultTempPath(QString::null); setDefaultTempPath(QString::null);
} }
setAppendLabelToSavePath(Preferences::appendTorrentLabel());
preAllocateAllFiles(Preferences::preAllocateAllFiles()); preAllocateAllFiles(Preferences::preAllocateAllFiles());
startTorrentsInPause(Preferences::addTorrentsInPause()); startTorrentsInPause(Preferences::addTorrentsInPause());
// * Scan dir // * Scan dir
@ -1279,6 +1281,38 @@ void Bittorrent::setDefaultTempPath(QString temppath) {
defaultTempPath = 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 // Enable directory scanning
void Bittorrent::enableDirectoryScanning(QString scan_dir) { void Bittorrent::enableDirectoryScanning(QString scan_dir) {
if(!scan_dir.isEmpty()) { if(!scan_dir.isEmpty()) {
@ -1672,15 +1706,32 @@ QString Bittorrent::getSavePath(QString hash) {
QString savePath; QString savePath;
if(TorrentTempData::hasTempData(hash)) { if(TorrentTempData::hasTempData(hash)) {
savePath = TorrentTempData::getSavePath(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()); qDebug("getSavePath, got save_path from temp data: %s", savePath.toLocal8Bit().data());
} else { } else {
savePath = TorrentPersistentData::getSavePath(hash); savePath = TorrentPersistentData::getSavePath(hash);
qDebug("getSavePath, got save_path from persistent data: %s", savePath.toLocal8Bit().data()); if(savePath.isEmpty())
}
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; 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 // Checking if savePath Dir exists
// create it if it is not // create it if it is not
@ -1688,8 +1739,7 @@ QString Bittorrent::getSavePath(QString hash) {
if(!saveDir.exists()) { if(!saveDir.exists()) {
if(!saveDir.mkpath(saveDir.path())) { if(!saveDir.mkpath(saveDir.path())) {
std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n"; std::cerr << "Couldn't create the save directory: " << saveDir.path().toLocal8Bit().data() << "\n";
// XXX: handle this better // XXX: Do something else?
return QDir::homePath();
} }
} }
return savePath; return savePath;

3
src/bittorrent.h

@ -109,6 +109,7 @@ private:
bool DHTEnabled; bool DHTEnabled;
bool PeXEnabled; bool PeXEnabled;
bool queueingEnabled; bool queueingEnabled;
bool appendLabelToSavePath;
QString defaultSavePath; QString defaultSavePath;
QString defaultTempPath; QString defaultTempPath;
// GeoIP // GeoIP
@ -199,6 +200,8 @@ public slots:
void setSessionSettings(session_settings sessionSettings); void setSessionSettings(session_settings sessionSettings);
void startTorrentsInPause(bool b); void startTorrentsInPause(bool b);
void setDefaultTempPath(QString temppath); void setDefaultTempPath(QString temppath);
void setAppendLabelToSavePath(bool append);
void appendLabelToTorrentSavePath(QTorrentHandle h);
void applyEncryptionSettings(pe_settings se); void applyEncryptionSettings(pe_settings se);
void setDownloadLimit(QString hash, long val); void setDownloadLimit(QString hash, long val);
void setUploadLimit(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){
// Downloads tab // Downloads tab
connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableTempPathInput(bool))); connect(checkTempFolder, SIGNAL(toggled(bool)), this, SLOT(enableTempPathInput(bool)));
connect(checkScanDir, SIGNAL(toggled(bool)), this, SLOT(enableDirScan(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(actionTorrentDlOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); connect(actionTorrentFnOnDblClBox, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
connect(checkTempFolder, SIGNAL(toggled(bool)), 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("SavePath"), getSavePath());
settings.setValue(QString::fromUtf8("TempPathEnabled"), isTempPathEnabled()); settings.setValue(QString::fromUtf8("TempPathEnabled"), isTempPathEnabled());
settings.setValue(QString::fromUtf8("TempPath"), getTempPath()); 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("PreAllocation"), preAllocateAllFiles());
settings.setValue(QString::fromUtf8("DiskCache"), spinCache->value()); settings.setValue(QString::fromUtf8("DiskCache"), spinCache->value());
settings.setValue(QString::fromUtf8("AdditionDialog"), useAdditionDialog()); settings.setValue(QString::fromUtf8("AdditionDialog"), useAdditionDialog());
@ -580,6 +584,8 @@ void options_imp::loadOptions(){
enableTempPathInput(checkTempFolder->isChecked()); enableTempPathInput(checkTempFolder->isChecked());
} }
textTempPath->setText(Preferences::getTempPath()); textTempPath->setText(Preferences::getTempPath());
checkAppendLabel->setChecked(Preferences::appendTorrentLabel());
checkAppendqB->setChecked(Preferences::useIncompleteFilesExtension());
checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles()); checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles());
spinCache->setValue(Preferences::diskCacheSize()); spinCache->setValue(Preferences::diskCacheSize());
checkAdditionDialog->setChecked(Preferences::useAdditionDialog()); checkAdditionDialog->setChecked(Preferences::useAdditionDialog());

10
src/preferences.h

@ -133,6 +133,16 @@ public:
return settings.value(QString::fromUtf8("Preferences/Downloads/TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString(); 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() { static bool preAllocateAllFiles() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool(); return settings.value(QString::fromUtf8("Preferences/Downloads/PreAllocation"), false).toBool();

188
src/ui/options.ui

@ -639,7 +639,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>642</width> <width>642</width>
<height>472</height> <height>515</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_17"> <layout class="QVBoxLayout" name="verticalLayout_17">
@ -655,29 +655,26 @@
<string>File system</string> <string>File system</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_12"> <layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<layout class="QHBoxLayout">
<property name="spacing"> <property name="spacing">
<number>6</number> <number>3</number>
</property>
<property name="margin">
<number>0</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout"> <widget class="QGroupBox" name="groupBox_3">
<property name="spacing"> <property name="styleSheet">
<number>6</number> <string>QGroupBox::title {
font-weight: normal;
margin-left: -3px;
}
QGroupBox {
border-width: 0;
}</string>
</property> </property>
<property name="margin"> <property name="title">
<number>0</number> <string>Destination Folder:</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_26">
<item> <item>
<widget class="QLabel" name="lblSavePath"> <layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="text">
<string>Download folder:</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLineEdit" name="textSavePath"> <widget class="QLineEdit" name="textSavePath">
<property name="text"> <property name="text">
@ -710,22 +707,35 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QCheckBox" name="checkAppendLabel">
<property name="text">
<string>Append the torrent's label</string>
</property>
</widget>
</item>
</layout> </layout>
</widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QCheckBox" name="checkTempFolder"> <widget class="QCheckBox" name="checkTempFolder">
<property name="text"> <property name="text">
<string>Temp folder:</string> <string>Use a different folder for incomplete downloads:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QLineEdit" name="textTempPath"> <widget class="QLineEdit" name="textTempPath">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet">
<string>QLineEdit {
margin-left: 23px;
}</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -759,6 +769,65 @@
</item> </item>
</layout> </layout>
</item> </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> <item>
<widget class="QCheckBox" name="checkPreallocateAll"> <widget class="QCheckBox" name="checkPreallocateAll">
<property name="text"> <property name="text">
@ -813,68 +882,6 @@
</layout> </layout>
</widget> </widget>
</item> </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> <item>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
@ -1125,7 +1132,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>602</width> <width>451</width>
<height>513</height> <height>513</height>
</rect> </rect>
</property> </property>
@ -1546,8 +1553,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>620</width> <width>468</width>
<height>490</height> <height>376</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_19"> <layout class="QVBoxLayout" name="verticalLayout_19">
@ -2454,8 +2461,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>218</width> <width>620</width>
<height>220</height> <height>490</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_23"> <layout class="QVBoxLayout" name="verticalLayout_23">
@ -2618,8 +2625,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>451</width> <width>620</width>
<height>195</height> <height>490</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_24"> <layout class="QVBoxLayout" name="verticalLayout_24">
@ -2834,7 +2841,6 @@
<tabstop>checkPreallocateAll</tabstop> <tabstop>checkPreallocateAll</tabstop>
<tabstop>checkAdditionDialog</tabstop> <tabstop>checkAdditionDialog</tabstop>
<tabstop>checkStartPaused</tabstop> <tabstop>checkStartPaused</tabstop>
<tabstop>checkScanDir</tabstop>
<tabstop>browseScanDirButton</tabstop> <tabstop>browseScanDirButton</tabstop>
<tabstop>spinPort</tabstop> <tabstop>spinPort</tabstop>
<tabstop>checkUPnP</tabstop> <tabstop>checkUPnP</tabstop>

Loading…
Cancel
Save