From a53a70742d6103b21ca1dc9e7ad452ae4884109e Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 18 Feb 2012 16:44:20 +0200 Subject: [PATCH] Drop support for libtorrent v0.14.x --- INSTALL | 4 +- configure | 4 +- qcm/libtorrent-rasterbar.qcm | 4 +- src/preferences/advancedsettings.h | 16 +-- src/preferences/options_imp.cpp | 7 -- src/preferences/preferences.h | 4 - src/previewselect.cpp | 3 +- src/properties/propertieswidget.cpp | 4 - src/properties/trackerlist.cpp | 15 --- src/qtlibtorrent/qbtsession.cpp | 118 +---------------------- src/qtlibtorrent/qbtsession.h | 9 -- src/qtlibtorrent/qtorrenthandle.cpp | 48 ++++----- src/qtlibtorrent/trackerinfos.h | 12 --- src/torrentadditiondlg.cpp | 5 - src/torrentcreator/torrentcreatordlg.cpp | 2 - src/torrentimportdlg.cpp | 11 --- src/torrentimportdlg.h | 2 - src/torrentpersistentdata.h | 2 - src/transferlistwidget.cpp | 10 -- src/webui/eventmanager.cpp | 15 --- 20 files changed, 35 insertions(+), 260 deletions(-) diff --git a/INSTALL b/INSTALL index db6dc9d99..13a40129a 100644 --- a/INSTALL +++ b/INSTALL @@ -14,7 +14,7 @@ qBittorrent - A BitTorrent client in C++ / Qt4 - pkg-config executable - - libtorrent-rasterbar by Arvid Norberg (>= 0.14.4 REQUIRED, compatible with v0.15.x/v0.16.x) + - libtorrent-rasterbar by Arvid Norberg (>= 0.15.0) -> http://www.libtorrent.net Be careful: another library (the one used by rTorrent) uses a similar name. @@ -44,7 +44,7 @@ qBittorrent - A BitTorrent client in C++ / Qt4 - pkg-config executable - - libtorrent-rasterbar by Arvid Norberg (>= 0.14.4 REQUIRED, >= v0.15.0 ADVISED) + - libtorrent-rasterbar by Arvid Norberg (>= v0.15.0) -> http://www.libtorrent.net Be careful: another library (the one used by rTorrent) uses a similar name. diff --git a/configure b/configure index 687960c85..64739574c 100755 --- a/configure +++ b/configure @@ -419,11 +419,11 @@ class qc_libtorrent_rasterbar : public ConfObj { public: qc_libtorrent_rasterbar(Conf *c) : ConfObj(c) {} - QString name() const { return "libtorrent-rasterbar >= 0.14.4"; } + QString name() const { return "libtorrent-rasterbar >= 0.15.0"; } QString shortname() const { return "libtorrent-rasterbar"; } bool exec(){ QStringList incs; - QString req_ver = "0.14.4"; + QString req_ver = "0.15.0"; QString version, libs, other; VersionMode mode = VersionMin; if(!conf->findPkgConfig("libtorrent-rasterbar", mode, req_ver, &version, &incs, &libs, &other)) diff --git a/qcm/libtorrent-rasterbar.qcm b/qcm/libtorrent-rasterbar.qcm index ecb8ded0d..7c57f6d67 100644 --- a/qcm/libtorrent-rasterbar.qcm +++ b/qcm/libtorrent-rasterbar.qcm @@ -8,11 +8,11 @@ class qc_libtorrent_rasterbar : public ConfObj { public: qc_libtorrent_rasterbar(Conf *c) : ConfObj(c) {} - QString name() const { return "libtorrent-rasterbar >= 0.14.4"; } + QString name() const { return "libtorrent-rasterbar >= 0.15.0"; } QString shortname() const { return "libtorrent-rasterbar"; } bool exec(){ QStringList incs; - QString req_ver = "0.14.4"; + QString req_ver = "0.15.0"; QString version, libs, other; VersionMode mode = VersionMin; if(!conf->findPkgConfig("libtorrent-rasterbar", mode, req_ver, &version, &incs, &libs, &other)) diff --git a/src/preferences/advancedsettings.h b/src/preferences/advancedsettings.h index a8bd3297c..36d3c3198 100644 --- a/src/preferences/advancedsettings.h +++ b/src/preferences/advancedsettings.h @@ -21,9 +21,7 @@ enum AdvSettingsRows {DISK_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_L USE_ICON_THEME, #endif CONFIRM_DELETE_TORRENT, TRACKER_EXCHANGE, - #if LIBTORRENT_VERSION_MINOR > 14 ANNOUNCE_ALL_TRACKERS, - #endif ROW_COUNT}; class AdvancedSettings: public QTableWidget { @@ -41,9 +39,7 @@ private: #if defined(Q_WS_X11) && (QT_VERSION >= QT_VERSION_CHECK(4,6,0)) QCheckBox cb_use_icon_theme; #endif -#if LIBTORRENT_VERSION_MINOR > 14 - QCheckBox cb_announce_all_trackers; -#endif + QCheckBox cb_announce_all_trackers; QLineEdit txt_network_address; public: @@ -85,10 +81,8 @@ public slots: pref.resolvePeerHostNames(cb_resolve_hosts.isChecked()); // Max Half-Open connections pref.setMaxHalfOpenConnections(spin_maxhalfopen.value()); -#if LIBTORRENT_VERSION_MINOR > 14 // Super seeding pref.enableSuperSeeding(cb_super_seeding.isChecked()); -#endif // Network interface if(combo_iface.currentIndex() == 0) { // All interfaces (default) @@ -117,9 +111,7 @@ public slots: pref.setConfirmTorrentDeletion(cb_confirm_torrent_deletion.isChecked()); // Tracker exchange pref.setTrackerExchangeEnabled(cb_enable_tracker_ext.isChecked()); -#if LIBTORRENT_VERSION_MINOR > 14 pref.setAnnounceToAllTrackers(cb_announce_all_trackers.isChecked()); -#endif } signals: @@ -201,11 +193,7 @@ private slots: spin_maxhalfopen.setValue(pref.getMaxHalfOpenConnections()); setRow(MAX_HALF_OPEN, tr("Maximum number of half-open connections [0: Disabled]"), &spin_maxhalfopen); // Super seeding -#if LIBTORRENT_VERSION_MINOR > 14 cb_super_seeding.setChecked(pref.isSuperSeedingEnabled()); -#else - cb_super_seeding.setEnabled(false); -#endif setRow(SUPER_SEEDING, tr("Strict super seeding"), &cb_super_seeding); // Network interface combo_iface.addItem(tr("Any interface", "i.e. Any network interface")); @@ -247,11 +235,9 @@ private slots: // Tracker exchange cb_enable_tracker_ext.setChecked(pref.trackerExchangeEnabled()); setRow(TRACKER_EXCHANGE, tr("Exchange trackers with other peers"), &cb_enable_tracker_ext); -#if LIBTORRENT_VERSION_MINOR > 14 // Announce to all trackers cb_announce_all_trackers.setChecked(pref.announceToAllTrackers()); setRow(ANNOUNCE_ALL_TRACKERS, tr("Always announce to all trackers"), &cb_announce_all_trackers); -#endif } }; diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 01ac1c270..66b160545 100644 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -246,9 +246,6 @@ options_imp::options_imp(QWidget *parent): applyButton->setEnabled(false); // Tab selection mecanism connect(tabSelection, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWidgetItem*))); -#if LIBTORRENT_VERSION_MINOR < 15 - checkAppendqB->setVisible(false); -#endif #if LIBTORRENT_VERSION_MINOR < 16 checkuTP->setVisible(false); checkLimituTPConnections->setVisible(false); @@ -392,9 +389,7 @@ void options_imp::saveOptions(){ #endif pref.setTempPath(temp_path); pref.setAppendTorrentLabel(checkAppendLabel->isChecked()); -#if LIBTORRENT_VERSION_MINOR > 14 pref.useIncompleteFilesExtension(checkAppendqB->isChecked()); -#endif pref.preAllocateAllFiles(preAllocateAllFiles()); pref.useAdditionDialog(useAdditionDialog()); pref.addTorrentsInPause(addTorrentsInPause()); @@ -569,9 +564,7 @@ void options_imp::loadOptions(){ #endif textTempPath->setText(temp_path); checkAppendLabel->setChecked(pref.appendTorrentLabel()); -#if LIBTORRENT_VERSION_MINOR > 14 checkAppendqB->setChecked(pref.useIncompleteFilesExtension()); -#endif checkPreallocateAll->setChecked(pref.preAllocateAllFiles()); checkAdditionDialog->setChecked(pref.useAdditionDialog()); checkStartPaused->setChecked(pref.addTorrentsInPause()); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index c33606b0c..c6acb3bbd 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -205,7 +205,6 @@ public: setValue(QString::fromUtf8("Preferences/Downloads/TempPath"), path); } -#if LIBTORRENT_VERSION_MINOR > 14 bool useIncompleteFilesExtension() const { return value(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), false).toBool(); } @@ -213,7 +212,6 @@ public: void useIncompleteFilesExtension(bool enabled) { setValue(QString::fromUtf8("Preferences/Downloads/UseIncompleteExtension"), enabled); } -#endif bool appendTorrentLabel() const { return value(QString::fromUtf8("Preferences/Downloads/AppendLabel"), false).toBool(); @@ -1025,7 +1023,6 @@ public: } #endif -#if LIBTORRENT_VERSION_MINOR > 14 bool isSuperSeedingEnabled() const { return value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool(); } @@ -1041,7 +1038,6 @@ public: void setAnnounceToAllTrackers(bool enabled) { setValue(QString::fromUtf8("Preferences/Advanced/AnnounceToAllTrackers"), enabled); } -#endif #if defined(Q_WS_X11) && (QT_VERSION >= QT_VERSION_CHECK(4,6,0)) bool useSystemIconTheme() const { diff --git a/src/previewselect.cpp b/src/previewselect.cpp index d5f3ddd68..c249712c6 100644 --- a/src/previewselect.cpp +++ b/src/previewselect.cpp @@ -96,10 +96,9 @@ void PreviewSelect::on_previewButton_clicked(){ QModelIndex index; QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(NAME); if(selectedIndexes.size() == 0) return; -#if LIBTORRENT_VERSION_MINOR > 14 // Flush data h.flush_cache(); -#endif + QString path; foreach(index, selectedIndexes){ path = h.absolute_files_path().at(indexes.at(index.row())); diff --git a/src/properties/propertieswidget.cpp b/src/properties/propertieswidget.cpp index 6cbcf9c4d..09468cc03 100644 --- a/src/properties/propertieswidget.cpp +++ b/src/properties/propertieswidget.cpp @@ -420,10 +420,8 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { const QString filename = h.filepath_at(i); const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); qDebug("Trying to open file at %s", qPrintable(file_path)); -#if LIBTORRENT_VERSION_MINOR > 14 // Flush data h.flush_cache(); -#endif if(QFile::exists(file_path)) { QDesktopServices::openUrl(QUrl::fromLocalFile(file_path)); } else { @@ -442,10 +440,8 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) { const QString filename = path_items.join(QDir::separator()); const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); qDebug("Trying to open folder at %s", qPrintable(file_path)); -#if LIBTORRENT_VERSION_MINOR > 14 // Flush data h.flush_cache(); -#endif if(QFile::exists(file_path)) { QDesktopServices::openUrl(QUrl::fromLocalFile(file_path)); } else { diff --git a/src/properties/trackerlist.cpp b/src/properties/trackerlist.cpp index 69a3f7407..07032d32f 100644 --- a/src/properties/trackerlist.cpp +++ b/src/properties/trackerlist.cpp @@ -247,7 +247,6 @@ void TrackerList::loadTrackers() { } TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); QString error_message = data.last_message.trimmed(); -#if LIBTORRENT_VERSION_MINOR > 14 if(it->verified) { item->setText(COL_STATUS, tr("Working")); item->setText(COL_MSG, ""); @@ -265,20 +264,6 @@ void TrackerList::loadTrackers() { } } } -#else - if(data.verified) { - item->setText(COL_STATUS, tr("Working")); - item->setText(COL_MSG, ""); - } else { - if(data.fail_count > 0) { - item->setText(COL_STATUS, tr("Not working")); - item->setText(COL_MSG, error_message); - } else { - item->setText(COL_STATUS, tr("Not contacted yet")); - item->setText(COL_MSG, ""); - } - } -#endif item->setText(COL_PEERS, QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers)); } // Remove old trackers diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 2f823c34d..ca9433d89 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -57,9 +57,7 @@ #include #include #include -#if LIBTORRENT_VERSION_MINOR > 14 #include -#endif #include #include //#include @@ -139,10 +137,8 @@ QBtSession::QBtSession() // Enabling plugins //s->add_extension(&create_metadata_plugin); s->add_extension(&create_ut_metadata_plugin); -#if LIBTORRENT_VERSION_MINOR > 14 if(pref.trackerExchangeEnabled()) s->add_extension(&create_lt_trackers_plugin); -#endif if(pref.isPeXEnabled()) { PeXEnabled = true; s->add_extension(&create_ut_pex_plugin); @@ -154,9 +150,7 @@ QBtSession::QBtSession() connect(timerAlerts, SIGNAL(timeout()), SLOT(readAlerts())); timerAlerts->start(1000); appendLabelToSavePath = pref.appendTorrentLabel(); -#if LIBTORRENT_VERSION_MINOR > 14 appendqBExtension = pref.useIncompleteFilesExtension(); -#endif connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), SLOT(addTorrentsFromScanFolder(QStringList&))); // Apply user settings to Bittorrent session configureSession(); @@ -179,9 +173,6 @@ QBtSession::~QBtSession() { delete m_speedMonitor; qDebug("Deleted the torrent speed monitor"); // Do some BT related saving -#if LIBTORRENT_VERSION_MINOR < 15 - saveDHTEntry(); -#endif saveSessionState(); saveFastResumeData(); // Delete our objects @@ -309,9 +300,7 @@ void QBtSession::configureSession() { setDefaultTempPath(QString::null); } setAppendLabelToSavePath(pref.appendTorrentLabel()); -#if LIBTORRENT_VERSION_MINOR > 14 setAppendqBExtension(pref.useIncompleteFilesExtension()); -#endif preAllocateAllFiles(pref.preAllocateAllFiles()); startTorrentsInPause(pref.addTorrentsInPause()); // * Export Dir @@ -404,22 +393,18 @@ void QBtSession::configureSession() { sessionSettings.stop_tracker_timeout = 1; //sessionSettings.announce_to_all_trackers = true; sessionSettings.auto_scrape_interval = 1200; // 20 minutes -#if LIBTORRENT_VERSION_MINOR > 14 bool announce_to_all = pref.announceToAllTrackers(); sessionSettings.announce_to_all_trackers = announce_to_all; sessionSettings.announce_to_all_tiers = announce_to_all; sessionSettings.auto_scrape_min_interval = 900; // 15 minutes -#endif sessionSettings.cache_size = pref.diskCacheSize()*64; qDebug() << "Using a disk cache size of" << pref.diskCacheSize() << "MiB"; // Disable OS cache to avoid memory problems (uTorrent behavior) #ifdef Q_WS_WIN -#if LIBTORRENT_VERSION_MINOR > 14 // Fixes huge memory usage on Windows 7 (especially when checking files) sessionSettings.disk_io_write_mode = session_settings::disable_os_cache; sessionSettings.disk_io_read_mode = session_settings::disable_os_cache; #endif -#endif #if LIBTORRENT_VERSION_MINOR > 15 sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled(); if (sessionSettings.anonymous_mode) { @@ -461,9 +446,7 @@ void QBtSession::configureSession() { #endif } // Super seeding -#if LIBTORRENT_VERSION_MINOR > 14 sessionSettings.strict_super_seeding = pref.isSuperSeedingEnabled(); -#endif #if LIBTORRENT_VERSION_MINOR > 15 // * Max Half-open connections sessionSettings.half_open_limit = pref.getMaxHalfOpenConnections(); @@ -1163,11 +1146,10 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr qDebug("This is a NEW torrent (first time)..."); loadTorrentTempData(h, savePath, false); -#if LIBTORRENT_VERSION_MINOR > 14 // Append .!qB to incomplete files if(appendqBExtension) appendqBextensionToTorrent(h, true); -#endif + // Backup torrent file const QString newFile = torrentBackup.absoluteFilePath(hash + ".torrent"); if(path != newFile) @@ -1232,15 +1214,11 @@ add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) { add_torrent_params p; // Seeding mode -#if LIBTORRENT_VERSION_MINOR > 14 // Skip checking and directly start seeding (new in libtorrent v0.15) if(TorrentTempData::isSeedingMode(hash)) p.seed_mode=true; else p.seed_mode=false; -#else - Q_UNUSED(hash); -#endif // Preallocation mode if(preAllocateAll) @@ -1503,7 +1481,6 @@ void QBtSession::loadSessionState() { QFile::remove(state_path); return; } -#if LIBTORRENT_VERSION_MINOR > 14 QFile state_file(state_path); if(!state_file.open(QIODevice::ReadOnly)) return; std::vector in; @@ -1522,20 +1499,11 @@ void QBtSession::loadSessionState() { #endif s->load_state(e); } -#else - boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() - , std::ios_base::binary); - ses_state_file.unsetf(std::ios_base::skipws); - s->load_state(bdecode( - std::istream_iterator(ses_state_file) - , std::istream_iterator())); -#endif } void QBtSession::saveSessionState() { qDebug("Saving session state to disk..."); const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); -#if LIBTORRENT_VERSION_MINOR > 14 entry session_state; s->save_state(session_state); vector out; @@ -1545,38 +1513,16 @@ void QBtSession::saveSessionState() { session_file.write(&out[0], out.size()); session_file.close(); } -#else - entry session_state = s->state(); - boost::filesystem::ofstream out(state_path.toLocal8Bit().constData() - , std::ios_base::binary); - out.unsetf(std::ios_base::skipws); - bencode(std::ostream_iterator(out), session_state); -#endif } // Enable DHT bool QBtSession::enableDHT(bool b) { if(b) { if(!DHTEnabled) { -#if LIBTORRENT_VERSION_MINOR < 15 - entry dht_state; - const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); - if(QFile::exists(dht_state_path)) { - boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().constData(), std::ios_base::binary); - dht_state_file.unsetf(std::ios_base::skipws); - try{ - dht_state = bdecode(std::istream_iterator(dht_state_file), std::istream_iterator()); - }catch (std::exception&) {} - } -#endif try { qDebug() << "Starting DHT..."; -#if LIBTORRENT_VERSION_MINOR > 14 Q_ASSERT(!s->is_dht_running()); s->start_dht(); -#else - s->start_dht(dht_state); -#endif s->add_dht_router(std::make_pair(std::string("router.bittorrent.com"), 6881)); s->add_dht_router(std::make_pair(std::string("router.utorrent.com"), 6881)); s->add_dht_router(std::make_pair(std::string("dht.transmissionbt.com"), 6881)); @@ -1807,7 +1753,6 @@ void QBtSession::setDefaultTempPath(QString temppath) { defaultTempPath = temppath; } -#if LIBTORRENT_VERSION_MINOR > 14 void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append) { if(!h.is_valid() || !h.has_metadata()) return; std::vector fp; @@ -1834,7 +1779,6 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append } } } -#endif void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) { if(!h.is_valid()) return; @@ -1879,7 +1823,6 @@ void QBtSession::setAppendLabelToSavePath(bool append) { } } -#if LIBTORRENT_VERSION_MINOR > 14 void QBtSession::setAppendqBExtension(bool append) { if(appendqBExtension != append) { appendqBExtension = !appendqBExtension; @@ -1892,7 +1835,6 @@ void QBtSession::setAppendqBExtension(bool append) { } } } -#endif // Set the ports range in which is chosen the port the Bittorrent // session will listen to @@ -2191,11 +2133,10 @@ void QBtSession::readAlerts() { if(h.is_valid()) { const QString hash = h.hash(); qDebug("Got a torrent finished alert for %s", qPrintable(h.name())); -#if LIBTORRENT_VERSION_MINOR > 14 // Remove .!qB extension if necessary if(appendqBExtension) appendqBextensionToTorrent(h, false); -#endif + const bool was_already_seeded = TorrentPersistentData::isSeed(hash); qDebug("Was already seeded: %d", was_already_seeded); if(!was_already_seeded) { @@ -2341,18 +2282,7 @@ void QBtSession::readAlerts() { } else if (torrent_deleted_alert* p = dynamic_cast(a.get())) { qDebug("A torrent was deleted from the hard disk, attempting to remove the root folder too..."); - QString hash; -#if LIBTORRENT_VERSION_MINOR > 14 - hash = misc::toQString(p->info_hash); -#else - // Unfortunately libtorrent v0.14 does not provide the hash, - // only the torrent handle that is often invalid when it arrives - try { - if(p->handle.is_valid()) { - hash = misc::toQString(p->handle.info_hash()); - } - }catch(std::exception){} -#endif + QString hash = misc::toQString(p->info_hash); if(!hash.isEmpty()) { if(savePathsToRemove.contains(hash)) { const QString dirpath = savePathsToRemove.take(hash); @@ -2403,11 +2333,9 @@ void QBtSession::readAlerts() { // Copy the torrent file to the export folder if(torrentExport) exportTorrentFile(h); -#if LIBTORRENT_VERSION_MINOR > 14 // Append .!qB to incomplete files if(appendqBExtension) appendqBextensionToTorrent(h, true); -#endif // Truncate root folder const QString root_folder = misc::truncateRootFolder(p->handle); TorrentPersistentData::setRootFolder(h.hash(), root_folder); @@ -2451,7 +2379,6 @@ void QBtSession::readAlerts() { } } } -#if LIBTORRENT_VERSION_MINOR > 14 else if (file_completed_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); qDebug("A file completed download in torrent %s", qPrintable(h.name())); @@ -2466,7 +2393,6 @@ void QBtSession::readAlerts() { } } } -#endif else if (torrent_paused_alert* p = dynamic_cast(a.get())) { if(p->handle.is_valid()) { QTorrentHandle h(p->handle); @@ -2486,10 +2412,6 @@ void QBtSession::readAlerts() { QHash trackers_data = trackersInfos.value(h.hash(), QHash()); TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); data.last_message = misc::toQString(p->msg); -#if LIBTORRENT_VERSION_MINOR < 15 - data.verified = false; - ++data.fail_count; -#endif trackers_data.insert(tracker_url, data); trackersInfos[h.hash()] = trackers_data; } else { @@ -2507,10 +2429,6 @@ void QBtSession::readAlerts() { TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); data.last_message = ""; // Reset error/warning message data.num_peers = p->num_peers; -#if LIBTORRENT_VERSION_MINOR < 15 - data.fail_count = 0; - data.verified = true; -#endif trackers_data.insert(tracker_url, data); trackersInfos[h.hash()] = trackers_data; } @@ -2522,10 +2440,6 @@ void QBtSession::readAlerts() { const QString tracker_url = misc::toQString(p->url); TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); data.last_message = misc::toQString(p->msg); // Store warning message -#if LIBTORRENT_VERSION_MINOR < 15 - data.verified = true; - data.fail_count = 0; -#endif trackers_data.insert(tracker_url, data); trackersInfos[h.hash()] = trackers_data; qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); @@ -2560,12 +2474,7 @@ void QBtSession::readAlerts() { QTorrentHandle h(p->handle); if(h.is_valid()) { qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); -#if LIBTORRENT_VERSION_MINOR < 15 - QString msg = QString::fromLocal8Bit(p->message().c_str()); - if(msg.contains("filesize", Qt::CaseInsensitive) && msg.contains("mismatch", Qt::CaseInsensitive) && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { -#else if(p->error.value() == 134 && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { -#endif const QString hash = h.hash(); // Mismatching file size (files were probably moved addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); @@ -2775,27 +2684,6 @@ qreal QBtSession::getPayloadUploadRate() const{ return s->status().payload_upload_rate; } -#if LIBTORRENT_VERSION_MINOR < 15 -// Save DHT entry to hard drive -void QBtSession::saveDHTEntry() { - // Save DHT entry - if(DHTEnabled) { - try{ - entry dht_state = s->dht_state(); - const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); - if(QFile::exists(dht_path)) - misc::safeRemove(dht_path); - boost::filesystem::ofstream out(dht_path.toLocal8Bit().constData(), std::ios_base::binary); - out.unsetf(std::ios_base::skipws); - bencode(std::ostream_iterator(out), dht_state); - qDebug("DHT entry saved"); - }catch (std::exception& e) { - std::cerr << e.what() << std::endl; - } - } -} -#endif - void QBtSession::applyEncryptionSettings(pe_settings se) { qDebug("Applying encryption settings"); s->set_pe_settings(se); diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index 650a58566..824d6e846 100644 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -146,10 +146,8 @@ public slots: void setAppendLabelToSavePath(bool append); void appendLabelToTorrentSavePath(const QTorrentHandle &h); void changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label); -#if LIBTORRENT_VERSION_MINOR > 14 void appendqBextensionToTorrent(const QTorrentHandle &h, bool append); void setAppendqBExtension(bool append); -#endif void applyEncryptionSettings(libtorrent::pe_settings se); void setDownloadLimit(QString hash, long val); void setUploadLimit(QString hash, long val); @@ -216,11 +214,6 @@ signals: void ipFilterParsed(bool error, int ruleCount); void listenSucceeded(); -private: -#if LIBTORRENT_VERSION_MINOR < 15 - void saveDHTEntry(); -#endif - private: // Bittorrent libtorrent::session *s; @@ -252,9 +245,7 @@ private: bool queueingEnabled; bool appendLabelToSavePath; bool torrentExport; -#if LIBTORRENT_VERSION_MINOR > 14 bool appendqBExtension; -#endif QString defaultSavePath; QString defaultTempPath; // IP filtering diff --git a/src/qtlibtorrent/qtorrenthandle.cpp b/src/qtlibtorrent/qtorrenthandle.cpp index a2c859f85..f5343b5ad 100644 --- a/src/qtlibtorrent/qtorrenthandle.cpp +++ b/src/qtlibtorrent/qtorrenthandle.cpp @@ -43,6 +43,9 @@ #include #include #include +#if LIBTORRENT_VERSION_MINOR < 15 +#include +#endif #ifdef Q_WS_WIN #include @@ -51,6 +54,21 @@ using namespace libtorrent; using namespace std; +#if LIBTORRENT_VERSION_MINOR < 16 +static QString boostTimeToQString(const boost::posix_time::ptime &boostDate) { + if(boostDate.is_not_a_date_time()) return ""; + struct std::tm tm; + try { + tm = boost::posix_time::to_tm(boostDate); + } catch(std::exception e) { + return ""; + } + const time_t t = mktime(&tm); + const QDateTime dt = QDateTime::fromTime_t(t); + return dt.toString(Qt::DefaultLocaleLongDate); +} +#endif + QTorrentHandle::QTorrentHandle(torrent_handle h): torrent_handle(h) {} // @@ -74,10 +92,13 @@ QString QTorrentHandle::creation_date() const { boost::optional t = torrent_handle::get_torrent_info().creation_date(); if (t) return QDateTime::fromTime_t(*t).toString(Qt::DefaultLocaleLongDate); - return tr("Unknown"); + return ""; #else boost::optional boostDate = torrent_handle::get_torrent_info().creation_date(); - return misc::boostTimeToQString(boostDate); + if (boostDate) { + return boostTimeToQString(*boostDate); + } + return ""; #endif } @@ -574,11 +595,7 @@ return torrent_handle::status(0x0).distributed_copies; } void QTorrentHandle::file_progress(std::vector& fp) const { - torrent_handle::file_progress(fp -#if LIBTORRENT_VERSION_MINOR > 14 - , torrent_handle::piece_granularity -#endif - ); + torrent_handle::file_progress(fp, torrent_handle::piece_granularity); } // @@ -745,24 +762,7 @@ void QTorrentHandle::prioritize_files(const vector &files) const { } void QTorrentHandle::add_tracker(const announce_entry& url) const { -#if LIBTORRENT_VERSION_MINOR > 14 torrent_handle::add_tracker(url); -#else - std::vector trackers = torrent_handle::trackers(); - bool exists = false; - std::vector::iterator it = trackers.begin(); - while(it != trackers.end()) { - if(it->url == url.url) { - exists = true; - break; - } - it++; - } - if(!exists) { - trackers.push_back(url); - torrent_handle::replace_trackers(trackers); - } -#endif } void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const { diff --git a/src/qtlibtorrent/trackerinfos.h b/src/qtlibtorrent/trackerinfos.h index 127c80de0..f501542a8 100644 --- a/src/qtlibtorrent/trackerinfos.h +++ b/src/qtlibtorrent/trackerinfos.h @@ -38,10 +38,6 @@ public: QString name_or_url; QString last_message; unsigned long num_peers; -#if LIBTORRENT_VERSION_MINOR < 15 - bool verified; - uint fail_count; -#endif //TrackerInfos() {} TrackerInfos(const TrackerInfos &b) { @@ -49,16 +45,8 @@ public: Q_ASSERT(!name_or_url.isEmpty()); last_message = b.last_message; num_peers = b.num_peers; -#if LIBTORRENT_VERSION_MINOR < 15 - verified = b.verified; - fail_count = b.fail_count; -#endif } TrackerInfos(QString name_or_url): name_or_url(name_or_url), last_message(""), num_peers(0) { -#if LIBTORRENT_VERSION_MINOR < 15 - fail_count = 0; - verified = false; -#endif } }; diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index 8f181cbac..c0927f9e8 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -112,9 +112,6 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) : comboLabel->addItem(label); } -#if LIBTORRENT_VERSION_MINOR < 15 - addInSeed->setVisible(false); -#endif // Set Add button as default OkButton->setDefault(true); } @@ -663,7 +660,6 @@ void torrentAdditionDialog::on_OkButton_clicked(){ TorrentTempData::setFilesPath(hash, files_path); } } -#if LIBTORRENT_VERSION_MINOR > 14 // Skip file checking and directly start seeding if(addInSeed->isChecked()) { // Check if local file(s) actually exist @@ -674,7 +670,6 @@ void torrentAdditionDialog::on_OkButton_clicked(){ return; } } -#endif // Check if there is at least one selected file if(!is_magnet && t->num_files() > 1 && allFiltered()){ QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent")); diff --git a/src/torrentcreator/torrentcreatordlg.cpp b/src/torrentcreator/torrentcreatordlg.cpp index f789b246d..af0bffee6 100644 --- a/src/torrentcreator/torrentcreatordlg.cpp +++ b/src/torrentcreator/torrentcreatordlg.cpp @@ -171,10 +171,8 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) save_path = QDir(save_path).absoluteFilePath(root_folder); } TorrentTempData::setSavePath(hash, save_path); -#if LIBTORRENT_VERSION_MINOR > 14 // Enable seeding mode (do not recheck the files) TorrentTempData::setSeedingMode(hash, true); -#endif emit torrent_to_seed(path); } QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path); diff --git a/src/torrentimportdlg.cpp b/src/torrentimportdlg.cpp index 10b36d7c1..eca7143c2 100644 --- a/src/torrentimportdlg.cpp +++ b/src/torrentimportdlg.cpp @@ -51,9 +51,6 @@ TorrentImportDlg::TorrentImportDlg(QWidget *parent) : ui->lbl_info->setFixedWidth(ui->lbl_info->height()); ui->importBtn->setIcon(IconProvider::instance()->getIcon("document-import")); // Libtorrent < 0.15 does not support skipping file checking -#if LIBTORRENT_VERSION_MINOR < 15 - ui->checkSkipCheck->setVisible(false); -#endif loadSettings(); } @@ -107,7 +104,6 @@ void TorrentImportDlg::on_browseContentBtn_clicked() #else ui->lineContent->setText(m_contentPath); #endif -#if LIBTORRENT_VERSION_MINOR >= 15 // Check file size const qint64 file_size = QFile(m_contentPath).size(); if(t->file_at(0).size == file_size) { @@ -118,7 +114,6 @@ void TorrentImportDlg::on_browseContentBtn_clicked() ui->checkSkipCheck->setChecked(false); ui->checkSkipCheck->setEnabled(false); } -#endif // Handle file renaming QStringList parts = m_contentPath.replace("\\", "/").split("/"); QString new_file_name = parts.takeLast(); @@ -145,7 +140,6 @@ void TorrentImportDlg::on_browseContentBtn_clicked() #else ui->lineContent->setText(m_contentPath); #endif -#if LIBTORRENT_VERSION_MINOR >= 15 bool size_mismatch = false; QDir content_dir(m_contentPath); // Check file sizes @@ -172,7 +166,6 @@ void TorrentImportDlg::on_browseContentBtn_clicked() qDebug("The file size matches, allowing fast seeding..."); ui->checkSkipCheck->setEnabled(true); } -#endif } // Enable the import button ui->importBtn->setEnabled(true); @@ -214,9 +207,7 @@ void TorrentImportDlg::importTorrent() const QString hash = misc::toQString(t->info_hash()); qDebug() << "Torrent hash is" << hash; TorrentTempData::setSavePath(hash, content_path); -#if LIBTORRENT_VERSION_MINOR >= 15 TorrentTempData::setSeedingMode(hash, dlg.skipFileChecking()); -#endif qDebug("Adding the torrent to the session..."); QBtSession::instance()->addTorrent(torrent_path); // Remember the last opened folder @@ -280,12 +271,10 @@ boost::intrusive_ptr TorrentImportDlg::torrent() const return t; } -#if LIBTORRENT_VERSION_MINOR >= 15 bool TorrentImportDlg::skipFileChecking() const { return ui->checkSkipCheck->isChecked(); } -#endif void TorrentImportDlg::loadSettings() { diff --git a/src/torrentimportdlg.h b/src/torrentimportdlg.h index e8118b09e..a7e6ea7d0 100644 --- a/src/torrentimportdlg.h +++ b/src/torrentimportdlg.h @@ -56,9 +56,7 @@ public: QString getContentPath() const; bool fileRenamed() const; boost::intrusive_ptr torrent() const; -#if LIBTORRENT_VERSION_MINOR >= 15 bool skipFileChecking() const; -#endif protected slots: void loadTorrent(const QString &torrent_path); diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 7a5909aa0..fcb2edd68 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -118,7 +118,6 @@ public: return data.value("sequential", false).toBool(); } -#if LIBTORRENT_VERSION_MINOR > 14 static void setSeedingMode(QString hash,bool seed){ QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents-tmp").toHash(); @@ -134,7 +133,6 @@ public: const QHash data = all_data.value(hash).toHash(); return data.value("seeding", false).toBool(); } -#endif static QString getSavePath(QString hash) { QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index e3c0257c4..1e37fec32 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -547,7 +547,6 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&){ } void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const { -#if LIBTORRENT_VERSION_MINOR > 14 const QStringList hashes = getSelectedTorrentsHashes(); foreach(const QString &hash, hashes) { QTorrentHandle h = BTSession->getTorrentHandle(hash); @@ -555,7 +554,6 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const { h.super_seeding(!h.super_seeding()); } } -#endif } void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const { @@ -672,11 +670,9 @@ void TransferListWidget::displayListMenu(const QPoint&) { connect(&actionForce_recheck, SIGNAL(triggered()), this, SLOT(recheckSelectedTorrents())); QAction actionCopy_magnet_link(QIcon(":/Icons/magnet.png"), tr("Copy magnet link"), 0); connect(&actionCopy_magnet_link, SIGNAL(triggered()), this, SLOT(copySelectedMagnetURIs())); -#if LIBTORRENT_VERSION_MINOR > 14 QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0); actionSuper_seeding_mode.setCheckable(true); connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding())); -#endif QAction actionRename(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."), 0); connect(&actionRename, SIGNAL(triggered()), this, SLOT(renameSelectedTorrent())); QAction actionSequential_download(tr("Download in sequential order"), 0); @@ -690,10 +686,8 @@ void TransferListWidget::displayListMenu(const QPoint&) { // Enable/disable pause/start action given the DL state QModelIndexList selectedIndexes = selectionModel()->selectedRows(); bool has_pause = false, has_start = false, has_preview = false; -#if LIBTORRENT_VERSION_MINOR > 14 bool all_same_super_seeding = true; bool super_seeding_mode = false; -#endif bool all_same_sequential_download_mode = true, all_same_prio_firstlast = true; bool sequential_download_mode = false, prioritize_first_last = false; bool one_has_metadata = false, one_not_seed = false; @@ -724,7 +718,6 @@ void TransferListWidget::displayListMenu(const QPoint&) { } } } -#if LIBTORRENT_VERSION_MINOR > 14 else { if(!one_not_seed && all_same_super_seeding && h.has_metadata()) { if(first) { @@ -736,7 +729,6 @@ void TransferListWidget::displayListMenu(const QPoint&) { } } } -#endif if(h.is_paused()) { if(!has_start) { listMenu.addAction(&actionStart); @@ -776,12 +768,10 @@ void TransferListWidget::displayListMenu(const QPoint&) { listMenu.addAction(&actionSet_download_limit); listMenu.addAction(&actionSet_max_ratio); listMenu.addAction(&actionSet_upload_limit); -#if LIBTORRENT_VERSION_MINOR > 14 if(!one_not_seed && all_same_super_seeding && one_has_metadata) { actionSuper_seeding_mode.setChecked(super_seeding_mode); listMenu.addAction(&actionSuper_seeding_mode); } -#endif listMenu.addSeparator(); bool added_preview_action = false; if(has_preview) { diff --git a/src/webui/eventmanager.cpp b/src/webui/eventmanager.cpp index 4495c2679..cba4636b7 100644 --- a/src/webui/eventmanager.cpp +++ b/src/webui/eventmanager.cpp @@ -68,7 +68,6 @@ QList EventManager::getPropTrackersInfo(QString hash) const { tracker["url"] = tracker_url; TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); QString error_message = data.last_message.trimmed(); -#if LIBTORRENT_VERSION_MINOR > 14 if(it->verified) { tracker["status"] = tr("Working"); } else { @@ -82,16 +81,6 @@ QList EventManager::getPropTrackersInfo(QString hash) const { } } } -#else - if(data.verified) { - tracker["status"] = tr("Working"); - } else { - if(data.fail_count > 0) - tracker["status"] = tr("Not working"); - else - tracker["status"] = tr("Not contacted yet"); - } -#endif tracker["num_peers"] = QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers); tracker["msg"] = error_message; trackersInfo << tracker; @@ -209,10 +198,8 @@ void EventManager::setGlobalPreferences(QVariantMap m) { pref.setMaxActiveUploads(m["max_active_uploads"].toInt()); if(m.contains("dont_count_slow_torrents")) pref.setIgnoreSlowTorrentsForQueueing(m["dont_count_slow_torrents"].toBool()); -#if LIBTORRENT_VERSION_MINOR > 14 if(m.contains("incomplete_files_ext")) pref.useIncompleteFilesExtension(m["incomplete_files_ext"].toBool()); -#endif // Connection if(m.contains("listen_port")) pref.setSessionPort(m["listen_port"].toInt()); @@ -360,9 +347,7 @@ QVariantMap EventManager::getGlobalPreferences() const { data["max_active_torrents"] = pref.getMaxActiveTorrents(); data["max_active_uploads"] = pref.getMaxActiveUploads(); data["dont_count_slow_torrents"] = pref.ignoreSlowTorrentsForQueueing(); -#if LIBTORRENT_VERSION_MINOR > 14 data["incomplete_files_ext"] = pref.useIncompleteFilesExtension(); -#endif // Connection data["listen_port"] = pref.getSessionPort(); data["upnp"] = pref.isUPnPEnabled();