From d1074f64ae66113a1e0f31875fda4bc5840d65dd Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Wed, 8 Apr 2026 01:02:16 -0400 Subject: [PATCH] refactor(ipc): use more QStringLiterals --- src/lib/deskflow/ipc/CoreIpc.cpp | 2 +- src/lib/deskflow/ipc/CoreIpcServer.cpp | 2 +- src/lib/deskflow/ipc/DaemonIpcServer.cpp | 22 +++++++++++----------- src/lib/deskflow/ipc/IpcServer.cpp | 12 ++++++------ src/lib/gui/ipc/CoreIpcClient.cpp | 2 +- src/lib/gui/ipc/DaemonIpcClient.cpp | 18 +++++++++--------- src/lib/gui/ipc/IpcClient.cpp | 8 ++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/lib/deskflow/ipc/CoreIpc.cpp b/src/lib/deskflow/ipc/CoreIpc.cpp index 7dad7ca71..b48f1554d 100644 --- a/src/lib/deskflow/ipc/CoreIpc.cpp +++ b/src/lib/deskflow/ipc/CoreIpc.cpp @@ -24,5 +24,5 @@ void ipcSendToClient(const QString &command, const QString &args) void ipcSendConnectionState(deskflow::core::ConnectionState state) { const auto metaEnum = QMetaEnum::fromType(); - ipcSendToClient("connectionState", metaEnum.valueToKey(static_cast(state))); + ipcSendToClient(QStringLiteral("connectionState"), metaEnum.valueToKey(static_cast(state))); } diff --git a/src/lib/deskflow/ipc/CoreIpcServer.cpp b/src/lib/deskflow/ipc/CoreIpcServer.cpp index f73f72631..f0ad0a39d 100644 --- a/src/lib/deskflow/ipc/CoreIpcServer.cpp +++ b/src/lib/deskflow/ipc/CoreIpcServer.cpp @@ -15,7 +15,7 @@ namespace deskflow::core::ipc { static CoreIpcServer *s_instance = nullptr; -CoreIpcServer::CoreIpcServer(QObject *parent) : IpcServer(parent, kCoreIpcName, "core") +CoreIpcServer::CoreIpcServer(QObject *parent) : IpcServer(parent, kCoreIpcName, QStringLiteral("core")) { assert(s_instance == nullptr); s_instance = this; diff --git a/src/lib/deskflow/ipc/DaemonIpcServer.cpp b/src/lib/deskflow/ipc/DaemonIpcServer.cpp index 9d34eabca..374a9217b 100644 --- a/src/lib/deskflow/ipc/DaemonIpcServer.cpp +++ b/src/lib/deskflow/ipc/DaemonIpcServer.cpp @@ -17,7 +17,7 @@ const auto kAckMessage = "ok"; const auto kErrorMessage = "error"; DaemonIpcServer::DaemonIpcServer(QObject *parent, const QString &logFilename) - : IpcServer(parent, kDaemonIpcName, "daemon"), + : IpcServer(parent, kDaemonIpcName, QStringLiteral("daemon")), m_logFilename(logFilename) { // do nothing @@ -25,24 +25,24 @@ DaemonIpcServer::DaemonIpcServer(QObject *parent, const QString &logFilename) void DaemonIpcServer::processCommand(QLocalSocket *clientSocket, const QString &command, const QStringList &parts) { - if (command == "logLevel") { + if (command == QStringLiteral("logLevel")) { processLogLevel(clientSocket, parts); - } else if (command == "elevate") { + } else if (command == QStringLiteral("elevate")) { processElevate(clientSocket, parts); - } else if (command == "command") { + } else if (command == QStringLiteral("command")) { processCommandMessage(clientSocket, parts); - } else if (command == "start") { + } else if (command == QStringLiteral("start")) { LOG_DEBUG("daemon ipc server got start message"); Q_EMIT startProcessRequested(); writeToClientSocket(clientSocket, kAckMessage); - } else if (command == "stop") { + } else if (command == QStringLiteral("stop")) { LOG_DEBUG("daemon ipc server got stop message"); Q_EMIT stopProcessRequested(); writeToClientSocket(clientSocket, kAckMessage); - } else if (command == "logPath") { + } else if (command == QStringLiteral("logPath")) { LOG_DEBUG("daemon ipc server got log path request"); - writeToClientSocket(clientSocket, "logPath=" + m_logFilename.toUtf8()); - } else if (command == "clearSettings") { + writeToClientSocket(clientSocket, QStringLiteral("logPath=%1").arg(m_logFilename.toUtf8())); + } else if (command == QStringLiteral("clearSettings")) { LOG_DEBUG("daemon ipc server got clear settings message"); Q_EMIT clearSettingsRequested(); writeToClientSocket(clientSocket, kAckMessage); @@ -80,14 +80,14 @@ void DaemonIpcServer::processElevate(QLocalSocket *&clientSocket, const QStringL } const auto &elevate = messageParts[1]; - if (elevate != "yes" && elevate != "no") { + if (elevate != QStringLiteral("yes") && elevate != QStringLiteral("no")) { LOG_ERR("daemon ipc server got invalid elevate value: %s", elevate.toUtf8().constData()); writeToClientSocket(clientSocket, kErrorMessage); return; } LOG_DEBUG("daemon ipc server got new elevate value: %s", elevate.toUtf8().constData()); - Q_EMIT elevateModeChanged(elevate == "yes"); + Q_EMIT elevateModeChanged(elevate == QStringLiteral("yes")); writeToClientSocket(clientSocket, kAckMessage); } diff --git a/src/lib/deskflow/ipc/IpcServer.cpp b/src/lib/deskflow/ipc/IpcServer.cpp index 50ebe04f5..616a3f388 100644 --- a/src/lib/deskflow/ipc/IpcServer.cpp +++ b/src/lib/deskflow/ipc/IpcServer.cpp @@ -107,11 +107,11 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag const auto parts = message.split('='); if (parts.isEmpty()) { LOG_ERR("%s ipc server got invalid message: %s", m_typeName.constData(), message.toUtf8().constData()); - writeToClientSocket(clientSocket, "error"); + writeToClientSocket(clientSocket, QStringLiteral("error")); return; } - if (const auto &command = parts.at(0); command == "hello") { + if (const auto &command = parts.at(0); command == QStringLiteral("hello")) { if (parts.size() < 2) { LOG_ERR("%s ipc client hello missing version", m_typeName.constData()); writeToClientSocket(clientSocket, "error=missing version"); @@ -136,7 +136,7 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag } LOG_DEBUG("%s ipc server sending hello back", m_typeName.constData()); - writeToClientSocket(clientSocket, QString("hello=%1").arg(versionId)); + writeToClientSocket(clientSocket, QStringLiteral("hello=%1").arg(versionId)); // Replay messages that were queued before any clients connected. LOG_DEBUG1("ipc server replaying %d pending messages", m_pendingMessages.size()); @@ -145,9 +145,9 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag writeToClientSocket(clientSocket, pending); } m_pendingMessages.clear(); - } else if (command == "noop") { + } else if (command == QStringLiteral("noop")) { LOG_DEBUG("%s ipc server got noop message", m_typeName.constData()); - writeToClientSocket(clientSocket, "ok"); + writeToClientSocket(clientSocket, QStringLiteral("ok")); } else { processCommand(clientSocket, command, parts); } @@ -157,7 +157,7 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag void IpcServer::broadcastCommand(const QString &command, const QString &args) { - const auto message = args.isEmpty() ? command : command + "=" + args; + const auto message = args.isEmpty() ? command : QStringLiteral("%1=%2").arg(command, args); if (m_clients.isEmpty()) { LOG_DEBUG1( diff --git a/src/lib/gui/ipc/CoreIpcClient.cpp b/src/lib/gui/ipc/CoreIpcClient.cpp index ccfa2ed5e..c4633b2ab 100644 --- a/src/lib/gui/ipc/CoreIpcClient.cpp +++ b/src/lib/gui/ipc/CoreIpcClient.cpp @@ -15,7 +15,7 @@ namespace deskflow::gui::ipc { -CoreIpcClient::CoreIpcClient(QObject *parent) : IpcClient(parent, kCoreIpcName, "core") +CoreIpcClient::CoreIpcClient(QObject *parent) : IpcClient(parent, kCoreIpcName, QStringLiteral("core")) { // do nothing } diff --git a/src/lib/gui/ipc/DaemonIpcClient.cpp b/src/lib/gui/ipc/DaemonIpcClient.cpp index 454d8f354..41a4bba66 100644 --- a/src/lib/gui/ipc/DaemonIpcClient.cpp +++ b/src/lib/gui/ipc/DaemonIpcClient.cpp @@ -12,41 +12,41 @@ namespace deskflow::gui::ipc { -DaemonIpcClient::DaemonIpcClient(QObject *parent) : IpcClient(parent, kDaemonIpcName, "daemon") +DaemonIpcClient::DaemonIpcClient(QObject *parent) : IpcClient(parent, kDaemonIpcName, QStringLiteral("daemon")) { } void DaemonIpcClient::sendLogLevel(const QString &logLevel) { - sendMessage("logLevel=" + logLevel); + sendMessage(QStringLiteral("logLevel=%1").arg(logLevel)); } void DaemonIpcClient::sendStartProcess(const QString &command, bool elevate) { const auto elevateStr = elevate ? QStringLiteral("yes") : QStringLiteral("no"); - sendMessage("elevate=" + elevateStr); - sendMessage("command=" + command); - sendMessage("start"); + sendMessage(QStringLiteral("elevate=%1").arg(elevateStr)); + sendMessage(QStringLiteral("command=%1").arg(command)); + sendMessage(QStringLiteral("start")); } void DaemonIpcClient::sendStopProcess() { - sendMessage("stop"); + sendMessage(QStringLiteral("stop")); } void DaemonIpcClient::sendClearSettings() { - sendMessage("clearSettings"); + sendMessage(QStringLiteral("clearSettings")); } void DaemonIpcClient::requestLogPath() { - sendMessage("logPath"); + sendMessage(QStringLiteral("logPath")); } void DaemonIpcClient::processCommand(const QString &command, const QStringList &parts) { - if (command == "logPath" && parts.size() == 2) { + if (command == QStringLiteral("logPath") && parts.size() == 2) { Q_EMIT logPathReceived(parts[1]); } } diff --git a/src/lib/gui/ipc/IpcClient.cpp b/src/lib/gui/ipc/IpcClient.cpp index 37a7ee856..79a5d1187 100644 --- a/src/lib/gui/ipc/IpcClient.cpp +++ b/src/lib/gui/ipc/IpcClient.cpp @@ -161,15 +161,15 @@ void IpcClient::handleReadyRead() void IpcClient::handleHandshakeMessage(const QStringList &parts) { - if (parts.at(0) == "error") { - const auto detail = parts.size() >= 2 ? parts.at(1) : QString("unknown"); - qCritical().noquote() << m_typeName << "ipc server rejected connection:" << detail; + if (parts.at(0) == QStringLiteral("error")) { + const auto detail = parts.size() >= 2 ? parts.at(1) : QStringLiteral("unknown"); + qCritical().noquote() << QStringLiteral("%1 ipc server rejected connection: %2").arg(m_typeName, detail); disconnectFromServer(); Q_EMIT connectionFailed(); return; } - if (parts.at(0) != "hello") { + if (parts.at(0) != QStringLiteral("hello")) { return; }