Browse Source

don't use deprecated libtorrent functions

adaptive-webui-19844
arvidn 11 years ago
parent
commit
c1c824bcf7
  1. 26
      src/addnewtorrentdialog.cpp
  2. 9
      src/properties/peerlistwidget.cpp
  3. 4
      src/properties/peerlistwidget.h
  4. 8
      src/properties/propertieswidget.cpp
  5. 33
      src/qtlibtorrent/qbtsession.cpp
  6. 4
      src/qtlibtorrent/qbtsession.h
  7. 124
      src/qtlibtorrent/qtorrenthandle.cpp
  8. 6
      src/transferlistwidget.cpp

26
src/addnewtorrentdialog.cpp

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

9
src/properties/peerlistwidget.cpp

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

4
src/properties/peerlistwidget.h

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

8
src/properties/propertieswidget.cpp

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

33
src/qtlibtorrent/qbtsession.cpp

@ -72,7 +72,7 @@
#include <string.h> #include <string.h>
#include "dnsupdater.h" #include "dnsupdater.h"
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
#include <libtorrent/upnp.hpp> #include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp> #include <libtorrent/natpmp.hpp>
#endif #endif
@ -110,7 +110,7 @@ QBtSession::QBtSession()
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #endif
, m_tracker(0), m_shutdownAct(NO_SHUTDOWN) , m_tracker(0), m_shutdownAct(NO_SHUTDOWN)
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
, m_upnp(0), m_natpmp(0) , m_upnp(0), m_natpmp(0)
#endif #endif
, m_dynDNSUpdater(0) , m_dynDNSUpdater(0)
@ -476,12 +476,12 @@ void QBtSession::configureSession() {
if (pref.isDHTEnabled()) { if (pref.isDHTEnabled()) {
// Set DHT Port // Set DHT Port
if (enableDHT(true)) { if (enableDHT(true)) {
int dht_port; int dht_port = 0;
if (pref.isDHTPortSameAsBT()) #if LIBTORRENT_VERSION_NUM < 10000
dht_port = 0; if (!pref.isDHTPortSameAsBT())
else
dht_port = pref.getDHTPort(); dht_port = pref.getDHTPort();
setDHTPort(dht_port); setDHTPort(dht_port);
#endif
if (dht_port == 0) dht_port = new_listenPort; if (dht_port == 0) dht_port = new_listenPort;
addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue")); addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue"));
} else { } else {
@ -491,6 +491,7 @@ void QBtSession::configureSession() {
enableDHT(false); enableDHT(false);
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue")); addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue"));
} }
// * PeX // * PeX
if (PeXEnabled) { if (PeXEnabled) {
addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue")); addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue"));
@ -1112,7 +1113,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
if (resumed) { if (resumed) {
if (loadFastResumeData(hash, buf)) { if (loadFastResumeData(hash, buf)) {
fastResume = true; fastResume = true;
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
p.resume_data = &buf; p.resume_data = &buf;
#else #else
p.resume_data = buf; p.resume_data = buf;
@ -1228,9 +1229,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
// Seeding mode // Seeding mode
// Skip checking and directly start seeding (new in libtorrent v0.15) // Skip checking and directly start seeding (new in libtorrent v0.15)
if (TorrentTempData::isSeedingMode(hash)) if (TorrentTempData::isSeedingMode(hash))
p.seed_mode=true; p.flags |= add_torrent_params::flag_seed_mode;
else else
p.seed_mode=false; p.flags &= ~add_torrent_params::flag_seed_mode;
// Preallocation mode // Preallocation mode
if (preAllocateAll) if (preAllocateAll)
@ -1252,9 +1253,9 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par
}*/ }*/
// Start in pause // Start in pause
p.paused = true; p.flags |= add_torrent_params::flag_paused;
p.duplicate_is_error = false; // Already checked p.flags &= ~add_torrent_params::flag_duplicate_is_error; // Already checked
p.auto_managed = false; // Because it is added in paused state p.flags &= ~add_torrent_params::flag_auto_managed; // Because it is added in paused state
} }
void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) { void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) {
@ -1442,7 +1443,7 @@ void QBtSession::enableUPnP(bool b) {
Preferences pref; Preferences pref;
if (b) { if (b) {
qDebug("Enabling UPnP / NAT-PMP"); qDebug("Enabling UPnP / NAT-PMP");
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
m_upnp = s->start_upnp(); m_upnp = s->start_upnp();
m_natpmp = s->start_natpmp(); m_natpmp = s->start_natpmp();
#else #else
@ -1452,7 +1453,7 @@ void QBtSession::enableUPnP(bool b) {
// Use UPnP/NAT-PMP for Web UI too // Use UPnP/NAT-PMP for Web UI too
if (pref.isWebUiEnabled() && pref.useUPnPForWebUIPort()) { if (pref.isWebUiEnabled() && pref.useUPnPForWebUIPort()) {
const qint16 port = pref.getWebUiPort(); const qint16 port = pref.getWebUiPort();
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
m_upnp->add_mapping(upnp::tcp, port, port); m_upnp->add_mapping(upnp::tcp, port, port);
m_natpmp->add_mapping(natpmp::tcp, port, port); m_natpmp->add_mapping(natpmp::tcp, port, port);
#else #else
@ -1464,7 +1465,7 @@ void QBtSession::enableUPnP(bool b) {
s->stop_upnp(); s->stop_upnp();
s->stop_natpmp(); s->stop_natpmp();
#if LIBTORRENT_VERSION_MAJOR < 1 #if LIBTORRENT_VERSION_NUM < 10000
m_upnp = 0; m_upnp = 0;
m_natpmp = 0; m_natpmp = 0;
#endif #endif
@ -1981,6 +1982,7 @@ void QBtSession::updateRatioTimer()
} }
} }
#if LIBTORRENT_VERSION_NUM < 10000
// Set DHT port (>= 1 or 0 if same as BT) // Set DHT port (>= 1 or 0 if same as BT)
void QBtSession::setDHTPort(int dht_port) { void QBtSession::setDHTPort(int dht_port) {
if (dht_port >= 0) { if (dht_port >= 0) {
@ -1992,6 +1994,7 @@ void QBtSession::setDHTPort(int dht_port) {
qDebug("Set DHT Port to %d", dht_port); qDebug("Set DHT Port to %d", dht_port);
} }
} }
#endif
// Enable IP Filtering // Enable IP Filtering
void QBtSession::enableIPFilter(const QString &filter_path, bool force) { void QBtSession::enableIPFilter(const QString &filter_path, bool force) {

4
src/qtlibtorrent/qbtsession.h

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

124
src/qtlibtorrent/qtorrenthandle.cpp

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

6
src/transferlistwidget.cpp

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

Loading…
Cancel
Save