Skip to content

Commit

Permalink
Merge pull request #636 from sledgehammer999/libtorrent_trunk
Browse files Browse the repository at this point in the history
Fix compilation with libtorrent 1.x.x.
  • Loading branch information
Christophe Dumez committed Jun 8, 2013
2 parents b8598bf + 22e2baf commit f4e5d7b
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 99 deletions.
6 changes: 3 additions & 3 deletions src/addnewtorrentdialog.cpp
Expand Up @@ -188,13 +188,13 @@ 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();

#if LIBTORRENT_VERSION_MINOR >= 16
#if LIBTORRENT_VERSION_NUM >= 001600
file_storage fs = m_torrentInfo->files();
#endif

// Populate m_filesList
for (int i = 0; i < m_torrentInfo->num_files(); ++i) {
#if LIBTORRENT_VERSION_MINOR >= 16
#if LIBTORRENT_VERSION_NUM >= 001600
m_filesPath << misc::toQStringU(fs.file_path(m_torrentInfo->file_at(i)));
#else
m_filesPath << misc::toQStringU(m_torrentInfo->file_at(i).path.string());
Expand All @@ -220,7 +220,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)
#if LIBTORRENT_VERSION_MINOR >= 16
#if LIBTORRENT_VERSION_NUM >= 001600
QString single_file_relpath = misc::toQStringU(fs.file_path(m_torrentInfo->file_at(0)));
#else
QString single_file_relpath = misc::toQStringU(m_torrentInfo->file_at(0).path.string());
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.cpp
Expand Up @@ -619,7 +619,7 @@ void MainWindow::handleDownloadFromUrlFailure(QString url, QString reason) const
void MainWindow::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered");
bool ok;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
int cur_limit = QBtSession::instance()->getSession()->settings().upload_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->upload_rate_limit();
Expand All @@ -638,7 +638,7 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() {
void MainWindow::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered");
bool ok;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
int cur_limit = QBtSession::instance()->getSession()->settings().download_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->download_rate_limit();
Expand Down
2 changes: 1 addition & 1 deletion src/misc.cpp
Expand Up @@ -502,7 +502,7 @@ QString misc::parseHtmlLinks(const QString &raw_text)
return result;
}

#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
QString misc::toQString(const boost::posix_time::ptime& boostDate) {
if (boostDate.is_not_a_date_time()) return "";
struct std::tm tm;
Expand Down
2 changes: 1 addition & 1 deletion src/misc.h
Expand Up @@ -114,7 +114,7 @@ class misc
static QList<int> intListfromStringList(const QStringList &l);
static QList<bool> boolListfromStringList(const QStringList &l);

#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
static QString toQString(const boost::posix_time::ptime& boostDate);
#else
static QString toQString(time_t t);
Expand Down
10 changes: 5 additions & 5 deletions src/preferences/options_imp.cpp
Expand Up @@ -125,7 +125,7 @@ options_imp::options_imp(QWidget *parent):
checkStartup->setVisible(false);
groupFileAssociation->setVisible(false);
#endif
#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
checkAnonymousMode->setVisible(false);
label_anonymous->setVisible(false);
#endif
Expand Down Expand Up @@ -206,7 +206,7 @@ options_imp::options_imp(QWidget *parent):
connect(spinMaxConnecPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinMaxUploadsPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkDHT, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
connect(checkAnonymousMode, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
#endif
connect(checkPeX, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
Expand Down Expand Up @@ -252,7 +252,7 @@ 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 < 16
#if LIBTORRENT_VERSION_NUM < 001600
checkuTP->setVisible(false);
checkLimituTPConnections->setVisible(false);
#endif
Expand Down Expand Up @@ -455,7 +455,7 @@ void options_imp::saveOptions() {
pref.setDHTPort(getDHTPort());
pref.setLSDEnabled(isLSDEnabled());
pref.setEncryptionSetting(getEncryptionSetting());
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
pref.enableAnonymousMode(checkAnonymousMode->isChecked());
#endif
pref.setGlobalMaxRatio(getMaxRatio());
Expand Down Expand Up @@ -727,7 +727,7 @@ void options_imp::loadOptions() {
checkPeX->setChecked(pref.isPeXEnabled());
checkLSD->setChecked(pref.isLSDEnabled());
comboEncryption->setCurrentIndex(pref.getEncryptionSetting());
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
checkAnonymousMode->setChecked(pref.isAnonymousModeEnabled());
/* make sure ui matches options */
toggleAnonymousMode(checkAnonymousMode->isChecked());
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/preferences.h
Expand Up @@ -1065,7 +1065,7 @@ class Preferences : private QIniSettings {
return value(QString::fromUtf8("Preferences/Connection/InetAddress"), QString()).toString();
}

#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
bool isAnonymousModeEnabled() const {
return value(QString::fromUtf8("Preferences/Advanced/AnonymousMode"), false).toBool();
}
Expand Down
6 changes: 3 additions & 3 deletions src/properties/peerlistwidget.cpp
Expand Up @@ -222,7 +222,7 @@ void PeerListWidget::limitUpRateSelectedPeers(const QStringList& peer_ips)

bool ok = false;
int cur_limit = -1;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
boost::asio::ip::tcp::endpoint first_ep = m_peerEndpoints.value(peer_ips.first(),
boost::asio::ip::tcp::endpoint());
if (first_ep != boost::asio::ip::tcp::endpoint())
Expand Down Expand Up @@ -257,7 +257,7 @@ void PeerListWidget::limitDlRateSelectedPeers(const QStringList& peer_ips)
return;
bool ok = false;
int cur_limit = -1;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
boost::asio::ip::tcp::endpoint first_ep = m_peerEndpoints.value(peer_ips.first(),
boost::asio::ip::tcp::endpoint());
if (first_ep != boost::asio::ip::tcp::endpoint())
Expand Down Expand Up @@ -419,7 +419,7 @@ QString PeerListWidget::getConnectionString(int connection_type)
{
QString connection;
switch(connection_type) {
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
case peer_info::bittorrent_utp:
connection = "uTP";
break;
Expand Down
2 changes: 1 addition & 1 deletion src/properties/propertieswidget.cpp
Expand Up @@ -459,7 +459,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&) {
myFilesLlistMenu.addSeparator();
}
QMenu subMenu;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
if (!h.status(0x0).is_seeding) {
#else
if (!static_cast<torrent_handle>(h).is_seed()) {
Expand Down
2 changes: 1 addition & 1 deletion src/properties/proplistdelegate.h
Expand Up @@ -161,7 +161,7 @@ class PropListDelegate: public QItemDelegate {
if (index.column() != PRIORITY) return 0;
if (properties) {
QTorrentHandle h = properties->getCurrentTorrent();
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
if (!h.is_valid() || !h.has_metadata() || h.status(0x0).is_seeding) return 0;
#else
if (!h.is_valid() || !h.has_metadata() || static_cast<libtorrent::torrent_handle>(h).is_seed()) return 0;
Expand Down
40 changes: 20 additions & 20 deletions src/qtlibtorrent/qbtsession.cpp
Expand Up @@ -70,12 +70,12 @@
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/upnp.hpp>
#include <libtorrent/natpmp.hpp>
#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#endif
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
#include "libtorrent/error_code.hpp"
#endif
#include <queue>
Expand Down Expand Up @@ -119,7 +119,7 @@ QBtSession::QBtSession()
BigRatioTimer->setInterval(10000);
connect(BigRatioTimer, SIGNAL(timeout()), SLOT(processBigRatios()));
Preferences pref;
#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
// To avoid some exceptions
boost::filesystem::path::default_name_check(boost::filesystem::no_check);
#endif
Expand Down Expand Up @@ -395,7 +395,7 @@ void QBtSession::configureSession() {

sessionSettings.upnp_ignore_nonrouters = true;
sessionSettings.use_dht_as_fallback = false;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
// Disable support for SSL torrents for now
sessionSettings.ssl_listen = 0;
#endif
Expand All @@ -412,7 +412,7 @@ void QBtSession::configureSession() {
int cache_size = pref.diskCacheSize();
sessionSettings.cache_size = cache_size ? cache_size * 64 : -1;
qDebug() << "Using a disk cache size of" << cache_size << "MiB";
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled();
if (sessionSettings.anonymous_mode) {
addConsoleMessage(tr("Anonymous mode [ON]"), "blue");
Expand Down Expand Up @@ -443,7 +443,7 @@ void QBtSession::configureSession() {
// IP address to announce to trackers
QString announce_ip = pref.getNetworkAddress();
if (!announce_ip.isEmpty()) {
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
sessionSettings.announce_ip = announce_ip.toStdString();
#else
boost::system::error_code ec;
Expand All @@ -456,7 +456,7 @@ void QBtSession::configureSession() {
}
// Super seeding
sessionSettings.strict_super_seeding = pref.isSuperSeedingEnabled();
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
// * Max Half-open connections
sessionSettings.half_open_limit = pref.getMaxHalfOpenConnections();
// * Max connections limit
Expand All @@ -467,7 +467,7 @@ void QBtSession::configureSession() {
// * Max connections limit
setMaxConnections(pref.getMaxConnecs());
#endif
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
// uTP
if (pref.isuTPEnabled()) {
sessionSettings.enable_incoming_utp = true;
Expand Down Expand Up @@ -1100,7 +1100,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
qDebug("Successfully loaded fast resume data");
}
}
#if LIBTORRENT_VERSION_MINOR < 16
#if LIBTORRENT_VERSION_NUM < 001600
else {
// Generate fake resume data to make sure unwanted files
// are not allocated
Expand Down Expand Up @@ -1235,7 +1235,7 @@ add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) {
p.storage_mode = storage_mode_sparse;

// Priorities
/*#if LIBTORRENT_VERSION_MINOR > 15
/*#if LIBTORRENT_VERSION_NUM >= 001600
if (TorrentTempData::hasTempData(hash)) {
std::vector<int> fp;
TorrentTempData::getFilesPriority(hash, fp);
Expand Down Expand Up @@ -1352,7 +1352,7 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren

bool urlseeds_added = false;
const QStringList old_urlseeds = h_ex.url_seeds();
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
std::vector<web_seed_entry> new_urlseeds = t->web_seeds();

std::vector<web_seed_entry>::iterator it = new_urlseeds.begin();
Expand Down Expand Up @@ -1422,7 +1422,7 @@ void QBtSession::exportTorrentFiles(QString path) {

// Set the maximum number of opened connections
void QBtSession::setMaxConnections(int maxConnec) {
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
Q_UNUSED(maxConnec);
Q_ASSERT(0); // Should not be used
#else
Expand Down Expand Up @@ -1521,7 +1521,7 @@ void QBtSession::loadSessionState() {
state_file.read(&in[0], content_size);
// bdecode
lazy_entry e;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec;
lazy_bdecode(&in[0], &in[0] + in.size(), e, ec);
if (!ec) {
Expand Down Expand Up @@ -1611,7 +1611,7 @@ void QBtSession::saveTempFastResumeData() {
QTorrentHandle h = QTorrentHandle(*torrentIT);
try {
if (!h.is_valid() || !h.has_metadata() /*|| h.is_seed() || h.is_paused()*/) continue;
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
if (!h.need_save_resume_data()) continue;
#endif
if (h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue;
Expand Down Expand Up @@ -1905,12 +1905,12 @@ void QBtSession::setListeningPort(int port) {
qDebug() << Q_FUNC_INFO << port;
Preferences pref;
std::pair<int,int> ports(port, port);
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
libtorrent::error_code ec;
#endif
const QString iface_name = pref.getNetworkInterface();
if (iface_name.isEmpty()) {
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
s->listen_on(ports, ec);
#else
s->listen_on(ports);
Expand All @@ -1928,7 +1928,7 @@ void QBtSession::setListeningPort(int port) {
qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());
foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
s->listen_on(ports, ec, entry.ip().toString().toAscii().constData());
if (!ec) {
#else
Expand All @@ -1951,7 +1951,7 @@ void QBtSession::setListeningPort(int port) {
void QBtSession::setDownloadRateLimit(long rate) {
qDebug() << Q_FUNC_INFO << rate;
Q_ASSERT(rate == -1 || rate >= 0);
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
session_settings settings = s->settings();
settings.download_rate_limit = rate;
s->set_settings(settings);
Expand All @@ -1965,7 +1965,7 @@ void QBtSession::setDownloadRateLimit(long rate) {
void QBtSession::setUploadRateLimit(long rate) {
qDebug() << Q_FUNC_INFO << rate;
Q_ASSERT(rate == -1 || rate >= 0);
#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
session_settings settings = s->settings();
settings.upload_rate_limit = rate;
s->set_settings(settings);
Expand Down Expand Up @@ -2073,7 +2073,7 @@ void QBtSession::setSessionSettings(const session_settings &sessionSettings) {
void QBtSession::setProxySettings(proxy_settings proxySettings) {
qDebug() << Q_FUNC_INFO;

#if LIBTORRENT_VERSION_MINOR > 15
#if LIBTORRENT_VERSION_NUM >= 001600
proxySettings.proxy_peer_connections = Preferences().proxyPeerConnections();
s->set_proxy(proxySettings);
#else
Expand Down

0 comments on commit f4e5d7b

Please sign in to comment.