From 79afa0b84d91468bdc663642b9d4ed27c1badc8f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 17 Jul 2023 23:18:26 +0800 Subject: [PATCH] Clean up coding style --- src/gui/powermanagement/powermanagement.h | 2 +- .../powermanagement/powermanagement_x11.cpp | 54 ++++++++++--------- src/gui/powermanagement/powermanagement_x11.h | 10 ++-- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/gui/powermanagement/powermanagement.h b/src/gui/powermanagement/powermanagement.h index d8019d79c..6fc42c679 100644 --- a/src/gui/powermanagement/powermanagement.h +++ b/src/gui/powermanagement/powermanagement.h @@ -61,6 +61,6 @@ private: PowerManagementInhibitor *m_inhibitor = nullptr; #endif #ifdef Q_OS_MACOS - IOPMAssertionID m_assertionID; + IOPMAssertionID m_assertionID {}; #endif }; diff --git a/src/gui/powermanagement/powermanagement_x11.cpp b/src/gui/powermanagement/powermanagement_x11.cpp index c50b99bc3..94f4dc8ea 100644 --- a/src/gui/powermanagement/powermanagement_x11.cpp +++ b/src/gui/powermanagement/powermanagement_x11.cpp @@ -38,17 +38,15 @@ PowerManagementInhibitor::PowerManagementInhibitor(QObject *parent) : QObject(parent) { - if (!QDBusConnection::sessionBus().isConnected()) { + if (!QDBusConnection::sessionBus().isConnected()) + { qDebug("D-Bus: Could not connect to session bus"); m_state = Error; } - else { + else + { m_state = Idle; } - - m_intendedState = Idle; - m_cookie = 0; - m_useGSM = true; } void PowerManagementInhibitor::requestIdle() @@ -73,12 +71,11 @@ void PowerManagementInhibitor::requestIdle() u"UnInhibit"_s); call.setArguments({m_cookie}); - QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); - auto *watcher = new QDBusPendingCallWatcher(pcall, this); + const QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); + const auto *watcher = new QDBusPendingCallWatcher(pcall, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); } - void PowerManagementInhibitor::requestBusy() { m_intendedState = Busy; @@ -108,45 +105,55 @@ void PowerManagementInhibitor::requestBusy() args << 4u; call.setArguments(args); - QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); - auto *watcher = new QDBusPendingCallWatcher(pcall, this); + const QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); + const auto *watcher = new QDBusPendingCallWatcher(pcall, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); } void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) { - if (m_state == RequestIdle) { - QDBusPendingReply<> reply = *call; + call->deleteLater(); - if (reply.isError()) { + if (m_state == RequestIdle) + { + const QDBusPendingReply reply = *call; + + if (reply.isError()) + { qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); m_state = Error; } - else { + else + { m_state = Idle; qDebug("D-Bus: PowerManagementInhibitor: Request successful"); if (m_intendedState == Busy) requestBusy(); } } - else if (m_state == RequestBusy) { - QDBusPendingReply reply = *call; + else if (m_state == RequestBusy) + { + const QDBusPendingReply reply = *call; - if (reply.isError()) { + if (reply.isError()) + { qDebug("D-Bus: Reply: Error: %s", qUtf8Printable(reply.error().message())); - if (m_useGSM) { + if (m_useGSM) + { qDebug("D-Bus: Falling back to org.freedesktop.PowerManagement"); m_useGSM = false; m_state = Idle; if (m_intendedState == Busy) requestBusy(); } - else { + else + { m_state = Error; } } - else { + else + { m_state = Busy; m_cookie = reply.value(); qDebug("D-Bus: PowerManagementInhibitor: Request successful, cookie is %d", m_cookie); @@ -154,10 +161,9 @@ void PowerManagementInhibitor::onAsyncReply(QDBusPendingCallWatcher *call) requestIdle(); } } - else { + else + { qDebug("D-Bus: Unexpected reply in state %d", m_state); m_state = Error; } - - call->deleteLater(); } diff --git a/src/gui/powermanagement/powermanagement_x11.h b/src/gui/powermanagement/powermanagement_x11.h index 5b9b6a88d..c40502e20 100644 --- a/src/gui/powermanagement/powermanagement_x11.h +++ b/src/gui/powermanagement/powermanagement_x11.h @@ -32,7 +32,7 @@ class QDBusPendingCallWatcher; -class PowerManagementInhibitor : public QObject +class PowerManagementInhibitor final : public QObject { Q_OBJECT Q_DISABLE_COPY_MOVE(PowerManagementInhibitor) @@ -57,9 +57,9 @@ private: RequestIdle }; - enum State m_state; - enum State m_intendedState; - unsigned int m_cookie; + enum State m_state = Error; + enum State m_intendedState = Idle; + quint32 m_cookie = 0; - bool m_useGSM; + bool m_useGSM = true; };