mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-11 07:46:17 -07: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
10 changed files with 41 additions and 49 deletions
|
@ -105,7 +105,7 @@ BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const Path &path,
|
||||||
}
|
}
|
||||||
|
|
||||||
const QRegularExpression filenamePattern {u"^([A-Fa-f0-9]{40})\\.fastresume$"_s};
|
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());
|
m_registeredTorrents.reserve(filenames.size());
|
||||||
for (const QString &filename : filenames)
|
for (const QString &filename : filenames)
|
||||||
|
|
|
@ -124,8 +124,8 @@ void TorrentCreator::run()
|
||||||
QDirIterator dirIter {m_params.inputPath.data(), (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories};
|
QDirIterator dirIter {m_params.inputPath.data(), (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories};
|
||||||
while (dirIter.hasNext())
|
while (dirIter.hasNext())
|
||||||
{
|
{
|
||||||
dirIter.next();
|
const QString filePath = dirIter.next();
|
||||||
dirs.append(dirIter.filePath());
|
dirs.append(filePath);
|
||||||
}
|
}
|
||||||
std::sort(dirs.begin(), dirs.end(), naturalLessThan);
|
std::sort(dirs.begin(), dirs.end(), naturalLessThan);
|
||||||
|
|
||||||
|
@ -139,11 +139,11 @@ void TorrentCreator::run()
|
||||||
QDirIterator fileIter {dir, QDir::Files};
|
QDirIterator fileIter {dir, QDir::Files};
|
||||||
while (fileIter.hasNext())
|
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());
|
tmpNames.append(relFilePath.toString());
|
||||||
fileSizeMap[tmpNames.last()] = fileIter.fileInfo().size();
|
fileSizeMap[tmpNames.last()] = fileInfo.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(tmpNames.begin(), tmpNames.end(), naturalLessThan);
|
std::sort(tmpNames.begin(), tmpNames.end(), naturalLessThan);
|
||||||
|
|
|
@ -74,12 +74,11 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// python 2: remove "*.pyc" files
|
// python 2: remove "*.pyc" files
|
||||||
const QStringList files = QDir(dir.data()).entryList(QDir::Files);
|
QDirIterator it {dir.data(), {u"*.pyc"_s}, QDir::Files};
|
||||||
for (const QString &file : files)
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
const Path path {file};
|
const QString filePath = it.next();
|
||||||
if (path.hasExtension(u".pyc"_s))
|
Utils::Fs::removeFile(Path(filePath));
|
||||||
Utils::Fs::removeFile(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,11 +297,13 @@ bool SearchPluginManager::uninstallPlugin(const QString &name)
|
||||||
clearPythonCache(engineLocation());
|
clearPythonCache(engineLocation());
|
||||||
|
|
||||||
// remove it from hard drive
|
// remove it from hard drive
|
||||||
const Path pluginsPath = pluginsLocation();
|
QDirIterator iter {pluginsLocation().data(), {name + u".*"}, QDir::Files};
|
||||||
const QStringList filters {name + u".*"};
|
while (iter.hasNext())
|
||||||
const QStringList files = QDir(pluginsPath.data()).entryList(filters, QDir::Files, QDir::Unsorted);
|
{
|
||||||
for (const QString &file : files)
|
const QString filePath = iter.next();
|
||||||
Utils::Fs::removeFile(pluginsPath / Path(file));
|
Utils::Fs::removeFile(Path(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
// Remove it from supported engines
|
// Remove it from supported engines
|
||||||
delete m_plugins.take(name);
|
delete m_plugins.take(name);
|
||||||
|
|
||||||
|
|
|
@ -443,10 +443,10 @@ void TorrentFilesWatcher::Worker::processFolder(const Path &path, const Path &wa
|
||||||
|
|
||||||
if (options.recursive)
|
if (options.recursive)
|
||||||
{
|
{
|
||||||
QDirIterator dirIter {path.data(), (QDir::Dirs | QDir::NoDot | QDir::NoDotDot)};
|
QDirIterator iter {path.data(), (QDir::Dirs | QDir::NoDotAndDotDot)};
|
||||||
while (dirIter.hasNext())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
const Path folderPath {dirIter.next()};
|
const Path folderPath {iter.next()};
|
||||||
// Skip processing of subdirectory that is explicitly set as watched folder
|
// Skip processing of subdirectory that is explicitly set as watched folder
|
||||||
if (!m_watchedFolders.contains(folderPath))
|
if (!m_watchedFolders.contains(folderPath))
|
||||||
processFolder(folderPath, watchedFolderPath, options);
|
processFolder(folderPath, watchedFolderPath, options);
|
||||||
|
|
|
@ -151,11 +151,11 @@ qint64 Utils::Fs::computePathSize(const Path &path)
|
||||||
|
|
||||||
// Compute folder size based on its content
|
// Compute folder size based on its content
|
||||||
qint64 size = 0;
|
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())
|
while (iter.hasNext())
|
||||||
{
|
{
|
||||||
iter.next();
|
const QFileInfo fileInfo = iter.nextFileInfo();
|
||||||
size += iter.fileInfo().size();
|
size += fileInfo.size();
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QStringView>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
|
|
||||||
#include "base/path.h"
|
#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));
|
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))
|
if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "base/pathfwd.h"
|
#include "base/pathfwd.h"
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
class QStringView;
|
||||||
|
|
||||||
/* Miscellaneous functions that can be useful */
|
/* Miscellaneous functions that can be useful */
|
||||||
namespace Utils::Misc
|
namespace Utils::Misc
|
||||||
|
@ -82,5 +83,5 @@ namespace Utils::Misc
|
||||||
// time duration like "1d 2h 10m".
|
// time duration like "1d 2h 10m".
|
||||||
QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1, TimeResolution resolution = TimeResolution::Minutes);
|
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()
|
void OptionsDialog::initializeLanguageCombo()
|
||||||
{
|
{
|
||||||
// List language files
|
// List language files
|
||||||
const QDir langDir(u":/lang"_s);
|
const QStringList langFiles = QDir(u":/lang"_s).entryList({u"qbittorrent_*.qm"_s}, QDir::Files, QDir::Name);
|
||||||
const QStringList langFiles = langDir.entryList(QStringList(u"qbittorrent_*.qm"_s), QDir::Files);
|
|
||||||
for (const QString &langFile : langFiles)
|
for (const QString &langFile : langFiles)
|
||||||
{
|
{
|
||||||
const QString localeStr = langFile.section(u"_"_s, 1, -1).section(u"."_s, 0, 0); // remove "qbittorrent_" and ".qm"
|
const QString langCode = QStringView(langFile).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
|
||||||
m_ui->comboI18n->addItem(/*QIcon(":/icons/flags/"+country+".svg"), */ Utils::Misc::languageToLocalizedString(localeStr), localeStr);
|
m_ui->comboI18n->addItem(Utils::Misc::languageToLocalizedString(langCode), langCode);
|
||||||
qDebug() << "Supported locale:" << localeStr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,20 +153,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="comboI18n">
|
<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>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="1" column="2">
|
||||||
<spacer name="horizontalSpacer_111">
|
<spacer name="horizontalSpacer_111">
|
||||||
|
@ -1097,7 +1084,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkUnwantedFolder">
|
<widget class="QCheckBox" name="checkUnwantedFolder">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Keep unselected files in ".unwanted" folder</string>
|
<string>Keep unselected files in ".unwanted" folder</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -125,14 +125,18 @@ namespace
|
||||||
QString createLanguagesOptionsHtml()
|
QString createLanguagesOptionsHtml()
|
||||||
{
|
{
|
||||||
// List language files
|
// List language files
|
||||||
const QDir langDir {u":/www/translations"_s};
|
const QStringList langFiles = QDir(u":/www/translations"_s)
|
||||||
const QStringList langFiles = langDir.entryList(QStringList(u"webui_*.qm"_s), QDir::Files);
|
.entryList({u"webui_*.qm"_s}, QDir::Files, QDir::Name);
|
||||||
|
|
||||||
QStringList languages;
|
QStringList languages;
|
||||||
|
languages.reserve(langFiles.size());
|
||||||
|
|
||||||
for (const QString &langFile : langFiles)
|
for (const QString &langFile : langFiles)
|
||||||
{
|
{
|
||||||
const QString localeStr = langFile.section(u"_"_s, 1, -1).section(u"."_s, 0, 0); // remove "webui_" and ".qm"
|
const auto langCode = QStringView(langFile).sliced(6).chopped(3); // remove "webui_" and ".qm"
|
||||||
languages << u"<option value=\"%1\">%2</option>"_s.arg(localeStr, Utils::Misc::languageToLocalizedString(localeStr));
|
const QString entry = u"<option value=\"%1\">%2</option>"_s
|
||||||
qDebug() << "Supported locale:" << localeStr;
|
.arg(langCode, Utils::Misc::languageToLocalizedString(langCode));
|
||||||
|
languages.append(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return languages.join(u'\n');
|
return languages.join(u'\n');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue