Browse Source

Initial support for libtorrent v0.16 (still a lot of deprecation warning but it compiles...)

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
3b3642bbba
  1. 4
      src/geoip/geoipmanager.cpp
  2. 32
      src/misc.cpp
  3. 3
      src/misc.h
  4. 1
      src/properties/peerlistwidget.h
  5. 12
      src/properties/propertieswidget.cpp
  6. 2
      src/properties/trackerlist.cpp
  7. 28
      src/qtlibtorrent/qbtsession.cpp
  8. 50
      src/qtlibtorrent/qtorrenthandle.cpp
  9. 3
      src/qtlibtorrent/qtorrenthandle.h
  10. 22
      src/torrentadditiondlg.cpp
  11. 17
      src/torrentcreator/torrentcreatorthread.cpp
  12. 34
      src/torrentfilesmodel.h
  13. 25
      src/torrentimportdlg.cpp
  14. 2
      src/transferlistwidget.cpp
  15. 2
      src/webui/eventmanager.cpp

4
src/geoip/geoipmanager.cpp

@ -118,9 +118,7 @@ void GeoIPManager::loadDatabase(session *s) {
#endif #endif
if(QFile::exists(geoipDBpath(false))) { if(QFile::exists(geoipDBpath(false))) {
qDebug("Loading GeoIP database from %s...", qPrintable(geoipDBpath(false))); qDebug("Loading GeoIP database from %s...", qPrintable(geoipDBpath(false)));
if(!s->load_country_db(geoipDBpath(false).toLocal8Bit().constData())) { s->load_country_db(geoipDBpath(false).toLocal8Bit().constData());
std::cerr << "Failed to load Geoip Database at " << qPrintable(geoipDBpath(false)) << std::endl;
}
} else { } else {
qDebug("ERROR: Impossible to find local Geoip Database"); qDebug("ERROR: Impossible to find local Geoip Database");
} }

32
src/misc.cpp

@ -268,10 +268,17 @@ void misc::shutdownComputer() {
} }
QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) { QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
#endif
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 >= 16
QString path = toQStringU(fs.file_path(t->file_at(0)));
#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
QStringList path_parts = path.split("/", QString::SkipEmptyParts); QStringList path_parts = path.split("/", QString::SkipEmptyParts);
t->rename_file(0, path_parts.last().toUtf8().data()); t->rename_file(0, path_parts.last().toUtf8().data());
return QString::null; return QString::null;
@ -279,7 +286,11 @@ QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
QString root_folder; QString root_folder;
int i = 0; int i = 0;
for(torrent_info::file_iterator it = t->begin_files(); it < t->end_files(); it++) { for(torrent_info::file_iterator it = t->begin_files(); it < t->end_files(); it++) {
#if LIBTORRENT_VERSION_MINOR >= 16
QString path = toQStringU(fs.file_path(*it));
#else
QString path = QString::fromUtf8(it->path.string().c_str()); QString path = QString::fromUtf8(it->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();
@ -292,10 +303,17 @@ QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
QString misc::truncateRootFolder(libtorrent::torrent_handle h) { QString misc::truncateRootFolder(libtorrent::torrent_handle h) {
torrent_info t = h.get_torrent_info(); torrent_info t = h.get_torrent_info();
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t.files();
#endif
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 >= 16
QString path = misc::toQStringU(fs.file_path(t.file_at(0)));
#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
QStringList path_parts = path.split("/", QString::SkipEmptyParts); QStringList path_parts = path.split("/", QString::SkipEmptyParts);
t.rename_file(0, path_parts.last().toUtf8().data()); t.rename_file(0, path_parts.last().toUtf8().data());
return QString::null; return QString::null;
@ -303,7 +321,11 @@ QString misc::truncateRootFolder(libtorrent::torrent_handle h) {
QString root_folder; QString root_folder;
int i = 0; int i = 0;
for(torrent_info::file_iterator it = t.begin_files(); it < t.end_files(); it++) { for(torrent_info::file_iterator it = t.begin_files(); it < t.end_files(); it++) {
#if LIBTORRENT_VERSION_MINOR >= 16
QString path = toQStringU(fs.file_path(*it));
#else
QString path = QString::fromUtf8(it->path.string().c_str()); QString path = QString::fromUtf8(it->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();
@ -627,7 +649,7 @@ QString misc::magnetUriToHash(QString magnet_uri) {
return hash; return hash;
} }
QString misc::boostTimeToQString(const boost::optional<boost::posix_time::ptime> boostDate) { QString misc::boostTimeToQString(const boost::optional<boost::posix_time::ptime> &boostDate) {
if(!boostDate || !boostDate.is_initialized() || boostDate->is_not_a_date_time()) return tr("Unknown"); if(!boostDate || !boostDate.is_initialized() || boostDate->is_not_a_date_time()) return tr("Unknown");
struct std::tm tm; struct std::tm tm;
try { try {
@ -644,6 +666,14 @@ QString misc::boostTimeToQString(const boost::optional<boost::posix_time::ptime>
return dt.toString(Qt::DefaultLocaleLongDate); return dt.toString(Qt::DefaultLocaleLongDate);
} }
QString misc::time_tToQString(const boost::optional<time_t> &t) {
if(!t.is_initialized() || *t < 0) return tr("Unknown");
QDateTime dt = QDateTime::fromTime_t(*t);
if(dt.isNull() || !dt.isValid())
return tr("Unknown");
return dt.toString(Qt::DefaultLocaleLongDate);
}
// Replace ~ in path // Replace ~ in path
QString misc::expandPath(QString path) { QString misc::expandPath(QString path) {
path = path.trimmed(); path = path.trimmed();

3
src/misc.h

@ -156,7 +156,8 @@ public:
static QString magnetUriToName(QString magnet_uri); static QString magnetUriToName(QString magnet_uri);
static QString magnetUriToHash(QString magnet_uri); static QString magnetUriToHash(QString magnet_uri);
static QString bcLinkToMagnet(QString bc_link); static QString bcLinkToMagnet(QString bc_link);
static QString boostTimeToQString(const boost::optional<boost::posix_time::ptime> boostDate); static QString boostTimeToQString(const boost::optional<boost::posix_time::ptime> &boostDate);
static QString time_tToQString(const boost::optional<time_t> &t);
// Replace ~ in path // Replace ~ in path
static QString expandPath(QString path); static QString expandPath(QString path);
// Take a number of seconds and return an user-friendly // Take a number of seconds and return an user-friendly

1
src/properties/peerlistwidget.h

@ -35,6 +35,7 @@
#include <QHash> #include <QHash>
#include <QPointer> #include <QPointer>
#include <QSet> #include <QSet>
#include <libtorrent/peer_info.hpp>
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
#include "misc.h" #include "misc.h"

12
src/properties/propertieswidget.cpp

@ -436,7 +436,7 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
if(PropListModel->getType(index) == TFILE) { if(PropListModel->getType(index) == TFILE) {
int i = PropListModel->getFileIndex(index); int i = PropListModel->getFileIndex(index);
const QDir saveDir(h.save_path()); const QDir saveDir(h.save_path());
const QString filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); const QString filename = h.filepath_at(i);
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename)); const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open file at %s", qPrintable(file_path)); qDebug("Trying to open file at %s", qPrintable(file_path));
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
@ -545,7 +545,7 @@ void PropertiesWidget::renameSelectedFile() {
// File renaming // File renaming
const int file_index = PropListModel->getFileIndex(index); const int file_index = PropListModel->getFileIndex(index);
if(!h.is_valid() || !h.has_metadata()) return; if(!h.is_valid() || !h.has_metadata()) return;
QString old_name = misc::toQStringU(h.get_torrent_info().file_at(file_index).path.string()); QString old_name = h.filepath_at(file_index);
old_name = old_name.replace("\\", "/"); old_name = old_name.replace("\\", "/");
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB"; new_name_last += ".!qB";
@ -563,9 +563,9 @@ void PropertiesWidget::renameSelectedFile() {
for(int i=0; i<h.num_files(); ++i) { for(int i=0; i<h.num_files(); ++i) {
if(i == file_index) continue; if(i == file_index) continue;
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) { if(h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) {
#else #else
if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) { if(h.filepath_at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
#endif #endif
// Display error message // Display error message
QMessageBox::warning(this, tr("The file could not be renamed"), QMessageBox::warning(this, tr("The file could not be renamed"),
@ -600,7 +600,7 @@ void PropertiesWidget::renameSelectedFile() {
// Check for overwriting // Check for overwriting
const int num_files = h.num_files(); const int num_files = h.num_files();
for(int i=0; i<num_files; ++i) { for(int i=0; i<num_files; ++i) {
const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); const QString current_name = h.filepath_at(i);
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(current_name.startsWith(new_path, Qt::CaseSensitive)) { if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else #else
@ -615,7 +615,7 @@ void PropertiesWidget::renameSelectedFile() {
bool force_recheck = false; bool force_recheck = false;
// Replace path in all files // Replace path in all files
for(int i=0; i<num_files; ++i) { for(int i=0; i<num_files; ++i) {
const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); const QString current_name = h.filepath_at(i);
if(current_name.startsWith(old_path)) { if(current_name.startsWith(old_path)) {
QString new_name = current_name; QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path); new_name.replace(0, old_path.length(), new_path);

2
src/properties/trackerlist.cpp

@ -35,7 +35,7 @@
#include <QAction> #include <QAction>
#include <QColor> #include <QColor>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <libtorrent/peer_info.hpp>
#include "trackerlist.h" #include "trackerlist.h"
#include "propertieswidget.h" #include "propertieswidget.h"
#include "trackersadditiondlg.h" #include "trackersadditiondlg.h"

28
src/qtlibtorrent/qbtsession.cpp

@ -67,6 +67,11 @@
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <boost/filesystem/exception.hpp> #include <boost/filesystem/exception.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#if LIBTORRENT_VERSION_MINOR > 15
#include "libtorrent/error_code.hpp"
#endif
#include <queue> #include <queue>
using namespace libtorrent; using namespace libtorrent;
@ -91,7 +96,7 @@ QBtSession::QBtSession()
Preferences pref; Preferences pref;
m_tracker = 0; m_tracker = 0;
// To avoid some exceptions // To avoid some exceptions
fs::path::default_name_check(fs::no_check); boost::filesystem::path::default_name_check(boost::filesystem::no_check);
// For backward compatibility // For backward compatibility
// Move .qBittorrent content to XDG folder // Move .qBittorrent content to XDG folder
// TODO: Remove after some releases (introduced in v2.1.0) // TODO: Remove after some releases (introduced in v2.1.0)
@ -1374,8 +1379,15 @@ void QBtSession::loadSessionState() {
if (load_file(state_path.toLocal8Bit().constData(), in) == 0) if (load_file(state_path.toLocal8Bit().constData(), in) == 0)
{ {
lazy_entry e; lazy_entry e;
#if LIBTORRENT_VERSION_MINOR > 15
error_code ec;
lazy_bdecode(&in[0], &in[0] + in.size(), e, ec);
if(!ec)
s->load_state(e);
#else
if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0) if (lazy_bdecode(&in[0], &in[0] + in.size(), e) == 0)
s->load_state(e); s->load_state(e);
#endif
} }
#else #else
boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData()
@ -1654,7 +1666,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
if(append) { if(append) {
const qulonglong file_size = h.filesize_at(i); const qulonglong file_size = h.filesize_at(i);
if(file_size > 0 && (fp[i]/(double)file_size) < 1.) { if(file_size > 0 && (fp[i]/(double)file_size) < 1.) {
const QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); const QString name = h.filepath_at(i);
if(!name.endsWith(".!qB")) { if(!name.endsWith(".!qB")) {
const QString new_name = name+".!qB"; const QString new_name = name+".!qB";
qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name)); qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name));
@ -1662,7 +1674,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
} }
} }
} else { } else {
QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string()); QString name = h.filepath_at(i);
if(name.endsWith(".!qB")) { if(name.endsWith(".!qB")) {
const QString old_name = name; const QString old_name = name;
name.chop(4); name.chop(4);
@ -1902,7 +1914,7 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) {
void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
torrent_info::file_iterator it; torrent_info::file_iterator it;
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); 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()); const QString torrent_relpath = h.filepath(*it);
if(torrent_relpath.endsWith(".torrent")) { if(torrent_relpath.endsWith(".torrent")) {
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name())); addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(torrent_relpath).arg(h.name()));
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath; const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
@ -1978,8 +1990,8 @@ void QBtSession::readAlerts() {
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(torrent_info::file_iterator it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
qDebug("File path: %s", it->path.string().c_str()); qDebug() << "File path:" << h.filepath(*it);
const QString torrent_relpath = misc::toQStringU(it->path.string()).replace("\\", "/"); const QString torrent_relpath = h.filepath(*it).replace("\\", "/");
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;
@ -2070,7 +2082,7 @@ void QBtSession::readAlerts() {
if(h.is_valid()) { if(h.is_valid()) {
if(h.num_files() > 1) { if(h.num_files() > 1) {
// Check if folders were renamed // Check if folders were renamed
QStringList old_path_parts = misc::toQStringU(h.get_torrent_info().orig_files().at(p->index).path.string()).split("/"); QStringList old_path_parts = h.orig_filepath_at(p->index).split("/");
old_path_parts.removeLast(); old_path_parts.removeLast();
QString old_path = old_path_parts.join("/"); QString old_path = old_path_parts.join("/");
QStringList new_path_parts = misc::toQStringU(p->name).split("/"); QStringList new_path_parts = misc::toQStringU(p->name).split("/");
@ -2205,7 +2217,7 @@ void QBtSession::readAlerts() {
qDebug("A file completed download in torrent %s", qPrintable(h.name())); qDebug("A file completed download in torrent %s", qPrintable(h.name()));
if(appendqBExtension) { if(appendqBExtension) {
qDebug("appendqBTExtension is true"); qDebug("appendqBTExtension is true");
QString name = misc::toQStringU(h.get_torrent_info().file_at(p->index).path.string()); QString name = h.filepath_at(p->index);
if(name.endsWith(".!qB")) { if(name.endsWith(".!qB")) {
const QString old_name = name; const QString old_name = name;
name.chop(4); name.chop(4);

50
src/qtlibtorrent/qtorrenthandle.cpp

@ -66,8 +66,13 @@ QString QTorrentHandle::name() const {
} }
QString QTorrentHandle::creation_date() const { QString QTorrentHandle::creation_date() const {
#if LIBTORRENT_VERSION_MINOR >= 16
boost::optional<time_t> t = torrent_handle::get_torrent_info().creation_date();
return misc::time_tToQString(t);
#else
boost::optional<boost::posix_time::ptime> boostDate = torrent_handle::get_torrent_info().creation_date(); boost::optional<boost::posix_time::ptime> boostDate = torrent_handle::get_torrent_info().creation_date();
return misc::boostTimeToQString(boostDate); return misc::boostTimeToQString(boostDate);
#endif
} }
QString QTorrentHandle::next_announce() const { QString QTorrentHandle::next_announce() const {
@ -131,7 +136,7 @@ bool QTorrentHandle::first_last_piece_first() const {
it++; it++;
++rank; ++rank;
} }
qDebug("Main file in the torrent is %s", main_file.path.string().c_str()); qDebug() << "Main file in the torrent is" << filepath(main_file);
int piece_size = torrent_handle::get_torrent_info().piece_length(); int piece_size = torrent_handle::get_torrent_info().piece_length();
Q_ASSERT(piece_size>0); Q_ASSERT(piece_size>0);
int first_piece = floor((main_file.offset+1)/(double)piece_size); int first_piece = floor((main_file.offset+1)/(double)piece_size);
@ -177,7 +182,11 @@ int QTorrentHandle::num_incomplete() const {
} }
QString QTorrentHandle::save_path() const { QString QTorrentHandle::save_path() const {
#if LIBTORRENT_VERSION_MINOR > 15
return misc::toQStringU(torrent_handle::save_path()).replace("\\", "/");
#else
return misc::toQStringU(torrent_handle::save_path().string()).replace("\\", "/"); return misc::toQStringU(torrent_handle::save_path().string()).replace("\\", "/");
#endif
} }
QStringList QTorrentHandle::url_seeds() const { QStringList QTorrentHandle::url_seeds() const {
@ -214,7 +223,11 @@ int QTorrentHandle::num_files() const {
QString QTorrentHandle::filename_at(unsigned int index) const { QString QTorrentHandle::filename_at(unsigned int index) const {
Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files()); Q_ASSERT(index < (unsigned int)torrent_handle::get_torrent_info().num_files());
#if LIBTORRENT_VERSION_MINOR > 15
return filepath_at(index).replace("\\", "/").split("/").last();
#else
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.leaf()); return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.leaf());
#endif
} }
size_type QTorrentHandle::filesize_at(unsigned int index) const { size_type QTorrentHandle::filesize_at(unsigned int index) const {
@ -222,6 +235,33 @@ 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 {
#if LIBTORRENT_VERSION_MINOR > 15
file_storage fs = torrent_handle::get_torrent_info().files();
return misc::toQStringU(fs.file_path(fs.at(index)));
#else
return misc::toQStringU(torrent_handle::get_torrent_info().file_at(index).path.string());
#endif
}
QString QTorrentHandle::orig_filepath_at(unsigned int index) const {
#if LIBTORRENT_VERSION_MINOR > 15
file_storage fs = torrent_handle::get_torrent_info().orig_files();
return misc::toQStringU(fs.file_path(fs.at(index)));
#else
return misc::toQStringU(torrent_handle::get_torrent_info().orig_files().at(index).path.string());
#endif
}
torrent_status::state_t QTorrentHandle::state() const { torrent_status::state_t QTorrentHandle::state() const {
return torrent_handle::status().state; return torrent_handle::status().state;
} }
@ -273,7 +313,7 @@ QStringList QTorrentHandle::files_path() const {
QStringList res; QStringList res;
torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files(); torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_files();
while(fi != torrent_handle::get_torrent_info().end_files()) { while(fi != torrent_handle::get_torrent_info().end_files()) {
res << QDir::cleanPath(saveDir.absoluteFilePath(misc::toQStringU(fi->path.string()))); res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi)));
fi++; fi++;
} }
return res; return res;
@ -287,7 +327,7 @@ QStringList QTorrentHandle::uneeded_files_path() const {
int i = 0; int i = 0;
while(fi != torrent_handle::get_torrent_info().end_files()) { while(fi != torrent_handle::get_torrent_info().end_files()) {
if(fp[i] == 0) if(fp[i] == 0)
res << QDir::cleanPath(saveDir.absoluteFilePath(misc::toQStringU(fi->path.string()))); res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi)));
fi++; fi++;
++i; ++i;
} }
@ -353,7 +393,7 @@ QString QTorrentHandle::firstFileSavePath() const {
fsave_path = fsave_path.replace("\\", "/"); fsave_path = fsave_path.replace("\\", "/");
if(!fsave_path.endsWith("/")) if(!fsave_path.endsWith("/"))
fsave_path += "/"; fsave_path += "/";
fsave_path += misc::toQStringU(torrent_handle::get_torrent_info().file_at(0).path.string()); fsave_path += filepath_at(0);
// Remove .!qB extension // Remove .!qB extension
if(fsave_path.endsWith(".!qB", Qt::CaseInsensitive)) if(fsave_path.endsWith(".!qB", Qt::CaseInsensitive))
fsave_path.chop(4); fsave_path.chop(4);
@ -525,7 +565,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
it++; it++;
++rank; ++rank;
} }
qDebug("Main file in the torrent is %s", main_file.path.string().c_str()); qDebug() << "Main file in the torrent is" << filepath(main_file);
// Determine the priority to set // Determine the priority to set
int prio = 7; // MAX int prio = 7; // MAX
if(!b) prio = torrent_handle::file_priority(main_file_index); if(!b) prio = torrent_handle::file_priority(main_file_index);

3
src/qtlibtorrent/qtorrenthandle.h

@ -82,6 +82,9 @@ class QTorrentHandle : public libtorrent::torrent_handle {
bool is_queued() const; bool is_queued() const;
QString filename_at(unsigned int index) const; QString filename_at(unsigned int index) const;
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 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;

22
src/torrentadditiondlg.cpp

@ -252,6 +252,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
close(); close();
return; return;
} }
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
#endif
// Truncate root folder // Truncate root folder
QString root_folder = misc::truncateRootFolder(t); QString root_folder = misc::truncateRootFolder(t);
// Setting file name // Setting file name
@ -271,8 +274,13 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(updateDiskSpaceLabels())); connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(updateDiskSpaceLabels()));
// Loads files path in the torrent // Loads files path in the torrent
for(uint i=0; i<nbFiles; ++i) { for(uint i=0; i<nbFiles; ++i) {
#if LIBTORRENT_VERSION_MINOR >= 16
files_path << misc::toQStringU(fs.file_path(t->file_at(i)));
#else
files_path << misc::toQStringU(t->file_at(i).path.string()); files_path << misc::toQStringU(t->file_at(i).path.string());
#endif
} }
} }
// Load save path history // Load save path history
@ -298,7 +306,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
} }
if(nbFiles == 1) { if(nbFiles == 1) {
// single file torrent // single file torrent
#if LIBTORRENT_VERSION_MINOR >= 16
QString single_file_relpath = misc::toQStringU(fs.file_path(t->file_at(0)));
#else
QString single_file_relpath = misc::toQStringU(t->file_at(0).path.string()); QString single_file_relpath = misc::toQStringU(t->file_at(0).path.string());
#endif
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath.replace("/", "\\"); single_file_relpath = single_file_relpath.replace("/", "\\");
#endif #endif
@ -601,10 +613,16 @@ void torrentAdditionDialog::renameSelectedFile() {
if(!is_magnet) { if(!is_magnet) {
bool path_changed = false; bool path_changed = false;
for(uint i=0; i<nbFiles; ++i) { for(uint i=0; i<nbFiles; ++i) {
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
QString old_path = misc::toQStringU(fs.file_path(t->file_at(i)));
#else
QString old_path = misc::toQStringU(t->file_at(i).path.string());
#endif
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseSensitive) != 0) { if(files_path.at(i).compare(old_path, Qt::CaseSensitive) != 0) {
#else #else
if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) { if(files_path.at(i).compare(old_path, Qt::CaseInsensitive) != 0) {
#endif #endif
path_changed = true; path_changed = true;
break; break;

17
src/torrentcreator/torrentcreatorthread.cpp

@ -88,9 +88,13 @@ void TorrentCreatorThread::run() {
char const* creator_str = "qBittorrent "VERSION; char const* creator_str = "qBittorrent "VERSION;
try { try {
file_storage fs; file_storage fs;
path full_path = complete(path(input_path.toUtf8().constData())); #if LIBTORRENT_VERSION_MINOR >= 16
add_files(fs, input_path.toUtf8().constData(), file_filter);
#else
// Adding files to the torrent // Adding files to the torrent
path full_path = complete(path(input_path.toUtf8().constData()));
add_files(fs, full_path, file_filter); add_files(fs, full_path, file_filter);
#endif
if(abort) return; if(abort) return;
create_torrent t(fs, piece_size); create_torrent t(fs, piece_size);
@ -103,7 +107,16 @@ void TorrentCreatorThread::run() {
} }
if(abort) return; if(abort) return;
// calculate the hash for all pieces // calculate the hash for all pieces
#if LIBTORRENT_VERSION_MINOR >= 16
QString parent_path = input_path.replace("\\", "/");
QStringList parts = parent_path.split("/");
parts.removeLast();
parent_path = parts.join("/");
set_piece_hashes(t, parent_path.toUtf8().constData(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
#else
QString parent_path = misc::toQStringU(full_path.branch_path().string());
set_piece_hashes(t, full_path.branch_path(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this)); set_piece_hashes(t, full_path.branch_path(), boost::bind<void>(&sendProgressUpdateSignal, _1, t.num_pieces(), this));
#endif
// Set qBittorrent as creator and add user comment to // Set qBittorrent as creator and add user comment to
// torrent_info structure // torrent_info structure
t.set_creator(creator_str); t.set_creator(creator_str);
@ -115,7 +128,7 @@ void TorrentCreatorThread::run() {
ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary); ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary);
bencode(std::ostream_iterator<char>(out), t.generate()); bencode(std::ostream_iterator<char>(out), t.generate());
emit updateProgress(100); emit updateProgress(100);
emit creationSuccess(save_path, QString::fromUtf8(full_path.branch_path().string().c_str())); emit creationSuccess(save_path, parent_path);
} }
catch (std::exception& e){ catch (std::exception& e){
emit creationFailure(QString::fromUtf8(e.what())); emit creationFailure(QString::fromUtf8(e.what()));

34
src/torrentfilesmodel.h

@ -59,12 +59,17 @@ private:
public: public:
// File Construction // File Construction
TreeItem(libtorrent::file_entry f, TreeItem *parent, int _file_index) { TreeItem(const libtorrent::torrent_info &t, const libtorrent::file_entry &f, TreeItem *parent, int _file_index) {
Q_ASSERT(parent); Q_ASSERT(parent);
parentItem = parent; parentItem = parent;
type = TFILE; type = TFILE;
file_index = _file_index; file_index = _file_index;
#if LIBTORRENT_VERSION_MINOR >= 16
QString name = misc::toQStringU(t.files().file_path(f)).replace("\\", "/").split("/").last();
#else
Q_UNUSED(t);
QString name = misc::toQStringU(f.path.string()).split("/").last(); QString name = misc::toQStringU(f.path.string()).split("/").last();
#endif
// Do not display incomplete extensions // Do not display incomplete extensions
if(name.endsWith(".!qB")) if(name.endsWith(".!qB"))
name.chop(4); name.chop(4);
@ -518,7 +523,7 @@ public:
emit layoutChanged(); emit layoutChanged();
} }
void setupModelData(libtorrent::torrent_info const& t) { void setupModelData(const libtorrent::torrent_info &t) {
qDebug("setup model data called"); qDebug("setup model data called");
if(t.num_files() == 0) return; if(t.num_files() == 0) return;
// Initialize files_index array // Initialize files_index array
@ -526,25 +531,6 @@ public:
files_index = new TreeItem*[t.num_files()]; files_index = new TreeItem*[t.num_files()];
TreeItem *parent = this->rootItem; TreeItem *parent = this->rootItem;
/*if(t.num_files() == 1) {
// Create possible parent folder
QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/", QString::SkipEmptyParts);
path_parts.removeLast();
foreach(const QString &part, path_parts) {
TreeItem *folder = new TreeItem(part, parent);
parent = folder;
}
TreeItem *f = new TreeItem(t.file_at(0), parent, 0);
//parent->appendChild(f);
files_index[0] = f;
emit layoutChanged();
return;
}*/
// Create parent folder
//QString root_name = misc::toQString(t.file_at(0).path.string()).split("/").first();
//TreeItem *current_parent = new TreeItem(root_name, parent);
//parent->appendChild(current_parent);
//TreeItem *root_folder = current_parent;
TreeItem *root_folder = parent; TreeItem *root_folder = parent;
TreeItem *current_parent; TreeItem *current_parent;
@ -553,7 +539,11 @@ public:
libtorrent::torrent_info::file_iterator fi = t.begin_files(); libtorrent::torrent_info::file_iterator fi = t.begin_files();
while(fi != t.end_files()) { while(fi != t.end_files()) {
current_parent = root_folder; current_parent = root_folder;
#if LIBTORRENT_VERSION_MINOR >= 16
QString path = QDir::cleanPath(misc::toQStringU(t.files().file_path(*fi))).replace("\\", "/");
#else
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())).replace("\\", "/"); QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())).replace("\\", "/");
#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("/");
pathFolders.takeLast(); pathFolders.takeLast();
@ -565,7 +555,7 @@ public:
current_parent = new_parent; current_parent = new_parent;
} }
// Actually create the file // Actually create the file
TreeItem *f = new TreeItem(*fi, current_parent, i); TreeItem *f = new TreeItem(t, *fi, current_parent, i);
files_index[i] = f; files_index[i] = f;
fi++; fi++;
++i; ++i;

25
src/torrentimportdlg.cpp

@ -73,9 +73,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
{ {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
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 LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
#endif
if(t->num_files() == 1) { if(t->num_files() == 1) {
// Single file torrent // Single file torrent
#if LIBTORRENT_VERSION_MINOR >= 16
const QString file_name = misc::toQStringU(fs.file_path(t->file_at(0))).replace("\\", "/").split("/").last();
#else
const QString file_name = misc::toQStringU(t->file_at(0).path.leaf()); const QString file_name = misc::toQStringU(t->file_at(0).path.leaf());
#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));
@ -141,11 +148,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Check file sizes // Check file sizes
torrent_info::file_iterator it; t->begin_files(); torrent_info::file_iterator it; t->begin_files();
for(it = t->begin_files(); it != t->end_files(); it++) { for(it = t->begin_files(); it != t->end_files(); it++) {
if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(misc::toQStringU(it->path.string())))).size() != it->size) { #if LIBTORRENT_VERSION_MINOR >= 16
const QString rel_path = misc::toQStringU(fs.file_path(*it));
#else
const QString rel_path = misc::toQStringU(it->path.string());
#endif
if(QFile(QDir::cleanPath(content_dir.absoluteFilePath(rel_path))).size() != it->size) {
qDebug("%s is %lld", qDebug("%s is %lld",
qPrintable(QDir::cleanPath(content_dir.absoluteFilePath(misc::toQStringU(it->path.string())))), (long long int) QFile(QDir::cleanPath(content_dir.absoluteFilePath(misc::toQStringU(it->path.string())))).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",
it->path.string().c_str(), (long long int)it->size); qPrintable(rel_path), (long long int)it->size);
size_mismatch = true; size_mismatch = true;
break; break;
} }
@ -236,8 +248,15 @@ void TorrentImportDlg::initializeFilesPath()
{ {
m_filesPath.clear(); m_filesPath.clear();
// Loads files path in the torrent // Loads files path in the torrent
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
#endif
for(int i=0; i<t->num_files(); ++i) { for(int i=0; i<t->num_files(); ++i) {
#if LIBTORRENT_VERSION_MINOR >= 16
m_filesPath << misc::toQStringU(fs.file_path(t->file_at(i))).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
} }
} }

2
src/transferlistwidget.cpp

@ -881,7 +881,7 @@ bool TransferListWidget::loadColWidthList() {
if(line.isEmpty()) if(line.isEmpty())
return false; return false;
const QStringList width_list = line.split(" "); const QStringList width_list = line.split(" ");
const unsigned int listSize = width_list.size(); const int listSize = width_list.size();
if(listSize != listModel->columnCount()) { if(listSize != listModel->columnCount()) {
qDebug("Corrupted values for transfer list columns sizes"); qDebug("Corrupted values for transfer list columns sizes");
return false; return false;

2
src/webui/eventmanager.cpp

@ -108,7 +108,7 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
int i=0; int i=0;
for(fi=t.begin_files(); fi != t.end_files(); fi++) { for(fi=t.begin_files(); fi != t.end_files(); fi++) {
QVariantMap file; QVariantMap file;
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string())); QString path = h.filepath(*fi);
QString name = path.split('/').last(); QString name = path.split('/').last();
file["name"] = name; file["name"] = name;
file["size"] = misc::friendlyUnit((double)fi->size); file["size"] = misc::friendlyUnit((double)fi->size);

Loading…
Cancel
Save