Browse Source

Merge pull request #1221 from arvidn/master

compatibility fixes for libtorrent 1.0 (trunk)
adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
3daae802eb
  1. 26
      src/addnewtorrentdialog.cpp
  2. 2
      src/misc.h
  3. 9
      src/properties/peerlistwidget.cpp
  4. 4
      src/properties/peerlistwidget.h
  5. 8
      src/properties/propertieswidget.cpp
  6. 71
      src/qtlibtorrent/qbtsession.cpp
  7. 4
      src/qtlibtorrent/qbtsession.h
  8. 124
      src/qtlibtorrent/qtorrenthandle.cpp
  9. 6
      src/transferlistwidget.cpp

26
src/addnewtorrentdialog.cpp

@ -214,15 +214,15 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString @@ -214,15 +214,15 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
ui->date_lbl->setText(m_torrentInfo->creation_date() ? misc::toQString(*m_torrentInfo->creation_date()) : tr("Not available"));
updateDiskSpaceLabel();
file_storage fs = m_torrentInfo->files();
file_storage const& fs = m_torrentInfo->files();
// Populate m_filesList
for (int i = 0; i < m_torrentInfo->num_files(); ++i) {
m_filesPath << misc::toQStringU(fs.file_path(m_torrentInfo->file_at(i)));
for (int i = 0; i < fs.num_files(); ++i) {
m_filesPath << misc::toQStringU(fs.file_path(i));
}
// Prepare content tree
if (m_torrentInfo->num_files() > 1) {
if (fs.num_files() > 1) {
m_contentModel = new TorrentContentFilterModel(this);
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
ui->content_tree->setModel(m_contentModel);
@ -240,7 +240,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString @@ -240,7 +240,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
ui->content_tree->header()->setResizeMode(0, QHeaderView::Stretch);
} else {
// Update save paths (append file name to them)
QString single_file_relpath = misc::toQStringU(fs.file_path(m_torrentInfo->file_at(0)));
QString single_file_relpath = misc::toQStringU(fs.file_path(0));
for (int i=0; i<ui->save_path_combo->count()-1; ++i) {
ui->save_path_combo->setItemText(i, fsutils::toDisplayPath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
}
@ -340,7 +340,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() @@ -340,7 +340,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
Q_ASSERT(priorities.size() == (uint) m_torrentInfo->num_files());
for (uint i=0; i<priorities.size(); ++i) {
if (priorities[i] > 0)
torrent_size += m_torrentInfo->file_at(i).size;
torrent_size += m_torrentInfo->files().file_size(i);
}
} else {
torrent_size = m_torrentInfo->total_size();
@ -649,7 +649,11 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { @@ -649,7 +649,11 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
disconnect(this, SLOT(updateMetadata(const QTorrentHandle&)));
Q_ASSERT(h.has_metadata());
#if LIBTORRENT_VERSION_NUM < 10000
m_torrentInfo = new torrent_info(h.get_torrent_info());
#else
m_torrentInfo = new torrent_info(*h.torrent_file());
#endif
// Good to go
m_hasMetadata = true;
@ -665,15 +669,15 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { @@ -665,15 +669,15 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
ui->date_lbl->setText(m_torrentInfo->creation_date() ? misc::toQString(*m_torrentInfo->creation_date()) : tr("Not available"));
updateDiskSpaceLabel();
file_storage fs = m_torrentInfo->files();
file_storage const& fs = m_torrentInfo->files();
// Populate m_filesList
for (int i = 0; i < m_torrentInfo->num_files(); ++i) {
m_filesPath << misc::toQStringU(fs.file_path(m_torrentInfo->file_at(i)));
for (int i = 0; i < fs.num_files(); ++i) {
m_filesPath << misc::toQStringU(fs.file_path(i));
}
// Prepare content tree
if (m_torrentInfo->num_files() > 1) {
if (fs.num_files() > 1) {
m_contentModel = new TorrentContentFilterModel(this);
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
ui->content_tree->setModel(m_contentModel);
@ -691,7 +695,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { @@ -691,7 +695,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
ui->content_tree->header()->setResizeMode(0, QHeaderView::Stretch);
} else {
// Update save paths (append file name to them)
QString single_file_relpath = misc::toQStringU(fs.file_path(m_torrentInfo->file_at(0)));
QString single_file_relpath = misc::toQStringU(fs.file_path(0));
for (int i=0; i<ui->save_path_combo->count()-1; ++i) {
ui->save_path_combo->setItemText(i, fsutils::toDisplayPath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
}

2
src/misc.h

@ -70,7 +70,7 @@ namespace misc @@ -70,7 +70,7 @@ namespace misc
inline QString toQString(const libtorrent::sha1_hash &hash) {
char out[41];
to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out);
libtorrent::to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out);
return QString(out);
}

9
src/properties/peerlistwidget.cpp

@ -160,16 +160,20 @@ void PeerListWidget::showPeerListMenu(const QPoint&) @@ -160,16 +160,20 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
empty_menu = false;
}
// Per Peer Speed limiting actions
#if LIBTORRENT_VERSION_NUM < 10000
QAction *upLimitAct = 0;
QAction *dlLimitAct = 0;
#endif
QAction *banAct = 0;
QAction *copyIPAct = 0;
if (!selectedPeerIPs.isEmpty()) {
copyIPAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy IP"));
menu.addSeparator();
#if LIBTORRENT_VERSION_NUM < 10000
dlLimitAct = menu.addAction(QIcon(":/Icons/skin/download.png"), tr("Limit download rate..."));
upLimitAct = menu.addAction(QIcon(":/Icons/skin/seeding.png"), tr("Limit upload rate..."));
menu.addSeparator();
#endif
banAct = menu.addAction(IconProvider::instance()->getIcon("user-group-delete"), tr("Ban peer permanently"));
empty_menu = false;
}
@ -190,6 +194,7 @@ void PeerListWidget::showPeerListMenu(const QPoint&) @@ -190,6 +194,7 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
}
return;
}
#if LIBTORRENT_VERSION_NUM < 10000
if (act == upLimitAct) {
limitUpRateSelectedPeers(selectedPeerIPs);
return;
@ -198,6 +203,7 @@ void PeerListWidget::showPeerListMenu(const QPoint&) @@ -198,6 +203,7 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
limitDlRateSelectedPeers(selectedPeerIPs);
return;
}
#endif
if (act == banAct) {
banSelectedPeers(selectedPeerIPs);
return;
@ -229,6 +235,7 @@ void PeerListWidget::banSelectedPeers(const QStringList& peer_ips) @@ -229,6 +235,7 @@ void PeerListWidget::banSelectedPeers(const QStringList& peer_ips)
loadPeers(m_properties->getCurrentTorrent());
}
#if LIBTORRENT_VERSION_NUM < 10000
void PeerListWidget::limitUpRateSelectedPeers(const QStringList& peer_ips)
{
if (peer_ips.empty())
@ -294,7 +301,7 @@ void PeerListWidget::limitDlRateSelectedPeers(const QStringList& peer_ips) @@ -294,7 +301,7 @@ void PeerListWidget::limitDlRateSelectedPeers(const QStringList& peer_ips)
}
}
}
#endif
void PeerListWidget::clear() {
qDebug("clearing peer list");

4
src/properties/peerlistwidget.h

@ -77,8 +77,12 @@ protected slots: @@ -77,8 +77,12 @@ protected slots:
void loadSettings();
void saveSettings() const;
void showPeerListMenu(const QPoint&);
#if LIBTORRENT_VERSION_NUM < 10000
void limitUpRateSelectedPeers(const QStringList& peer_ips);
void limitDlRateSelectedPeers(const QStringList& peer_ips);
#endif
void banSelectedPeers(const QStringList& peer_ips);
void handleSortColumnChanged(int col);

8
src/properties/propertieswidget.cpp

@ -253,7 +253,11 @@ void PropertiesWidget::loadTorrentInfos(const QTorrentHandle& _h) @@ -253,7 +253,11 @@ void PropertiesWidget::loadTorrentInfos(const QTorrentHandle& _h)
// URL seeds
loadUrlSeeds();
// List files in torrent
#if LIBTORRENT_VERSION_NUM < 10000
PropListModel->model()->setupModelData(h.get_torrent_info());
#else
PropListModel->model()->setupModelData(*h.torrent_file());
#endif
filesList->setExpanded(PropListModel->index(0, 0), true);
// Load file priorities
PropListModel->model()->updateFilesPriorities(h.file_priorities());
@ -338,7 +342,11 @@ void PropertiesWidget::loadDynamicData() { @@ -338,7 +342,11 @@ void PropertiesWidget::loadDynamicData() {
if (!h.is_seed()) {
showPiecesDownloaded(true);
// Downloaded pieces
#if LIBTORRENT_VERSION_NUM < 10000
bitfield bf(h.get_torrent_info().num_pieces(), 0);
#else
bitfield bf(h.torrent_file()->num_pieces(), 0);
#endif
h.downloading_pieces(bf);
downloaded_pieces->setProgress(h.pieces(), bf);
// Pieces availability

71
src/qtlibtorrent/qbtsession.cpp

@ -67,13 +67,16 @@ @@ -67,13 +67,16 @@
#include <libtorrent/identify_client.hpp>
#include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#include <libtorrent/error_code.hpp>
#include <queue>
#include <string.h>
#include "dnsupdater.h"
#if LIBTORRENT_VERSION_NUM < 10000
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#endif
//initialize static member variables
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
@ -106,8 +109,11 @@ QBtSession::QBtSession() @@ -106,8 +109,11 @@ QBtSession::QBtSession()
#ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false)
#endif
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN),
m_upnp(0), m_natpmp(0), m_dynDNSUpdater(0)
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN)
#if LIBTORRENT_VERSION_NUM < 10000
, m_upnp(0), m_natpmp(0)
#endif
, m_dynDNSUpdater(0)
{
BigRatioTimer = new QTimer(this);
BigRatioTimer->setInterval(10000);
@ -470,12 +476,12 @@ void QBtSession::configureSession() { @@ -470,12 +476,12 @@ void QBtSession::configureSession() {
if (pref.isDHTEnabled()) {
// Set DHT Port
if (enableDHT(true)) {
int dht_port;
if (pref.isDHTPortSameAsBT())
dht_port = 0;
else
int dht_port = 0;
#if LIBTORRENT_VERSION_NUM < 10000
if (!pref.isDHTPortSameAsBT())
dht_port = pref.getDHTPort();
setDHTPort(dht_port);
#endif
if (dht_port == 0) dht_port = new_listenPort;
addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue"));
} else {
@ -485,6 +491,7 @@ void QBtSession::configureSession() { @@ -485,6 +491,7 @@ void QBtSession::configureSession() {
enableDHT(false);
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
}
// * PeX
if (PeXEnabled) {
addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
@ -1106,7 +1113,11 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr @@ -1106,7 +1113,11 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (resumed) {
if (loadFastResumeData(hash, buf)) {
fastResume = true;
#if LIBTORRENT_VERSION_NUM < 10000
p.resume_data = &buf;
#else
p.resume_data = buf;
#endif
qDebug("Successfully loaded fast resume data");
}
}
@ -1218,9 +1229,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par @@ -1218,9 +1229,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
// Seeding mode
// Skip checking and directly start seeding (new in libtorrent v0.15)
if (TorrentTempData::isSeedingMode(hash))
p.seed_mode=true;
p.flags |= add_torrent_params::flag_seed_mode;
else
p.seed_mode=false;
p.flags &= ~add_torrent_params::flag_seed_mode;
// Preallocation mode
if (preAllocateAll)
@ -1242,9 +1253,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par @@ -1242,9 +1253,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
}*/
// Start in pause
p.paused = true;
p.duplicate_is_error = false; // Already checked
p.auto_managed = false; // Because it is added in paused state
p.flags |= add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_duplicate_is_error; // Already checked
p.flags &= ~add_torrent_params::flag_auto_managed; // Because it is added in paused state
}
void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) {
@ -1431,25 +1442,33 @@ void QBtSession::setMaxUploadsPerTorrent(int max) { @@ -1431,25 +1442,33 @@ void QBtSession::setMaxUploadsPerTorrent(int max) {
void QBtSession::enableUPnP(bool b) {
Preferences pref;
if (b) {
if (!m_upnp) {
qDebug("Enabling UPnP / NAT-PMP");
m_upnp = s->start_upnp();
m_natpmp = s->start_natpmp();
}
qDebug("Enabling UPnP / NAT-PMP");
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp = s->start_upnp();
m_natpmp = s->start_natpmp();
#else
s->start_upnp();
s->start_natpmp();
#endif
// Use UPnP/NAT-PMP for Web UI too
if (pref.isWebUiEnabled() && pref.useUPnPForWebUIPort()) {
const qint16 port = pref.getWebUiPort();
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp->add_mapping(upnp::tcp, port, port);
m_natpmp->add_mapping(natpmp::tcp, port, port);
#else
s->add_port_mapping(session::tcp, port, port);
#endif
}
} else {
if (m_upnp) {
qDebug("Disabling UPnP / NAT-PMP");
s->stop_upnp();
s->stop_natpmp();
m_upnp = 0;
m_natpmp = 0;
}
qDebug("Disabling UPnP / NAT-PMP");
s->stop_upnp();
s->stop_natpmp();
#if LIBTORRENT_VERSION_NUM < 10000
m_upnp = 0;
m_natpmp = 0;
#endif
}
}
@ -1963,6 +1982,7 @@ void QBtSession::updateRatioTimer() @@ -1963,6 +1982,7 @@ void QBtSession::updateRatioTimer()
}
}
#if LIBTORRENT_VERSION_NUM < 10000
// Set DHT port (>= 1 or 0 if same as BT)
void QBtSession::setDHTPort(int dht_port) {
if (dht_port >= 0) {
@ -1974,6 +1994,7 @@ void QBtSession::setDHTPort(int dht_port) { @@ -1974,6 +1994,7 @@ void QBtSession::setDHTPort(int dht_port) {
qDebug("Set DHT Port to %d", dht_port);
}
}
#endif
// Enable IP Filtering
void QBtSession::enableIPFilter(const QString &filter_path, bool force) {

4
src/qtlibtorrent/qbtsession.h

@ -145,7 +145,9 @@ public slots: @@ -145,7 +145,9 @@ public slots:
void setMaxRatioPerTorrent(const QString &hash, qreal ratio);
qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const;
void removeRatioPerTorrent(const QString &hash);
#if LIBTORRENT_VERSION_NUM < 10000
void setDHTPort(int dht_port);
#endif
void setProxySettings(libtorrent::proxy_settings proxySettings);
void setSessionSettings(const libtorrent::session_settings &sessionSettings);
void setDefaultSavePath(const QString &savepath);
@ -279,8 +281,10 @@ private: @@ -279,8 +281,10 @@ private:
TorrentSpeedMonitor *m_speedMonitor;
shutDownAction m_shutdownAct;
// Port forwarding
#if LIBTORRENT_VERSION_NUM < 10000
libtorrent::upnp *m_upnp;
libtorrent::natpmp *m_natpmp;
#endif
// DynDNS
DNSUpdater *m_dynDNSUpdater;
};

124
src/qtlibtorrent/qtorrenthandle.cpp

@ -84,13 +84,21 @@ QString QTorrentHandle::hash() const { @@ -84,13 +84,21 @@ QString QTorrentHandle::hash() const {
QString QTorrentHandle::name() const {
QString name = TorrentPersistentData::getName(hash());
if (name.isEmpty()) {
#if LIBTORRENT_VERSION_NUM < 10000
name = misc::toQStringU(torrent_handle::name());
#else
name = misc::toQStringU(torrent_handle::status(torrent_handle::query_name).name);
#endif
}
return name;
}
QString QTorrentHandle::creation_date() const {
#if LIBTORRENT_VERSION_NUM < 10000
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
#else
boost::optional<time_t> t = torrent_handle::torrent_file()->creation_date();
#endif
return t ? misc::toQString(*t) : "";
}
@ -132,34 +140,50 @@ bool QTorrentHandle::is_queued() const { @@ -132,34 +140,50 @@ bool QTorrentHandle::is_queued() const {
}
size_type QTorrentHandle::total_size() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().total_size();
#else
return torrent_handle::torrent_file()->total_size();
#endif
}
size_type QTorrentHandle::piece_length() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().piece_length();
#else
return torrent_handle::torrent_file()->piece_length();
#endif
}
int QTorrentHandle::num_pieces() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().num_pieces();
#else
return torrent_handle::torrent_file()->num_pieces();
#endif
}
bool QTorrentHandle::first_last_piece_first() const {
const torrent_info& t = get_torrent_info();
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* t = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> t = torrent_file();
#endif
// Get int first media file
int index = 0;
for (index = 0; index < t.num_files(); ++index) {
QString path = misc::toQStringU(t.file_at(index).path);
for (index = 0; index < t->num_files(); ++index) {
QString path = misc::toQStringU(t->file_at(index).path);
const QString ext = fsutils::fileExtension(path);
if (misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0)
break;
}
if (index >= t.num_files()) // No media file
if (index >= t->num_files()) // No media file
return false;
QPair<int, int> extremities = get_file_extremity_pieces (t, index);
QPair<int, int> extremities = get_file_extremity_pieces(*t, index);
return (torrent_handle::piece_priority(extremities.first) == 7)
&& (torrent_handle::piece_priority(extremities.second) == 7);
@ -198,7 +222,13 @@ int QTorrentHandle::num_incomplete() const { @@ -198,7 +222,13 @@ int QTorrentHandle::num_incomplete() const {
}
QString QTorrentHandle::save_path() const {
return misc::toQStringU(torrent_handle::save_path()).replace("\\", "/");
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::save_path())
.replace("\\", "/");
#else
return misc::toQStringU(status(torrent_handle::query_save_path).save_path)
.replace("\\", "/");
#endif
}
QString QTorrentHandle::save_path_parsed() const {
@ -248,25 +278,46 @@ bool QTorrentHandle::has_filtered_pieces() const { @@ -248,25 +278,46 @@ bool QTorrentHandle::has_filtered_pieces() const {
}
int QTorrentHandle::num_files() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().num_files();
#else
return torrent_handle::torrent_file()->num_files();
#endif
}
QString QTorrentHandle::filename_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
#else
Q_ASSERT(index < (unsigned int)torrent_handle::torrent_file()->num_files());
#endif
return fsutils::fileName(filepath_at(index));
}
size_type QTorrentHandle::filesize_at(unsigned int index) const {
#if LIBTORRENT_VERSION_NUM < 10000
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
return torrent_handle::get_torrent_info().file_at(index).size;
return torrent_handle::get_torrent_info().files().file_size(index);
#else
Q_ASSERT(index < (unsigned int)torrent_handle::torrent_file()->num_files());
return torrent_handle::torrent_file()->files().file_size(index);
#endif
}
QString QTorrentHandle::filepath_at(unsigned int index) const {
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path);
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index));
#else
return misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index));
#endif
}
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path);
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().file_path(index));
#else
return misc::toQStringU(torrent_handle::torrent_file()->orig_files().file_path(index));
#endif
}
torrent_status::state_t QTorrentHandle::state() const {
@ -274,11 +325,19 @@ torrent_status::state_t QTorrentHandle::state() const { @@ -274,11 +325,19 @@ torrent_status::state_t QTorrentHandle::state() const {
}
QString QTorrentHandle::creator() const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().creator());
#else
return misc::toQStringU(torrent_handle::torrent_file()->creator());
#endif
}
QString QTorrentHandle::comment() const {
#if LIBTORRENT_VERSION_NUM < 10000
return misc::toQStringU(torrent_handle::get_torrent_info().comment());
#else
return misc::toQStringU(torrent_handle::torrent_file()->comment());
#endif
}
size_type QTorrentHandle::total_failed_bytes() const {
@ -394,7 +453,11 @@ int QTorrentHandle::connections_limit() const { @@ -394,7 +453,11 @@ int QTorrentHandle::connections_limit() const {
}
bool QTorrentHandle::priv() const {
#if LIBTORRENT_VERSION_NUM < 10000
return torrent_handle::get_torrent_info().priv();
#else
return torrent_handle::torrent_file()->priv();
#endif
}
QString QTorrentHandle::firstFileSavePath() const {
@ -416,11 +479,11 @@ QString QTorrentHandle::root_path() const @@ -416,11 +479,11 @@ QString QTorrentHandle::root_path() const
{
if (num_files() < 2)
return save_path();
QString first_filepath = filepath_at(0);
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
if (slashIndex >= 0)
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
return save_path();
QString first_filepath = filepath_at(0);
const int slashIndex = first_filepath.indexOf(QRegExp("[/\\\\]"));
if (slashIndex >= 0)
return QDir(save_path()).absoluteFilePath(first_filepath.left(slashIndex));
return save_path();
}
bool QTorrentHandle::has_error() const {
@ -519,10 +582,14 @@ void QTorrentHandle::move_storage(const QString& new_path) const { @@ -519,10 +582,14 @@ void QTorrentHandle::move_storage(const QString& new_path) const {
bool QTorrentHandle::save_torrent_file(const QString& path) const {
if (!has_metadata()) return false;
const torrent_info& t = torrent_handle::get_torrent_info();
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* t = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> t = torrent_file();
#endif
entry meta = bdecode(t.metadata().get(),
t.metadata().get() + t.metadata_size());
entry meta = bdecode(t->metadata().get(),
t->metadata().get() + t->metadata_size());
entry torrent_entry(entry::dictionary_t);
torrent_entry["info"] = meta;
if (!torrent_handle::trackers().empty())
@ -549,7 +616,11 @@ void QTorrentHandle::file_priority(int index, int priority) const { @@ -549,7 +616,11 @@ void QTorrentHandle::file_priority(int index, int priority) const {
}
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
#if LIBTORRENT_VERSION_NUM < 10000
if ((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
#else
if ((int)files.size() != torrent_handle::torrent_file()->num_files()) return;
#endif
qDebug() << Q_FUNC_INFO;
bool was_seed = is_seed();
vector<size_type> progress;
@ -557,10 +628,13 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const { @@ -557,10 +628,13 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
qDebug() << Q_FUNC_INFO << "Changing files priorities...";
torrent_handle::prioritize_files(files);
qDebug() << Q_FUNC_INFO << "Moving unwanted files to .unwanted folder and conversely...";
QString spath = save_path();
for (uint i = 0; i < files.size(); ++i) {
// Move unwanted files to a .unwanted subfolder
if (files[i] == 0) {
QString old_abspath = QDir(save_path()).absoluteFilePath(filepath_at(i));
QString old_abspath = QDir(spath).absoluteFilePath(filepath_at(i));
QString parent_abspath = fsutils::branchPath(old_abspath);
// Make sure the file does not already exists
if (QDir(parent_abspath).dirName() != ".unwanted") {
@ -602,8 +676,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const { @@ -602,8 +676,8 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
else
rename_file(i, QDir(new_relpath).filePath(old_name));
// Remove .unwanted directory if empty
qDebug() << "Attempting to remove .unwanted folder at " << QDir(save_path() + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
QDir(save_path() + QDir::separator() + new_relpath).rmdir(".unwanted");
qDebug() << "Attempting to remove .unwanted folder at " << QDir(spath + QDir::separator() + new_relpath).absoluteFilePath(".unwanted");
QDir(spath + QDir::separator() + new_relpath).rmdir(".unwanted");
}
}
}
@ -616,7 +690,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const { @@ -616,7 +690,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
const Preferences pref;
if (pref.isTempPathEnabled()) {
QString tmp_path = pref.getTempPath();
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << save_path();
qDebug() << "tmp folder is enabled, move torrent to " << tmp_path << " from " << spath;
move_storage(tmp_path);
}
}
@ -626,7 +700,13 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const { @@ -626,7 +700,13 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
// Determine the priority to set
int prio = b ? 7 : torrent_handle::file_priority(file_index);
QPair<int, int> extremities = get_file_extremity_pieces (get_torrent_info(), file_index);
#if LIBTORRENT_VERSION_NUM < 10000
torrent_info const* tf = &get_torrent_info();
#else
boost::intrusive_ptr<torrent_info const> tf = torrent_file();
#endif
QPair<int, int> extremities = get_file_extremity_pieces(*tf, file_index);
piece_priority(extremities.first, prio);
piece_priority(extremities.second, prio);
}

6
src/transferlistwidget.cpp

@ -575,7 +575,7 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const { @@ -575,7 +575,7 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
foreach (const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if (h.is_valid() && h.has_metadata()) {
h.super_seeding(!h.super_seeding());
h.super_seeding(!h.status(0).super_seeding);
}
}
}
@ -747,9 +747,9 @@ void TransferListWidget::displayListMenu(const QPoint&) { @@ -747,9 +747,9 @@ void TransferListWidget::displayListMenu(const QPoint&) {
else {
if (!one_not_seed && all_same_super_seeding && h.has_metadata()) {
if (first) {
super_seeding_mode = h.super_seeding();
super_seeding_mode = h.status(0).super_seeding;
} else {
if (super_seeding_mode != h.super_seeding()) {
if (super_seeding_mode != h.status(0).super_seeding) {
all_same_super_seeding = false;
}
}

Loading…
Cancel
Save