diff --git a/Changelog b/Changelog index 0867594c6..1df5acd29 100644 --- a/Changelog +++ b/Changelog @@ -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 - v2.0.0 - FEATURE: Added program option to disable splash screen diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index f4325d3e3..bd4e11ef8 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -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 fp; + h.file_progress(fp); + for(int i=0; i torrents = getTorrents(); + std::vector::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(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(a.get())) { // Level: fatal int tried_port = p->endpoint.port(); diff --git a/src/bittorrent.h b/src/bittorrent.h index 4434c704b..58f7f48a5 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -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); diff --git a/src/options_imp.cpp b/src/options_imp.cpp index a6e3769e9..e0a4aa235 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -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()); diff --git a/src/preferences.h b/src/preferences.h index f5b5ac4a9..c2c0d8a84 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -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"); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index c19438d28..cf5542d87 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -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 // diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 1897024ac..930537b61 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -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 diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 2094f7a8d..60dddf993 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -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); } } diff --git a/src/ui/options.ui b/src/ui/options.ui index f32f35eba..885ee7b14 100644 --- a/src/ui/options.ui +++ b/src/ui/options.ui @@ -1132,7 +1132,7 @@ QGroupBox { 0 0 - 451 + 602 513