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. 656
      src/torrentadditiondlg.cpp
  11. 17
      src/torrentcreator/torrentcreatorthread.cpp
  12. 34
      src/torrentfilesmodel.h
  13. 29
      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;

656
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
@ -402,366 +414,372 @@ void torrentAdditionDialog::renameSelectedFile() {
#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(new_name, Qt::CaseSensitive) == 0) { if(files_path.at(i).compare(new_name, Qt::CaseSensitive) == 0) {
#else #else
if(files_path.at(i).compare(new_name, Qt::CaseInsensitive) == 0) { if(files_path.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"),
tr("This name is already in use in this folder. Please use a different name."), tr("This name is already in use in this folder. Please use a different name."),
QMessageBox::Ok); QMessageBox::Ok);
return; return;
}
}
new_name = QDir::cleanPath(new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
// Rename file in files_path
files_path.replace(file_index, new_name);
// Rename in torrent files model too
PropListModel->setData(index, new_name_last);
} else {
// Folder renaming
QStringList path_items;
path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) {
path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent);
} }
const QString old_path = path_items.join("/"); }
path_items.removeLast(); new_name = QDir::cleanPath(new_name);
path_items << new_name_last; qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
QString new_path = path_items.join("/"); // Rename file in files_path
if(!new_path.endsWith("/")) new_path += "/"; files_path.replace(file_index, new_name);
// Check for overwriting // Rename in torrent files model too
for(uint i=0; i<nbFiles; ++i) { PropListModel->setData(index, new_name_last);
const QString &current_name = files_path.at(i); } else {
// Folder renaming
QStringList path_items;
path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) {
path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent);
}
const QString old_path = path_items.join("/");
path_items.removeLast();
path_items << new_name_last;
QString new_path = path_items.join("/");
if(!new_path.endsWith("/")) new_path += "/";
// Check for overwriting
for(uint i=0; i<nbFiles; ++i) {
const QString &current_name = files_path.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
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) { if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
#endif #endif
QMessageBox::warning(this, tr("The folder could not be renamed"), QMessageBox::warning(this, tr("The folder could not be renamed"),
tr("This name is already in use in this folder. Please use a different name."), tr("This name is already in use in this folder. Please use a different name."),
QMessageBox::Ok); QMessageBox::Ok);
return; return;
} }
} }
// Replace path in all files // Replace path in all files
for(uint i=0; i<nbFiles; ++i) { for(uint i=0; i<nbFiles; ++i) {
const QString &current_name = files_path.at(i); const QString &current_name = files_path.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);
new_name = QDir::cleanPath(new_name); new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name)); qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
// Rename in files_path // Rename in files_path
files_path.replace(i, new_name); files_path.replace(i, new_name);
}
}
// Rename folder in torrent files model too
PropListModel->setData(index, new_name_last);
} }
} }
// Rename folder in torrent files model too
PropListModel->setData(index, new_name_last);
} }
}
}
void torrentAdditionDialog::updateDiskSpaceLabels() { void torrentAdditionDialog::updateDiskSpaceLabels() {
qDebug("Updating disk space label..."); qDebug("Updating disk space label...");
const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->currentText())); const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->currentText()));
lbl_disk_space->setText(misc::friendlyUnit(available)); lbl_disk_space->setText(misc::friendlyUnit(available));
if(!is_magnet) { if(!is_magnet) {
// Determine torrent size // Determine torrent size
qulonglong torrent_size = 0; qulonglong torrent_size = 0;
if(t->num_files() > 1) { if(t->num_files() > 1) {
const unsigned int nbFiles = t->num_files(); const unsigned int nbFiles = t->num_files();
const std::vector<int> priorities = PropListModel->getFilesPriorities(nbFiles); const std::vector<int> priorities = PropListModel->getFilesPriorities(nbFiles);
for(unsigned int i=0; i<nbFiles; ++i) { for(unsigned int i=0; i<nbFiles; ++i) {
if(priorities[i] > 0) if(priorities[i] > 0)
torrent_size += t->file_at(i).size; torrent_size += t->file_at(i).size;
}
} else {
torrent_size = t->total_size();
}
lbl_torrent_size->setText(misc::friendlyUnit(torrent_size));
// Check if free space is sufficient
if(available > 0) {
if((unsigned long long)available > torrent_size) {
// Space is sufficient
label_space_msg->setText(tr("(%1 left after torrent download)", "e.g. (100MiB left after torrent download)").arg(misc::friendlyUnit(available-torrent_size)));
} else {
// Space is unsufficient
label_space_msg->setText("<font color=\"red\">"+tr("(%1 more are required to download)", "e.g. (100MiB more are required to download)").arg(misc::friendlyUnit(torrent_size-available))+"</font>");
}
} else {
// Available disk space is unknown
label_space_msg->setText("");
}
} }
} else {
torrent_size = t->total_size();
} }
lbl_torrent_size->setText(misc::friendlyUnit(torrent_size));
void torrentAdditionDialog::on_browseButton_clicked(){ // Check if free space is sufficient
Q_ASSERT(!is_magnet); if(available > 0) {
QString new_path; if((unsigned long long)available > torrent_size) {
if(t->num_files() == 1) { // Space is sufficient
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText()); label_space_msg->setText(tr("(%1 left after torrent download)", "e.g. (100MiB left after torrent download)").arg(misc::friendlyUnit(available-torrent_size)));
} else { } else {
QString root_folder; // Space is unsufficient
QString truncated_path = getCurrentTruncatedSavePath(&root_folder); label_space_msg->setText("<font color=\"red\">"+tr("(%1 more are required to download)", "e.g. (100MiB more are required to download)").arg(misc::friendlyUnit(torrent_size-available))+"</font>");
if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path);
}else{
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
}
if(!new_path.isEmpty()) {
QStringList path_parts = new_path.replace("\\", "/").split("/");
if(path_parts.last().isEmpty())
path_parts.removeLast();
// Append label
const QString label_name = comboLabel->currentText();
if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty())
path_parts << label_name;
// Append root folder
if(!root_folder.isEmpty())
path_parts << root_folder;
// Construct new_path
new_path = path_parts.join(QDir::separator());
}
} }
if(!new_path.isEmpty()) { } else {
// Check if this new path already exists in the list // Available disk space is unknown
QString new_truncated_path = getTruncatedSavePath(new_path); label_space_msg->setText("");
}
}
}
void torrentAdditionDialog::on_browseButton_clicked(){
Q_ASSERT(!is_magnet);
QString new_path;
if(t->num_files() == 1) {
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText());
} else {
QString root_folder;
QString truncated_path = getCurrentTruncatedSavePath(&root_folder);
if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path);
}else{
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
}
if(!new_path.isEmpty()) {
QStringList path_parts = new_path.replace("\\", "/").split("/");
if(path_parts.last().isEmpty())
path_parts.removeLast();
// Append label
const QString label_name = comboLabel->currentText();
if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty())
path_parts << label_name;
// Append root folder
if(!root_folder.isEmpty())
path_parts << root_folder;
// Construct new_path
new_path = path_parts.join(QDir::separator());
}
}
if(!new_path.isEmpty()) {
// Check if this new path already exists in the list
QString new_truncated_path = getTruncatedSavePath(new_path);
#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)
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseInsensitive)); const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseInsensitive));
#else #else
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseSensitive)); const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseSensitive));
#endif #endif
if(cur_index >= 0) { if(cur_index >= 0) {
savePathTxt->setCurrentIndex(cur_index); savePathTxt->setCurrentIndex(cur_index);
} }
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path.replace("/", "\\"); new_path = new_path.replace("/", "\\");
#endif #endif
savePathTxt->setEditText(new_path); savePathTxt->setEditText(new_path);
} }
} }
void torrentAdditionDialog::on_CancelButton_clicked(){ void torrentAdditionDialog::on_CancelButton_clicked(){
close(); close();
} }
bool torrentAdditionDialog::allFiltered() const { bool torrentAdditionDialog::allFiltered() const {
Q_ASSERT(!is_magnet); Q_ASSERT(!is_magnet);
return PropListModel->allFiltered(); return PropListModel->allFiltered();
} }
void torrentAdditionDialog::savePiecesPriorities(){ void torrentAdditionDialog::savePiecesPriorities(){
qDebug("Saving pieces priorities"); qDebug("Saving pieces priorities");
Q_ASSERT(!is_magnet); Q_ASSERT(!is_magnet);
const std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files()); const std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files());
TorrentTempData::setFilesPriority(hash, priorities); TorrentTempData::setFilesPriority(hash, priorities);
} }
void torrentAdditionDialog::on_OkButton_clicked(){ void torrentAdditionDialog::on_OkButton_clicked(){
qDebug() << "void torrentAdditionDialog::on_OkButton_clicked() - ENTER"; qDebug() << "void torrentAdditionDialog::on_OkButton_clicked() - ENTER";
if(savePathTxt->currentText().trimmed().isEmpty()){ if(savePathTxt->currentText().trimmed().isEmpty()){
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path")); QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
return; return;
} }
QString save_path = savePathTxt->currentText(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("\\", "/"); save_path = save_path.replace("\\", "/");
#endif
save_path = misc::expandPath(save_path);
qDebug("Save path is %s", qPrintable(save_path));
if(!is_magnet && t->num_files() == 1) {
// Remove file name
QStringList parts = save_path.split("/");
const QString single_file_name = parts.takeLast();
Q_ASSERT(files_path.isEmpty());
files_path << single_file_name;
save_path = parts.join("/");
}
qDebug("Save path dir is %s", qPrintable(save_path));
QDir savePath(save_path);
const QString current_label = comboLabel->currentText().trimmed();
if (!current_label.isEmpty() && !misc::isValidFileSystemName(current_label)) {
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
return;
}
// Save savepath
qDebug("Saving save path to temp data: %s", qPrintable(savePath.absolutePath()));
TorrentTempData::setSavePath(hash, savePath.absolutePath());
qDebug("Torrent label is: %s", qPrintable(comboLabel->currentText().trimmed()));
if(!current_label.isEmpty())
TorrentTempData::setLabel(hash, current_label);
// Is download sequential?
TorrentTempData::setSequential(hash, checkIncrementalDL->isChecked());
// Save files path
// Loads files path in the torrent
if(!is_magnet) {
bool path_changed = false;
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 #endif
save_path = misc::expandPath(save_path);
qDebug("Save path is %s", qPrintable(save_path));
if(!is_magnet && t->num_files() == 1) {
// Remove file name
QStringList parts = save_path.split("/");
const QString single_file_name = parts.takeLast();
Q_ASSERT(files_path.isEmpty());
files_path << single_file_name;
save_path = parts.join("/");
}
qDebug("Save path dir is %s", qPrintable(save_path));
QDir savePath(save_path);
const QString current_label = comboLabel->currentText().trimmed();
if (!current_label.isEmpty() && !misc::isValidFileSystemName(current_label)) {
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
return;
}
// Save savepath
qDebug("Saving save path to temp data: %s", qPrintable(savePath.absolutePath()));
TorrentTempData::setSavePath(hash, savePath.absolutePath());
qDebug("Torrent label is: %s", qPrintable(comboLabel->currentText().trimmed()));
if(!current_label.isEmpty())
TorrentTempData::setLabel(hash, current_label);
// Is download sequential?
TorrentTempData::setSequential(hash, checkIncrementalDL->isChecked());
// Save files path
// Loads files path in the torrent
if(!is_magnet) {
bool path_changed = false;
for(uint i=0; i<nbFiles; ++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(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;
} }
} }
if(path_changed) { if(path_changed) {
qDebug("Changing files paths"); qDebug("Changing files paths");
TorrentTempData::setFilesPath(hash, files_path); TorrentTempData::setFilesPath(hash, files_path);
} }
} }
#if LIBTORRENT_VERSION_MINOR > 14 #if LIBTORRENT_VERSION_MINOR > 14
// Skip file checking and directly start seeding // Skip file checking and directly start seeding
if(addInSeed->isChecked()) { if(addInSeed->isChecked()) {
// Check if local file(s) actually exist // Check if local file(s) actually exist
if(is_magnet || QFile::exists(savePathTxt->currentText())) { if(is_magnet || QFile::exists(savePathTxt->currentText())) {
TorrentTempData::setSeedingMode(hash, true); TorrentTempData::setSeedingMode(hash, true);
} else { } else {
QMessageBox::warning(0, tr("Seeding mode error"), tr("You chose to skip file checking. However, local files do not seem to exist in the current destionation folder. Please disable this feature or update the save path.")); QMessageBox::warning(0, tr("Seeding mode error"), tr("You chose to skip file checking. However, local files do not seem to exist in the current destionation folder. Please disable this feature or update the save path."));
return; return;
} }
} }
#endif #endif
// Check if there is at least one selected file // Check if there is at least one selected file
if(!is_magnet && t->num_files() > 1 && allFiltered()){ if(!is_magnet && t->num_files() > 1 && allFiltered()){
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent")); QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
return; return;
} }
// Save path history // Save path history
saveTruncatedPathHistory(); saveTruncatedPathHistory();
// Check if savePath exists // Check if savePath exists
if(!savePath.exists()){ if(!savePath.exists()){
if(!savePath.mkpath(savePath.path())){ if(!savePath.mkpath(savePath.path())){
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path")); QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
return; return;
} }
} }
// save filtered files // save filtered files
if(!is_magnet && t->num_files() > 1) if(!is_magnet && t->num_files() > 1)
savePiecesPriorities(); savePiecesPriorities();
// Add to download list // Add to download list
QTorrentHandle h; QTorrentHandle h;
if(is_magnet) if(is_magnet)
h = QBtSession::instance()->addMagnetUri(from_url, false); h = QBtSession::instance()->addMagnetUri(from_url, false);
else else
h = QBtSession::instance()->addTorrent(filePath, false, from_url); h = QBtSession::instance()->addTorrent(filePath, false, from_url);
if(addInPause->isChecked() && h.is_valid()) { if(addInPause->isChecked() && h.is_valid()) {
h.pause(); h.pause();
} }
// Close the dialog // Close the dialog
qDebug("Closing torrent addition dialog..."); qDebug("Closing torrent addition dialog...");
close(); close();
qDebug("Closed"); qDebug("Closed");
} }
void torrentAdditionDialog::resetComboLabelIndex(QString text) { void torrentAdditionDialog::resetComboLabelIndex(QString text) {
// Select first index // Select first index
if(text != comboLabel->itemText(comboLabel->currentIndex())) { if(text != comboLabel->itemText(comboLabel->currentIndex())) {
comboLabel->setItemText(0, text); comboLabel->setItemText(0, text);
comboLabel->setCurrentIndex(0); comboLabel->setCurrentIndex(0);
} }
} }
void torrentAdditionDialog::updateLabelInSavePath(QString label) { void torrentAdditionDialog::updateLabelInSavePath(QString label) {
if(appendLabelToSavePath) { if(appendLabelToSavePath) {
// Update Label in combobox // Update Label in combobox
savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label)); savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label));
// update edit text // update edit text
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label)); savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label));
old_label = label; old_label = label;
} }
} }
void torrentAdditionDialog::updateSavePathCurrentText() { void torrentAdditionDialog::updateSavePathCurrentText() {
qDebug("updateSavePathCurrentText() - ENTER"); qDebug("updateSavePathCurrentText() - ENTER");
savePathTxt->setItemText(savePathTxt->currentIndex(), savePathTxt->currentText()); savePathTxt->setItemText(savePathTxt->currentIndex(), savePathTxt->currentText());
qDebug("path_history.size() == %d", path_history.size()); qDebug("path_history.size() == %d", path_history.size());
qDebug("savePathTxt->currentIndex() == %d", savePathTxt->currentIndex()); qDebug("savePathTxt->currentIndex() == %d", savePathTxt->currentIndex());
path_history.replace(savePathTxt->currentIndex(), getCurrentTruncatedSavePath()); path_history.replace(savePathTxt->currentIndex(), getCurrentTruncatedSavePath());
QString root_folder_or_file_name = ""; QString root_folder_or_file_name = "";
getCurrentTruncatedSavePath(&root_folder_or_file_name); getCurrentTruncatedSavePath(&root_folder_or_file_name);
// Update other combo items // Update other combo items
for(int i=0; i<savePathTxt->count(); ++i) { for(int i=0; i<savePathTxt->count(); ++i) {
if(i == savePathTxt->currentIndex()) continue; if(i == savePathTxt->currentIndex()) continue;
QString item_path = path_history.at(i); QString item_path = path_history.at(i);
if(item_path.isEmpty()) continue; if(item_path.isEmpty()) continue;
// Append label // Append label
if(i == 0 && appendLabelToSavePath && QDir(item_path) == QDir(defaultSavePath) && !comboLabel->currentText().isEmpty()) if(i == 0 && appendLabelToSavePath && QDir(item_path) == QDir(defaultSavePath) && !comboLabel->currentText().isEmpty())
item_path += comboLabel->currentText() + "/"; item_path += comboLabel->currentText() + "/";
// Append root_folder or filename // Append root_folder or filename
if(!root_folder_or_file_name.isEmpty()) if(!root_folder_or_file_name.isEmpty())
item_path += root_folder_or_file_name; item_path += root_folder_or_file_name;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path.replace("/", "\\"); item_path = item_path.replace("/", "\\");
#endif #endif
savePathTxt->setItemText(i, item_path); savePathTxt->setItemText(i, item_path);
} }
} }
QString torrentAdditionDialog::getCurrentTruncatedSavePath(QString* root_folder_or_file_name) const { QString torrentAdditionDialog::getCurrentTruncatedSavePath(QString* root_folder_or_file_name) const {
QString save_path = savePathTxt->currentText(); QString save_path = savePathTxt->currentText();
return getTruncatedSavePath(save_path, root_folder_or_file_name); return getTruncatedSavePath(save_path, root_folder_or_file_name);
} }
// Get current save path without the torrent root folder nor the label label // Get current save path without the torrent root folder nor the label label
QString torrentAdditionDialog::getTruncatedSavePath(QString save_path, QString* root_folder_or_file_name) const { QString torrentAdditionDialog::getTruncatedSavePath(QString save_path, QString* root_folder_or_file_name) const {
// Expand and clean path (~, .., .) // Expand and clean path (~, .., .)
save_path = misc::expandPath(save_path); save_path = misc::expandPath(save_path);
QStringList parts = save_path.replace("\\", "/").split("/"); QStringList parts = save_path.replace("\\", "/").split("/");
// Remove torrent root folder // Remove torrent root folder
if(!QDir(save_path).exists() || (!is_magnet && t->num_files() == 1)) { if(!QDir(save_path).exists() || (!is_magnet && t->num_files() == 1)) {
QString tmp = parts.takeLast(); QString tmp = parts.takeLast();
if(root_folder_or_file_name) if(root_folder_or_file_name)
*root_folder_or_file_name = tmp; *root_folder_or_file_name = tmp;
} }
// Remove label // Remove label
if(appendLabelToSavePath && savePathTxt->currentIndex() == 0 && parts.last() == comboLabel->currentText()) { if(appendLabelToSavePath && savePathTxt->currentIndex() == 0 && parts.last() == comboLabel->currentText()) {
parts.removeLast(); parts.removeLast();
} }
QString truncated_path = parts.join("/"); QString truncated_path = parts.join("/");
if(!truncated_path.endsWith("/")) if(!truncated_path.endsWith("/"))
truncated_path += "/"; truncated_path += "/";
qDebug("Truncated save path: %s", qPrintable(truncated_path)); qDebug("Truncated save path: %s", qPrintable(truncated_path));
return truncated_path; return truncated_path;
} }
void torrentAdditionDialog::saveTruncatedPathHistory() { void torrentAdditionDialog::saveTruncatedPathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
const QString current_save_path = getCurrentTruncatedSavePath(); const QString current_save_path = getCurrentTruncatedSavePath();
// Get current history // Get current history
QStringList history = settings.value("TorrentAdditionDlg/save_path_history").toStringList(); QStringList history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
#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(!history.contains(current_save_path, Qt::CaseSensitive)) { if(!history.contains(current_save_path, Qt::CaseSensitive)) {
#else #else
if(!history.contains(current_save_path, Qt::CaseInsensitive)) { if(!history.contains(current_save_path, Qt::CaseInsensitive)) {
#endif #endif
// Add save path to history // Add save path to history
history << current_save_path; history << current_save_path;
// Limit list size // Limit list size
if(history.size() > 8) if(history.size() > 8)
history.removeFirst(); history.removeFirst();
// Save history // Save history
settings.setValue("TorrentAdditionDlg/save_path_history", history); settings.setValue("TorrentAdditionDlg/save_path_history", history);
} }
} }
void torrentAdditionDialog::loadSavePathHistory() { void torrentAdditionDialog::loadSavePathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Load save path history // Load save path history
QStringList raw_path_history = settings.value("TorrentAdditionDlg/save_path_history").toStringList(); QStringList raw_path_history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
foreach(const QString &sp, raw_path_history) { foreach(const QString &sp, raw_path_history) {
if(QDir(sp) != QDir(defaultSavePath)) { if(QDir(sp) != QDir(defaultSavePath)) {
QString dsp = sp; QString dsp = sp;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp.replace("/", "\\"); dsp = dsp.replace("/", "\\");
#endif #endif
path_history << sp; path_history << sp;
savePathTxt->addItem(dsp); savePathTxt->addItem(dsp);
} }
} }
} }

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;

29
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));
@ -94,7 +101,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Update display // Update display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\")); ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else #else
ui->lineContent->setText(m_contentPath); ui->lineContent->setText(m_contentPath);
#endif #endif
#if LIBTORRENT_VERSION_MINOR >= 15 #if LIBTORRENT_VERSION_MINOR >= 15
@ -132,7 +139,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Update the display // Update the display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\")); ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else #else
ui->lineContent->setText(m_contentPath); ui->lineContent->setText(m_contentPath);
#endif #endif
#if LIBTORRENT_VERSION_MINOR >= 15 #if LIBTORRENT_VERSION_MINOR >= 15
@ -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