mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
Merge latest fixes from stable branch
This commit is contained in:
parent
b67938aa3f
commit
4e1366bf0d
@ -945,12 +945,12 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||
boost::intrusive_ptr<torrent_info> t;
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
// Windows hack
|
||||
if(!path.endsWith(".torrent")) {
|
||||
if(QFile::rename(path, path+".torrent"))
|
||||
path += ".torrent";
|
||||
}
|
||||
qDebug("Downloading torrent at path: %s", qPrintable(path));
|
||||
// Windows hack
|
||||
if(!path.endsWith(".torrent")) {
|
||||
if(QFile::rename(path, path+".torrent"))
|
||||
path += ".torrent";
|
||||
}
|
||||
qDebug("Downloading torrent at path: %s", qPrintable(path));
|
||||
#endif
|
||||
|
||||
// Checking if BT_backup Dir exists
|
||||
@ -1626,7 +1626,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
||||
if(append) {
|
||||
const qulonglong file_size = h.filesize_at(i);
|
||||
if(file_size > 0 && (fp[i]/(double)file_size) < 1.) {
|
||||
const QString &name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString &name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
if(!name.endsWith(".!qB")) {
|
||||
const QString new_name = name+".!qB";
|
||||
qDebug("Renaming %s to %s", qPrintable(name), qPrintable(new_name));
|
||||
@ -1634,7 +1634,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QString name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
QString name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
if(name.endsWith(".!qB")) {
|
||||
const QString old_name = name;
|
||||
name.chop(4);
|
||||
@ -1927,7 +1927,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
||||
qDebug("Checking if the torrent contains torrent files to download");
|
||||
// Check if there are torrent files inside
|
||||
for(int i=0; i<h.get_torrent_info().num_files(); ++i) {
|
||||
const QString &torrent_relpath = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString &torrent_relpath = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
if(torrent_relpath.endsWith(".torrent")) {
|
||||
qDebug("Found possible recursive torrent download.");
|
||||
const QString torrent_fullpath = h.save_path()+QDir::separator()+torrent_relpath;
|
||||
@ -1974,6 +1974,22 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (file_renamed_alert* p = dynamic_cast<file_renamed_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(h.is_valid() && 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("/");
|
||||
old_path_parts.removeLast();
|
||||
QString old_path = old_path_parts.join("/");
|
||||
QStringList new_path_parts = misc::toQStringU(p->name).split("/");
|
||||
new_path_parts.removeLast();
|
||||
if(old_path != new_path_parts.join("/")) {
|
||||
old_path = h.save_path()+"/"+old_path;
|
||||
qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path));
|
||||
QDir().rmpath(old_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (storage_moved_alert* p = dynamic_cast<storage_moved_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(h.is_valid()) {
|
||||
@ -2052,7 +2068,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
||||
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) {
|
||||
QTorrentHandle h(p->handle);
|
||||
if(appendqBExtension) {
|
||||
QString name = misc::toQString(h.get_torrent_info().file_at(p->index).path.string());
|
||||
QString name = misc::toQStringU(h.get_torrent_info().file_at(p->index).path.string());
|
||||
if(name.endsWith(".!qB")) {
|
||||
const QString old_name = name;
|
||||
name.chop(4);
|
||||
|
@ -264,7 +264,7 @@ void torrentCreatorThread::run() {
|
||||
// Set qBittorrent as creator and add user comment to
|
||||
// torrent_info structure
|
||||
t.set_creator(creator_str);
|
||||
t.set_comment((const char*)comment.toLocal8Bit());
|
||||
t.set_comment((const char*)comment.toUtf8());
|
||||
// Is private ?
|
||||
t.set_priv(is_private);
|
||||
if(abort) return;
|
||||
|
@ -59,6 +59,14 @@ public:
|
||||
return QString::fromLocal8Bit(str);
|
||||
}
|
||||
|
||||
static inline QString toQStringU(std::string str) {
|
||||
return QString::fromUtf8(str.c_str());
|
||||
}
|
||||
|
||||
static inline QString toQStringU(char* str) {
|
||||
return QString::fromUtf8(str);
|
||||
}
|
||||
|
||||
static inline QString toQString(sha1_hash hash) {
|
||||
std::ostringstream o;
|
||||
o << hash;
|
||||
|
@ -483,17 +483,22 @@ 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::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString &filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
|
||||
const QString &file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
|
||||
qDebug("Trying to open file at %s", qPrintable(file_path));
|
||||
#ifdef LIBTORRENT_0_15
|
||||
// Flush data
|
||||
h.flush_cache();
|
||||
#endif
|
||||
if(QFile::exists(file_path))
|
||||
if(QFile::exists(file_path)) {
|
||||
#ifdef Q_WS_WIN
|
||||
QDesktopServices::openUrl(QUrl("file:///"+file_path));
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl("file://"+file_path));
|
||||
else
|
||||
#endif
|
||||
} else {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
||||
}
|
||||
} else {
|
||||
// FOLDER
|
||||
QStringList path_items;
|
||||
@ -511,10 +516,15 @@ void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
|
||||
// Flush data
|
||||
h.flush_cache();
|
||||
#endif
|
||||
if(QFile::exists(file_path))
|
||||
if(QFile::exists(file_path)) {
|
||||
#ifdef Q_WS_WIN
|
||||
QDesktopServices::openUrl(QUrl("file:///"+file_path));
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl("file://"+file_path));
|
||||
else
|
||||
#endif
|
||||
} else {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ QString QTorrentHandle::name() const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
QString name = TorrentPersistentData::getName(hash());
|
||||
if(name.isEmpty()) {
|
||||
name = misc::toQString(h.name());
|
||||
name = misc::toQStringU(h.name());
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@ -292,7 +292,7 @@ void QTorrentHandle::save_resume_data() const {
|
||||
QString QTorrentHandle::file_at(unsigned int index) const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
Q_ASSERT(index < (unsigned int)h.get_torrent_info().num_files());
|
||||
return misc::toQString(h.get_torrent_info().file_at(index).path.leaf());
|
||||
return misc::toQStringU(h.get_torrent_info().file_at(index).path.leaf());
|
||||
}
|
||||
|
||||
size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
||||
@ -323,7 +323,7 @@ QString QTorrentHandle::creator() const {
|
||||
|
||||
QString QTorrentHandle::comment() const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
return misc::toQString(h.get_torrent_info().comment());
|
||||
return misc::toQStringU(h.get_torrent_info().comment());
|
||||
}
|
||||
|
||||
size_type QTorrentHandle::total_failed_bytes() const {
|
||||
@ -452,9 +452,9 @@ bool QTorrentHandle::priv() const {
|
||||
QString QTorrentHandle::root_path() const {
|
||||
Q_ASSERT(h.is_valid());
|
||||
if(num_files() == 0) return "";
|
||||
QStringList path_list = misc::toQString(h.get_torrent_info().file_at(0).path.string()).split(QDir::separator());
|
||||
QStringList path_list = misc::toQString(h.get_torrent_info().file_at(0).path.string()).split("/");
|
||||
if(path_list.size() > 1)
|
||||
return save_path()+QDir::separator()+path_list.first();
|
||||
return save_path()+"/"+path_list.first();
|
||||
return save_path();
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ public:
|
||||
}
|
||||
nbFiles = t->num_files();
|
||||
// Setting file name
|
||||
fileName = misc::toQString(t->name());
|
||||
fileName = misc::toQStringU(t->name());
|
||||
hash = misc::toQString(t->info_hash());
|
||||
// Use left() to remove .old extension
|
||||
QString newFileName;
|
||||
@ -250,7 +250,7 @@ public:
|
||||
}
|
||||
// Loads files path in the torrent
|
||||
for(uint i=0; i<nbFiles; ++i) {
|
||||
files_path << misc::toQString(t->file_at(i).path.string());
|
||||
files_path << misc::toQStringU(t->file_at(i).path.string());
|
||||
}
|
||||
// Show the dialog
|
||||
show();
|
||||
@ -478,15 +478,16 @@ public slots:
|
||||
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::toQString(t->file_at(i).path.string()), Qt::CaseSensitive) != 0) {
|
||||
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::toQString(t->file_at(i).path.string()), Qt::CaseInsensitive) != 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -494,7 +495,7 @@ public slots:
|
||||
// Skip file checking and directly start seeding
|
||||
if(addInSeed->isChecked()) {
|
||||
// Check if local file(s) actually exist
|
||||
if(is_magnet || savePath.exists(misc::toQString(t->name()))) {
|
||||
if(is_magnet || savePath.exists(misc::toQStringU(t->name()))) {
|
||||
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."));
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
parentItem = parent;
|
||||
type = TFILE;
|
||||
file_index = _file_index;
|
||||
QString name = misc::toQString(f.path.string()).split("/").last();
|
||||
QString name = misc::toQStringU(f.path.string()).split("/").last();
|
||||
// Do not display incomplete extensions
|
||||
if(name.endsWith(".!qB"))
|
||||
name.chop(4);
|
||||
@ -510,7 +510,7 @@ public:
|
||||
TreeItem *parent = this->rootItem;
|
||||
/*if(t.num_files() == 1) {
|
||||
// Create possible parent folder
|
||||
QStringList path_parts = misc::toQString(t.file_at(0).path.string()).split("/");
|
||||
QStringList path_parts = misc::toQStringU(t.file_at(0).path.string()).split("/");
|
||||
path_parts.removeLast();
|
||||
foreach(const QString &part, path_parts) {
|
||||
TreeItem *folder = new TreeItem(part, parent);
|
||||
@ -535,7 +535,7 @@ public:
|
||||
torrent_info::file_iterator fi = t.begin_files();
|
||||
while(fi != t.end_files()) {
|
||||
current_parent = root_folder;
|
||||
QString path = QDir::cleanPath(misc::toQString(fi->path.string()));
|
||||
QString path = QDir::cleanPath(misc::toQStringU(fi->path.string()));
|
||||
// Iterate of parts of the path to create necessary folders
|
||||
QStringList pathFolders = path.split("/");
|
||||
//Q_ASSERT(pathFolders.size() >= 2);
|
||||
|
@ -763,9 +763,14 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
|
||||
const QTorrentHandle &h = BTSession->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
const QString &savePath = h.root_path();
|
||||
qDebug("Opening path at %s", qPrintable(savePath));
|
||||
if(!pathsList.contains(savePath)) {
|
||||
pathsList.append(savePath);
|
||||
#ifdef Q_WS_WIN
|
||||
QDesktopServices::openUrl(QUrl(QString("file:///")+savePath));
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl(QString("file://")+savePath));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user