Browse Source

Fix compilation error with libtorrent v0.14

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
fc8a822dac
  1. 246
      src/qtlibtorrent/qbtsession.cpp

246
src/qtlibtorrent/qbtsession.cpp

@ -80,9 +80,9 @@ Bittorrent::Bittorrent() @@ -80,9 +80,9 @@ Bittorrent::Bittorrent()
UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
torrentExport(false), exiting(false)
#ifndef DISABLE_GUI
#ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false)
#endif
#endif
{
m_tracker = 0;
// To avoid some exceptions
@ -882,7 +882,11 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { @@ -882,7 +882,11 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
}
QString torrent_name = misc::magnetUriToName(magnet_uri);
const QString savePath(getSavePath(hash, false, QString::null, torrent_name));
if(!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash) && !TorrentTempData::isSeedingMode(hash)) {
if(!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)
#if LIBTORRENT_VERSION_MINOR > 14
&& !TorrentTempData::isSeedingMode(hash)
#endif
) {
qDebug("addMagnetURI: Temp folder is enabled.");
qDebug("addTorrent::Temp folder is enabled.");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
@ -1134,7 +1138,11 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr @@ -1134,7 +1138,11 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
} else {
savePath = getSavePath(hash, fromScanDir, path, root_folder);
}
if(!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash) && !TorrentTempData::isSeedingMode(hash)) {
if(!defaultTempPath.isEmpty() && !TorrentPersistentData::isSeed(hash)
#if LIBTORRENT_VERSION_MINOR > 14
&& !TorrentTempData::isSeedingMode(hash)
#endif
) {
qDebug("addTorrent::Temp folder is enabled.");
QString torrent_tmp_path = defaultTempPath.replace("\\", "/");
if(!root_folder.isEmpty()) {
@ -1634,7 +1642,7 @@ QStringList Bittorrent::getPeerBanMessages() const { @@ -1634,7 +1642,7 @@ QStringList Bittorrent::getPeerBanMessages() const {
#ifdef DISABLE_GUI
void Bittorrent::addConsoleMessage(QString msg, QString) {
#else
void Bittorrent::addConsoleMessage(QString msg, QColor color) {
void Bittorrent::addConsoleMessage(QString msg, QColor color) {
if(consoleMessages.size() > 100) {
consoleMessages.removeFirst();
}
@ -1644,9 +1652,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1644,9 +1652,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
consoleMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - <font color='") + color.name() +QString::fromUtf8("'><i>") + msg + QString::fromUtf8("</i></font>"));
#endif
emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg);
}
}
void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) {
void Bittorrent::addPeerBanMessage(QString ip, bool from_ipfilter) {
if(peerBanMessages.size() > 100) {
peerBanMessages.removeFirst();
}
@ -1654,9 +1662,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1654,9 +1662,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was blocked due to your IP filter</i>", "x.y.z.w was blocked").arg(ip));
else
peerBanMessages.append(QString::fromUtf8("<font color='grey'>")+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + QString::fromUtf8("</font> - ")+tr("<font color='red'>%1</font> <i>was banned due to corrupt pieces</i>", "x.y.z.w was banned").arg(ip));
}
}
bool Bittorrent::isFilePreviewPossible(QString hash) const{
bool Bittorrent::isFilePreviewPossible(QString hash) const{
// See if there are supported files in the torrent
const QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_valid() || !h.has_metadata()) {
@ -1669,9 +1677,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1669,9 +1677,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
return true;
}
return false;
}
}
void Bittorrent::addTorrentsFromScanFolder(QStringList &pathList) {
void Bittorrent::addTorrentsFromScanFolder(QStringList &pathList) {
foreach(const QString &file, pathList) {
qDebug("File %s added", qPrintable(file));
try {
@ -1682,17 +1690,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1682,17 +1690,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
qDebug("Ignoring incomplete torrent file: %s", qPrintable(file));
}
}
}
}
QString Bittorrent::getDefaultSavePath() const {
QString Bittorrent::getDefaultSavePath() const {
return defaultSavePath;
}
}
bool Bittorrent::useTemporaryFolder() const {
bool Bittorrent::useTemporaryFolder() const {
return !defaultTempPath.isEmpty();
}
}
void Bittorrent::setDefaultTempPath(QString temppath) {
void Bittorrent::setDefaultTempPath(QString temppath) {
if(defaultTempPath == temppath)
return;
if(temppath.isEmpty()) {
@ -1726,10 +1734,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1726,10 +1734,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
defaultTempPath = temppath;
}
}
#if LIBTORRENT_VERSION_MINOR > 14
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle &h, bool append) {
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle &h, bool append) {
if(!h.is_valid() || !h.has_metadata()) return;
std::vector<size_type> fp;
h.file_progress(fp);
@ -1754,10 +1762,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1754,10 +1762,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
}
}
}
#endif
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle &h, QString old_label, QString new_label) {
void Bittorrent::changeLabelInTorrentSavePath(QTorrentHandle &h, QString old_label, QString new_label) {
if(!h.is_valid()) return;
if(!appendLabelToSavePath) return;
QString old_save_path = TorrentPersistentData::getSavePath(h.hash());
@ -1769,9 +1777,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1769,9 +1777,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
QDir().mkpath(new_save_path);
h.move_storage(new_save_path);
}
}
}
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle& h) {
void Bittorrent::appendLabelToTorrentSavePath(QTorrentHandle& h) {
if(!h.is_valid()) return;
const QString label = TorrentPersistentData::getLabel(h.hash());
if(label.isEmpty()) return;
@ -1783,9 +1791,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1783,9 +1791,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
QDir().mkpath(new_save_path);
h.move_storage(new_save_path);
}
}
}
void Bittorrent::setAppendLabelToSavePath(bool append) {
void Bittorrent::setAppendLabelToSavePath(bool append) {
if(appendLabelToSavePath != append) {
appendLabelToSavePath = !appendLabelToSavePath;
if(appendLabelToSavePath) {
@ -1798,10 +1806,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1798,10 +1806,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
}
}
}
#if LIBTORRENT_VERSION_MINOR > 14
void Bittorrent::setAppendqBExtension(bool append) {
void Bittorrent::setAppendqBExtension(bool append) {
if(appendqBExtension != append) {
appendqBExtension = !appendqBExtension;
// append or remove .!qB extension for incomplete files
@ -1812,12 +1820,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1812,12 +1820,12 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
appendqBextensionToTorrent(h, appendqBExtension);
}
}
}
}
#endif
// Set the ports range in which is chosen the port the Bittorrent
// session will listen to
void Bittorrent::setListeningPort(int port) {
// Set the ports range in which is chosen the port the Bittorrent
// session will listen to
void Bittorrent::setListeningPort(int port) {
std::pair<int,int> ports(port, port);
const QString& iface_name = Preferences::getNetworkInterface();
if(iface_name.isEmpty()) {
@ -1835,30 +1843,30 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1835,30 +1843,30 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
qDebug("Listening on interface %s with ip %s", qPrintable(iface_name), qPrintable(ip));
s->listen_on(ports, ip.toLocal8Bit().constData());
}
}
// Set download rate limit
// -1 to disable
void Bittorrent::setDownloadRateLimit(long rate) {
// Set download rate limit
// -1 to disable
void Bittorrent::setDownloadRateLimit(long rate) {
Q_ASSERT(rate == -1 || rate >= 0);
qDebug("Setting a global download rate limit at %ld", rate);
s->set_download_rate_limit(rate);
}
}
session* Bittorrent::getSession() const{
session* Bittorrent::getSession() const{
return s;
}
}
// Set upload rate limit
// -1 to disable
void Bittorrent::setUploadRateLimit(long rate) {
// Set upload rate limit
// -1 to disable
void Bittorrent::setUploadRateLimit(long rate) {
Q_ASSERT(rate == -1 || rate >= 0);
s->set_upload_rate_limit(rate);
}
}
// Torrents will a ratio superior to the given value will
// be automatically deleted
void Bittorrent::setMaxRatio(float ratio) {
// Torrents will a ratio superior to the given value will
// be automatically deleted
void Bittorrent::setMaxRatio(float ratio) {
if(ratio < 0) ratio = -1.;
if(ratio_limit == -1 && ratio != -1) {
Q_ASSERT(!BigRatioTimer);
@ -1875,10 +1883,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1875,10 +1883,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
qDebug("* Set deleteRatio to %.1f", ratio_limit);
processBigRatios();
}
}
}
// Set DHT port (>= 1 or 0 if same as BT)
void Bittorrent::setDHTPort(int dht_port) {
// Set DHT port (>= 1 or 0 if same as BT)
void Bittorrent::setDHTPort(int dht_port) {
if(dht_port >= 0) {
if(dht_port == current_dht_port) return;
struct dht_settings DHTSettings;
@ -1887,10 +1895,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1887,10 +1895,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
current_dht_port = dht_port;
qDebug("Set DHT Port to %d", dht_port);
}
}
}
// Enable IP Filtering
void Bittorrent::enableIPFilter(QString filter) {
// Enable IP Filtering
void Bittorrent::enableIPFilter(QString filter) {
qDebug("Enabling IPFiler");
if(!filterParser) {
filterParser = new FilterParserThread(this, s);
@ -1899,32 +1907,32 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1899,32 +1907,32 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
filterPath = filter;
filterParser->processFilterFile(filter);
}
}
}
// Disable IP Filtering
void Bittorrent::disableIPFilter() {
// Disable IP Filtering
void Bittorrent::disableIPFilter() {
qDebug("Disabling IPFilter");
s->set_ip_filter(ip_filter());
if(filterParser) {
delete filterParser;
}
filterPath = "";
}
}
// Set BT session settings (user_agent)
void Bittorrent::setSessionSettings(const session_settings &sessionSettings) {
// Set BT session settings (user_agent)
void Bittorrent::setSessionSettings(const session_settings &sessionSettings) {
qDebug("Set session settings");
s->set_settings(sessionSettings);
}
}
// Set Proxy
void Bittorrent::setPeerProxySettings(const proxy_settings &proxySettings) {
// Set Proxy
void Bittorrent::setPeerProxySettings(const proxy_settings &proxySettings) {
qDebug("Set Peer Proxy settings");
s->set_peer_proxy(proxySettings);
s->set_dht_proxy(proxySettings);
}
}
void Bittorrent::setHTTPProxySettings(const proxy_settings &proxySettings) {
void Bittorrent::setHTTPProxySettings(const proxy_settings &proxySettings) {
s->set_tracker_proxy(proxySettings);
s->set_web_seed_proxy(proxySettings);
QString proxy_str;
@ -1968,9 +1976,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1968,9 +1976,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
else
setenv("http_proxy", proxy_str.toLocal8Bit().constData(), 1);
#endif
}
}
void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) {
void Bittorrent::recursiveTorrentDownload(const QTorrentHandle &h) {
torrent_info::file_iterator it;
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
const QString torrent_relpath = misc::toQStringU(it->path.string());
@ -1989,13 +1997,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -1989,13 +1997,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
}
}
}
}
void Bittorrent::cleanUpAutoRunProcess(int) {
void Bittorrent::cleanUpAutoRunProcess(int) {
sender()->deleteLater();
}
}
void Bittorrent::autoRunExternalProgram(QTorrentHandle h, bool async) {
void Bittorrent::autoRunExternalProgram(QTorrentHandle h, bool async) {
if(!h.is_valid()) return;
QString program = Preferences::getAutoRunProgram().trimmed();
if(program.isEmpty()) return;
@ -2014,9 +2022,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2014,9 +2022,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
process->execute(program);
delete process;
}
}
}
void Bittorrent::sendNotificationEmail(QTorrentHandle h) {
void Bittorrent::sendNotificationEmail(QTorrentHandle h) {
// Prepare mail content
QString content = tr("Torrent name: %1").arg(h.name()) + "\n";
content += tr("Torrent size: %1").arg(misc::friendlyUnit(h.actual_size())) + "\n";
@ -2025,10 +2033,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2025,10 +2033,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
content += tr("Thank you for using qBittorrent.") + "\n";
// Send the notification email
new Smtp("notification@qbittorrent.org", Preferences::getMailNotificationEmail(), tr("[qBittorrent] %1 has finished downloading").arg(h.name()), content);
}
}
// Read alerts sent by the Bittorrent session
void Bittorrent::readAlerts() {
// Read alerts sent by the Bittorrent session
void Bittorrent::readAlerts() {
// look at session alerts and display some infos
std::auto_ptr<alert> a = s->pop_alert();
while (a.get()) {
@ -2431,9 +2439,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2431,9 +2439,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
a = s->pop_alert();
}
}
}
void Bittorrent::recheckTorrent(QString hash) {
void Bittorrent::recheckTorrent(QString hash) {
QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata()) {
if(h.is_paused()) {
@ -2444,22 +2452,22 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2444,22 +2452,22 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
}
h.force_recheck();
}
}
}
QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{
QHash<QString, TrackerInfos> Bittorrent::getTrackersInfo(QString hash) const{
return trackersInfos.value(hash, QHash<QString, TrackerInfos>());
}
}
int Bittorrent::getListenPort() const{
int Bittorrent::getListenPort() const{
qDebug("LISTEN PORT: %d", s->listen_port());
return s->listen_port();
}
}
session_status Bittorrent::getSessionStatus() const{
session_status Bittorrent::getSessionStatus() const{
return s->status();
}
}
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath, QString root_folder) {
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath, QString root_folder) {
QString savePath;
if(TorrentTempData::hasTempData(hash)) {
savePath = TorrentTempData::getSavePath(hash);
@ -2514,33 +2522,33 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2514,33 +2522,33 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
if(!savePath.endsWith("/"))
savePath += "/";
return savePath;
}
}
// Take an url string to a torrent file,
// download the torrent file to a tmp location, then
// add it to download list
void Bittorrent::downloadFromUrl(QString url) {
// Take an url string to a torrent file,
// download the torrent file to a tmp location, then
// add it to download list
void Bittorrent::downloadFromUrl(QString url) {
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url)
#ifndef DISABLE_GUI
#ifndef DISABLE_GUI
, QPalette::WindowText
#endif
#endif
);
//emit aboutToDownloadFromUrl(url);
// Launch downloader thread
downloader->downloadTorrentUrl(url);
}
}
void Bittorrent::downloadFromURLList(const QStringList& urls) {
void Bittorrent::downloadFromURLList(const QStringList& urls) {
foreach(const QString &url, urls) {
downloadFromUrl(url);
}
}
}
void Bittorrent::addMagnetSkipAddDlg(QString uri) {
void Bittorrent::addMagnetSkipAddDlg(QString uri) {
addMagnetUri(uri, false);
}
}
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
void Bittorrent::downloadUrlAndSkipDialog(QString url, QString save_path) {
//emit aboutToDownloadFromUrl(url);
const QUrl qurl = QUrl::fromEncoded(url.toLocal8Bit());
if(!save_path.isEmpty())
@ -2548,10 +2556,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2548,10 +2556,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
url_skippingDlg << qurl;
// Launch downloader thread
downloader->downloadUrl(url);
}
}
// Add to Bittorrent session the downloaded torrent file
void Bittorrent::processDownloadedFile(QString url, QString file_path) {
// Add to Bittorrent session the downloaded torrent file
void Bittorrent::processDownloadedFile(QString url, QString file_path) {
const int index = url_skippingDlg.indexOf(QUrl::fromEncoded(url.toLocal8Bit()));
if(index < 0) {
// Add file to torrent download list
@ -2573,25 +2581,25 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2573,25 +2581,25 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
url_skippingDlg.removeAt(index);
addTorrent(file_path, false, url, false);
}
}
}
// Return current download rate for the BT
// session. Payload means that it only take into
// account "useful" part of the rate
float Bittorrent::getPayloadDownloadRate() const{
// Return current download rate for the BT
// session. Payload means that it only take into
// account "useful" part of the rate
float Bittorrent::getPayloadDownloadRate() const{
return s->status().payload_download_rate;
}
}
// Return current upload rate for the BT
// session. Payload means that it only take into
// account "useful" part of the rate
float Bittorrent::getPayloadUploadRate() const{
// Return current upload rate for the BT
// session. Payload means that it only take into
// account "useful" part of the rate
float Bittorrent::getPayloadUploadRate() const{
return s->status().payload_upload_rate;
}
}
#if LIBTORRENT_VERSION_MINOR < 15
// Save DHT entry to hard drive
void Bittorrent::saveDHTEntry() {
// Save DHT entry to hard drive
void Bittorrent::saveDHTEntry() {
// Save DHT entry
if(DHTEnabled) {
try{
@ -2607,17 +2615,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2607,17 +2615,17 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
std::cerr << e.what() << std::endl;
}
}
}
}
#endif
void Bittorrent::applyEncryptionSettings(pe_settings se) {
void Bittorrent::applyEncryptionSettings(pe_settings se) {
qDebug("Applying encryption settings");
s->set_pe_settings(se);
}
}
// Will fast resume torrents in
// backup directory
void Bittorrent::startUpTorrents() {
// Will fast resume torrents in
// backup directory
void Bittorrent::startUpTorrents() {
qDebug("Resuming unfinished torrents");
const QDir torrentBackup(misc::BTBackupLocation());
const QStringList known_torrents = TorrentPersistentData::knownTorrents();
@ -2675,4 +2683,4 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { @@ -2675,4 +2683,4 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
QIniSettings settings("qBittorrent", "qBittorrent");
settings.setValue("ported_to_new_savepath_system", true);
qDebug("Unfinished torrents resumed");
}
}

Loading…
Cancel
Save