Browse Source

Merge pull request #11041 from Chocobo1/splitRef

Revise operations in TorrentHandle class
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
2427f5d324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/base/bittorrent/session.cpp
  2. 89
      src/base/bittorrent/torrenthandle.cpp
  3. 2
      src/base/bittorrent/torrenthandle.h
  4. 7
      src/base/bittorrent/torrentinfo.cpp
  5. 10
      src/base/http/connection.cpp
  6. 21
      src/base/search/searchhandler.cpp
  7. 6
      src/base/search/searchpluginmanager.cpp
  8. 2
      src/base/utils/misc.cpp
  9. 17
      src/gui/downloadfromurldialog.cpp
  10. 13
      src/gui/mainwindow.cpp
  11. 8
      src/gui/programupdater.cpp
  12. 6
      src/gui/properties/trackersadditiondialog.cpp
  13. 2
      src/gui/search/pluginselectdialog.cpp
  14. 14
      src/gui/torrentcontentmodel.cpp

6
src/base/bittorrent/session.cpp

@ -1505,10 +1505,12 @@ void Session::enableBandwidthScheduler()
void Session::populateAdditionalTrackers() void Session::populateAdditionalTrackers()
{ {
m_additionalTrackerList.clear(); m_additionalTrackerList.clear();
for (QString tracker : asConst(additionalTrackers().split('\n'))) {
const QString trackers = additionalTrackers();
for (QStringRef tracker : asConst(trackers.splitRef('\n'))) {
tracker = tracker.trimmed(); tracker = tracker.trimmed();
if (!tracker.isEmpty()) if (!tracker.isEmpty())
m_additionalTrackerList << tracker; m_additionalTrackerList << tracker.toString();
} }
} }

89
src/base/bittorrent/torrenthandle.cpp

@ -104,6 +104,8 @@ namespace
std::vector<LTDownloadPriority> toLTDownloadPriorities(const QVector<DownloadPriority> &priorities) std::vector<LTDownloadPriority> toLTDownloadPriorities(const QVector<DownloadPriority> &priorities)
{ {
std::vector<LTDownloadPriority> out; std::vector<LTDownloadPriority> out;
out.reserve(priorities.size());
std::transform(priorities.cbegin(), priorities.cend() std::transform(priorities.cbegin(), priorities.cend()
, std::back_inserter(out), [](BitTorrent::DownloadPriority priority) , std::back_inserter(out), [](BitTorrent::DownloadPriority priority)
{ {
@ -264,16 +266,17 @@ InfoHash TorrentHandle::hash() const
QString TorrentHandle::name() const QString TorrentHandle::name() const
{ {
QString name = m_name; QString name = m_name;
if (name.isEmpty()) if (!name.isEmpty()) return name;
name = QString::fromStdString(m_nativeStatus.name); name = QString::fromStdString(m_nativeStatus.name);
if (!name.isEmpty()) return name;
if (name.isEmpty() && hasMetadata()) if (hasMetadata()) {
name = QString::fromStdString(m_torrentInfo.nativeInfo()->orig_files().name()); name = QString::fromStdString(m_torrentInfo.nativeInfo()->orig_files().name());
if (!name.isEmpty()) return name;
}
if (name.isEmpty()) return m_hash;
name = m_hash;
return name;
} }
QDateTime TorrentHandle::creationDate() const QDateTime TorrentHandle::creationDate() const
@ -353,13 +356,14 @@ QString TorrentHandle::rootPath(bool actual) const
return QDir(savePath(actual)).absoluteFilePath(firstFilePath); return QDir(savePath(actual)).absoluteFilePath(firstFilePath);
} }
QString TorrentHandle::contentPath(bool actual) const QString TorrentHandle::contentPath(const bool actual) const
{ {
if (filesCount() == 1) if (filesCount() == 1)
return QDir(savePath(actual)).absoluteFilePath(filePath(0)); return QDir(savePath(actual)).absoluteFilePath(filePath(0));
else if (hasRootFolder())
if (hasRootFolder())
return rootPath(actual); return rootPath(actual);
else
return savePath(actual); return savePath(actual);
} }
@ -412,12 +416,14 @@ void TorrentHandle::setAutoManaged(const bool enable)
QVector<TrackerEntry> TorrentHandle::trackers() const QVector<TrackerEntry> TorrentHandle::trackers() const
{ {
const std::vector<lt::announce_entry> announces = m_nativeHandle.trackers(); const std::vector<lt::announce_entry> nativeTrackers = m_nativeHandle.trackers();
QVector<TrackerEntry> entries; QVector<TrackerEntry> entries;
entries.reserve(announces.size()); entries.reserve(nativeTrackers.size());
for (const lt::announce_entry &tracker : announces)
for (const lt::announce_entry &tracker : nativeTrackers)
entries << tracker; entries << tracker;
return entries; return entries;
} }
@ -428,7 +434,9 @@ QHash<QString, TrackerInfo> TorrentHandle::trackerInfos() const
void TorrentHandle::addTrackers(const QVector<TrackerEntry> &trackers) void TorrentHandle::addTrackers(const QVector<TrackerEntry> &trackers)
{ {
const QVector<TrackerEntry> currentTrackers = this->trackers(); QSet<TrackerEntry> currentTrackers;
for (const lt::announce_entry &entry : m_nativeHandle.trackers())
currentTrackers << entry;
QVector<TrackerEntry> newTrackers; QVector<TrackerEntry> newTrackers;
newTrackers.reserve(trackers.size()); newTrackers.reserve(trackers.size());
@ -451,16 +459,17 @@ void TorrentHandle::replaceTrackers(const QVector<TrackerEntry> &trackers)
QVector<TrackerEntry> newTrackers; QVector<TrackerEntry> newTrackers;
newTrackers.reserve(trackers.size()); newTrackers.reserve(trackers.size());
std::vector<lt::announce_entry> announces; std::vector<lt::announce_entry> nativeTrackers;
nativeTrackers.reserve(trackers.size());
for (const TrackerEntry &tracker : trackers) { for (const TrackerEntry &tracker : trackers) {
announces.emplace_back(tracker.nativeEntry()); nativeTrackers.emplace_back(tracker.nativeEntry());
if (!currentTrackers.removeOne(tracker)) if (!currentTrackers.removeOne(tracker))
newTrackers << tracker; newTrackers << tracker;
} }
m_nativeHandle.replace_trackers(announces); m_nativeHandle.replace_trackers(nativeTrackers);
if (newTrackers.isEmpty() && currentTrackers.isEmpty()) { if (newTrackers.isEmpty() && currentTrackers.isEmpty()) {
// when existing tracker reorders // when existing tracker reorders
@ -477,12 +486,12 @@ void TorrentHandle::replaceTrackers(const QVector<TrackerEntry> &trackers)
QVector<QUrl> TorrentHandle::urlSeeds() const QVector<QUrl> TorrentHandle::urlSeeds() const
{ {
const std::set<std::string> seeds = m_nativeHandle.url_seeds(); const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
QVector<QUrl> urlSeeds; QVector<QUrl> urlSeeds;
urlSeeds.reserve(seeds.size()); urlSeeds.reserve(currentSeeds.size());
for (const std::string &urlSeed : seeds) for (const std::string &urlSeed : currentSeeds)
urlSeeds.append(QUrl(urlSeed.c_str())); urlSeeds.append(QUrl(urlSeed.c_str()));
return urlSeeds; return urlSeeds;
@ -490,11 +499,17 @@ QVector<QUrl> TorrentHandle::urlSeeds() const
void TorrentHandle::addUrlSeeds(const QVector<QUrl> &urlSeeds) void TorrentHandle::addUrlSeeds(const QVector<QUrl> &urlSeeds)
{ {
const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
QVector<QUrl> addedUrlSeeds; QVector<QUrl> addedUrlSeeds;
addedUrlSeeds.reserve(urlSeeds.size()); addedUrlSeeds.reserve(urlSeeds.size());
for (const QUrl &urlSeed : urlSeeds) {
if (addUrlSeed(urlSeed)) for (const QUrl &url : urlSeeds) {
addedUrlSeeds << urlSeed; const std::string nativeUrl = url.toString().toStdString();
if (currentSeeds.find(nativeUrl) == currentSeeds.end()) {
m_nativeHandle.add_url_seed(nativeUrl);
addedUrlSeeds << url;
}
} }
if (!addedUrlSeeds.isEmpty()) if (!addedUrlSeeds.isEmpty())
@ -503,35 +518,23 @@ void TorrentHandle::addUrlSeeds(const QVector<QUrl> &urlSeeds)
void TorrentHandle::removeUrlSeeds(const QVector<QUrl> &urlSeeds) void TorrentHandle::removeUrlSeeds(const QVector<QUrl> &urlSeeds)
{ {
const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
QVector<QUrl> removedUrlSeeds; QVector<QUrl> removedUrlSeeds;
removedUrlSeeds.reserve(urlSeeds.size()); removedUrlSeeds.reserve(urlSeeds.size());
for (const QUrl &urlSeed : urlSeeds) {
if (removeUrlSeed(urlSeed)) for (const QUrl &url : urlSeeds) {
removedUrlSeeds << urlSeed; const std::string nativeUrl = url.toString().toStdString();
if (currentSeeds.find(nativeUrl) != currentSeeds.end()) {
m_nativeHandle.remove_url_seed(nativeUrl);
removedUrlSeeds << url;
}
} }
if (!removedUrlSeeds.isEmpty()) if (!removedUrlSeeds.isEmpty())
m_session->handleTorrentUrlSeedsRemoved(this, removedUrlSeeds); m_session->handleTorrentUrlSeedsRemoved(this, removedUrlSeeds);
} }
bool TorrentHandle::addUrlSeed(const QUrl &urlSeed)
{
const QVector<QUrl> seeds = urlSeeds();
if (seeds.contains(urlSeed)) return false;
m_nativeHandle.add_url_seed(urlSeed.toString().toStdString());
return true;
}
bool TorrentHandle::removeUrlSeed(const QUrl &urlSeed)
{
const QVector<QUrl> seeds = urlSeeds();
if (!seeds.contains(urlSeed)) return false;
m_nativeHandle.remove_url_seed(urlSeed.toString().toStdString());
return true;
}
bool TorrentHandle::connectPeer(const PeerAddress &peerAddress) bool TorrentHandle::connectPeer(const PeerAddress &peerAddress)
{ {
lt::error_code ec; lt::error_code ec;

2
src/base/bittorrent/torrenthandle.h

@ -394,8 +394,6 @@ namespace BitTorrent
void move_impl(QString path, bool overwrite); void move_impl(QString path, bool overwrite);
void moveStorage(const QString &newPath, bool overwrite); void moveStorage(const QString &newPath, bool overwrite);
void manageIncompleteFiles(); void manageIncompleteFiles();
bool addUrlSeed(const QUrl &urlSeed);
bool removeUrlSeed(const QUrl &urlSeed);
void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {}); void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {});
Session *const m_session; Session *const m_session;

7
src/base/bittorrent/torrentinfo.cpp

@ -429,9 +429,10 @@ void TorrentInfo::stripRootFolder()
lt::file_storage files = m_nativeInfo->files(); lt::file_storage files = m_nativeInfo->files();
// Solution for case of renamed root folder // Solution for case of renamed root folder
const std::string testName = filePath(0).split('/').value(0).toStdString(); const QString path = filePath(0);
if (files.name() != testName) { const std::string newName = path.left(path.indexOf('/')).toStdString();
files.set_name(testName); if (files.name() != newName) {
files.set_name(newName);
for (int i = 0; i < files.num_files(); ++i) for (int i = 0; i < files.num_files(); ++i)
files.rename_file(LTFileIndex {i}, files.file_path(LTFileIndex {i})); files.rename_file(LTFileIndex {i}, files.file_path(LTFileIndex {i}));
} }

10
src/base/http/connection.cpp

@ -131,9 +131,9 @@ bool Connection::acceptsGzipEncoding(QString codings)
{ {
// [rfc7231] 5.3.4. Accept-Encoding // [rfc7231] 5.3.4. Accept-Encoding
const auto isCodingAvailable = [](const QStringList &list, const QString &encoding) -> bool const auto isCodingAvailable = [](const QVector<QStringRef> &list, const QString &encoding) -> bool
{ {
for (const QString &str : list) { for (const QStringRef &str : list) {
if (!str.startsWith(encoding)) if (!str.startsWith(encoding))
continue; continue;
@ -142,11 +142,11 @@ bool Connection::acceptsGzipEncoding(QString codings)
return true; return true;
// [rfc7231] 5.3.1. Quality Values // [rfc7231] 5.3.1. Quality Values
const QStringRef substr = str.midRef(encoding.size() + 3); // ex. skip over "gzip;q=" const QStringRef substr = str.mid(encoding.size() + 3); // ex. skip over "gzip;q="
bool ok = false; bool ok = false;
const double qvalue = substr.toDouble(&ok); const double qvalue = substr.toDouble(&ok);
if (!ok || (qvalue <= 0.0)) if (!ok || (qvalue <= 0))
return false; return false;
return true; return true;
@ -154,7 +154,7 @@ bool Connection::acceptsGzipEncoding(QString codings)
return false; return false;
}; };
const QStringList list = codings.remove(' ').remove('\t').split(',', QString::SkipEmptyParts); const QVector<QStringRef> list = codings.remove(' ').remove('\t').splitRef(',', QString::SkipEmptyParts);
if (list.isEmpty()) if (list.isEmpty())
return false; return false;

21
src/base/search/searchhandler.cpp

@ -32,9 +32,9 @@
#include <QProcess> #include <QProcess>
#include <QTimer> #include <QTimer>
#include "../global.h" #include "base/global.h"
#include "../utils/foreignapps.h" #include "base/utils/foreignapps.h"
#include "../utils/fs.h" #include "base/utils/fs.h"
#include "searchpluginmanager.h" #include "searchpluginmanager.h"
namespace namespace
@ -161,24 +161,29 @@ void SearchHandler::processFailed()
// file url | file name | file size | nb seeds | nb leechers | Search engine url // file url | file name | file size | nb seeds | nb leechers | Search engine url
bool SearchHandler::parseSearchResult(const QString &line, SearchResult &searchResult) bool SearchHandler::parseSearchResult(const QString &line, SearchResult &searchResult)
{ {
const QStringList parts = line.split('|'); const QVector<QStringRef> parts = line.splitRef('|');
const int nbFields = parts.size(); const int nbFields = parts.size();
if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional
searchResult = SearchResult(); searchResult = SearchResult();
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed(); // download URL searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed().toString(); // download URL
searchResult.fileName = parts.at(PL_NAME).trimmed(); // Name searchResult.fileName = parts.at(PL_NAME).trimmed().toString(); // Name
searchResult.fileSize = parts.at(PL_SIZE).trimmed().toLongLong(); // Size searchResult.fileSize = parts.at(PL_SIZE).trimmed().toLongLong(); // Size
bool ok = false; bool ok = false;
searchResult.nbSeeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok); // Seeders searchResult.nbSeeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok); // Seeders
if (!ok || (searchResult.nbSeeders < 0)) if (!ok || (searchResult.nbSeeders < 0))
searchResult.nbSeeders = -1; searchResult.nbSeeders = -1;
searchResult.nbLeechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok); // Leechers searchResult.nbLeechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok); // Leechers
if (!ok || (searchResult.nbLeechers < 0)) if (!ok || (searchResult.nbLeechers < 0))
searchResult.nbLeechers = -1; searchResult.nbLeechers = -1;
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed(); // Search site URL
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed().toString(); // Search site URL
if (nbFields == NB_PLUGIN_COLUMNS) if (nbFields == NB_PLUGIN_COLUMNS)
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed(); // Description Link searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed().toString(); // Description Link
return true; return true;
} }

6
src/base/search/searchpluginmanager.cpp

@ -376,8 +376,10 @@ void SearchPluginManager::pluginDownloadFinished(const Net::DownloadResult &resu
Utils::Fs::forceRemove(filePath); Utils::Fs::forceRemove(filePath);
} }
else { else {
QString pluginName = result.url.split('/').last(); const QString url = result.url;
QString pluginName = url.mid(url.lastIndexOf('/') + 1);
pluginName.replace(".py", "", Qt::CaseInsensitive); pluginName.replace(".py", "", Qt::CaseInsensitive);
if (pluginInfo(pluginName)) if (pluginInfo(pluginName))
emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(result.errorString)); emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(result.errorString));
else else
@ -462,7 +464,7 @@ void SearchPluginManager::update()
plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text(); plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text();
plugin->url = engineElem.elementsByTagName("url").at(0).toElement().text(); plugin->url = engineElem.elementsByTagName("url").at(0).toElement().text();
const auto categories = engineElem.elementsByTagName("categories").at(0).toElement().text().split(' '); const QStringList categories = engineElem.elementsByTagName("categories").at(0).toElement().text().split(' ');
for (QString cat : categories) { for (QString cat : categories) {
cat = cat.trimmed(); cat = cat.trimmed();
if (!cat.isEmpty()) if (!cat.isEmpty())

2
src/base/utils/misc.cpp

@ -465,7 +465,7 @@ QString Utils::Misc::libtorrentVersionString()
QString Utils::Misc::opensslVersionString() QString Utils::Misc::opensslVersionString()
{ {
const QString version {OPENSSL_VERSION_TEXT}; const QString version {OPENSSL_VERSION_TEXT};
return version.split(' ', QString::SkipEmptyParts)[1]; return version.splitRef(' ', QString::SkipEmptyParts)[1].toString();
} }
QString Utils::Misc::zlibVersionString() QString Utils::Misc::zlibVersionString()

17
src/gui/downloadfromurldialog.cpp

@ -67,13 +67,15 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
m_ui->textUrls->setWordWrapMode(QTextOption::NoWrap); m_ui->textUrls->setWordWrapMode(QTextOption::NoWrap);
// Paste clipboard if there is an URL in it // Paste clipboard if there is an URL in it
const QStringList clipboardList = qApp->clipboard()->text().split('\n'); const QString clipboardText = qApp->clipboard()->text();
const QVector<QStringRef> clipboardList = clipboardText.splitRef('\n');
QSet<QString> uniqueURLs; QSet<QString> uniqueURLs;
for (QString str : clipboardList) { for (QStringRef strRef : clipboardList) {
str = str.trimmed(); strRef = strRef.trimmed();
if (str.isEmpty()) continue; if (strRef.isEmpty()) continue;
const QString str = strRef.toString();
if (isDownloadable(str)) if (isDownloadable(str))
uniqueURLs << str; uniqueURLs << str;
} }
@ -90,14 +92,15 @@ DownloadFromURLDialog::~DownloadFromURLDialog()
void DownloadFromURLDialog::downloadButtonClicked() void DownloadFromURLDialog::downloadButtonClicked()
{ {
const QStringList urls = m_ui->textUrls->toPlainText().split('\n'); const QString plainText = m_ui->textUrls->toPlainText();
const QVector<QStringRef> urls = plainText.splitRef('\n');
QSet<QString> uniqueURLs; QSet<QString> uniqueURLs;
for (QString url : urls) { for (QStringRef url : urls) {
url = url.trimmed(); url = url.trimmed();
if (url.isEmpty()) continue; if (url.isEmpty()) continue;
uniqueURLs << url; uniqueURLs << url.toString();
} }
if (uniqueURLs.isEmpty()) { if (uniqueURLs.isEmpty()) {

13
src/gui/mainwindow.cpp

@ -1354,10 +1354,12 @@ void MainWindow::on_actionOpen_triggered()
QFileDialog::getOpenFileNames(this, tr("Open Torrent Files"), pref->getMainLastDir(), QFileDialog::getOpenFileNames(this, tr("Open Torrent Files"), pref->getMainLastDir(),
tr("Torrent Files") + " (*" + C_TORRENT_FILE_EXTENSION + ')'); tr("Torrent Files") + " (*" + C_TORRENT_FILE_EXTENSION + ')');
if (pathsList.isEmpty())
return;
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled(); const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
if (!pathsList.isEmpty()) {
for (const QString &file : pathsList) { for (const QString &file : pathsList) {
qDebug("Dropped file %s on download list", qUtf8Printable(file));
if (useTorrentAdditionDialog) if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this); AddNewTorrentDialog::show(file, this);
else else
@ -1365,10 +1367,9 @@ void MainWindow::on_actionOpen_triggered()
} }
// Save last dir to remember it // Save last dir to remember it
QStringList topDir = Utils::Fs::toUniformPath(pathsList.at(0)).split('/'); QString topDir = Utils::Fs::toUniformPath(pathsList.at(0));
topDir.removeLast(); topDir = topDir.left(topDir.lastIndexOf('/'));
pref->setMainLastDir(Utils::Fs::toUniformPath(topDir.join('/'))); pref->setMainLastDir(topDir);
}
} }
void MainWindow::activate() void MainWindow::activate()

8
src/gui/programupdater.cpp

@ -139,10 +139,10 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
{ {
const QRegularExpressionMatch regVerMatch = QRegularExpression("([0-9.]+)").match(QBT_VERSION); const QRegularExpressionMatch regVerMatch = QRegularExpression("([0-9.]+)").match(QBT_VERSION);
if (regVerMatch.hasMatch()) { if (regVerMatch.hasMatch()) {
QString localVersion = regVerMatch.captured(1); const QString localVersion = regVerMatch.captured(1);
qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION; const QVector<QStringRef> remoteParts = remoteVersion.splitRef('.');
QStringList remoteParts = remoteVersion.split('.'); const QVector<QStringRef> localParts = localVersion.splitRef('.');
QStringList localParts = localVersion.split('.');
for (int i = 0; i < qMin(remoteParts.size(), localParts.size()); ++i) { for (int i = 0; i < qMin(remoteParts.size(), localParts.size()); ++i) {
if (remoteParts[i].toInt() > localParts[i].toInt()) if (remoteParts[i].toInt() > localParts[i].toInt())
return true; return true;

6
src/gui/properties/trackersadditiondialog.cpp

@ -56,11 +56,13 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
QStringList TrackersAdditionDialog::newTrackers() const QStringList TrackersAdditionDialog::newTrackers() const
{ {
const QString plainText = m_ui->textEditTrackersList->toPlainText();
QStringList cleanTrackers; QStringList cleanTrackers;
for (QString url : asConst(m_ui->textEditTrackersList->toPlainText().split('\n'))) { for (QStringRef url : asConst(plainText.splitRef('\n'))) {
url = url.trimmed(); url = url.trimmed();
if (!url.isEmpty()) if (!url.isEmpty())
cleanTrackers << url; cleanTrackers << url.toString();
} }
return cleanTrackers; return cleanTrackers;
} }

2
src/gui/search/pluginselectdialog.cpp

@ -119,7 +119,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
} }
} }
else { else {
files = event->mimeData()->text().split(QLatin1String("\n")); files = event->mimeData()->text().split('\n');
} }
if (files.isEmpty()) return; if (files.isEmpty()) return;

14
src/gui/torrentcontentmodel.cpp

@ -469,14 +469,18 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
// Iterate over files // Iterate over files
for (int i = 0; i < filesCount; ++i) { for (int i = 0; i < filesCount; ++i) {
currentParent = m_rootItem; currentParent = m_rootItem;
QString path = Utils::Fs::toUniformPath(info.filePath(i)); const QString path = Utils::Fs::toUniformPath(info.filePath(i));
// Iterate of parts of the path to create necessary folders // Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split('/', QString::SkipEmptyParts); QVector<QStringRef> pathFolders = path.splitRef('/', QString::SkipEmptyParts);
pathFolders.removeLast(); pathFolders.removeLast();
for (const QString &pathPart : asConst(pathFolders)) {
if (pathPart == ".unwanted") for (const QStringRef &pathPartRef : asConst(pathFolders)) {
if (pathPartRef == QLatin1String(".unwanted"))
continue; continue;
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);
const QString pathPart = pathPartRef.toString();
TorrentContentModelFolder *newParent = currentParent->childFolderWithName(pathPart);
if (!newParent) { if (!newParent) {
newParent = new TorrentContentModelFolder(pathPart, currentParent); newParent = new TorrentContentModelFolder(pathPart, currentParent);
currentParent->appendChild(newParent); currentParent->appendChild(newParent);

Loading…
Cancel
Save