Use QStringLiteral
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Utilities {
|
||||
|
||||
QString ColorToRgba(const QColor &c) {
|
||||
|
||||
return QString("rgba(%1, %2, %3, %4)")
|
||||
return QStringLiteral("rgba(%1, %2, %3, %4)")
|
||||
.arg(c.red())
|
||||
.arg(c.green())
|
||||
.arg(c.blue())
|
||||
|
||||
@@ -49,7 +49,7 @@ QString CoverUtils::AlbumCoverFilename(QString artist, QString album, const QStr
|
||||
QString filename = artist + "-" + album;
|
||||
filename = Utilities::Transliterate(filename.toLower());
|
||||
filename = filename.replace(' ', '-')
|
||||
.replace("--", "-")
|
||||
.replace(QLatin1String("--"), QLatin1String("-"))
|
||||
.remove(QRegularExpression(QString(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption))
|
||||
.simplified();
|
||||
|
||||
@@ -94,7 +94,7 @@ QString CoverUtils::CoverFilePath(const CoverOptions &options, const Song::Sourc
|
||||
filename = CoverFilenameFromVariable(options, artist, album);
|
||||
filename.remove(QRegularExpression(QString(kInvalidFatCharactersRegex), QRegularExpression::CaseInsensitiveOption)).remove('/').remove('\\');
|
||||
if (options.cover_lowercase) filename = filename.toLower();
|
||||
if (options.cover_replace_spaces) filename.replace(QRegularExpression("\\s"), "-");
|
||||
if (options.cover_replace_spaces) filename.replace(QRegularExpression(QStringLiteral("\\s")), QStringLiteral("-"));
|
||||
if (!extension.isEmpty()) {
|
||||
filename.append('.');
|
||||
filename.append(extension);
|
||||
@@ -155,9 +155,9 @@ QString CoverUtils::CoverFilenameFromVariable(const CoverOptions &options, const
|
||||
album = Song::AlbumRemoveDisc(album);
|
||||
|
||||
QString filename(options.cover_pattern);
|
||||
filename.replace("%albumartist", artist);
|
||||
filename.replace("%artist", artist);
|
||||
filename.replace("%album", album);
|
||||
filename.replace(QLatin1String("%albumartist"), artist);
|
||||
filename.replace(QLatin1String("%artist"), artist);
|
||||
filename.replace(QLatin1String("%album"), album);
|
||||
if (!extension.isEmpty()) {
|
||||
filename.append('.');
|
||||
filename.append(extension);
|
||||
|
||||
@@ -45,16 +45,16 @@ void SetEnv(const char *key, const QString &value) {
|
||||
|
||||
QString DesktopEnvironment() {
|
||||
|
||||
const QString de = GetEnv("XDG_CURRENT_DESKTOP");
|
||||
const QString de = GetEnv(QStringLiteral("XDG_CURRENT_DESKTOP"));
|
||||
if (!de.isEmpty()) return de;
|
||||
|
||||
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) return "KDE";
|
||||
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return "Gnome";
|
||||
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) return QStringLiteral("KDE");
|
||||
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return QStringLiteral("Gnome");
|
||||
|
||||
QString session = GetEnv("DESKTOP_SESSION");
|
||||
QString session = GetEnv(QStringLiteral("DESKTOP_SESSION"));
|
||||
qint64 slash = session.lastIndexOf('/');
|
||||
if (slash != -1) {
|
||||
QSettings desktop_file(QString("%1.desktop").arg(session), QSettings::IniFormat);
|
||||
QSettings desktop_file(QStringLiteral("%1.desktop").arg(session), QSettings::IniFormat);
|
||||
desktop_file.beginGroup("Desktop Entry");
|
||||
QString name = desktop_file.value("DesktopNames").toString();
|
||||
desktop_file.endGroup();
|
||||
@@ -62,11 +62,11 @@ QString DesktopEnvironment() {
|
||||
session = session.mid(slash + 1);
|
||||
}
|
||||
|
||||
if (session == "kde") return "KDE";
|
||||
else if (session == "gnome") return "Gnome";
|
||||
else if (session == "xfce") return "XFCE";
|
||||
if (session == "kde") return QStringLiteral("KDE");
|
||||
else if (session == "gnome") return QStringLiteral("Gnome");
|
||||
else if (session == "xfce") return QStringLiteral("XFCE");
|
||||
|
||||
return "Unknown";
|
||||
return QStringLiteral("Unknown");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
|
||||
QProcess proc;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
proc.startCommand("xdg-mime query default inode/directory");
|
||||
proc.startCommand(QStringLiteral("xdg-mime query default inode/directory"));
|
||||
#else
|
||||
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
||||
#endif
|
||||
@@ -52,21 +52,21 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
QString desktop_file = proc.readLine().simplified();
|
||||
QString xdg_data_dirs = QString(qgetenv("XDG_DATA_DIRS"));
|
||||
if (xdg_data_dirs.isEmpty()) {
|
||||
xdg_data_dirs = "/usr/local/share/:/usr/share/";
|
||||
xdg_data_dirs = QStringLiteral("/usr/local/share/:/usr/share/");
|
||||
}
|
||||
QStringList data_dirs = xdg_data_dirs.split(":");
|
||||
QStringList data_dirs = xdg_data_dirs.split(QStringLiteral(":"));
|
||||
|
||||
QString command;
|
||||
QStringList command_params;
|
||||
for (const QString &data_dir : data_dirs) {
|
||||
QString desktop_file_path = QString("%1/applications/%2").arg(data_dir, desktop_file);
|
||||
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("Desktop Entry");
|
||||
if (setting.contains("Exec")) {
|
||||
QString cmd = setting.value("Exec").toString();
|
||||
if (cmd.isEmpty()) break;
|
||||
cmd = cmd.remove(QRegularExpression("[%][a-zA-Z]*( |$)", QRegularExpression::CaseInsensitiveOption));
|
||||
cmd = cmd.remove(QRegularExpression(QStringLiteral("[%][a-zA-Z]*( |$)"), QRegularExpression::CaseInsensitiveOption));
|
||||
# if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
||||
command_params = cmd.split(' ', Qt::SkipEmptyParts);
|
||||
# else
|
||||
@@ -79,23 +79,23 @@ void OpenInFileManager(const QString &path, const QUrl &url) {
|
||||
if (!command.isEmpty()) break;
|
||||
}
|
||||
|
||||
if (command.startsWith("/usr/bin/")) {
|
||||
command = command.split("/").last();
|
||||
if (command.startsWith(QLatin1String("/usr/bin/"))) {
|
||||
command = command.split(QStringLiteral("/")).last();
|
||||
}
|
||||
|
||||
if (command.isEmpty() || command == "exo-open") {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||
}
|
||||
else if (command.startsWith("nautilus")) {
|
||||
proc.startDetached(command, QStringList() << command_params << "--select" << url.toLocalFile());
|
||||
else if (command.startsWith(QLatin1String("nautilus"))) {
|
||||
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--select") << url.toLocalFile());
|
||||
}
|
||||
else if (command.startsWith("dolphin") || command.startsWith("konqueror") || command.startsWith("kfmclient")) {
|
||||
proc.startDetached(command, QStringList() << command_params << "--select" << url.toLocalFile());
|
||||
else if (command.startsWith(QLatin1String("dolphin")) || command.startsWith(QLatin1String("konqueror")) || command.startsWith(QLatin1String("kfmclient"))) {
|
||||
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--select") << url.toLocalFile());
|
||||
}
|
||||
else if (command.startsWith("caja")) {
|
||||
proc.startDetached(command, QStringList() << command_params << "--no-desktop" << path);
|
||||
else if (command.startsWith(QLatin1String("caja"))) {
|
||||
proc.startDetached(command, QStringList() << command_params << QStringLiteral("--no-desktop") << path);
|
||||
}
|
||||
else if (command.startsWith("pcmanfm") || command.startsWith("thunar") || command.startsWith("spacefm")) {
|
||||
else if (command.startsWith(QLatin1String("pcmanfm")) || command.startsWith(QLatin1String("thunar")) || command.startsWith(QLatin1String("spacefm"))) {
|
||||
proc.startDetached(command, QStringList() << command_params << path);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -123,7 +123,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(":/pictures/cdcase.png");
|
||||
QImage image(QStringLiteral(":/pictures/cdcase.png"));
|
||||
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:
|
||||
|
||||
@@ -41,7 +41,7 @@ QString MacAddress() {
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.isEmpty()) ret = "00:00:00:00:00:00";
|
||||
if (ret.isEmpty()) ret = QStringLiteral("00:00:00:00:00:00");
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -27,17 +27,17 @@
|
||||
namespace Utilities {
|
||||
|
||||
QString GetRandomStringWithChars(const int len) {
|
||||
const QString UseCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
QString GetRandomStringWithCharsAndNumbers(const int len) {
|
||||
const QString UseCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
QString CryptographicRandomString(const int len) {
|
||||
const QString UseCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~");
|
||||
const QString UseCharacters(QStringLiteral("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"));
|
||||
return GetRandomString(len, UseCharacters);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,17 +94,17 @@ QStringList Updateify(const QStringList &list) {
|
||||
QString DecodeHtmlEntities(const QString &text) {
|
||||
|
||||
QString copy(text);
|
||||
copy.replace("&", "&")
|
||||
.replace("&", "&")
|
||||
.replace(""", "\"")
|
||||
.replace(""", "\"")
|
||||
.replace("'", "'")
|
||||
.replace("'", "'")
|
||||
.replace("<", "<")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace(">", ">")
|
||||
.replace("'", "'");
|
||||
copy.replace(QLatin1String("&"), QLatin1String("&"))
|
||||
.replace(QLatin1String("&"), QLatin1String("&"))
|
||||
.replace(QLatin1String("""), QLatin1String("\""))
|
||||
.replace(QLatin1String("""), QLatin1String("\""))
|
||||
.replace(QLatin1String("'"), QLatin1String("'"))
|
||||
.replace(QLatin1String("'"), QLatin1String("'"))
|
||||
.replace(QLatin1String("<"), QLatin1String("<"))
|
||||
.replace(QLatin1String("<"), QLatin1String("<"))
|
||||
.replace(QLatin1String(">"), QLatin1String(">"))
|
||||
.replace(QLatin1String(">"), QLatin1String(">"))
|
||||
.replace(QLatin1String("'"), QLatin1String("'"));
|
||||
|
||||
return copy;
|
||||
|
||||
@@ -112,7 +112,7 @@ QString DecodeHtmlEntities(const QString &text) {
|
||||
|
||||
QString ReplaceMessage(const QString &message, const Song &song, const QString &newline, const bool html_escaped) {
|
||||
|
||||
QRegularExpression variable_replacer("[%][a-z]+[%]");
|
||||
QRegularExpression variable_replacer(QStringLiteral("[%][a-z]+[%]"));
|
||||
QString copy(message);
|
||||
|
||||
// Replace the first line
|
||||
@@ -125,7 +125,7 @@ QString ReplaceMessage(const QString &message, const Song &song, const QString &
|
||||
pos += match.capturedLength();
|
||||
}
|
||||
|
||||
qint64 index_of = copy.indexOf(QRegularExpression(" - (>|$)"));
|
||||
qint64 index_of = copy.indexOf(QRegularExpression(QStringLiteral(" - (>|$)")));
|
||||
if (index_of >= 0) copy = copy.remove(index_of, 3);
|
||||
|
||||
return copy;
|
||||
|
||||
@@ -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(" ");
|
||||
return parts.join(QStringLiteral(" "));
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ QString PrettyFutureDate(const QDate date) {
|
||||
|
||||
QDateTime ParseRFC822DateTime(const QString &text) {
|
||||
|
||||
QRegularExpression regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
||||
QRegularExpression regexp(QStringLiteral("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})"));
|
||||
QRegularExpressionMatch re_match = regexp.match(text);
|
||||
if (!re_match.hasMatch()) {
|
||||
return QDateTime();
|
||||
@@ -116,30 +116,30 @@ QDateTime ParseRFC822DateTime(const QString &text) {
|
||||
enum class MatchNames { DAYS = 1, MONTHS, YEARS, HOURS, MINUTES, SECONDS };
|
||||
|
||||
QMap<QString, int> monthmap;
|
||||
monthmap["Jan"] = 1;
|
||||
monthmap["Feb"] = 2;
|
||||
monthmap["Mar"] = 3;
|
||||
monthmap["Apr"] = 4;
|
||||
monthmap["May"] = 5;
|
||||
monthmap["Jun"] = 6;
|
||||
monthmap["Jul"] = 7;
|
||||
monthmap["Aug"] = 8;
|
||||
monthmap["Sep"] = 9;
|
||||
monthmap["Oct"] = 10;
|
||||
monthmap["Nov"] = 11;
|
||||
monthmap["Dec"] = 12;
|
||||
monthmap["January"] = 1;
|
||||
monthmap["February"] = 2;
|
||||
monthmap["March"] = 3;
|
||||
monthmap["April"] = 4;
|
||||
monthmap["May"] = 5;
|
||||
monthmap["June"] = 6;
|
||||
monthmap["July"] = 7;
|
||||
monthmap["August"] = 8;
|
||||
monthmap["September"] = 9;
|
||||
monthmap["October"] = 10;
|
||||
monthmap["November"] = 11;
|
||||
monthmap["December"] = 12;
|
||||
monthmap[QStringLiteral("Jan")] = 1;
|
||||
monthmap[QStringLiteral("Feb")] = 2;
|
||||
monthmap[QStringLiteral("Mar")] = 3;
|
||||
monthmap[QStringLiteral("Apr")] = 4;
|
||||
monthmap[QStringLiteral("May")] = 5;
|
||||
monthmap[QStringLiteral("Jun")] = 6;
|
||||
monthmap[QStringLiteral("Jul")] = 7;
|
||||
monthmap[QStringLiteral("Aug")] = 8;
|
||||
monthmap[QStringLiteral("Sep")] = 9;
|
||||
monthmap[QStringLiteral("Oct")] = 10;
|
||||
monthmap[QStringLiteral("Nov")] = 11;
|
||||
monthmap[QStringLiteral("Dec")] = 12;
|
||||
monthmap[QStringLiteral("January")] = 1;
|
||||
monthmap[QStringLiteral("February")] = 2;
|
||||
monthmap[QStringLiteral("March")] = 3;
|
||||
monthmap[QStringLiteral("April")] = 4;
|
||||
monthmap[QStringLiteral("May")] = 5;
|
||||
monthmap[QStringLiteral("June")] = 6;
|
||||
monthmap[QStringLiteral("July")] = 7;
|
||||
monthmap[QStringLiteral("August")] = 8;
|
||||
monthmap[QStringLiteral("September")] = 9;
|
||||
monthmap[QStringLiteral("October")] = 10;
|
||||
monthmap[QStringLiteral("November")] = 11;
|
||||
monthmap[QStringLiteral("December")] = 12;
|
||||
|
||||
const QDate date(re_match.captured(static_cast<int>(MatchNames::YEARS)).toInt(), monthmap[re_match.captured(static_cast<int>(MatchNames::MONTHS))], re_match.captured(static_cast<int>(MatchNames::DAYS)).toInt());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user