Browse Source

fix libtorrent 1.0 compatibility

adaptive-webui-19844
arvidn 11 years ago
parent
commit
3b4f9d2eeb
  1. 2
      src/misc.h
  2. 50
      src/qtlibtorrent/qbtsession.cpp
  3. 2
      src/qtlibtorrent/qbtsession.h

2
src/misc.h

@ -70,7 +70,7 @@ namespace misc
inline QString toQString(const libtorrent::sha1_hash &hash) { inline QString toQString(const libtorrent::sha1_hash &hash) {
char out[41]; 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); return QString(out);
} }

50
src/qtlibtorrent/qbtsession.cpp

@ -67,13 +67,16 @@
#include <libtorrent/identify_client.hpp> #include <libtorrent/identify_client.hpp>
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#include <libtorrent/error_code.hpp> #include <libtorrent/error_code.hpp>
#include <queue> #include <queue>
#include <string.h> #include <string.h>
#include "dnsupdater.h" #include "dnsupdater.h"
#if LIBTORRENT_VERSION_MAJOR < 1
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#endif
//initialize static member variables //initialize static member variables
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>(); QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
QHash<QString, bool> HiddenData::data = QHash<QString, bool>(); QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
@ -106,8 +109,11 @@ QBtSession::QBtSession()
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, 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)
m_upnp(0), m_natpmp(0), m_dynDNSUpdater(0) #if LIBTORRENT_VERSION_MAJOR < 1
, m_upnp(0), m_natpmp(0)
#endif
, m_dynDNSUpdater(0)
{ {
BigRatioTimer = new QTimer(this); BigRatioTimer = new QTimer(this);
BigRatioTimer->setInterval(10000); BigRatioTimer->setInterval(10000);
@ -1106,7 +1112,11 @@ 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
p.resume_data = &buf; p.resume_data = &buf;
#else
p.resume_data = buf;
#endif
qDebug("Successfully loaded fast resume data"); qDebug("Successfully loaded fast resume data");
} }
} }
@ -1431,25 +1441,33 @@ void QBtSession::setMaxUploadsPerTorrent(int max) {
void QBtSession::enableUPnP(bool b) { void QBtSession::enableUPnP(bool b) {
Preferences pref; Preferences pref;
if (b) { if (b) {
if (!m_upnp) { qDebug("Enabling UPnP / NAT-PMP");
qDebug("Enabling UPnP / NAT-PMP"); #if LIBTORRENT_VERSION_MAJOR < 1
m_upnp = s->start_upnp(); m_upnp = s->start_upnp();
m_natpmp = s->start_natpmp(); m_natpmp = s->start_natpmp();
} #else
s->start_upnp();
s->start_natpmp();
#endif
// 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
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
s->add_port_mapping(session::tcp, port, port);
#endif
} }
} else { } else {
if (m_upnp) { qDebug("Disabling UPnP / NAT-PMP");
qDebug("Disabling UPnP / NAT-PMP"); s->stop_upnp();
s->stop_upnp(); s->stop_natpmp();
s->stop_natpmp();
m_upnp = 0; #if LIBTORRENT_VERSION_MAJOR < 1
m_natpmp = 0; m_upnp = 0;
} m_natpmp = 0;
#endif
} }
} }

2
src/qtlibtorrent/qbtsession.h

@ -279,8 +279,10 @@ private:
TorrentSpeedMonitor *m_speedMonitor; TorrentSpeedMonitor *m_speedMonitor;
shutDownAction m_shutdownAct; shutDownAction m_shutdownAct;
// Port forwarding // Port forwarding
#if LIBTORRENT_VERSION_MAJOR < 1
libtorrent::upnp *m_upnp; libtorrent::upnp *m_upnp;
libtorrent::natpmp *m_natpmp; libtorrent::natpmp *m_natpmp;
#endif
// DynDNS // DynDNS
DNSUpdater *m_dynDNSUpdater; DNSUpdater *m_dynDNSUpdater;
}; };

Loading…
Cancel
Save