Port to QStringLiteral operator
This commit is contained in:
@@ -97,8 +97,8 @@ QString CoverUtils::CoverFilePath(const CoverOptions &options, const Song::Sourc
|
||||
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("-"));
|
||||
static const QRegularExpression regex_whitespaces(u"\\s"_s);
|
||||
filename.replace(regex_whitespaces, u"-"_s);
|
||||
}
|
||||
if (!extension.isEmpty()) {
|
||||
filename.append(u'.');
|
||||
|
||||
@@ -47,28 +47,28 @@ void SetEnv(const char *key, const QString &value) {
|
||||
|
||||
QString DesktopEnvironment() {
|
||||
|
||||
const QString de = GetEnv(QStringLiteral("XDG_CURRENT_DESKTOP"));
|
||||
const QString de = GetEnv(u"XDG_CURRENT_DESKTOP"_s);
|
||||
if (!de.isEmpty()) return de;
|
||||
|
||||
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) return QStringLiteral("KDE");
|
||||
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return QStringLiteral("Gnome");
|
||||
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) return u"KDE"_s;
|
||||
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return u"Gnome"_s;
|
||||
|
||||
QString session = GetEnv(QStringLiteral("DESKTOP_SESSION"));
|
||||
QString session = GetEnv(u"DESKTOP_SESSION"_s);
|
||||
qint64 slash = session.lastIndexOf(u'/');
|
||||
if (slash != -1) {
|
||||
QSettings desktop_file(QStringLiteral("%1.desktop").arg(session), QSettings::IniFormat);
|
||||
desktop_file.beginGroup(QStringLiteral("Desktop Entry"));
|
||||
QString name = desktop_file.value(QStringLiteral("DesktopNames")).toString();
|
||||
desktop_file.beginGroup(u"Desktop Entry"_s);
|
||||
QString name = desktop_file.value(u"DesktopNames"_s).toString();
|
||||
desktop_file.endGroup();
|
||||
if (!name.isEmpty()) return name;
|
||||
session = session.mid(slash + 1);
|
||||
}
|
||||
|
||||
if (session == "kde"_L1) return QStringLiteral("KDE");
|
||||
else if (session == "gnome"_L1) return QStringLiteral("Gnome");
|
||||
else if (session == "xfce"_L1) return QStringLiteral("XFCE");
|
||||
if (session == "kde"_L1) return u"KDE"_s;
|
||||
else if (session == "gnome"_L1) return u"Gnome"_s;
|
||||
else if (session == "xfce"_L1) return u"XFCE"_s;
|
||||
|
||||
return QStringLiteral("Unknown");
|
||||
return u"Unknown"_s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
if (!url.isLocalFile()) return;
|
||||
|
||||
QProcess proc;
|
||||
proc.startCommand(QStringLiteral("xdg-mime query default inode/directory"));
|
||||
proc.startCommand(u"xdg-mime query default inode/directory"_s);
|
||||
proc.waitForFinished();
|
||||
QString desktop_file = QString::fromUtf8(proc.readLine()).simplified();
|
||||
QString xdg_data_dirs = QString::fromUtf8(qgetenv("XDG_DATA_DIRS"));
|
||||
@@ -60,11 +60,11 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
QString desktop_file_path = QStringLiteral("%1/applications/%2").arg(data_dir, desktop_file);
|
||||
if (!QFile::exists(desktop_file_path)) continue;
|
||||
QSettings setting(desktop_file_path, QSettings::IniFormat);
|
||||
setting.beginGroup(QStringLiteral("Desktop Entry"));
|
||||
setting.beginGroup(u"Desktop Entry"_s);
|
||||
if (setting.contains("Exec"_L1)) {
|
||||
QString cmd = setting.value(QStringLiteral("Exec")).toString();
|
||||
QString cmd = setting.value(u"Exec"_s).toString();
|
||||
if (cmd.isEmpty()) break;
|
||||
static const QRegularExpression regex(QStringLiteral("[%][a-zA-Z]*( |$)"), QRegularExpression::CaseInsensitiveOption);
|
||||
static const QRegularExpression regex(u"[%][a-zA-Z]*( |$)"_s, QRegularExpression::CaseInsensitiveOption);
|
||||
cmd = cmd.remove(regex);
|
||||
command_params = cmd.split(u' ', Qt::SkipEmptyParts);
|
||||
command = command_params.first();
|
||||
@@ -85,10 +85,10 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
command.startsWith("dolphin"_L1) ||
|
||||
command.startsWith("konqueror"_L1) ||
|
||||
command.startsWith("kfmclient"_L1)) {
|
||||
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--select") << url.toLocalFile());
|
||||
proc.startDetached(command, QStringList() << command_params << u"--select"_s << url.toLocalFile());
|
||||
}
|
||||
else if (command.startsWith("caja"_L1)) {
|
||||
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--no-desktop") << path);
|
||||
proc.startDetached(command, QStringList() << command_params << u"--no-desktop"_s << path);
|
||||
}
|
||||
else if (command.startsWith("pcmanfm"_L1) || command.startsWith("thunar"_L1) || command.startsWith("spacefm"_L1)) {
|
||||
proc.startDetached(command, QStringList() << command_params << path);
|
||||
@@ -103,14 +103,14 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
#ifdef Q_OS_MACOS
|
||||
// Better than openUrl(dirname(path)) - also highlights file at path
|
||||
void RevealFileInFinder(const QString &path) {
|
||||
QProcess::execute(QStringLiteral("/usr/bin/open"), QStringList() << QStringLiteral("-R") << path);
|
||||
QProcess::execute(u"/usr/bin/open"_s, QStringList() << u"-R"_s << path);
|
||||
}
|
||||
#endif // Q_OS_MACOS
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
void ShowFileInExplorer(const QString &path);
|
||||
void ShowFileInExplorer(const QString &path) {
|
||||
QProcess::execute(QStringLiteral("explorer.exe"), QStringList() << QStringLiteral("/select,") << QDir::toNativeSeparators(path));
|
||||
QProcess::execute(u"explorer.exe"_s, QStringList() << u"/select,"_s << QDir::toNativeSeparators(path));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include "fileutils.h"
|
||||
#include "mimeutils.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
QStringList ImageUtils::kSupportedImageMimeTypes;
|
||||
QStringList ImageUtils::kSupportedImageFormats;
|
||||
|
||||
@@ -81,7 +83,7 @@ QByteArray ImageUtils::FileToJpegData(const QString &filename) {
|
||||
if (filename.isEmpty()) return QByteArray();
|
||||
|
||||
QByteArray image_data = Utilities::ReadDataFromFile(filename);
|
||||
if (Utilities::MimeTypeFromData(image_data) == QStringLiteral("image/jpeg")) {
|
||||
if (Utilities::MimeTypeFromData(image_data) == u"image/jpeg"_s) {
|
||||
return image_data;
|
||||
}
|
||||
|
||||
@@ -127,7 +129,7 @@ QImage ImageUtils::ScaleImage(const QImage &image, const QSize desired_size, con
|
||||
|
||||
QImage ImageUtils::GenerateNoCoverImage(const QSize size, const qreal device_pixel_ratio) {
|
||||
|
||||
QImage image(QStringLiteral(":/pictures/cdcase.png"));
|
||||
QImage image(u":/pictures/cdcase.png"_s);
|
||||
QSize scale_size(static_cast<int>(size.width() * device_pixel_ratio), static_cast<int>(size.height() * device_pixel_ratio));
|
||||
|
||||
// Get a square version of the nocover image with some transparency:
|
||||
|
||||
@@ -24,20 +24,22 @@
|
||||
|
||||
#include "randutils.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
namespace Utilities {
|
||||
|
||||
QString GetRandomStringWithChars(const int len) {
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
|
||||
const QString UseCharacters(u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"_s);
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
QString GetRandomStringWithCharsAndNumbers(const int len) {
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
|
||||
const QString UseCharacters(u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"_s);
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
QString CryptographicRandomString(const int len) {
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"));
|
||||
const QString UseCharacters(u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"_s);
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ QString DecodeHtmlEntities(const QString &text) {
|
||||
|
||||
QString ReplaceMessage(const QString &message, const Song &song, const QString &newline, const bool html_escaped) {
|
||||
|
||||
static const QRegularExpression variable_replacer(QStringLiteral("[%][a-z]+[%]"));
|
||||
static const QRegularExpression variable_replacer(u"[%][a-z]+[%]"_s);
|
||||
QString copy(message);
|
||||
|
||||
// Replace the first line
|
||||
@@ -127,7 +127,7 @@ QString ReplaceMessage(const QString &message, const Song &song, const QString &
|
||||
pos += match.capturedLength();
|
||||
}
|
||||
|
||||
static const QRegularExpression regexp(QStringLiteral(" - (>|$)"));
|
||||
static const QRegularExpression regexp(u" - (>|$)"_s);
|
||||
qint64 index_of = copy.indexOf(regexp);
|
||||
if (index_of >= 0) copy = copy.remove(index_of, 3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user