Replace QLatin1String with operator _L1

This commit is contained in:
Jonas Kvinge
2024-09-07 04:24:14 +02:00
parent e3e6a22172
commit 4270b12cd1
185 changed files with 2429 additions and 2139 deletions

View File

@@ -31,6 +31,8 @@
#include "coverutils.h"
#include "core/logging.h"
using namespace Qt::StringLiterals;
QByteArray CoverUtils::Sha1CoverHash(const QString &artist, const QString &album) {
QCryptographicHash hash(QCryptographicHash::Sha1);
@@ -43,18 +45,18 @@ QByteArray CoverUtils::Sha1CoverHash(const QString &artist, const QString &album
QString CoverUtils::AlbumCoverFilename(QString artist, QString album, const QString &extension) {
artist.remove(QLatin1Char('/')).remove(QLatin1Char('\\'));
album.remove(QLatin1Char('/')).remove(QLatin1Char('\\'));
artist.remove(u'/').remove(u'\\');
album.remove(u'/').remove(u'\\');
QString filename = artist + QLatin1Char('-') + album;
filename = Utilities::Transliterate(filename.toLower());
filename = filename.replace(QLatin1Char(' '), QLatin1Char('-'))
.replace(QLatin1String("--"), QLatin1String("-"))
filename = filename.replace(u' ', u'-')
.replace("--"_L1, "-"_L1)
.remove(QRegularExpression(QLatin1String(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption))
.simplified();
if (!extension.isEmpty()) {
filename.append(QLatin1Char('.'));
filename.append(u'.');
filename.append(extension);
}
@@ -76,7 +78,7 @@ QString CoverUtils::CoverFilePath(const CoverOptions &options, const Song::Sourc
path = Song::ImageCacheDir(source);
}
if (path.right(1) == QDir::separator() || path.right(1) == QLatin1Char('/')) {
if (path.right(1) == QDir::separator() || path.right(1) == u'/') {
path.chop(1);
}
@@ -92,14 +94,14 @@ QString CoverUtils::CoverFilePath(const CoverOptions &options, const Song::Sourc
options.cover_filename == CoverOptions::CoverFilename::Pattern &&
!options.cover_pattern.isEmpty()) {
filename = CoverFilenameFromVariable(options, artist, album);
filename.remove(QRegularExpression(QLatin1String(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption)).remove(QLatin1Char('/')).remove(QLatin1Char('\\'));
filename.remove(QRegularExpression(QLatin1String(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption)).remove(u'/').remove(u'\\');
if (options.cover_lowercase) filename = filename.toLower();
if (options.cover_replace_spaces) {
static const QRegularExpression regex_whitespaces(QStringLiteral("\\s"));
filename.replace(regex_whitespaces, QStringLiteral("-"));
}
if (!extension.isEmpty()) {
filename.append(QLatin1Char('.'));
filename.append(u'.');
filename.append(extension);
}
}
@@ -146,7 +148,7 @@ QString CoverUtils::CoverFilenameFromSource(const Song::Source source, const QUr
}
if (!extension.isEmpty()) {
filename.append(QLatin1Char('.'));
filename.append(u'.');
filename.append(extension);
}
@@ -159,11 +161,11 @@ QString CoverUtils::CoverFilenameFromVariable(const CoverOptions &options, const
album = Song::AlbumRemoveDisc(album);
QString filename(options.cover_pattern);
filename.replace(QLatin1String("%albumartist"), artist);
filename.replace(QLatin1String("%artist"), artist);
filename.replace(QLatin1String("%album"), album);
filename.replace("%albumartist"_L1, artist);
filename.replace("%artist"_L1, artist);
filename.replace("%album"_L1, album);
if (!extension.isEmpty()) {
filename.append(QLatin1Char('.'));
filename.append(u'.');
filename.append(extension);
}
return filename;

View File

@@ -26,6 +26,8 @@
#include "envutils.h"
using namespace Qt::StringLiterals;
namespace Utilities {
QString GetEnv(const QString &key) {
@@ -52,7 +54,7 @@ QString DesktopEnvironment() {
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return QStringLiteral("Gnome");
QString session = GetEnv(QStringLiteral("DESKTOP_SESSION"));
qint64 slash = session.lastIndexOf(QLatin1Char('/'));
qint64 slash = session.lastIndexOf(u'/');
if (slash != -1) {
QSettings desktop_file(QStringLiteral("%1.desktop").arg(session), QSettings::IniFormat);
desktop_file.beginGroup(QStringLiteral("Desktop Entry"));
@@ -62,9 +64,9 @@ QString DesktopEnvironment() {
session = session.mid(slash + 1);
}
if (session == QLatin1String("kde")) return QStringLiteral("KDE");
else if (session == QLatin1String("gnome")) return QStringLiteral("Gnome");
else if (session == QLatin1String("xfce")) return QStringLiteral("XFCE");
if (session == "kde"_L1) return QStringLiteral("KDE");
else if (session == "gnome"_L1) return QStringLiteral("Gnome");
else if (session == "xfce"_L1) return QStringLiteral("XFCE");
return QStringLiteral("Unknown");

View File

@@ -34,6 +34,8 @@
#include "filemanagerutils.h"
using namespace Qt::StringLiterals;
namespace Utilities {
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
@@ -48,9 +50,9 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
QString desktop_file = QString::fromUtf8(proc.readLine()).simplified();
QString xdg_data_dirs = QString::fromUtf8(qgetenv("XDG_DATA_DIRS"));
if (xdg_data_dirs.isEmpty()) {
xdg_data_dirs = QLatin1String("/usr/local/share/:/usr/share/");
xdg_data_dirs = "/usr/local/share/:/usr/share/"_L1;
}
const QStringList data_dirs = xdg_data_dirs.split(QLatin1Char(':'));
const QStringList data_dirs = xdg_data_dirs.split(u':');
QString command;
QStringList command_params;
@@ -59,12 +61,12 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
if (!QFile::exists(desktop_file_path)) continue;
QSettings setting(desktop_file_path, QSettings::IniFormat);
setting.beginGroup(QStringLiteral("Desktop Entry"));
if (setting.contains(QLatin1String("Exec"))) {
if (setting.contains("Exec"_L1)) {
QString cmd = setting.value(QStringLiteral("Exec")).toString();
if (cmd.isEmpty()) break;
static const QRegularExpression regex(QStringLiteral("[%][a-zA-Z]*( |$)"), QRegularExpression::CaseInsensitiveOption);
cmd = cmd.remove(regex);
command_params = cmd.split(QLatin1Char(' '), Qt::SkipEmptyParts);
command_params = cmd.split(u' ', Qt::SkipEmptyParts);
command = command_params.first();
command_params.removeFirst();
}
@@ -72,23 +74,23 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
if (!command.isEmpty()) break;
}
if (command.startsWith(QLatin1String("/usr/bin/"))) {
command = command.split(QLatin1Char('/')).last();
if (command.startsWith("/usr/bin/"_L1)) {
command = command.split(u'/').last();
}
if (command.isEmpty() || command == QLatin1String("exo-open")) {
if (command.isEmpty() || command == "exo-open"_L1) {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
else if (command.startsWith(QLatin1String("nautilus")) ||
command.startsWith(QLatin1String("dolphin")) ||
command.startsWith(QLatin1String("konqueror")) ||
command.startsWith(QLatin1String("kfmclient"))) {
else if (command.startsWith("nautilus"_L1) ||
command.startsWith("dolphin"_L1) ||
command.startsWith("konqueror"_L1) ||
command.startsWith("kfmclient"_L1)) {
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--select") << url.toLocalFile());
}
else if (command.startsWith(QLatin1String("caja"))) {
else if (command.startsWith("caja"_L1)) {
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--no-desktop") << path);
}
else if (command.startsWith(QLatin1String("pcmanfm")) || command.startsWith(QLatin1String("thunar")) || command.startsWith(QLatin1String("spacefm"))) {
else if (command.startsWith("pcmanfm"_L1) || command.startsWith("thunar"_L1) || command.startsWith("spacefm"_L1)) {
proc.startDetached(command, QStringList() << command_params << path);
}
else {

View File

@@ -86,7 +86,7 @@ bool Copy(QIODevice *source, QIODevice *destination) {
bool CopyRecursive(const QString &source, const QString &destination) {
// Make the destination directory
QString dir_name = source.section(QLatin1Char('/'), -1, -1);
QString dir_name = source.section(u'/', -1, -1);
QString dest_path = destination + QLatin1Char('/') + dir_name;
QDir().mkpath(dest_path);

View File

@@ -23,6 +23,8 @@
#include "macaddrutils.h"
using namespace Qt::StringLiterals;
namespace Utilities {
QString MacAddress() {
@@ -31,7 +33,7 @@ QString MacAddress() {
for (QNetworkInterface &netif : QNetworkInterface::allInterfaces()) {
if (
(netif.hardwareAddress() == QLatin1String("00:00:00:00:00:00")) ||
(netif.hardwareAddress() == "00:00:00:00:00:00"_L1) ||
(netif.flags() & QNetworkInterface::IsLoopBack) ||
!(netif.flags() & QNetworkInterface::IsUp) ||
!(netif.flags() & QNetworkInterface::IsRunning)
@@ -41,7 +43,7 @@ QString MacAddress() {
}
}
if (ret.isEmpty()) ret = QLatin1String("00:00:00:00:00:00");
if (ret.isEmpty()) ret = "00:00:00:00:00:00"_L1;
return ret;

View File

@@ -27,6 +27,8 @@
#include "strutils.h"
#include "core/song.h"
using namespace Qt::StringLiterals;
namespace Utilities {
QString PrettySize(const quint64 bytes) {
@@ -35,7 +37,7 @@ QString PrettySize(const quint64 bytes) {
if (bytes > 0LL) {
if (bytes <= 1000LL) {
ret = QString::number(bytes) + QLatin1String(" bytes");
ret = QString::number(bytes) + " bytes"_L1;
}
else if (bytes <= 1000LL * 1000LL) {
ret = QString::asprintf("%.1f KB", static_cast<float>(bytes) / 1000.0F);
@@ -56,7 +58,7 @@ QString PrettySize(const QSize size) {
}
QString PathWithoutFilenameExtension(const QString &filename) {
if (filename.section(QLatin1Char('/'), -1, -1).contains(QLatin1Char('.'))) return filename.section(QLatin1Char('.'), 0, -2);
if (filename.section(u'/', -1, -1).contains(u'.')) return filename.section(u'.', 0, -2);
return filename;
}
@@ -86,7 +88,7 @@ QStringList Prepend(const QString &text, const QStringList &list) {
QStringList Updateify(const QStringList &list) {
QStringList ret(list);
for (int i = 0; i < ret.count(); ++i) ret[i].prepend(ret[i] + QLatin1String(" = :"));
for (int i = 0; i < ret.count(); ++i) ret[i].prepend(ret[i] + " = :"_L1);
return ret;
}
@@ -94,17 +96,17 @@ QStringList Updateify(const QStringList &list) {
QString DecodeHtmlEntities(const QString &text) {
QString copy(text);
copy.replace(QLatin1String("&amp;"), QLatin1String("&"))
.replace(QLatin1String("&#38;"), QLatin1String("&"))
.replace(QLatin1String("&quot;"), QLatin1String("\""))
.replace(QLatin1String("&#34;"), QLatin1String("\""))
.replace(QLatin1String("&apos;"), QLatin1String("'"))
.replace(QLatin1String("&#39;"), QLatin1String("'"))
.replace(QLatin1String("&lt;"), QLatin1String("<"))
.replace(QLatin1String("&#60;"), QLatin1String("<"))
.replace(QLatin1String("&gt;"), QLatin1String(">"))
.replace(QLatin1String("&#62;"), QLatin1String(">"))
.replace(QLatin1String("&#x27;"), QLatin1String("'"));
copy.replace("&amp;"_L1, "&"_L1)
.replace("&#38;"_L1, "&"_L1)
.replace("&quot;"_L1, "\""_L1)
.replace("&#34;"_L1, "\""_L1)
.replace("&apos;"_L1, "'"_L1)
.replace("&#39;"_L1, "'"_L1)
.replace("&lt;"_L1, "<"_L1)
.replace("&#60;"_L1, "<"_L1)
.replace("&gt;"_L1, ">"_L1)
.replace("&#62;"_L1, ">"_L1)
.replace("&#x27;"_L1, "'"_L1);
return copy;
@@ -137,61 +139,61 @@ QString ReplaceVariable(const QString &variable, const Song &song, const QString
QString value = variable;
if (variable == QLatin1String("%title%")) {
if (variable == "%title%"_L1) {
value = song.PrettyTitle();
}
else if (variable == QLatin1String("%album%")) {
else if (variable == "%album%"_L1) {
value = song.album();
}
else if (variable == QLatin1String("%artist%")) {
else if (variable == "%artist%"_L1) {
value = song.artist();
}
else if (variable == QLatin1String("%albumartist%")) {
else if (variable == "%albumartist%"_L1) {
value = song.effective_albumartist();
}
else if (variable == QLatin1String("%track%")) {
else if (variable == "%track%"_L1) {
value.setNum(song.track());
}
else if (variable == QLatin1String("%disc%")) {
else if (variable == "%disc%"_L1) {
value.setNum(song.disc());
}
else if (variable == QLatin1String("%year%")) {
else if (variable == "%year%"_L1) {
value = song.PrettyYear();
}
else if (variable == QLatin1String("%originalyear%")) {
else if (variable == "%originalyear%"_L1) {
value = song.PrettyOriginalYear();
}
else if (variable == QLatin1String("%genre%")) {
else if (variable == "%genre%"_L1) {
value = song.genre();
}
else if (variable == QLatin1String("%composer%")) {
else if (variable == "%composer%"_L1) {
value = song.composer();
}
else if (variable == QLatin1String("%performer%")) {
else if (variable == "%performer%"_L1) {
value = song.performer();
}
else if (variable == QLatin1String("%grouping%")) {
else if (variable == "%grouping%"_L1) {
value = song.grouping();
}
else if (variable == QLatin1String("%length%")) {
else if (variable == "%length%"_L1) {
value = song.PrettyLength();
}
else if (variable == QLatin1String("%filename%")) {
else if (variable == "%filename%"_L1) {
value = song.basefilename();
}
else if (variable == QLatin1String("%url%")) {
else if (variable == "%url%"_L1) {
value = song.url().toString();
}
else if (variable == QLatin1String("%playcount%")) {
else if (variable == "%playcount%"_L1) {
value.setNum(song.playcount());
}
else if (variable == QLatin1String("%skipcount%")) {
else if (variable == "%skipcount%"_L1) {
value.setNum(song.skipcount());
}
else if (variable == QLatin1String("%rating%")) {
else if (variable == "%rating%"_L1) {
value = song.PrettyRating();
}
else if (variable == QLatin1String("%newline%")) {
else if (variable == "%newline%"_L1) {
return QString(newline); // No HTML escaping, return immediately.
}

View File

@@ -67,7 +67,7 @@ QString WordyTime(const quint64 seconds) {
if (days > 0) parts << (days == 1 ? QObject::tr("1 day") : QObject::tr("%1 days").arg(days));
parts << PrettyTime(static_cast<int>(seconds - days * 60 * 60 * 24));
return parts.join(QLatin1Char(' '));
return parts.join(u' ');
}