Use new Qt6 QStringLiteral operator

Shorter than typing QStringLiteral all the time
This commit is contained in:
Carl Schwan 2024-01-17 01:07:31 +01:00
parent b070f6e3f7
commit d161292426
No known key found for this signature in database
GPG key ID: 02325448204E452A
2 changed files with 23 additions and 21 deletions

View file

@ -14,10 +14,12 @@
#include "settings.h" #include "settings.h"
#include "version.h" #include "version.h"
using namespace Qt::Literals::StringLiterals;
QCommandLineParser *createParser() QCommandLineParser *createParser()
{ {
QCommandLineParser *parser = new QCommandLineParser; QCommandLineParser *parser = new QCommandLineParser;
parser->addOption(QCommandLineOption(QStringLiteral("apply-settings"), "Applies the correct system settings for the current environment.")); parser->addOption(QCommandLineOption(u"apply-settings"_s, u"Applies the correct system settings for the current environment."_s));
parser->addVersionOption(); parser->addVersionOption();
parser->addHelpOption(); parser->addHelpOption();
return parser; return parser;
@ -33,12 +35,12 @@ int main(int argc, char *argv[])
// start wizard // start wizard
KLocalizedString::setApplicationDomain("plasma-mobile-envmanager"); KLocalizedString::setApplicationDomain("plasma-mobile-envmanager");
QCoreApplication::setApplicationName(QStringLiteral("plasma-mobile-envmanager")); QCoreApplication::setApplicationName(u"plasma-mobile-envmanager"_s);
QCoreApplication::setApplicationVersion(QStringLiteral(PLASMA_MOBILE_VERSION_STRING)); QCoreApplication::setApplicationVersion(QStringLiteral(PLASMA_MOBILE_VERSION_STRING));
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); QCoreApplication::setOrganizationDomain(u"kde.org"_s);
// apply configuration // apply configuration
if (parser->isSet(QStringLiteral("apply-settings"))) { if (parser->isSet(u"apply-settings"_s)) {
Settings::self().applyConfiguration(); Settings::self().applyConfiguration();
} else { } else {
parser->showHelp(); parser->showHelp();

View file

@ -13,16 +13,18 @@
#include <QDebug> #include <QDebug>
#include <QProcess> #include <QProcess>
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc"); using namespace Qt::Literals::StringLiterals;
const QString SAVED_CONFIG_GROUP = QStringLiteral("SavedConfig");
const QString CONFIG_FILE = u"plasmamobilerc"_s;
const QString SAVED_CONFIG_GROUP = u"SavedConfig"_s;
Settings::Settings(QObject *parent) Settings::Settings(QObject *parent)
: QObject{parent} : QObject{parent}
, m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))} , m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(u"phone"_s)}
, m_mobileConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} , m_mobileConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)}
, m_kwinrcConfig{KSharedConfig::openConfig(QStringLiteral("kwinrc"), KConfig::SimpleConfig)} , m_kwinrcConfig{KSharedConfig::openConfig(u"kwinrc"_s, KConfig::SimpleConfig)}
, m_appBlacklistConfig{KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc"), KConfig::SimpleConfig)} , m_appBlacklistConfig{KSharedConfig::openConfig(u"applications-blacklistrc"_s, KConfig::SimpleConfig)}
, m_kdeglobalsConfig{KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig)} , m_kdeglobalsConfig{KSharedConfig::openConfig(u"kdeglobals"_s, KConfig::SimpleConfig)}
, m_configWatcher{KConfigWatcher::create(m_mobileConfig)} , m_configWatcher{KConfigWatcher::create(m_mobileConfig)}
{ {
} }
@ -49,17 +51,17 @@ void Settings::applyConfiguration()
void Settings::loadSavedConfiguration() void Settings::loadSavedConfiguration()
{ {
// kwinrc // kwinrc
loadKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig)); loadKeys(u"kwinrc"_s, m_kwinrcConfig, getKwinrcSettings(m_mobileConfig));
m_kwinrcConfig->sync(); m_kwinrcConfig->sync();
reloadKWinConfig(); reloadKWinConfig();
// applications-blacklistrc // applications-blacklistrc
loadKeys(QStringLiteral("applications-blacklistrc"), m_appBlacklistConfig, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS); loadKeys(u"applications-blacklistrc"_s, m_appBlacklistConfig, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS);
m_appBlacklistConfig->sync(); m_appBlacklistConfig->sync();
// kdeglobals // kdeglobals
loadKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS); loadKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS);
loadKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_SETTINGS); loadKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_SETTINGS);
m_kdeglobalsConfig->sync(); m_kdeglobalsConfig->sync();
// save our changes // save our changes
@ -69,23 +71,21 @@ void Settings::loadSavedConfiguration()
void Settings::applyMobileConfiguration() void Settings::applyMobileConfiguration()
{ {
// kwinrc // kwinrc
writeKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false); writeKeys(u"kwinrc"_s, m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false);
m_kwinrcConfig->sync(); m_kwinrcConfig->sync();
reloadKWinConfig(); reloadKWinConfig();
// applications-blacklistrc // applications-blacklistrc
writeKeys(QStringLiteral("applications-blacklistrc"), writeKeys(u"applications-blacklistrc"_s,
m_appBlacklistConfig, m_appBlacklistConfig,
APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS, APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS,
true); // only write entries if they are not already defined in the config true); // only write entries if they are not already defined in the config
m_appBlacklistConfig->sync(); m_appBlacklistConfig->sync();
// kdeglobals // kdeglobals
writeKeys(QStringLiteral("kdeglobals"), writeKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS,
m_kdeglobalsConfig,
KDEGLOBALS_DEFAULT_SETTINGS,
true); // only write entries if they are not already defined in the config true); // only write entries if they are not already defined in the config
writeKeys(QStringLiteral("kdeglobals"), m_kdeglobalsConfig, KDEGLOBALS_SETTINGS, false); writeKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_SETTINGS, false);
m_kdeglobalsConfig->sync(); m_kdeglobalsConfig->sync();
// save our changes // save our changes
@ -166,6 +166,6 @@ const QString Settings::loadSavedConfigSetting(KSharedConfig::Ptr &config, const
void Settings::reloadKWinConfig() void Settings::reloadKWinConfig()
{ {
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); QDBusMessage message = QDBusMessage::createSignal(u"/KWin"_s, u"org.kde.KWin"_s, u"reloadConfig"_s);
QDBusConnection::sessionBus().send(message); QDBusConnection::sessionBus().send(message);
} }