mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-27 19:50:31 +00:00
Sort languages combobox by language code
* Avoid creating redundant file lists * Sort languages combobox by language code PR #20365.
This commit is contained in:
parent
88a4990435
commit
f87ea1b5d3
@ -105,7 +105,7 @@ BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const Path &path,
|
||||
}
|
||||
|
||||
const QRegularExpression filenamePattern {u"^([A-Fa-f0-9]{40})\\.fastresume$"_s};
|
||||
const QStringList filenames = QDir(path.data()).entryList(QStringList(u"*.fastresume"_s), QDir::Files, QDir::Unsorted);
|
||||
const QStringList filenames = QDir(path.data()).entryList({u"*.fastresume"_s}, QDir::Files);
|
||||
|
||||
m_registeredTorrents.reserve(filenames.size());
|
||||
for (const QString &filename : filenames)
|
||||
|
@ -124,8 +124,8 @@ void TorrentCreator::run()
|
||||
QDirIterator dirIter {m_params.inputPath.data(), (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories};
|
||||
while (dirIter.hasNext())
|
||||
{
|
||||
dirIter.next();
|
||||
dirs.append(dirIter.filePath());
|
||||
const QString filePath = dirIter.next();
|
||||
dirs.append(filePath);
|
||||
}
|
||||
std::sort(dirs.begin(), dirs.end(), naturalLessThan);
|
||||
|
||||
@ -139,11 +139,11 @@ void TorrentCreator::run()
|
||||
QDirIterator fileIter {dir, QDir::Files};
|
||||
while (fileIter.hasNext())
|
||||
{
|
||||
fileIter.next();
|
||||
const QFileInfo fileInfo = fileIter.nextFileInfo();
|
||||
|
||||
const auto relFilePath = parentPath.relativePathOf(Path(fileIter.filePath()));
|
||||
const Path relFilePath = parentPath.relativePathOf(Path(fileInfo.filePath()));
|
||||
tmpNames.append(relFilePath.toString());
|
||||
fileSizeMap[tmpNames.last()] = fileIter.fileInfo().size();
|
||||
fileSizeMap[tmpNames.last()] = fileInfo.size();
|
||||
}
|
||||
|
||||
std::sort(tmpNames.begin(), tmpNames.end(), naturalLessThan);
|
||||
|
@ -74,12 +74,11 @@ namespace
|
||||
}
|
||||
|
||||
// python 2: remove "*.pyc" files
|
||||
const QStringList files = QDir(dir.data()).entryList(QDir::Files);
|
||||
for (const QString &file : files)
|
||||
QDirIterator it {dir.data(), {u"*.pyc"_s}, QDir::Files};
|
||||
while (it.hasNext())
|
||||
{
|
||||
const Path path {file};
|
||||
if (path.hasExtension(u".pyc"_s))
|
||||
Utils::Fs::removeFile(path);
|
||||
const QString filePath = it.next();
|
||||
Utils::Fs::removeFile(Path(filePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -298,11 +297,13 @@ bool SearchPluginManager::uninstallPlugin(const QString &name)
|
||||
clearPythonCache(engineLocation());
|
||||
|
||||
// remove it from hard drive
|
||||
const Path pluginsPath = pluginsLocation();
|
||||
const QStringList filters {name + u".*"};
|
||||
const QStringList files = QDir(pluginsPath.data()).entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
for (const QString &file : files)
|
||||
Utils::Fs::removeFile(pluginsPath / Path(file));
|
||||
QDirIterator iter {pluginsLocation().data(), {name + u".*"}, QDir::Files};
|
||||
while (iter.hasNext())
|
||||
{
|
||||
const QString filePath = iter.next();
|
||||
Utils::Fs::removeFile(Path(filePath));
|
||||
}
|
||||
|
||||
// Remove it from supported engines
|
||||
delete m_plugins.take(name);
|
||||
|
||||
|
@ -443,10 +443,10 @@ void TorrentFilesWatcher::Worker::processFolder(const Path &path, const Path &wa
|
||||
|
||||
if (options.recursive)
|
||||
{
|
||||
QDirIterator dirIter {path.data(), (QDir::Dirs | QDir::NoDot | QDir::NoDotDot)};
|
||||
while (dirIter.hasNext())
|
||||
QDirIterator iter {path.data(), (QDir::Dirs | QDir::NoDotAndDotDot)};
|
||||
while (iter.hasNext())
|
||||
{
|
||||
const Path folderPath {dirIter.next()};
|
||||
const Path folderPath {iter.next()};
|
||||
// Skip processing of subdirectory that is explicitly set as watched folder
|
||||
if (!m_watchedFolders.contains(folderPath))
|
||||
processFolder(folderPath, watchedFolderPath, options);
|
||||
|
@ -151,11 +151,11 @@ qint64 Utils::Fs::computePathSize(const Path &path)
|
||||
|
||||
// Compute folder size based on its content
|
||||
qint64 size = 0;
|
||||
QDirIterator iter {path.data(), QDir::Files | QDir::Hidden | QDir::NoSymLinks, QDirIterator::Subdirectories};
|
||||
QDirIterator iter {path.data(), (QDir::Files | QDir::Hidden | QDir::NoSymLinks), QDirIterator::Subdirectories};
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
size += iter.fileInfo().size();
|
||||
const QFileInfo fileInfo = iter.nextFileInfo();
|
||||
size += fileInfo.size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QStringView>
|
||||
#include <QSysInfo>
|
||||
|
||||
#include "base/path.h"
|
||||
@ -252,7 +253,7 @@ QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglo
|
||||
return QCoreApplication::translate("misc", "%1y %2d", "e.g: 2 years 10 days").arg(QString::number(years), QString::number(days));
|
||||
}
|
||||
|
||||
QString Utils::Misc::languageToLocalizedString(const QString &localeStr)
|
||||
QString Utils::Misc::languageToLocalizedString(const QStringView localeStr)
|
||||
{
|
||||
if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
|
||||
{
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "base/pathfwd.h"
|
||||
|
||||
class QString;
|
||||
class QStringView;
|
||||
|
||||
/* Miscellaneous functions that can be useful */
|
||||
namespace Utils::Misc
|
||||
@ -82,5 +83,5 @@ namespace Utils::Misc
|
||||
// time duration like "1d 2h 10m".
|
||||
QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1, TimeResolution resolution = TimeResolution::Minutes);
|
||||
|
||||
QString languageToLocalizedString(const QString &localeStr);
|
||||
QString languageToLocalizedString(QStringView localeStr);
|
||||
}
|
||||
|
@ -1379,13 +1379,11 @@ void OptionsDialog::saveWebUITabOptions() const
|
||||
void OptionsDialog::initializeLanguageCombo()
|
||||
{
|
||||
// List language files
|
||||
const QDir langDir(u":/lang"_s);
|
||||
const QStringList langFiles = langDir.entryList(QStringList(u"qbittorrent_*.qm"_s), QDir::Files);
|
||||
const QStringList langFiles = QDir(u":/lang"_s).entryList({u"qbittorrent_*.qm"_s}, QDir::Files, QDir::Name);
|
||||
for (const QString &langFile : langFiles)
|
||||
{
|
||||
const QString localeStr = langFile.section(u"_"_s, 1, -1).section(u"."_s, 0, 0); // remove "qbittorrent_" and ".qm"
|
||||
m_ui->comboI18n->addItem(/*QIcon(":/icons/flags/"+country+".svg"), */ Utils::Misc::languageToLocalizedString(localeStr), localeStr);
|
||||
qDebug() << "Supported locale:" << localeStr;
|
||||
const QString langCode = QStringView(langFile).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
|
||||
m_ui->comboI18n->addItem(Utils::Misc::languageToLocalizedString(langCode), langCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,20 +153,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboI18n">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToContents</enum>
|
||||
</property>
|
||||
<property name="modelColumn">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboI18n"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer_111">
|
||||
@ -1097,7 +1084,7 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkUnwantedFolder">
|
||||
<property name="text">
|
||||
<string>Keep unselected files in ".unwanted" folder</string>
|
||||
<string>Keep unselected files in ".unwanted" folder</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -125,14 +125,18 @@ namespace
|
||||
QString createLanguagesOptionsHtml()
|
||||
{
|
||||
// List language files
|
||||
const QDir langDir {u":/www/translations"_s};
|
||||
const QStringList langFiles = langDir.entryList(QStringList(u"webui_*.qm"_s), QDir::Files);
|
||||
const QStringList langFiles = QDir(u":/www/translations"_s)
|
||||
.entryList({u"webui_*.qm"_s}, QDir::Files, QDir::Name);
|
||||
|
||||
QStringList languages;
|
||||
languages.reserve(langFiles.size());
|
||||
|
||||
for (const QString &langFile : langFiles)
|
||||
{
|
||||
const QString localeStr = langFile.section(u"_"_s, 1, -1).section(u"."_s, 0, 0); // remove "webui_" and ".qm"
|
||||
languages << u"<option value=\"%1\">%2</option>"_s.arg(localeStr, Utils::Misc::languageToLocalizedString(localeStr));
|
||||
qDebug() << "Supported locale:" << localeStr;
|
||||
const auto langCode = QStringView(langFile).sliced(6).chopped(3); // remove "webui_" and ".qm"
|
||||
const QString entry = u"<option value=\"%1\">%2</option>"_s
|
||||
.arg(langCode, Utils::Misc::languageToLocalizedString(langCode));
|
||||
languages.append(entry);
|
||||
}
|
||||
|
||||
return languages.join(u'\n');
|
||||
|
Loading…
Reference in New Issue
Block a user