Commit e9cca953 authored by Frederik Gladhorn's avatar Frederik Gladhorn

Be strict about implicit string casts

Summary:
Use QT_NO_CAST_FROM_ASCII and friends. There are a bunch of places where
QString should really be QByteArray, but that's for the future.

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: zzag, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14065
parent 88843a4e
......@@ -7,6 +7,15 @@ set(KSCREEN_VERSION ${PROJECT_VERSION})
add_definitions("-DKSCREEN_VERSION=\"${KSCREEN_VERSION}\"")
add_definitions(
-DQT_USE_QSTRINGBUILDER
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_STRICT_ITERATORS
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
)
set(QT_MIN_VERSION "5.9.0")
set(KF5_MIN_VERSION "5.42.0")
......
......@@ -188,7 +188,7 @@ void Console::printJSONConfig()
void Console::printSerializations()
{
QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/kscreen/";
QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kscreen/");
qDebug() << "Configs in: " << path;
QDir dir(path);
......@@ -199,7 +199,7 @@ void Console::printSerializations()
Q_FOREACH(const QString fileName, files) {
QJsonParseError error;
qDebug() << fileName;
QFile file(path + "/" + fileName);
QFile file(path + QLatin1Char('/') + fileName);
file.open(QFile::ReadOnly);
QVariant data = parser.fromJson(file.readAll(), &error);
if (error.error != QJsonParseError::NoError) {
......
......@@ -48,7 +48,7 @@ QString Utils::outputName(const KScreen::Output *output)
name += output->edid()->name() + QLatin1Char(' ');
}
if (!name.trimmed().isEmpty()) {
return name + QStringLiteral("(%1)").arg(output->name());
return name + QLatin1Char('(') + output->name() + QLatin1Char(')');
}
}
return output->name();
......
......@@ -113,7 +113,7 @@ void KScreenDaemon::init()
connect(Device::self(), &Device::lidClosedChanged, this, &KScreenDaemon::lidClosedChanged);
connect(Device::self(), &Device::resumingFromSuspend, this,
[&]() {
KScreen::Log::instance()->setContext("resuming");
KScreen::Log::instance()->setContext(QLatin1String("resuming"));
qCDebug(KSCREEN_KDED) << "Resumed from suspend, checking for screen changes";
// We don't care about the result, we just want to force the backend
// to query XRandR so that it will detect possible changes that happened
......@@ -166,7 +166,7 @@ void KScreenDaemon::applyKnownConfig()
// We may look for a config that has been set when the lid was closed, Bug: 353029
if (Device::self()->isLaptop() && !Device::self()->isLidClosed()) {
Serializer::moveConfig(configId + QStringLiteral("_lidOpened"), configId);
Serializer::moveConfig(configId + QLatin1String("_lidOpened"), configId);
}
KScreen::ConfigPtr config = Serializer::config(m_monitoredConfig, configId);
......@@ -314,7 +314,7 @@ void KScreenDaemon::lidClosedChanged(bool lidIsClosed)
// then the configuration has changed while the lid was closed and we just
// use applyConfig() and see what we can do ...
const QString openConfigId = Serializer::configId(m_monitoredConfig) + QStringLiteral("_lidOpened");
const QString openConfigId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened");
if (Serializer::configExists(openConfigId)) {
const KScreen::ConfigPtr openedConfig = Serializer::config(m_monitoredConfig, openConfigId);
Serializer::removeConfig(openConfigId);
......@@ -344,7 +344,7 @@ void KScreenDaemon::lidClosedTimeout()
if (output->isConnected() && output->isEnabled()) {
// Save the current config with opened lid, just so that we know
// how to restore it later
const QString configId = Serializer::configId(m_monitoredConfig) + QStringLiteral("_lidOpened");
const QString configId = Serializer::configId(m_monitoredConfig) + QLatin1String("_lidOpened");
Serializer::saveConfig(m_monitoredConfig, configId);
disableOutput(m_monitoredConfig, output);
doApplyConfig(m_monitoredConfig);
......
......@@ -58,7 +58,7 @@ OsdManager::OsdManager(QObject *parent)
: QObject(parent)
, m_cleanupTimer(new QTimer(this))
{
qmlRegisterUncreatableType<OsdAction>("org.kde.KScreen", 1, 0, "OsdAction", "You cannot create OsdAction");
qmlRegisterUncreatableType<OsdAction>("org.kde.KScreen", 1, 0, "OsdAction", QStringLiteral("You cannot create OsdAction"));
// free up memory when the osd hasn't been used for more than 1 minute
m_cleanupTimer->setInterval(60000);
......
......@@ -75,7 +75,7 @@ QString Serializer::configId(const KScreen::ConfigPtr &currentConfig)
const QByteArray hash = QCryptographicHash::hash(hashList.join(QString()).toLatin1(),
QCryptographicHash::Md5).toHex();
//qCDebug(KSCREEN_KDED) << "\tConfig ID:" << hash;
return hash;
return QString::fromLatin1(hash);
}
bool Serializer::configExists(const KScreen::ConfigPtr &config)
......
......@@ -352,12 +352,12 @@ void TestSerializer::testIdenticalOutputs()
config->addOutput(output1);
QHash<QString, QPoint> positions;
positions["DisplayPort-0"] = QPoint(0, 1080);
positions["DisplayPort-1"] = QPoint(2100, 30);
positions["DisplayPort-2"] = QPoint(2100, 1080);
positions["DisplayPort-3"] = QPoint(4020, 0);
positions["DVI-0"] = QPoint(4020, 1080);
positions["DVI-1"] = QPoint(0, 0);
positions[QStringLiteral("DisplayPort-0")] = QPoint(0, 1080);
positions[QStringLiteral("DisplayPort-1")] = QPoint(2100, 30);
positions[QStringLiteral("DisplayPort-2")] = QPoint(2100, 1080);
positions[QStringLiteral("DisplayPort-3")] = QPoint(4020, 0);
positions[QStringLiteral("DVI-0")] = QPoint(4020, 1080);
positions[QStringLiteral("DVI-1")] = QPoint(0, 0);
config = Serializer::config(config, QStringLiteral("outputgrid_2x3.json"));
QVERIFY(config);
......@@ -402,7 +402,7 @@ void TestSerializer::testMoveConfig()
QCOMPARE(output2->isPrimary(), false);
// we fake the lid being closed, first save our current config to _lidOpened
Serializer::saveConfig(config, "0xdeadbeef_lidOpened");
Serializer::saveConfig(config, QStringLiteral("0xdeadbeef_lidOpened"));
// ... then switch off the panel, set primary to the other output
output->setEnabled(false);
......@@ -410,27 +410,27 @@ void TestSerializer::testMoveConfig()
output2->setPrimary(true);
// save config as the current one, this is the config we don't want restored, and which we'll overwrite
Serializer::saveConfig(config, "0xdeadbeef");
Serializer::saveConfig(config, QStringLiteral("0xdeadbeef"));
QCOMPARE(output->isEnabled(), false);
QCOMPARE(output->isPrimary(), false);
QCOMPARE(output2->isPrimary(), true);
// Check if both files exist
QFile openCfg(Serializer::configFileName("0xdeadbeef_lidOpened"));
QFile closedCfg(Serializer::configFileName("0xdeadbeef"));
QFile openCfg(Serializer::configFileName(QStringLiteral("0xdeadbeef_lidOpened")));
QFile closedCfg(Serializer::configFileName(QStringLiteral("0xdeadbeef")));
QVERIFY(openCfg.exists());
QVERIFY(closedCfg.exists());
// Switcheroo...
QVERIFY(Serializer::moveConfig("0xdeadbeef_lidOpened", "0xdeadbeef"));
QVERIFY(Serializer::moveConfig(QStringLiteral("0xdeadbeef_lidOpened"), QStringLiteral("0xdeadbeef")));
// Check actual files, src should be gone, dest must exist
QVERIFY(!openCfg.exists());
QVERIFY(closedCfg.exists());
// Now load the resulting config and make sure the laptop panel is enabled and primary again
config = Serializer::config(config, "0xdeadbeef");
config = Serializer::config(config, QStringLiteral("0xdeadbeef"));
output = config->connectedOutputs().first();
QCOMPARE(output->name(), QLatin1String("OUTPUT-1"));
......@@ -443,9 +443,9 @@ void TestSerializer::testMoveConfig()
QCOMPARE(output2->isPrimary(), false);
// Make sure we don't screw up when there's no _lidOpened config
QVERIFY(!Serializer::moveConfig("0xdeadbeef_lidOpened", "0xdeadbeef"));
QVERIFY(!Serializer::moveConfig(QStringLiteral("0xdeadbeef_lidOpened"), QStringLiteral("0xdeadbeef")));
config = Serializer::config(config, "0xdeadbeef");
config = Serializer::config(config, QStringLiteral("0xdeadbeef"));
output = config->connectedOutputs().first();
QCOMPARE(output->name(), QLatin1String("OUTPUT-1"));
......
......@@ -25,13 +25,13 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
QCommandLineOption dbus = QCommandLineOption(QStringList() << QStringLiteral("d") << "dbus",
QCommandLineOption dbus = QCommandLineOption(QStringList() << QStringLiteral("d") << QStringLiteral("dbus"),
QStringLiteral("Call over dbus"));
QCommandLineOption outputid = QCommandLineOption(QStringList() << QStringLiteral("o") << "outputidentifiers",
QCommandLineOption outputid = QCommandLineOption(QStringList() << QStringLiteral("o") << QStringLiteral("outputidentifiers"),
QStringLiteral("Show output identifier"));
QCommandLineOption icon = QCommandLineOption(QStringList() << QStringLiteral("i") << "icon",
QCommandLineOption icon = QCommandLineOption(QStringList() << QStringLiteral("i") << QStringLiteral("icon"),
QStringLiteral("Icon to use for OSD"), QStringLiteral("preferences-desktop-display-randr"));
QCommandLineOption message = QCommandLineOption(QStringList() << QStringLiteral("m") << "message",
QCommandLineOption message = QCommandLineOption(QStringList() << QStringLiteral("m") << QStringLiteral("message"),
QStringLiteral("Icon to use for OSD"), QStringLiteral("OSD Test"));
QCommandLineOption selector = QCommandLineOption({ QStringLiteral("s"), QStringLiteral("selector") },
QStringLiteral("Show new screen action selector"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment