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

This commit is contained in:
Christophe Dumez 2010-11-28 10:29:59 +00:00
parent 28eddb74ed
commit 3b3642bbba
15 changed files with 533 additions and 408 deletions

View file

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

View file

@ -268,10 +268,17 @@ void misc::shutdownComputer() {
}
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) {
// Single file torrent
// 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());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
t->rename_file(0, path_parts.last().toUtf8().data());
return QString::null;
@ -279,7 +286,11 @@ QString misc::truncateRootFolder(boost::intrusive_ptr<torrent_info> t) {
QString root_folder;
int i = 0;
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());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
if(path_parts.size() > 1) {
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) {
torrent_info t = h.get_torrent_info();
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t.files();
#endif
if(t.num_files() == 1) {
// Single file torrent
// 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());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
t.rename_file(0, path_parts.last().toUtf8().data());
return QString::null;
@ -303,7 +321,11 @@ QString misc::truncateRootFolder(libtorrent::torrent_handle h) {
QString root_folder;
int i = 0;
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());
#endif
QStringList path_parts = path.split("/", QString::SkipEmptyParts);
if(path_parts.size() > 1) {
root_folder = path_parts.takeFirst();
@ -627,7 +649,7 @@ QString misc::magnetUriToHash(QString magnet_uri) {
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");
struct std::tm tm;
try {
@ -644,6 +666,14 @@ QString misc::boostTimeToQString(const boost::optional<boost::posix_time::ptime>
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
QString misc::expandPath(QString path) {
path = path.trimmed();

View file

@ -156,7 +156,8 @@ public:
static QString magnetUriToName(QString magnet_uri);
static QString magnetUriToHash(QString magnet_uri);
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
static QString expandPath(QString path);
// Take a number of seconds and return an user-friendly

View file

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

View file

@ -436,7 +436,7 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
if(PropListModel->getType(index) == TFILE) {
int i = PropListModel->getFileIndex(index);
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));
qDebug("Trying to open file at %s", qPrintable(file_path));
#if LIBTORRENT_VERSION_MINOR > 14
@ -545,7 +545,7 @@ void PropertiesWidget::renameSelectedFile() {
// File renaming
const int file_index = PropListModel->getFileIndex(index);
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("\\", "/");
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB";
@ -563,9 +563,9 @@ void PropertiesWidget::renameSelectedFile() {
for(int i=0; i<h.num_files(); ++i) {
if(i == file_index) continue;
#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
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
// Display error message
QMessageBox::warning(this, tr("The file could not be renamed"),
@ -600,7 +600,7 @@ void PropertiesWidget::renameSelectedFile() {
// Check for overwriting
const int num_files = h.num_files();
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(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else
@ -615,7 +615,7 @@ void PropertiesWidget::renameSelectedFile() {
bool force_recheck = false;
// Replace path in all files
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)) {
QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path);

View file

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

View file

@ -67,6 +67,11 @@
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.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>
using namespace libtorrent;
@ -91,7 +96,7 @@ QBtSession::QBtSession()
Preferences pref;
m_tracker = 0;
// 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
// Move .qBittorrent content to XDG folder
// 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)
{
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)
s->load_state(e);
#endif
}
#else
boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData()
@ -1654,7 +1666,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
if(append) {
const qulonglong file_size = h.filesize_at(i);
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")) {
const QString new_name = name+".!qB";
qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name));
@ -1662,7 +1674,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
}
}
} else {
QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
QString name = h.filepath_at(i);
if(name.endsWith(".!qB")) {
const QString old_name = name;
name.chop(4);
@ -1902,7 +1914,7 @@ void QBtSession::setProxySettings(const proxy_settings &proxySettings) {
void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) {
torrent_info::file_iterator it;
for(it = h.get_torrent_info().begin_files(); it != h.get_torrent_info().end_files(); it++) {
const QString torrent_relpath = misc::toQStringU(it->path.string());
const QString torrent_relpath = h.filepath(*it);
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()));
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");
// 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++) {
qDebug("File path: %s", it->path.string().c_str());
const QString torrent_relpath = misc::toQStringU(it->path.string()).replace("\\", "/");
qDebug() << "File path:" << h.filepath(*it);
const QString torrent_relpath = h.filepath(*it).replace("\\", "/");
if(torrent_relpath.endsWith(".torrent", Qt::CaseInsensitive)) {
qDebug("Found possible recursive torrent download.");
const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath;
@ -2070,7 +2082,7 @@ void QBtSession::readAlerts() {
if(h.is_valid()) {
if(h.num_files() > 1) {
// 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();
QString old_path = old_path_parts.join("/");
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()));
if(appendqBExtension) {
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")) {
const QString old_name = name;
name.chop(4);

View file

@ -66,8 +66,13 @@ QString QTorrentHandle::name() 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();
return misc::boostTimeToQString(boostDate);
#endif
}
QString QTorrentHandle::next_announce() const {
@ -131,7 +136,7 @@ bool QTorrentHandle::first_last_piece_first() const {
it++;
++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();
Q_ASSERT(piece_size>0);
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 {
#if LIBTORRENT_VERSION_MINOR > 15
return misc::toQStringU(torrent_handle::save_path()).replace("\\", "/");
#else
return misc::toQStringU(torrent_handle::save_path().string()).replace("\\", "/");
#endif
}
QStringList QTorrentHandle::url_seeds() const {
@ -214,7 +223,11 @@ int QTorrentHandle::num_files() const {
QString QTorrentHandle::filename_at(unsigned int index) const {
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());
#endif
}
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;
}
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 {
return torrent_handle::status().state;
}
@ -273,7 +313,7 @@ QStringList QTorrentHandle::files_path() const {
QStringList res;
torrent_info::file_iterator fi = torrent_handle::get_torrent_info().begin_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++;
}
return res;
@ -287,7 +327,7 @@ QStringList QTorrentHandle::uneeded_files_path() const {
int i = 0;
while(fi != torrent_handle::get_torrent_info().end_files()) {
if(fp[i] == 0)
res << QDir::cleanPath(saveDir.absoluteFilePath(misc::toQStringU(fi->path.string())));
res << QDir::cleanPath(saveDir.absoluteFilePath(filepath(*fi)));
fi++;
++i;
}
@ -353,7 +393,7 @@ QString QTorrentHandle::firstFileSavePath() const {
fsave_path = fsave_path.replace("\\", "/");
if(!fsave_path.endsWith("/"))
fsave_path += "/";
fsave_path += misc::toQStringU(torrent_handle::get_torrent_info().file_at(0).path.string());
fsave_path += filepath_at(0);
// Remove .!qB extension
if(fsave_path.endsWith(".!qB", Qt::CaseInsensitive))
fsave_path.chop(4);
@ -525,7 +565,7 @@ void QTorrentHandle::prioritize_first_last_piece(bool b) const {
it++;
++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
int prio = 7; // MAX
if(!b) prio = torrent_handle::file_priority(main_file_index);

View file

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

View file

@ -252,6 +252,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
close();
return;
}
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
#endif
// Truncate root folder
QString root_folder = misc::truncateRootFolder(t);
// Setting file name
@ -271,8 +274,13 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(updateDiskSpaceLabels()));
// Loads files path in the torrent
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());
#endif
}
}
// Load save path history
@ -298,7 +306,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
if(nbFiles == 1) {
// 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());
#endif
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath.replace("/", "\\");
#endif
@ -402,366 +414,372 @@ void torrentAdditionDialog::renameSelectedFile() {
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(files_path.at(i).compare(new_name, Qt::CaseSensitive) == 0) {
#else
if(files_path.at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
if(files_path.at(i).compare(new_name, Qt::CaseInsensitive) == 0) {
#endif
// Display error message
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."),
QMessageBox::Ok);
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();
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(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
#endif
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."),
QMessageBox::Ok);
return;
}
}
// Replace path in all files
for(uint i=0; i<nbFiles; ++i) {
const QString &current_name = files_path.at(i);
if(current_name.startsWith(old_path)) {
QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path);
new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
// Rename in files_path
files_path.replace(i, new_name);
}
}
// Rename folder in torrent files model too
PropListModel->setData(index, new_name_last);
}
}
}
void torrentAdditionDialog::updateDiskSpaceLabels() {
qDebug("Updating disk space label...");
const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->currentText()));
lbl_disk_space->setText(misc::friendlyUnit(available));
if(!is_magnet) {
// Determine torrent size
qulonglong torrent_size = 0;
if(t->num_files() > 1) {
const unsigned int nbFiles = t->num_files();
const std::vector<int> priorities = PropListModel->getFilesPriorities(nbFiles);
for(unsigned int i=0; i<nbFiles; ++i) {
if(priorities[i] > 0)
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("");
}
}
}
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)
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseInsensitive));
#else
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseSensitive));
#endif
if(cur_index >= 0) {
savePathTxt->setCurrentIndex(cur_index);
}
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path.replace("/", "\\");
#endif
savePathTxt->setEditText(new_path);
}
}
void torrentAdditionDialog::on_CancelButton_clicked(){
close();
}
bool torrentAdditionDialog::allFiltered() const {
Q_ASSERT(!is_magnet);
return PropListModel->allFiltered();
}
void torrentAdditionDialog::savePiecesPriorities(){
qDebug("Saving pieces priorities");
Q_ASSERT(!is_magnet);
const std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files());
TorrentTempData::setFilesPriority(hash, priorities);
}
void torrentAdditionDialog::on_OkButton_clicked(){
qDebug() << "void torrentAdditionDialog::on_OkButton_clicked() - ENTER";
if(savePathTxt->currentText().trimmed().isEmpty()){
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
return;
}
QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
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 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) {
#else
if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) {
#endif
path_changed = true;
break;
}
}
if(path_changed) {
qDebug("Changing files paths");
TorrentTempData::setFilesPath(hash, files_path);
}
}
#if LIBTORRENT_VERSION_MINOR > 14
// Skip file checking and directly start seeding
if(addInSeed->isChecked()) {
// Check if local file(s) actually exist
if(is_magnet || QFile::exists(savePathTxt->currentText())) {
TorrentTempData::setSeedingMode(hash, true);
} 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."));
return;
}
}
#endif
// Check if there is at least one selected file
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"));
// Display error message
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."),
QMessageBox::Ok);
return;
}
// Save path history
saveTruncatedPathHistory();
// Check if savePath exists
if(!savePath.exists()){
if(!savePath.mkpath(savePath.path())){
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
return;
}
}
// save filtered files
if(!is_magnet && t->num_files() > 1)
savePiecesPriorities();
// Add to download list
QTorrentHandle h;
if(is_magnet)
h = QBtSession::instance()->addMagnetUri(from_url, false);
else
h = QBtSession::instance()->addTorrent(filePath, false, from_url);
if(addInPause->isChecked() && h.is_valid()) {
h.pause();
}
// Close the dialog
qDebug("Closing torrent addition dialog...");
close();
qDebug("Closed");
}
void torrentAdditionDialog::resetComboLabelIndex(QString text) {
// Select first index
if(text != comboLabel->itemText(comboLabel->currentIndex())) {
comboLabel->setItemText(0, text);
comboLabel->setCurrentIndex(0);
}
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);
}
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
if(appendLabelToSavePath) {
// Update Label in combobox
savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label));
// update edit text
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label));
old_label = label;
}
}
void torrentAdditionDialog::updateSavePathCurrentText() {
qDebug("updateSavePathCurrentText() - ENTER");
savePathTxt->setItemText(savePathTxt->currentIndex(), savePathTxt->currentText());
qDebug("path_history.size() == %d", path_history.size());
qDebug("savePathTxt->currentIndex() == %d", savePathTxt->currentIndex());
path_history.replace(savePathTxt->currentIndex(), getCurrentTruncatedSavePath());
QString root_folder_or_file_name = "";
getCurrentTruncatedSavePath(&root_folder_or_file_name);
// Update other combo items
for(int i=0; i<savePathTxt->count(); ++i) {
if(i == savePathTxt->currentIndex()) continue;
QString item_path = path_history.at(i);
if(item_path.isEmpty()) continue;
// Append label
if(i == 0 && appendLabelToSavePath && QDir(item_path) == QDir(defaultSavePath) && !comboLabel->currentText().isEmpty())
item_path += comboLabel->currentText() + "/";
// Append root_folder or filename
if(!root_folder_or_file_name.isEmpty())
item_path += root_folder_or_file_name;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path.replace("/", "\\");
#endif
savePathTxt->setItemText(i, item_path);
}
}
QString torrentAdditionDialog::getCurrentTruncatedSavePath(QString* root_folder_or_file_name) const {
QString save_path = savePathTxt->currentText();
return getTruncatedSavePath(save_path, root_folder_or_file_name);
}
// 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 {
// Expand and clean path (~, .., .)
save_path = misc::expandPath(save_path);
QStringList parts = save_path.replace("\\", "/").split("/");
// Remove torrent root folder
if(!QDir(save_path).exists() || (!is_magnet && t->num_files() == 1)) {
QString tmp = parts.takeLast();
if(root_folder_or_file_name)
*root_folder_or_file_name = tmp;
}
// Remove label
if(appendLabelToSavePath && savePathTxt->currentIndex() == 0 && parts.last() == comboLabel->currentText()) {
parts.removeLast();
}
QString truncated_path = parts.join("/");
if(!truncated_path.endsWith("/"))
truncated_path += "/";
qDebug("Truncated save path: %s", qPrintable(truncated_path));
return truncated_path;
}
void torrentAdditionDialog::saveTruncatedPathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
const QString current_save_path = getCurrentTruncatedSavePath();
// Get current history
QStringList history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
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(!history.contains(current_save_path, Qt::CaseSensitive)) {
if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else
if(!history.contains(current_save_path, Qt::CaseInsensitive)) {
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
#endif
// Add save path to history
history << current_save_path;
// Limit list size
if(history.size() > 8)
history.removeFirst();
// Save history
settings.setValue("TorrentAdditionDlg/save_path_history", history);
}
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."),
QMessageBox::Ok);
return;
}
}
// Replace path in all files
for(uint i=0; i<nbFiles; ++i) {
const QString &current_name = files_path.at(i);
if(current_name.startsWith(old_path)) {
QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path);
new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
// Rename in files_path
files_path.replace(i, new_name);
}
}
// Rename folder in torrent files model too
PropListModel->setData(index, new_name_last);
}
}
}
void torrentAdditionDialog::loadSavePathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Load save path history
QStringList raw_path_history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
foreach(const QString &sp, raw_path_history) {
if(QDir(sp) != QDir(defaultSavePath)) {
QString dsp = sp;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp.replace("/", "\\");
void torrentAdditionDialog::updateDiskSpaceLabels() {
qDebug("Updating disk space label...");
const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->currentText()));
lbl_disk_space->setText(misc::friendlyUnit(available));
if(!is_magnet) {
// Determine torrent size
qulonglong torrent_size = 0;
if(t->num_files() > 1) {
const unsigned int nbFiles = t->num_files();
const std::vector<int> priorities = PropListModel->getFilesPriorities(nbFiles);
for(unsigned int i=0; i<nbFiles; ++i) {
if(priorities[i] > 0)
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("");
}
}
}
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)
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseInsensitive));
#else
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseSensitive));
#endif
path_history << sp;
savePathTxt->addItem(dsp);
}
}
}
if(cur_index >= 0) {
savePathTxt->setCurrentIndex(cur_index);
}
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path.replace("/", "\\");
#endif
savePathTxt->setEditText(new_path);
}
}
void torrentAdditionDialog::on_CancelButton_clicked(){
close();
}
bool torrentAdditionDialog::allFiltered() const {
Q_ASSERT(!is_magnet);
return PropListModel->allFiltered();
}
void torrentAdditionDialog::savePiecesPriorities(){
qDebug("Saving pieces priorities");
Q_ASSERT(!is_magnet);
const std::vector<int> priorities = PropListModel->getFilesPriorities(t->num_files());
TorrentTempData::setFilesPriority(hash, priorities);
}
void torrentAdditionDialog::on_OkButton_clicked(){
qDebug() << "void torrentAdditionDialog::on_OkButton_clicked() - ENTER";
if(savePathTxt->currentText().trimmed().isEmpty()){
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
return;
}
QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
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
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(files_path.at(i).compare(old_path, Qt::CaseSensitive) != 0) {
#else
if(files_path.at(i).compare(old_path, Qt::CaseInsensitive) != 0) {
#endif
path_changed = true;
break;
}
}
if(path_changed) {
qDebug("Changing files paths");
TorrentTempData::setFilesPath(hash, files_path);
}
}
#if LIBTORRENT_VERSION_MINOR > 14
// Skip file checking and directly start seeding
if(addInSeed->isChecked()) {
// Check if local file(s) actually exist
if(is_magnet || QFile::exists(savePathTxt->currentText())) {
TorrentTempData::setSeedingMode(hash, true);
} 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."));
return;
}
}
#endif
// Check if there is at least one selected file
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"));
return;
}
// Save path history
saveTruncatedPathHistory();
// Check if savePath exists
if(!savePath.exists()){
if(!savePath.mkpath(savePath.path())){
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
return;
}
}
// save filtered files
if(!is_magnet && t->num_files() > 1)
savePiecesPriorities();
// Add to download list
QTorrentHandle h;
if(is_magnet)
h = QBtSession::instance()->addMagnetUri(from_url, false);
else
h = QBtSession::instance()->addTorrent(filePath, false, from_url);
if(addInPause->isChecked() && h.is_valid()) {
h.pause();
}
// Close the dialog
qDebug("Closing torrent addition dialog...");
close();
qDebug("Closed");
}
void torrentAdditionDialog::resetComboLabelIndex(QString text) {
// Select first index
if(text != comboLabel->itemText(comboLabel->currentIndex())) {
comboLabel->setItemText(0, text);
comboLabel->setCurrentIndex(0);
}
}
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
if(appendLabelToSavePath) {
// Update Label in combobox
savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label));
// update edit text
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label));
old_label = label;
}
}
void torrentAdditionDialog::updateSavePathCurrentText() {
qDebug("updateSavePathCurrentText() - ENTER");
savePathTxt->setItemText(savePathTxt->currentIndex(), savePathTxt->currentText());
qDebug("path_history.size() == %d", path_history.size());
qDebug("savePathTxt->currentIndex() == %d", savePathTxt->currentIndex());
path_history.replace(savePathTxt->currentIndex(), getCurrentTruncatedSavePath());
QString root_folder_or_file_name = "";
getCurrentTruncatedSavePath(&root_folder_or_file_name);
// Update other combo items
for(int i=0; i<savePathTxt->count(); ++i) {
if(i == savePathTxt->currentIndex()) continue;
QString item_path = path_history.at(i);
if(item_path.isEmpty()) continue;
// Append label
if(i == 0 && appendLabelToSavePath && QDir(item_path) == QDir(defaultSavePath) && !comboLabel->currentText().isEmpty())
item_path += comboLabel->currentText() + "/";
// Append root_folder or filename
if(!root_folder_or_file_name.isEmpty())
item_path += root_folder_or_file_name;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path.replace("/", "\\");
#endif
savePathTxt->setItemText(i, item_path);
}
}
QString torrentAdditionDialog::getCurrentTruncatedSavePath(QString* root_folder_or_file_name) const {
QString save_path = savePathTxt->currentText();
return getTruncatedSavePath(save_path, root_folder_or_file_name);
}
// 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 {
// Expand and clean path (~, .., .)
save_path = misc::expandPath(save_path);
QStringList parts = save_path.replace("\\", "/").split("/");
// Remove torrent root folder
if(!QDir(save_path).exists() || (!is_magnet && t->num_files() == 1)) {
QString tmp = parts.takeLast();
if(root_folder_or_file_name)
*root_folder_or_file_name = tmp;
}
// Remove label
if(appendLabelToSavePath && savePathTxt->currentIndex() == 0 && parts.last() == comboLabel->currentText()) {
parts.removeLast();
}
QString truncated_path = parts.join("/");
if(!truncated_path.endsWith("/"))
truncated_path += "/";
qDebug("Truncated save path: %s", qPrintable(truncated_path));
return truncated_path;
}
void torrentAdditionDialog::saveTruncatedPathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
const QString current_save_path = getCurrentTruncatedSavePath();
// Get current history
QStringList history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(!history.contains(current_save_path, Qt::CaseSensitive)) {
#else
if(!history.contains(current_save_path, Qt::CaseInsensitive)) {
#endif
// Add save path to history
history << current_save_path;
// Limit list size
if(history.size() > 8)
history.removeFirst();
// Save history
settings.setValue("TorrentAdditionDlg/save_path_history", history);
}
}
void torrentAdditionDialog::loadSavePathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Load save path history
QStringList raw_path_history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
foreach(const QString &sp, raw_path_history) {
if(QDir(sp) != QDir(defaultSavePath)) {
QString dsp = sp;
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp.replace("/", "\\");
#endif
path_history << sp;
savePathTxt->addItem(dsp);
}
}
}

View file

@ -88,9 +88,13 @@ void TorrentCreatorThread::run() {
char const* creator_str = "qBittorrent "VERSION;
try {
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
path full_path = complete(path(input_path.toUtf8().constData()));
add_files(fs, full_path, file_filter);
#endif
if(abort) return;
create_torrent t(fs, piece_size);
@ -103,7 +107,16 @@ void TorrentCreatorThread::run() {
}
if(abort) return;
// 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));
#endif
// Set qBittorrent as creator and add user comment to
// torrent_info structure
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);
bencode(std::ostream_iterator<char>(out), t.generate());
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){
emit creationFailure(QString::fromUtf8(e.what()));

View file

@ -59,12 +59,17 @@ private:
public:
// 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);
parentItem = parent;
type = TFILE;
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();
#endif
// Do not display incomplete extensions
if(name.endsWith(".!qB"))
name.chop(4);
@ -518,7 +523,7 @@ public:
emit layoutChanged();
}
void setupModelData(libtorrent::torrent_info const& t) {
void setupModelData(const libtorrent::torrent_info &t) {
qDebug("setup model data called");
if(t.num_files() == 0) return;
// Initialize files_index array
@ -526,25 +531,6 @@ public:
files_index = new TreeItem*[t.num_files()];
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 *current_parent;
@ -553,7 +539,11 @@ public:
libtorrent::torrent_info::file_iterator fi = t.begin_files();
while(fi != t.end_files()) {
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("\\", "/");
#endif
// Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split("/");
pathFolders.takeLast();
@ -565,7 +555,7 @@ public:
current_parent = new_parent;
}
// 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;
fi++;
++i;

View file

@ -73,9 +73,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
{
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
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) {
// 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());
#endif
qDebug("Torrent has only one file: %s", qPrintable(file_name));
QString extension = misc::file_extension(file_name);
qDebug("File extension is : %s", qPrintable(extension));
@ -94,7 +101,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Update display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else
#else
ui->lineContent->setText(m_contentPath);
#endif
#if LIBTORRENT_VERSION_MINOR >= 15
@ -132,7 +139,7 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Update the display
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
ui->lineContent->setText(m_contentPath.replace("/", "\\"));
#else
#else
ui->lineContent->setText(m_contentPath);
#endif
#if LIBTORRENT_VERSION_MINOR >= 15
@ -141,11 +148,16 @@ void TorrentImportDlg::on_browseContentBtn_clicked()
// Check file sizes
torrent_info::file_iterator it; t->begin_files();
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",
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",
it->path.string().c_str(), (long long int)it->size);
qPrintable(rel_path), (long long int)it->size);
size_mismatch = true;
break;
}
@ -236,8 +248,15 @@ void TorrentImportDlg::initializeFilesPath()
{
m_filesPath.clear();
// 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) {
#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("\\", "/");
#endif
}
}

View file

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

View file

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