Browse Source

Initial port to libtorrent v0.16

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
3995af6489
  1. 18
      src/mainwindow.cpp
  2. 28
      src/misc.cpp
  3. 11
      src/misc.h
  4. 2
      src/previewselect.cpp
  5. 4
      src/properties/propertieswidget.cpp
  6. 6
      src/properties/proplistdelegate.h
  7. 75
      src/qtlibtorrent/qbtsession.cpp
  8. 206
      src/qtlibtorrent/qtorrenthandle.cpp
  9. 5
      src/qtlibtorrent/qtorrenthandle.h
  10. 6
      src/qtlibtorrent/torrentspeedmonitor.cpp
  11. 26
      src/statusbar.h
  12. 13
      src/torrentfilesmodel.h
  13. 21
      src/torrentimportdlg.cpp
  14. 17
      src/webui/eventmanager.cpp
  15. 12
      src/webui/httpconnection.cpp

18
src/mainwindow.cpp

@ -590,10 +590,15 @@ void MainWindow::handleDownloadFromUrlFailure(QString url, QString reason) const
void MainWindow::on_actionSet_global_upload_limit_triggered() { void MainWindow::on_actionSet_global_upload_limit_triggered() {
qDebug("actionSet_global_upload_limit_triggered"); qDebug("actionSet_global_upload_limit_triggered");
bool ok; bool ok;
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), QBtSession::instance()->getSession()->upload_rate_limit()); #if LIBTORRENT_VERSION_MINOR > 15
int cur_limit = QBtSession::instance()->getSession()->settings().upload_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->upload_rate_limit();
#endif
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), cur_limit);
if(ok) { if(ok) {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
QBtSession::instance()->getSession()->set_upload_rate_limit(new_limit); QBtSession::instance()->setUploadRateLimit(new_limit);
if(new_limit <= 0) if(new_limit <= 0)
Preferences().setGlobalUploadLimit(-1); Preferences().setGlobalUploadLimit(-1);
else else
@ -604,10 +609,15 @@ void MainWindow::on_actionSet_global_upload_limit_triggered() {
void MainWindow::on_actionSet_global_download_limit_triggered() { void MainWindow::on_actionSet_global_download_limit_triggered() {
qDebug("actionSet_global_download_limit_triggered"); qDebug("actionSet_global_download_limit_triggered");
bool ok; bool ok;
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), QBtSession::instance()->getSession()->download_rate_limit()); #if LIBTORRENT_VERSION_MINOR > 15
int cur_limit = QBtSession::instance()->getSession()->settings().download_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->download_rate_limit();
#endif
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), cur_limit);
if(ok) { if(ok) {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
QBtSession::instance()->getSession()->set_download_rate_limit(new_limit); QBtSession::instance()->setDownloadRateLimit(new_limit);
if(new_limit <= 0) if(new_limit <= 0)
Preferences().setGlobalDownloadLimit(-1); Preferences().setGlobalDownloadLimit(-1);
else else

28
src/misc.cpp

@ -356,23 +356,29 @@ QString misc::fixFileNames(QString path) {
QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) { QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
if(t->num_files() == 1) { if(t->num_files() == 1) {
// Single file torrent // Single file torrent
#if LIBTORRENT_VERSION_MINOR > 15
QString path = QString::fromUtf8(t->file_at(0).path.c_str());
#else
QString path = QString::fromUtf8(t->file_at(0).path.string().c_str()); QString path = QString::fromUtf8(t->file_at(0).path.string().c_str());
#endif
// Remove possible subfolders // Remove possible subfolders
path = fixFileNames(fileName(path)); path = fixFileNames(fileName(path));
t->rename_file(0, path.toUtf8().data()); t->rename_file(0, path.toUtf8().data());
return QString(); return QString();
} }
QString root_folder; QString root_folder;
int i = 0; for(int i=0; i<t->num_files(); ++i) {
for(torrent_info::file_iterator it = t->begin_files(); it < t->end_files(); it++) { #if LIBTORRENT_VERSION_MINOR > 15
QString path = QString::fromUtf8(it->path.string().c_str()); QString path = QString::fromUtf8(t->file_at(i).path.c_str());
#else
QString path = QString::fromUtf8(t->file_at(i).path.string().c_str());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts); QStringList path_parts = path.split("/", QString::SkipEmptyParts);
if(path_parts.size() > 1) { if(path_parts.size() > 1) {
root_folder = path_parts.takeFirst(); root_folder = path_parts.takeFirst();
} }
path = fixFileNames(path_parts.join("/")); path = fixFileNames(path_parts.join("/"));
t->rename_file(i, path.toUtf8().data()); t->rename_file(i, path.toUtf8().data());
++i;
} }
return root_folder; return root_folder;
} }
@ -382,22 +388,28 @@ QString misc::truncateRootFolder(libtorrent::torrent_handle h) {
if(t.num_files() == 1) { if(t.num_files() == 1) {
// Single file torrent // Single file torrent
// Remove possible subfolders // Remove possible subfolders
#if LIBTORRENT_VERSION_MINOR > 15
QString path = QString::fromUtf8(t.file_at(0).path.c_str());
#else
QString path = QString::fromUtf8(t.file_at(0).path.string().c_str()); QString path = QString::fromUtf8(t.file_at(0).path.string().c_str());
#endif
path = fixFileNames(fileName(path)); path = fixFileNames(fileName(path));
t.rename_file(0, path.toUtf8().data()); t.rename_file(0, path.toUtf8().data());
return QString(); return QString();
} }
QString root_folder; QString root_folder;
int i = 0; for(int i=0; i<t.num_files(); ++i) {
for(torrent_info::file_iterator it = t.begin_files(); it < t.end_files(); it++) { #if LIBTORRENT_VERSION_MINOR > 15
QString path = QString::fromUtf8(it->path.string().c_str()); QString path = QString::fromUtf8(t.file_at(i).path.c_str());
#else
QString path = QString::fromUtf8(t.file_at(i).path.string().c_str());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts); QStringList path_parts = path.split("/", QString::SkipEmptyParts);
if(path_parts.size() > 1) { if(path_parts.size() > 1) {
root_folder = path_parts.takeFirst(); root_folder = path_parts.takeFirst();
} }
path = fixFileNames(path_parts.join("/")); path = fixFileNames(path_parts.join("/"));
h.rename_file(i, path.toUtf8().data()); h.rename_file(i, path.toUtf8().data());
++i;
} }
return root_folder; return root_folder;
} }

11
src/misc.h

@ -31,6 +31,9 @@
#ifndef MISC_H #ifndef MISC_H
#define MISC_H #define MISC_H
#include <libtorrent/version.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <sstream> #include <sstream>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@ -45,9 +48,6 @@
#include <QIcon> #include <QIcon>
#endif #endif
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/torrent_handle.hpp>
const qlonglong MAX_ETA = 8640000; const qlonglong MAX_ETA = 8640000;
/* Miscellaneaous functions that can be useful */ /* Miscellaneaous functions that can be useful */
@ -104,8 +104,9 @@ public:
static inline QString file_extension(const QString &filename) { static inline QString file_extension(const QString &filename) {
QString extension; QString extension;
if(filename.contains(".")) { int point_index = filename.lastIndexOf(".");
extension = filename.mid(filename.lastIndexOf(".")+1); if(point_index >= 0) {
extension = filename.mid(point_index+1);
} }
return extension; return extension;
} }

2
src/previewselect.cpp

@ -102,7 +102,7 @@ void PreviewSelect::on_previewButton_clicked(){
#endif #endif
QString path; QString path;
foreach(index, selectedIndexes){ foreach(index, selectedIndexes){
path = h.files_path().at(indexes.at(index.row())); path = h.absolute_files_path().at(indexes.at(index.row()));
// File // File
if(QFile::exists(path)){ if(QFile::exists(path)){
emit readyToPreviewFile(path); emit readyToPreviewFile(path);

4
src/properties/propertieswidget.cpp

@ -474,7 +474,11 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){
myFilesLlistMenu.addSeparator(); myFilesLlistMenu.addSeparator();
} }
QMenu subMenu; QMenu subMenu;
#if LIBTORRENT_VERSION_MINOR > 15
if(!h.status(0x0).is_seeding) {
#else
if(!static_cast<torrent_handle>(h).is_seed()) { if(!static_cast<torrent_handle>(h).is_seed()) {
#endif
subMenu.setTitle(tr("Priority")); subMenu.setTitle(tr("Priority"));
subMenu.addAction(actionNot_downloaded); subMenu.addAction(actionNot_downloaded);
subMenu.addAction(actionNormal); subMenu.addAction(actionNormal);

6
src/properties/proplistdelegate.h

@ -156,7 +156,11 @@ public:
if(index.column() != PRIORITY) return 0; if(index.column() != PRIORITY) return 0;
if(properties) { if(properties) {
QTorrentHandle h = properties->getCurrentTorrent(); QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid() || static_cast<libtorrent::torrent_handle>(h).is_seed() || !h.has_metadata()) return 0; #if LIBTORRENT_VERSION_MINOR > 15
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;
#endif
} }
if(index.data().toInt() <= 0) { if(index.data().toInt() <= 0) {
// IGNORED or MIXED // IGNORED or MIXED

75
src/qtlibtorrent/qbtsession.cpp

@ -65,6 +65,7 @@
//#include <libtorrent/extensions/metadata_transfer.hpp> //#include <libtorrent/extensions/metadata_transfer.hpp>
#include <libtorrent/entry.hpp> #include <libtorrent/entry.hpp>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/error_code.hpp>
#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>
@ -376,7 +377,7 @@ void QBtSession::configureSession() {
addConsoleMessage(tr("UPnP / NAT-PMP support [OFF]"), QString::fromUtf8("blue")); addConsoleMessage(tr("UPnP / NAT-PMP support [OFF]"), QString::fromUtf8("blue"));
} }
// * Session settings // * Session settings
session_settings sessionSettings; session_settings sessionSettings = s->settings();
sessionSettings.user_agent = "qBittorrent "VERSION; sessionSettings.user_agent = "qBittorrent "VERSION;
std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl; std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl;
addConsoleMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent))); addConsoleMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent)));
@ -734,7 +735,7 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) {
} else { } else {
QStringList uneeded_files; QStringList uneeded_files;
if(h.has_metadata()) if(h.has_metadata())
uneeded_files = h.uneeded_files_path(); uneeded_files = h.absolute_files_path_uneeded();
s->remove_torrent(h); s->remove_torrent(h);
// Remove unneeded and incomplete files // Remove unneeded and incomplete files
foreach(const QString &uneeded_file, uneeded_files) { foreach(const QString &uneeded_file, uneeded_files) {
@ -1217,7 +1218,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m
bool force_recheck = false; bool force_recheck = false;
if(files_path.size() == h.num_files()) { if(files_path.size() == h.num_files()) {
for(int i=0; i<h.num_files(); ++i) { for(int i=0; i<h.num_files(); ++i) {
QString old_path = h.files_path().at(i); QString old_path = h.absolute_files_path().at(i);
old_path = old_path.replace("\\", "/"); old_path = old_path.replace("\\", "/");
if(!QFile::exists(old_path)) { if(!QFile::exists(old_path)) {
// Remove old parent folder manually since we will // Remove old parent folder manually since we will
@ -1273,14 +1274,27 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
} }
bool urlseeds_added = false; bool urlseeds_added = false;
const QStringList old_urlseeds = h_ex.url_seeds(); const QStringList old_urlseeds = h_ex.url_seeds();
#if LIBTORRENT_VERSION_MINOR > 15
std::vector<web_seed_entry> new_urlseeds = t->web_seeds();
std::vector<web_seed_entry>::iterator it;
for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString new_url = misc::toQString(it->url.c_str());
if(!old_urlseeds.contains(new_url)) {
urlseeds_added = true;
h_ex.add_url_seed(new_url);
}
}
#else
std::vector<std::string> new_urlseeds = t->url_seeds(); std::vector<std::string> new_urlseeds = t->url_seeds();
for(std::vector<std::string>::iterator it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { std::vector<std::string>::iterator it;
for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString new_url = misc::toQString(it->c_str()); const QString new_url = misc::toQString(it->c_str());
if(!old_urlseeds.contains(new_url)) { if(!old_urlseeds.contains(new_url)) {
urlseeds_added = true; urlseeds_added = true;
h_ex.add_url_seed(new_url); h_ex.add_url_seed(new_url);
} }
} }
#endif
if(urlseeds_added) { if(urlseeds_added) {
addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent.")); addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent."));
} }
@ -1325,8 +1339,13 @@ void QBtSession::exportTorrentFiles(QString path) {
// Set the maximum number of opened connections // Set the maximum number of opened connections
void QBtSession::setMaxConnections(int maxConnec) { void QBtSession::setMaxConnections(int maxConnec) {
#if LIBTORRENT_VERSION_MINOR > 15
Q_UNUSED(maxConnec);
Q_ASSERT(0); // Should not be used
#else
qDebug() << Q_FUNC_INFO << maxConnec; qDebug() << Q_FUNC_INFO << maxConnec;
s->set_max_connections(maxConnec); s->set_max_connections(maxConnec);
#endif
} }
void QBtSession::setMaxConnectionsPerTorrent(int max) { void QBtSession::setMaxConnectionsPerTorrent(int max) {
@ -1416,8 +1435,15 @@ void QBtSession::loadSessionState() {
state_file.read(&in[0], content_size); state_file.read(&in[0], content_size);
// bdecode // bdecode
lazy_entry e; lazy_entry e;
if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) #if LIBTORRENT_VERSION_MINOR > 15
error_code ec;
lazy_bdecode(&in[0], &in[0] + in.size(), e, ec);
if(!ec) {
#else
if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) {
#endif
s->load_state(e); s->load_state(e);
}
#else #else
boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData()
, std::ios_base::binary); , std::ios_base::binary);
@ -1785,9 +1811,16 @@ void QBtSession::setAppendqBExtension(bool append) {
void QBtSession::setListeningPort(int port) { void QBtSession::setListeningPort(int port) {
Preferences pref; Preferences pref;
std::pair<int,int> ports(port, port); std::pair<int,int> ports(port, port);
#if LIBTORRENT_VERSION_MINOR > 15
error_code ec;
#endif
const QString iface_name = pref.getNetworkInterface(); const QString iface_name = pref.getNetworkInterface();
if(iface_name.isEmpty()) { if(iface_name.isEmpty()) {
#if LIBTORRENT_VERSION_MINOR > 15
s->listen_on(ports, ec);
#else
s->listen_on(ports); s->listen_on(ports);
#endif
return; return;
} }
// Attempt to listen on provided interface // Attempt to listen on provided interface
@ -1796,14 +1829,23 @@ void QBtSession::setListeningPort(int port) {
qDebug("Invalid network interface: %s", qPrintable(iface_name)); qDebug("Invalid network interface: %s", qPrintable(iface_name));
addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red"); addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red");
addConsoleMessage(tr("Trying any other network interface available instead.")); addConsoleMessage(tr("Trying any other network interface available instead."));
#if LIBTORRENT_VERSION_MINOR > 15
s->listen_on(ports, ec);
#else
s->listen_on(ports); s->listen_on(ports);
#endif
return; return;
} }
QString ip; QString ip;
qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size()); qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());
foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) { foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name)); qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));
#if LIBTORRENT_VERSION_MINOR > 15
s->listen_on(ports, ec, entry.ip().toString().toAscii().constData());
if(!ec) {
#else
if(s->listen_on(ports, entry.ip().toString().toAscii().constData())) { if(s->listen_on(ports, entry.ip().toString().toAscii().constData())) {
#endif
ip = entry.ip().toString(); ip = entry.ip().toString();
break; break;
} }
@ -1821,7 +1863,13 @@ void QBtSession::setListeningPort(int port) {
void QBtSession::setDownloadRateLimit(long rate) { void QBtSession::setDownloadRateLimit(long rate) {
qDebug() << Q_FUNC_INFO << rate; qDebug() << Q_FUNC_INFO << rate;
Q_ASSERT(rate == -1 || rate >= 0); Q_ASSERT(rate == -1 || rate >= 0);
#if LIBTORRENT_VERSION_MINOR > 15
session_settings settings = s->settings();
settings.download_rate_limit = rate;
s->set_settings(settings);
#else
s->set_download_rate_limit(rate); s->set_download_rate_limit(rate);
#endif
} }
// Set upload rate limit // Set upload rate limit
@ -1829,7 +1877,13 @@ void QBtSession::setDownloadRateLimit(long rate) {
void QBtSession::setUploadRateLimit(long rate) { void QBtSession::setUploadRateLimit(long rate) {
qDebug() << Q_FUNC_INFO << rate; qDebug() << Q_FUNC_INFO << rate;
Q_ASSERT(rate == -1 || rate >= 0); Q_ASSERT(rate == -1 || rate >= 0);
#if LIBTORRENT_VERSION_MINOR > 15
session_settings settings = s->settings();
settings.upload_rate_limit = rate;
s->set_settings(settings);
#else
s->set_upload_rate_limit(rate); s->set_upload_rate_limit(rate);
#endif
} }
// Torrents will a ratio superior to the given value will // Torrents will a ratio superior to the given value will
@ -1985,9 +2039,8 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) {
void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
try { try {
torrent_info::file_iterator it; for(int i=0; i<h.num_files(); ++i) {
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { const QString torrent_relpath = h.filepath_at(i);
const QString torrent_relpath = h.filepath(*it);
if(torrent_relpath.endsWith(".torrent")) { if(torrent_relpath.endsWith(".torrent")) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QString displayed_relpath = torrent_relpath; QString displayed_relpath = torrent_relpath;
@ -2070,9 +2123,9 @@ void QBtSession::readAlerts() {
h.save_resume_data(); h.save_resume_data();
qDebug("Checking if the torrent contains torrent files to download"); qDebug("Checking if the torrent contains torrent files to download");
// Check if there are torrent files inside // Check if there are torrent files inside
for(torrent_info::file_iterator it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) { for(int i=0; i<h.num_files(); ++i) {
qDebug() << "File path:" << h.filepath(*it); const QString torrent_relpath = h.filepath_at(i).replace("\\", "/");
const QString torrent_relpath = h.filepath(*it).replace("\\", "/"); qDebug() << "File path:" << torrent_relpath;
if(torrent_relpath.endsWith(".torrent", Qt::CaseInsensitive)) { if(torrent_relpath.endsWith(".torrent", Qt::CaseInsensitive)) {
qDebug("Found possible recursive torrent download."); qDebug("Found possible recursive torrent download.");
const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath; const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath;

206
src/qtlibtorrent/qtorrenthandle.cpp

@ -71,7 +71,7 @@ QString QTorrentHandle::name() const {
} }
QString QTorrentHandle::creation_date() const { QString QTorrentHandle::creation_date() const {
#if LIBTORRENT_VERSION_MINOR >= 16 #if LIBTORRENT_VERSION_MINOR > 15
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date(); boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
return misc::time_tToQString(t); return misc::time_tToQString(t);
#else #else
@ -81,35 +81,56 @@ QString QTorrentHandle::creation_date() const {
} }
QString QTorrentHandle::next_announce() const { QString QTorrentHandle::next_announce() const {
#if LIBTORRENT_VERSION_MINOR > 15
return misc::userFriendlyDuration(torrent_handle::status(0x0).next_announce.total_seconds());
#else
return misc::userFriendlyDuration(torrent_handle::status().next_announce.total_seconds()); return misc::userFriendlyDuration(torrent_handle::status().next_announce.total_seconds());
#endif
} }
qlonglong QTorrentHandle::next_announce_s() const { qlonglong QTorrentHandle::next_announce_s() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).next_announce.total_seconds();
#else
return torrent_handle::status().next_announce.total_seconds(); return torrent_handle::status().next_announce.total_seconds();
#endif
} }
qreal QTorrentHandle::progress() const { qreal QTorrentHandle::progress() const {
if(!torrent_handle::status().total_wanted) #if LIBTORRENT_VERSION_MINOR > 15
torrent_status st = torrent_handle::status(query_accurate_download_counters);
#else
torrent_status st = torrent_handle::status();
#endif
if(!st.total_wanted)
return 0.; return 0.;
if (torrent_handle::status().total_wanted_done == torrent_handle::status().total_wanted) if (st.total_wanted_done == st.total_wanted)
return 1.; return 1.;
qreal progress = (float)torrent_handle::status().total_wanted_done/(float)torrent_handle::status().total_wanted; qreal progress = (float)st.total_wanted_done/(float)st.total_wanted;
Q_ASSERT(progress >= 0. && progress <= 1.); Q_ASSERT(progress >= 0. && progress <= 1.);
return progress; return progress;
} }
bitfield QTorrentHandle::pieces() const { bitfield QTorrentHandle::pieces() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).pieces;
#else
return torrent_handle::status().pieces; return torrent_handle::status().pieces;
#endif
} }
QString QTorrentHandle::current_tracker() const { QString QTorrentHandle::current_tracker() const {
#if LIBTORRENT_VERSION_MINOR > 15
return misc::toQString(torrent_handle::status(0x0).current_tracker);
#else
return misc::toQString(torrent_handle::status().current_tracker); return misc::toQString(torrent_handle::status().current_tracker);
#endif
} }
bool QTorrentHandle::is_paused() const { bool QTorrentHandle::is_paused() const {
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
torrent_status status = torrent_handle::status(0x0); torrent_status st = torrent_handle::status(0x0);
return status.paused && !status.auto_managed; return st.paused && !st.auto_managed;
#else #else
return torrent_handle::is_paused() && !torrent_handle::is_auto_managed(); return torrent_handle::is_paused() && !torrent_handle::is_auto_managed();
#endif #endif
@ -117,8 +138,8 @@ bool QTorrentHandle::is_paused() const {
bool QTorrentHandle::is_queued() const { bool QTorrentHandle::is_queued() const {
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
torrent_status status = torrent_handle::status(0x0); torrent_status st = torrent_handle::status(0x0);
return status.paused && status.auto_managed; return st.paused && st.auto_managed;
#else #else
return torrent_handle::is_paused() && torrent_handle::is_auto_managed(); return torrent_handle::is_paused() && torrent_handle::is_auto_managed();
#endif #endif
@ -138,10 +159,14 @@ int QTorrentHandle::num_pieces() const {
bool QTorrentHandle::first_last_piece_first() const { bool QTorrentHandle::first_last_piece_first() const {
// Detect first media file // Detect first media file
torrent_info::file_iterator it;
int index = 0; int index = 0;
for(it = get_torrent_info().begin_files(); it != get_torrent_info().end_files(); it++) { for(index = 0; index < num_files(); ++index) {
const QString ext = misc::toQStringU(it->path.string()).split(".").last(); #if LIBTORRENT_VERSION_MINOR > 15
QString path = misc::toQStringU(get_torrent_info().file_at(index).path);
#else
QString path = misc::toQStringU(get_torrent_info().file_at(index).path.string());
#endif
const QString ext = misc::file_extension(path);
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) { if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
break; break;
} }
@ -162,35 +187,67 @@ bool QTorrentHandle::first_last_piece_first() const {
} }
size_type QTorrentHandle::total_wanted_done() const { size_type QTorrentHandle::total_wanted_done() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(query_accurate_download_counters).total_wanted_done;
#else
return torrent_handle::status().total_wanted_done; return torrent_handle::status().total_wanted_done;
#endif
} }
size_type QTorrentHandle::total_wanted() const { size_type QTorrentHandle::total_wanted() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_wanted;
#else
return torrent_handle::status().total_wanted; return torrent_handle::status().total_wanted;
#endif
} }
qreal QTorrentHandle::download_payload_rate() const { qreal QTorrentHandle::download_payload_rate() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).download_payload_rate;
#else
return torrent_handle::status().download_payload_rate; return torrent_handle::status().download_payload_rate;
#endif
} }
qreal QTorrentHandle::upload_payload_rate() const { qreal QTorrentHandle::upload_payload_rate() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).upload_payload_rate;
#else
return torrent_handle::status().upload_payload_rate; return torrent_handle::status().upload_payload_rate;
#endif
} }
int QTorrentHandle::num_peers() const { int QTorrentHandle::num_peers() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_peers;
#else
return torrent_handle::status().num_peers; return torrent_handle::status().num_peers;
#endif
} }
int QTorrentHandle::num_seeds() const { int QTorrentHandle::num_seeds() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_seeds;
#else
return torrent_handle::status().num_seeds; return torrent_handle::status().num_seeds;
#endif
} }
int QTorrentHandle::num_complete() const { int QTorrentHandle::num_complete() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_complete;
#else
return torrent_handle::status().num_complete; return torrent_handle::status().num_complete;
#endif
} }
int QTorrentHandle::num_incomplete() const { int QTorrentHandle::num_incomplete() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_incomplete;
#else
return torrent_handle::status().num_incomplete; return torrent_handle::status().num_incomplete;
#endif
} }
QString QTorrentHandle::save_path() const { QString QTorrentHandle::save_path() const {
@ -217,8 +274,12 @@ QStringList QTorrentHandle::url_seeds() const {
} }
// get the size of the torrent without the filtered files // get the size of the torrent without the filtered files
size_type QTorrentHandle::actual_size() const{ size_type QTorrentHandle::actual_size() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(query_accurate_download_counters).total_wanted;
#else
return torrent_handle::status().total_wanted; return torrent_handle::status().total_wanted;
#endif
} }
bool QTorrentHandle::has_filtered_pieces() const { bool QTorrentHandle::has_filtered_pieces() const {
@ -247,19 +308,9 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
return torrent_handle::get_torrent_info().file_at(index).size; return torrent_handle::get_torrent_info().file_at(index).size;
} }
QString QTorrentHandle::filepath(const libtorrent::file_entry &fe) const {
#if LIBTORRENT_VERSION_MINOR > 15
file_storage fs = torrent_handle::get_torrent_info().files();
return misc::toQStringU(fs.file_path(fe));
#else
return misc::toQStringU(fe.path.string());
#endif
}
QString QTorrentHandle::filepath_at(unsigned int index) const { QString QTorrentHandle::filepath_at(unsigned int index) const {
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
file_storage fs = torrent_handle::get_torrent_info().files(); return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path);
return misc::toQStringU(fs.file_path(fs.at(index)));
#else #else
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.string()); return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.string());
#endif #endif
@ -267,15 +318,18 @@ QString QTorrentHandle::filepath_at(unsigned int index) const {
QString QTorrentHandle::orig_filepath_at(unsigned int index) const { QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
file_storage fs = torrent_handle::get_torrent_info().orig_files(); return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path);
return misc::toQStringU(fs.file_path(fs.at(index)));
#else #else
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path.string()); return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path.string());
#endif #endif
} }
torrent_status::state_t QTorrentHandle::state() const { torrent_status::state_t QTorrentHandle::state() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).state;
#else
return torrent_handle::status().state; return torrent_handle::status().state;
#endif
} }
QString QTorrentHandle::creator() const { QString QTorrentHandle::creator() const {
@ -287,70 +341,98 @@ QString QTorrentHandle::comment() const {
} }
size_type QTorrentHandle::total_failed_bytes() const { size_type QTorrentHandle::total_failed_bytes() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_failed_bytes;
#else
return torrent_handle::status().total_failed_bytes; return torrent_handle::status().total_failed_bytes;
#endif
} }
size_type QTorrentHandle::total_redundant_bytes() const { size_type QTorrentHandle::total_redundant_bytes() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_redundant_bytes;
#else
return torrent_handle::status().total_redundant_bytes; return torrent_handle::status().total_redundant_bytes;
#endif
} }
bool QTorrentHandle::is_checking() const { bool QTorrentHandle::is_checking() const {
return torrent_handle::status().state == torrent_status::checking_files || torrent_handle::status().state == torrent_status::checking_resume_data; #if LIBTORRENT_VERSION_MINOR > 15
torrent_status st = torrent_handle::status(0x0);
#else
torrent_status st = torrent_handle::status();
#endif
return st.state == torrent_status::checking_files || st.state == torrent_status::checking_resume_data;
} }
size_type QTorrentHandle::total_done() const { size_type QTorrentHandle::total_done() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_done;
#else
return torrent_handle::status().total_done; return torrent_handle::status().total_done;
#endif
} }
size_type QTorrentHandle::all_time_download() const { size_type QTorrentHandle::all_time_download() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).all_time_download;
#else
return torrent_handle::status().all_time_download; return torrent_handle::status().all_time_download;
#endif
} }
size_type QTorrentHandle::all_time_upload() const { size_type QTorrentHandle::all_time_upload() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).all_time_upload;
#else
return torrent_handle::status().all_time_upload; return torrent_handle::status().all_time_upload;
#endif
} }
size_type QTorrentHandle::total_payload_download() const { size_type QTorrentHandle::total_payload_download() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_payload_download;
#else
return torrent_handle::status().total_payload_download; return torrent_handle::status().total_payload_download;
#endif
} }
size_type QTorrentHandle::total_payload_upload() const { size_type QTorrentHandle::total_payload_upload() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).total_payload_upload;
#else
return torrent_handle::status().total_payload_upload; return torrent_handle::status().total_payload_upload;
#endif
} }
// Return a list of absolute paths corresponding // Return a list of absolute paths corresponding
// to all files in a torrent // to all files in a torrent
QStringList QTorrentHandle::files_path() const { QStringList QTorrentHandle::absolute_files_path() const {
QDir saveDir(save_path()); QDir saveDir(save_path());
QStringList res; QStringList res;
torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); for(int i = 0; i<num_files(); ++i) {
while(fi != torrent_handle::get_torrent_info().end_files()) { res << QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi)));
fi++;
} }
return res; return res;
} }
QStringList QTorrentHandle::uneeded_files_path() const { QStringList QTorrentHandle::absolute_files_path_uneeded() const {
QDir saveDir(save_path()); QDir saveDir(save_path());
QStringList res; QStringList res;
std::vector<int> fp = torrent_handle::file_priorities(); std::vector<int> fp = torrent_handle::file_priorities();
torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files();
int i = 0; for(int i = 0; i < num_files(); ++i) {
while(fi != torrent_handle::get_torrent_info().end_files()) {
if(fp[i] == 0) { if(fp[i] == 0) {
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi))); const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filepath_at(i)));
if(file_path.contains(".unwanted")) if(file_path.contains(".unwanted"))
res << file_path; res << file_path;
} }
fi++;
++i;
} }
return res; return res;
} }
bool QTorrentHandle::has_missing_files() const { bool QTorrentHandle::has_missing_files() const {
const QStringList paths = files_path(); const QStringList paths = absolute_files_path();
foreach(const QString &path, paths) { foreach(const QString &path, paths) {
if(!QFile::exists(path)) return true; if(!QFile::exists(path)) return true;
} }
@ -364,7 +446,11 @@ int QTorrentHandle::queue_position() const {
} }
int QTorrentHandle::num_uploads() const { int QTorrentHandle::num_uploads() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_uploads;
#else
return torrent_handle::status().num_uploads; return torrent_handle::status().num_uploads;
#endif
} }
bool QTorrentHandle::is_seed() const { bool QTorrentHandle::is_seed() const {
@ -377,23 +463,44 @@ bool QTorrentHandle::is_seed() const {
} }
bool QTorrentHandle::is_auto_managed() const { bool QTorrentHandle::is_auto_managed() const {
#if LIBTORRENT_VERSION_MINOR > 15
torrent_status status = torrent_handle::status(0x0);
return status.auto_managed;
#else
return torrent_handle::is_auto_managed(); return torrent_handle::is_auto_managed();
#endif
} }
qlonglong QTorrentHandle::active_time() const { qlonglong QTorrentHandle::active_time() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).active_time;
#else
return torrent_handle::status().active_time; return torrent_handle::status().active_time;
#endif
} }
qlonglong QTorrentHandle::seeding_time() const { qlonglong QTorrentHandle::seeding_time() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).seeding_time;
#else
return torrent_handle::status().seeding_time; return torrent_handle::status().seeding_time;
#endif
} }
int QTorrentHandle::num_connections() const { int QTorrentHandle::num_connections() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).num_connections;
#else
return torrent_handle::status().num_connections; return torrent_handle::status().num_connections;
#endif
} }
int QTorrentHandle::connections_limit() const { int QTorrentHandle::connections_limit() const {
#if LIBTORRENT_VERSION_MINOR > 15
return torrent_handle::status(0x0).connections_limit;
#else
return torrent_handle::status().connections_limit; return torrent_handle::status().connections_limit;
#endif
} }
bool QTorrentHandle::priv() const { bool QTorrentHandle::priv() const {
@ -416,11 +523,20 @@ QString QTorrentHandle::firstFileSavePath() const {
} }
bool QTorrentHandle::has_error() const { bool QTorrentHandle::has_error() const {
#if LIBTORRENT_VERSION_MINOR > 15
torrent_status st = torrent_handle::status(0x0);
return st.paused && !st.error.empty();
#else
return torrent_handle::is_paused() && !torrent_handle::status().error.empty(); return torrent_handle::is_paused() && !torrent_handle::status().error.empty();
#endif
} }
QString QTorrentHandle::error() const { QString QTorrentHandle::error() const {
#if LIBTORRENT_VERSION_MINOR > 15
return misc::toQString(torrent_handle::status(0x0).error);
#else
return misc::toQString(torrent_handle::status().error); return misc::toQString(torrent_handle::status().error);
#endif
} }
void QTorrentHandle::downloading_pieces(bitfield &bf) const { void QTorrentHandle::downloading_pieces(bitfield &bf) const {
@ -498,7 +614,7 @@ void QTorrentHandle::move_storage(QString new_path) const {
} }
bool QTorrentHandle::save_torrent_file(QString path) const { bool QTorrentHandle::save_torrent_file(QString path) const {
if(!torrent_handle::has_metadata()) return false; if(!has_metadata()) return false;
QFile met_file(path); QFile met_file(path);
if(met_file.open(QIODevice::WriteOnly)) { if(met_file.open(QIODevice::WriteOnly)) {
entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size()); entry meta = bdecode(torrent_handle::get_torrent_info().metadata().get(), torrent_handle::get_torrent_info().metadata().get()+torrent_handle::get_torrent_info().metadata_size());
@ -632,18 +748,16 @@ void QTorrentHandle::prioritize_first_last_piece(int file_index, bool b) const {
} }
void QTorrentHandle::prioritize_first_last_piece(bool b) const { void QTorrentHandle::prioritize_first_last_piece(bool b) const {
if(!torrent_handle::has_metadata()) return; if(!has_metadata()) return;
// Download first and last pieces first for all media files in the torrent // Download first and last pieces first for all media files in the torrent
torrent_info::file_iterator it;
int index = 0; int index = 0;
torrent_info t = get_torrent_info(); for(index = 0; index < num_files(); ++index) {
for(it = t.begin_files(); it != t.end_files(); it++) { const QString path = filepath_at(index);
const QString ext = misc::toQStringU(it->path.string()).split(".").last(); const QString ext = misc::file_extension(path);
if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) { if(misc::isPreviewable(ext) && torrent_handle::file_priority(index) > 0) {
qDebug() << "File" << it->path.string().c_str() << "is previewable, toggle downloading of first/last pieces first"; qDebug() << "File" << path << "is previewable, toggle downloading of first/last pieces first";
prioritize_first_last_piece(index, b); prioritize_first_last_piece(index, b);
} }
++index;
} }
} }

5
src/qtlibtorrent/qtorrenthandle.h

@ -87,7 +87,6 @@ public:
libtorrent::size_type filesize_at(unsigned int index) const; libtorrent::size_type filesize_at(unsigned int index) const;
QString filepath_at(unsigned int index) const; QString filepath_at(unsigned int index) const;
QString orig_filepath_at(unsigned int index) const; QString orig_filepath_at(unsigned int index) const;
QString filepath(const libtorrent::file_entry &f) const;
libtorrent::torrent_status::state_t state() const; libtorrent::torrent_status::state_t state() const;
QString creator() const; QString creator() const;
QString comment() const; QString comment() const;
@ -98,8 +97,8 @@ public:
libtorrent::size_type all_time_upload() const; libtorrent::size_type all_time_upload() const;
libtorrent::size_type all_time_download() const; libtorrent::size_type all_time_download() const;
libtorrent::size_type total_done() const; libtorrent::size_type total_done() const;
QStringList files_path() const; QStringList absolute_files_path() const;
QStringList uneeded_files_path() const; QStringList absolute_files_path_uneeded() const;
bool has_missing_files() const; bool has_missing_files() const;
int num_uploads() const; int num_uploads() const;
bool is_seed() const; bool is_seed() const;

6
src/qtlibtorrent/torrentspeedmonitor.cpp

@ -125,8 +125,14 @@ void TorrentSpeedMonitor::getSamples()
std::vector<torrent_handle>::const_iterator it; std::vector<torrent_handle>::const_iterator it;
for(it = torrents.begin(); it != torrents.end(); it++) { for(it = torrents.begin(); it != torrents.end(); it++) {
try { try {
#if LIBTORRENT_VERSION_MINOR > 15
torrent_status st = it->status(0x0);
if(!st.paused)
m_samples[misc::toQString(it->info_hash())].addSample(st.download_payload_rate);
#else
if(!it->is_paused()) if(!it->is_paused())
m_samples[misc::toQString(it->info_hash())].addSample(it->status().download_payload_rate); m_samples[misc::toQString(it->info_hash())].addSample(it->status().download_payload_rate);
#endif
} catch(invalid_handle&){} } catch(invalid_handle&){}
} }
} }

26
src/statusbar.h

@ -212,19 +212,24 @@ public slots:
void capDownloadSpeed() { void capDownloadSpeed() {
bool ok = false; bool ok = false;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), QBtSession::instance()->getSession()->download_rate_limit()); #if LIBTORRENT_VERSION_MINOR > 15
int cur_limit = QBtSession::instance()->getSession()->settings().download_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->download_rate_limit();
#endif
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Download Speed Limit"), cur_limit);
if(ok) { if(ok) {
Preferences pref; Preferences pref;
bool alt = pref.isAltBandwidthEnabled(); bool alt = pref.isAltBandwidthEnabled();
if(new_limit <= 0) { if(new_limit <= 0) {
qDebug("Setting global download rate limit to Unlimited"); qDebug("Setting global download rate limit to Unlimited");
QBtSession::instance()->setDownloadRateLimit(-1);
if(!alt) if(!alt)
QBtSession::instance()->getSession()->set_download_rate_limit(-1);
pref.setGlobalDownloadLimit(-1); pref.setGlobalDownloadLimit(-1);
} else { } else {
qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global download rate limit to %.1fKb/s", new_limit/1024.);
QBtSession::instance()->setDownloadRateLimit(new_limit);
if(!alt) if(!alt)
QBtSession::instance()->getSession()->set_download_rate_limit(new_limit);
pref.setGlobalDownloadLimit(new_limit/1024.); pref.setGlobalDownloadLimit(new_limit/1024.);
} }
} }
@ -232,16 +237,25 @@ public slots:
void capUploadSpeed() { void capUploadSpeed() {
bool ok = false; bool ok = false;
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), QBtSession::instance()->getSession()->upload_rate_limit()); #if LIBTORRENT_VERSION_MINOR > 15
int cur_limit = QBtSession::instance()->getSession()->settings().upload_rate_limit;
#else
int cur_limit = QBtSession::instance()->getSession()->upload_rate_limit();
#endif
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Global Upload Speed Limit"), cur_limit);
if(ok) { if(ok) {
Preferences pref;
bool alt = pref.isAltBandwidthEnabled();
if(new_limit <= 0) { if(new_limit <= 0) {
qDebug("Setting global upload rate limit to Unlimited"); qDebug("Setting global upload rate limit to Unlimited");
QBtSession::instance()->getSession()->set_upload_rate_limit(-1); QBtSession::instance()->setUploadRateLimit(-1);
if(!alt)
Preferences().setGlobalUploadLimit(-1); Preferences().setGlobalUploadLimit(-1);
} else { } else {
qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.); qDebug("Setting global upload rate limit to %.1fKb/s", new_limit/1024.);
QBtSession::instance()->setUploadRateLimit(new_limit);
if(!alt)
Preferences().setGlobalUploadLimit(new_limit/1024.); Preferences().setGlobalUploadLimit(new_limit/1024.);
QBtSession::instance()->getSession()->set_upload_rate_limit(new_limit);
} }
} }
} }

13
src/torrentfilesmodel.h

@ -558,14 +558,13 @@ public:
TorrentFileItem *current_parent; TorrentFileItem *current_parent;
// Iterate over files // Iterate over files
int i = 0; for(int i=0; i<t.num_files(); ++i) {
libtorrent::torrent_info::file_iterator fi = t.begin_files(); libtorrent::file_entry fentry = t.file_at(i);
while(fi != t.end_files()) {
current_parent = root_folder; current_parent = root_folder;
#if LIBTORRENT_VERSION_MINOR >= 16 #if LIBTORRENT_VERSION_MINOR >= 16
QString path = QDir::cleanPath(misc::toQStringU(t.files().file_path(*fi))).replace("\\", "/"); QString path = QDir::cleanPath(misc::toQStringU(fentry.path)).replace("\\", "/");
#else #else
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())).replace("\\", "/"); QString path = QDir::cleanPath(misc::toQStringU(fentry.path.string())).replace("\\", "/");
#endif #endif
// Iterate of parts of the path to create necessary folders // Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split("/"); QStringList pathFolders = path.split("/");
@ -579,10 +578,8 @@ public:
current_parent = new_parent; current_parent = new_parent;
} }
// Actually create the file // Actually create the file
TorrentFileItem *f = new TorrentFileItem(t, *fi, current_parent, i); TorrentFileItem *f = new TorrentFileItem(t, fentry, current_parent, i);
files_index[i] = f; files_index[i] = f;
fi++;
++i;
} }
emit layoutChanged(); emit layoutChanged();
} }

21
src/torrentimportdlg.cpp

@ -81,7 +81,11 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
const QString default_dir = settings.value(QString::fromUtf8("TorrentImport/LastContentDir"), QDir::homePath()).toString(); const QString default_dir = settings.value(QString::fromUtf8("TorrentImport/LastContentDir"), QDir::homePath()).toString();
if(t->num_files() == 1) { if(t->num_files() == 1) {
// Single file torrent // Single file torrent
#if LIBTORRENT_VERSION_MINOR > 15
const QString file_name = misc::fileName(misc::toQStringU(t->file_at(0).path));
#else
const QString file_name = misc::toQStringU(t->file_at(0).path.filename()); const QString file_name = misc::toQStringU(t->file_at(0).path.filename());
#endif
qDebug("Torrent has only one file: %s", qPrintable(file_name)); qDebug("Torrent has only one file: %s", qPrintable(file_name));
QString extension = misc::file_extension(file_name); QString extension = misc::file_extension(file_name);
qDebug("File extension is : %s", qPrintable(extension)); qDebug("File extension is : %s", qPrintable(extension));
@ -145,14 +149,17 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
bool size_mismatch = false; bool size_mismatch = false;
QDir content_dir(m_contentPath); QDir content_dir(m_contentPath);
// Check file sizes // Check file sizes
torrent_info::file_iterator it; t->begin_files(); for(int i=0; i<t->num_files(); ++i) {
for(it = t->begin_files(); it != t->end_files(); it++) { #if LIBTORRENT_VERSION_MINOR > 15
const QString rel_path = misc::toQStringU(it->path.string()); const QString rel_path = misc::toQStringU(t->file_at(i).path);
if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != it->size) { #else
const QString rel_path = misc::toQStringU(t->file_at(i)->path.string());
#endif
if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != t->file_at(i).size) {
qDebug("%s is %lld", qDebug("%s is %lld",
qPrintable(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size()); qPrintable(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size());
qDebug("%s is %lld", qDebug("%s is %lld",
qPrintable(rel_path), (long long int)it->size); qPrintable(rel_path), (long long int)t->file_at(i).size);
size_mismatch = true; size_mismatch = true;
break; break;
} }
@ -254,7 +261,11 @@ void TorrentImportDlg::initializeFilesPath()
m_filesPath.clear(); m_filesPath.clear();
// Loads files path in the torrent // Loads files path in the torrent
for(int i=0; i<t->num_files(); ++i) { for(int i=0; i<t->num_files(); ++i) {
#if LIBTORRENT_VERSION_MINOR > 15
m_filesPath << misc::toQStringU(t->file_at(i).path).replace("\\", "/");
#else
m_filesPath << misc::toQStringU(t->file_at(i).path.string()).replace("\\", "/"); m_filesPath << misc::toQStringU(t->file_at(i).path.string()).replace("\\", "/");
#endif
} }
} }

17
src/webui/eventmanager.cpp

@ -103,24 +103,19 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
std::vector<int> priorities = h.file_priorities(); std::vector<int> priorities = h.file_priorities();
std::vector<size_type> fp; std::vector<size_type> fp;
h.file_progress(fp); h.file_progress(fp);
torrent_info t = h.get_torrent_info(); for(int i=0; i<h.num_files(); ++i) {
torrent_info::file_iterator fi;
int i=0;
for(fi=t.begin_files(); fi != t.end_files(); fi++) {
QVariantMap file; QVariantMap file;
QString path = h.filepath(*fi); file["name"] = h.filename_at(i);
QString name = misc::fileName(path); libtorrent::size_type size = h.filesize_at(i);
file["name"] = name; file["size"] = misc::friendlyUnit((double)size);
file["size"] = misc::friendlyUnit((double)fi->size); if(size > 0)
if(fi->size > 0) file["progress"] = fp[i]/(double)size;
file["progress"] = fp[i]/(double)fi->size;
else else
file["progress"] = 1.; // Empty file... file["progress"] = 1.; // Empty file...
file["priority"] = priorities[i]; file["priority"] = priorities[i];
if(i == 0) if(i == 0)
file["is_seed"] = h.is_seed(); file["is_seed"] = h.is_seed();
files << file; files << file;
++i;
} }
return files; return files;
} }

12
src/webui/httpconnection.cpp

@ -451,13 +451,21 @@ void HttpConnection::respondCommand(QString command)
if(command == "getGlobalUpLimit") { if(command == "getGlobalUpLimit") {
generator.setStatusLine(200, "OK"); generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("html"); generator.setContentTypeByExt("html");
#if LIBTORRENT_VERSION_MINOR > 15
generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().upload_rate_limit));
#else
generator.setMessage(QString::number(QBtSession::instance()->getSession()->upload_rate_limit())); generator.setMessage(QString::number(QBtSession::instance()->getSession()->upload_rate_limit()));
#endif
write(); write();
} }
if(command == "getGlobalDlLimit") { if(command == "getGlobalDlLimit") {
generator.setStatusLine(200, "OK"); generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("html"); generator.setContentTypeByExt("html");
#if LIBTORRENT_VERSION_MINOR > 15
generator.setMessage(QString::number(QBtSession::instance()->getSession()->settings().download_rate_limit));
#else
generator.setMessage(QString::number(QBtSession::instance()->getSession()->download_rate_limit())); generator.setMessage(QString::number(QBtSession::instance()->getSession()->download_rate_limit()));
#endif
write(); write();
} }
if(command == "getTorrentUpLimit") { if(command == "getTorrentUpLimit") {
@ -501,13 +509,13 @@ void HttpConnection::respondCommand(QString command)
if(command == "setGlobalUpLimit") { if(command == "setGlobalUpLimit") {
qlonglong limit = parser.post("limit").toLongLong(); qlonglong limit = parser.post("limit").toLongLong();
if(limit == 0) limit = -1; if(limit == 0) limit = -1;
QBtSession::instance()->getSession()->set_upload_rate_limit(limit); QBtSession::instance()->setUploadRateLimit(limit);
Preferences().setGlobalUploadLimit(limit/1024.); Preferences().setGlobalUploadLimit(limit/1024.);
} }
if(command == "setGlobalDlLimit") { if(command == "setGlobalDlLimit") {
qlonglong limit = parser.post("limit").toLongLong(); qlonglong limit = parser.post("limit").toLongLong();
if(limit == 0) limit = -1; if(limit == 0) limit = -1;
QBtSession::instance()->getSession()->set_download_rate_limit(limit); QBtSession::instance()->setDownloadRateLimit(limit);
Preferences().setGlobalDownloadLimit(limit/1024.); Preferences().setGlobalDownloadLimit(limit/1024.);
} }
if(command == "pause") { if(command == "pause") {

Loading…
Cancel
Save