mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 21:38:51 +03:00
- Initial implementation of "Append .!qB extension to incomplete files" (untested)
- Update torrent save path when its label is changed and "Append label to save path" setting is set
This commit is contained in:
parent
1fd57b5d63
commit
c61aded388
9 changed files with 112 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
|||
- 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
|
||||
- FEATURE: Append !.qB extension to incomplete files option (libtorrent >= v0.15 only)
|
||||
|
||||
* Thu Dec 10 2009 - Christophe Dumez <chris@qbittorrent.org> - v2.0.0
|
||||
- FEATURE: Added program option to disable splash screen
|
||||
|
|
|
@ -103,6 +103,9 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit
|
|||
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();
|
||||
#ifdef LIBTORRENT_0_15
|
||||
appendqBExtension = Preferences::useIncompleteFilesExtension();
|
||||
#endif
|
||||
// Apply user settings to Bittorrent session
|
||||
configureSession();
|
||||
qDebug("* BTSession constructed");
|
||||
|
@ -235,6 +238,9 @@ void Bittorrent::configureSession() {
|
|||
setDefaultTempPath(QString::null);
|
||||
}
|
||||
setAppendLabelToSavePath(Preferences::appendTorrentLabel());
|
||||
#ifdef LIBTORRENT_0_15
|
||||
setAppendqBExtension(Preferences::useIncompleteFilesExtension());
|
||||
#endif
|
||||
preAllocateAllFiles(Preferences::preAllocateAllFiles());
|
||||
startTorrentsInPause(Preferences::addTorrentsInPause());
|
||||
// * Scan dir
|
||||
|
@ -935,6 +941,11 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
|||
qDebug("addTorrent: Saving save_path in persistent data: %s", savePath.toLocal8Bit().data());
|
||||
TorrentPersistentData::saveSavePath(hash, savePath);
|
||||
}
|
||||
#ifdef LIBTORRENT_0_15
|
||||
// Append .!qB to incomplete files
|
||||
if(appendqBExtension)
|
||||
appendqBextensionToTorrent(h, true);
|
||||
#endif
|
||||
}
|
||||
QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent";
|
||||
if(file != newFile) {
|
||||
|
@ -1281,6 +1292,52 @@ void Bittorrent::setDefaultTempPath(QString temppath) {
|
|||
defaultTempPath = temppath;
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) {
|
||||
if(!h.is_valid()) return;
|
||||
std::vector<size_type> fp;
|
||||
h.file_progress(fp);
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
if(append) {
|
||||
if(fp[i] < 1.) {
|
||||
QString name = h.file_at(i);
|
||||
if(!name.endsWith(".!qB")) {
|
||||
h.rename_file(i, name + ".!qB");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QString name = h.file_at(i);
|
||||
if(name.endsWith(".!qB")) {
|
||||
name.chop(4);
|
||||
h.rename_file(i, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label) {
|
||||
if(!h.is_valid()) return;
|
||||
if(!appendLabelToSavePath) return;
|
||||
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
|
||||
QDir old_dir(old_save_path);
|
||||
bool move_storage = (old_dir == QDir(h.save_path()));
|
||||
if(!old_label.isEmpty()) {
|
||||
Q_ASSERT(old_dir.dirName() == old_label);
|
||||
old_dir.cdUp();
|
||||
}
|
||||
QString new_save_path;
|
||||
if(new_label.isEmpty())
|
||||
new_save_path = old_dir.absolutePath();
|
||||
else
|
||||
old_dir.absoluteFilePath(new_label);
|
||||
TorrentPersistentData::saveSavePath(h.hash(), new_save_path);
|
||||
if(move_storage) {
|
||||
// Move storage
|
||||
h.move_storage(new_save_path);
|
||||
}
|
||||
}
|
||||
|
||||
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) {
|
||||
if(!h.is_valid()) return;
|
||||
QString label = TorrentPersistentData::getLabel(h.hash());
|
||||
|
@ -1299,7 +1356,7 @@ void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle h) {
|
|||
}
|
||||
|
||||
void Bittorrent::setAppendLabelToSavePath(bool append) {
|
||||
if(appendLabelToSavePath != Preferences::appendTorrentLabel()) {
|
||||
if(appendLabelToSavePath != append) {
|
||||
appendLabelToSavePath = !appendLabelToSavePath;
|
||||
if(appendLabelToSavePath) {
|
||||
// Move torrents storage to sub folder with label name
|
||||
|
@ -1313,6 +1370,21 @@ void Bittorrent::setAppendLabelToSavePath(bool append) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
void Bittorrent::setAppendqBExtension(bool append) {
|
||||
if(appendqBExtension != append) {
|
||||
appendqBExtension = !appendqBExtension;
|
||||
// append or remove .!qB extension for incomplete files
|
||||
std::vector<torrent_handle> torrents = getTorrents();
|
||||
std::vector<torrent_handle>::iterator torrentIT;
|
||||
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||
QTorrentHandle h = QTorrentHandle(*torrentIT);
|
||||
appendqBextensionToTorrent(h, appendqBExtension);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Enable directory scanning
|
||||
void Bittorrent::enableDirectoryScanning(QString scan_dir) {
|
||||
if(!scan_dir.isEmpty()) {
|
||||
|
@ -1564,6 +1636,19 @@ void Bittorrent::readAlerts() {
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef LIBTORRENT_0_15
|
||||
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(appendqBExtension) {
|
||||
QString name = h.file_at(p->index);
|
||||
if(name.endsWith(".!qB")) {
|
||||
qDebug("File %s finished, removing .!qB extension", name.toLocal8Bit().data());
|
||||
name.chop(4);
|
||||
h.rename_file(p->index, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (listen_failed_alert* p = dynamic_cast<listen_failed_alert*>(a.get())) {
|
||||
// Level: fatal
|
||||
int tried_port = p->endpoint.port();
|
||||
|
|
|
@ -110,6 +110,9 @@ private:
|
|||
bool PeXEnabled;
|
||||
bool queueingEnabled;
|
||||
bool appendLabelToSavePath;
|
||||
#ifdef LIBTORRENT_0_15
|
||||
bool appendqBExtension;
|
||||
#endif
|
||||
QString defaultSavePath;
|
||||
QString defaultTempPath;
|
||||
// GeoIP
|
||||
|
@ -202,6 +205,11 @@ public slots:
|
|||
void setDefaultTempPath(QString temppath);
|
||||
void setAppendLabelToSavePath(bool append);
|
||||
void appendLabelToTorrentSavePath(QTorrentHandle h);
|
||||
void changeLabelInTorrentSavePath(QTorrentHandle h, QString old_label, QString new_label);
|
||||
#ifdef LIBTORRENT_0_15
|
||||
void appendqBextensionToTorrent(QTorrentHandle h, bool append);
|
||||
void setAppendqBExtension(bool append);
|
||||
#endif
|
||||
void applyEncryptionSettings(pe_settings se);
|
||||
void setDownloadLimit(QString hash, long val);
|
||||
void setUploadLimit(QString hash, long val);
|
||||
|
|
|
@ -267,6 +267,9 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
|
|||
}
|
||||
// Tab selection mecanism
|
||||
connect(tabSelection, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem*)));
|
||||
#ifndef LIBTORRENT_0_15
|
||||
checkAppendqB->setVisible(false);
|
||||
#endif
|
||||
// Adapt size
|
||||
loadWindowState();
|
||||
show();
|
||||
|
@ -372,7 +375,9 @@ void options_imp::saveOptions(){
|
|||
settings.setValue(QString::fromUtf8("TempPathEnabled"), isTempPathEnabled());
|
||||
settings.setValue(QString::fromUtf8("TempPath"), getTempPath());
|
||||
settings.setValue(QString::fromUtf8("AppendLabel"), checkAppendLabel->isChecked());
|
||||
#ifdef LIBTORRENT_0_15
|
||||
settings.setValue(QString::fromUtf8("UseIncompleteExtension"), checkAppendqB->isChecked());
|
||||
#endif
|
||||
settings.setValue(QString::fromUtf8("PreAllocation"), preAllocateAllFiles());
|
||||
settings.setValue(QString::fromUtf8("DiskCache"), spinCache->value());
|
||||
settings.setValue(QString::fromUtf8("AdditionDialog"), useAdditionDialog());
|
||||
|
@ -585,7 +590,9 @@ void options_imp::loadOptions(){
|
|||
}
|
||||
textTempPath->setText(Preferences::getTempPath());
|
||||
checkAppendLabel->setChecked(Preferences::appendTorrentLabel());
|
||||
#ifdef LIBTORRENT_0_15
|
||||
checkAppendqB->setChecked(Preferences::useIncompleteFilesExtension());
|
||||
#endif
|
||||
checkPreallocateAll->setChecked(Preferences::preAllocateAllFiles());
|
||||
spinCache->setValue(Preferences::diskCacheSize());
|
||||
checkAdditionDialog->setChecked(Preferences::useAdditionDialog());
|
||||
|
|
|
@ -133,10 +133,12 @@ public:
|
|||
return settings.value(QString::fromUtf8("Preferences/Downloads/TempPath"), home+"qBT_dir"+QDir::separator()+"temp").toString();
|
||||
}
|
||||
|
||||
#ifdef LIBTORRENT_0_15
|
||||
static bool useIncompleteFilesExtension() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
return settings.value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool();
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool appendTorrentLabel() {
|
||||
QSettings settings("qBittorrent", "qBittorrent");
|
||||
|
|
|
@ -618,6 +618,10 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) {
|
|||
h.piece_priority(last_piece, prio);
|
||||
}
|
||||
|
||||
void QTorrentHandle::rename_file(int index, QString name) {
|
||||
h.rename_file(index, name.toStdString());
|
||||
}
|
||||
|
||||
//
|
||||
// Operators
|
||||
//
|
||||
|
|
|
@ -158,6 +158,7 @@ class QTorrentHandle {
|
|||
void set_peer_download_limit(libtorrent::asio::ip::tcp::endpoint ip, int limit) const;
|
||||
void add_tracker(announce_entry const& url);
|
||||
void prioritize_first_last_piece(bool b);
|
||||
void rename_file(int index, QString name);
|
||||
|
||||
//
|
||||
// Operators
|
||||
|
|
|
@ -873,6 +873,8 @@ void TransferListWidget::setSelectionLabel(QString label) {
|
|||
proxyModel->setData(proxyModel->index(index.row(), TR_LABEL), QVariant(label));
|
||||
TorrentPersistentData::saveLabel(hash, label);
|
||||
emit torrentChangedLabel(old_label, label);
|
||||
// Update save path if necessary
|
||||
BTSession->changeLabelInTorrentSavePath(BTSession->getTorrentHandle(hash), old_label, label);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1132,7 +1132,7 @@ QGroupBox {
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>451</width>
|
||||
<width>602</width>
|
||||
<height>513</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
|
Loading…
Reference in a new issue