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
@ -461,9 +473,9 @@ void torrentAdditionDialog::renameSelectedFile() {
PropListModel->setData(index, new_name_last);
}
}
}
}
void torrentAdditionDialog::updateDiskSpaceLabels() {
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));
@ -497,9 +509,9 @@ void torrentAdditionDialog::renameSelectedFile() {
label_space_msg->setText("");
}
}
}
}
void torrentAdditionDialog::on_browseButton_clicked(){
void torrentAdditionDialog::on_browseButton_clicked(){
Q_ASSERT(!is_magnet);
QString new_path;
if(t->num_files() == 1) {
@ -543,25 +555,25 @@ void torrentAdditionDialog::renameSelectedFile() {
#endif
savePathTxt->setEditText(new_path);
}
}
}
void torrentAdditionDialog::on_CancelButton_clicked(){
void torrentAdditionDialog::on_CancelButton_clicked(){
close();
}
}
bool torrentAdditionDialog::allFiltered() const {
bool torrentAdditionDialog::allFiltered() const {
Q_ASSERT(!is_magnet);
return PropListModel->allFiltered();
}
}
void torrentAdditionDialog::savePiecesPriorities(){
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(){
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"));
@ -601,10 +613,16 @@ void torrentAdditionDialog::renameSelectedFile() {
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) {
#if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t->files();
QString old_path = misc::toQStringU(fs.file_path(t->file_at(i)));
#else
if(files_path.at(i).compare(misc::toQStringU(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) {
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;
@ -657,17 +675,17 @@ void torrentAdditionDialog::renameSelectedFile() {
qDebug("Closing torrent addition dialog...");
close();
qDebug("Closed");
}
}
void torrentAdditionDialog::resetComboLabelIndex(QString text) {
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) {
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
if(appendLabelToSavePath) {
// Update Label in combobox
savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label));
@ -675,9 +693,9 @@ void torrentAdditionDialog::renameSelectedFile() {
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label));
old_label = label;
}
}
}
void torrentAdditionDialog::updateSavePathCurrentText() {
void torrentAdditionDialog::updateSavePathCurrentText() {
qDebug("updateSavePathCurrentText() - ENTER");
savePathTxt->setItemText(savePathTxt->currentIndex(), savePathTxt->currentText());
qDebug("path_history.size() == %d", path_history.size());
@ -701,15 +719,15 @@ void torrentAdditionDialog::renameSelectedFile() {
#endif
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();
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 {
// 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("/");
@ -728,9 +746,9 @@ void torrentAdditionDialog::renameSelectedFile() {
truncated_path += "/";
qDebug("Truncated save path: %s", qPrintable(truncated_path));
return truncated_path;
}
}
void torrentAdditionDialog::saveTruncatedPathHistory() {
void torrentAdditionDialog::saveTruncatedPathHistory() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
const QString current_save_path = getCurrentTruncatedSavePath();
// Get current history
@ -748,9 +766,9 @@ void torrentAdditionDialog::renameSelectedFile() {
// Save history
settings.setValue("TorrentAdditionDlg/save_path_history", history);
}
}
}
void torrentAdditionDialog::loadSavePathHistory() {
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();
@ -764,4 +782,4 @@ void torrentAdditionDialog::renameSelectedFile() {
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);