Skip to content

Commit 6a9b4db

Browse files
committed
Refactor code for improved readability and consistency across CPU, GPU, and system monitoring components
1 parent 878a40c commit 6a9b4db

12 files changed

Lines changed: 163 additions & 151 deletions

src/backend/monitor/cpumonitor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ int readCpuTemperatureFromSensors() {
201201

202202
int readCpuTemperatureFromAcpi() {
203203
CommandRunner runner;
204-
const auto result = runner.run(QStringLiteral("acpi"), {QStringLiteral("-t")});
204+
const auto result =
205+
runner.run(QStringLiteral("acpi"), {QStringLiteral("-t")});
205206
return result.success() ? parseTemperatureFromPlainText(result.stdout) : 0;
206207
}
207208

@@ -330,9 +331,10 @@ void CpuMonitor::refresh() {
330331

331332
const int temperatureC = readCpuTemperatureC();
332333
setTemperatureC(temperatureC);
333-
setStatusMessage(temperatureC > 0
334-
? tr("CPU temperature is being read from system sensors.")
335-
: tr("CPU temperature sensor is not exposed by the kernel."));
334+
setStatusMessage(
335+
temperatureC > 0
336+
? tr("CPU temperature is being read from system sensors.")
337+
: tr("CPU temperature sensor is not exposed by the kernel."));
336338
setAvailable(true);
337339
}
338340

src/backend/monitor/cpumonitor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#pragma once
22

3-
#include <QObject>
43
#include <QElapsedTimer>
4+
#include <QObject>
55
#include <QTimer>
66

77
// Gercek zamanli CPU istatistikleri
88
class CpuMonitor : public QObject {
99
Q_OBJECT
1010
Q_PROPERTY(double usagePercent READ usagePercent NOTIFY usagePercentChanged)
1111
Q_PROPERTY(int temperatureC READ temperatureC NOTIFY temperatureCChanged)
12-
Q_PROPERTY(QString statusMessage READ statusMessage NOTIFY statusMessageChanged)
12+
Q_PROPERTY(
13+
QString statusMessage READ statusMessage NOTIFY statusMessageChanged)
1314
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
1415
Q_PROPERTY(bool running READ running NOTIFY runningChanged)
1516
Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval

src/backend/monitor/gpumonitor.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ bool readNvidiaTemperatureFromHwmonClass(int *value) {
119119
.entryInfoList({QStringLiteral("hwmon*")},
120120
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
121121
for (const QFileInfo &entry : hwmonEntries) {
122-
if (!isGpuHwmonName(readFileText(entry.absoluteFilePath() +
123-
QStringLiteral("/name")))) {
122+
if (!isGpuHwmonName(
123+
readFileText(entry.absoluteFilePath() + QStringLiteral("/name")))) {
124124
continue;
125125
}
126126

@@ -201,9 +201,10 @@ bool readTemperatureFromSensorsOutput(const QString &text, int *value) {
201201
bool readTemperatureFromSensorsCommand(CommandRunner &runner, int *value) {
202202
CommandRunner::RunOptions options;
203203
options.timeoutMs = 1500;
204-
const auto result = runner.run(QStringLiteral("sensors"),
205-
{QStringLiteral("-u")}, options);
206-
return result.success() && readTemperatureFromSensorsOutput(result.stdout, value);
204+
const auto result =
205+
runner.run(QStringLiteral("sensors"), {QStringLiteral("-u")}, options);
206+
return result.success() &&
207+
readTemperatureFromSensorsOutput(result.stdout, value);
207208
}
208209

209210
bool readTemperatureFromNvidiaSettings(CommandRunner &runner, int *value) {
@@ -218,9 +219,10 @@ bool readTemperatureFromNvidiaSettings(CommandRunner &runner, int *value) {
218219
return false;
219220
}
220221

221-
const QString line = result.stdout.split(QLatin1Char('\n'), Qt::SkipEmptyParts)
222-
.value(0)
223-
.trimmed();
222+
const QString line =
223+
result.stdout.split(QLatin1Char('\n'), Qt::SkipEmptyParts)
224+
.value(0)
225+
.trimmed();
224226
return parseMetricInt(line, value);
225227
}
226228

@@ -353,8 +355,8 @@ void GpuMonitor::refresh() {
353355
int nextUsed = 0;
354356
int nextTotal = 0;
355357

356-
const bool hasGenericMetrics = readGenericLinuxGpuMetrics(
357-
&nextTemp, &nextUtil, &nextUsed, &nextTotal);
358+
const bool hasGenericMetrics =
359+
readGenericLinuxGpuMetrics(&nextTemp, &nextUtil, &nextUsed, &nextTotal);
358360
const bool hasTemperatureFallback =
359361
nextTemp > 0 || readNvidiaTemperatureFallback(runner, &nextTemp);
360362

@@ -400,9 +402,10 @@ void GpuMonitor::refresh() {
400402
}
401403

402404
setAvailable(true);
403-
setStatusMessage(hasGenericMetrics
404-
? tr("GPU telemetry is being read from Linux metrics.")
405-
: tr("GPU temperature is being read from system sensors."));
405+
setStatusMessage(
406+
hasGenericMetrics
407+
? tr("GPU telemetry is being read from Linux metrics.")
408+
: tr("GPU temperature is being read from system sensors."));
406409
return;
407410
}
408411

@@ -450,7 +453,8 @@ void GpuMonitor::refresh() {
450453
totalAvailable;
451454
if (!telemetryAvailable) {
452455
setAvailable(false);
453-
setStatusMessage(tr("GPU telemetry output did not contain usable metrics."));
456+
setStatusMessage(
457+
tr("GPU telemetry output did not contain usable metrics."));
454458
clearMetrics();
455459
return;
456460
}

src/backend/monitor/gpumonitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class GpuMonitor : public QObject {
1717
int memoryTotalMiB READ memoryTotalMiB NOTIFY memoryTotalMiBChanged)
1818
Q_PROPERTY(int memoryUsagePercent READ memoryUsagePercent NOTIFY
1919
memoryUsagePercentChanged)
20-
Q_PROPERTY(QString statusMessage READ statusMessage NOTIFY statusMessageChanged)
20+
Q_PROPERTY(
21+
QString statusMessage READ statusMessage NOTIFY statusMessageChanged)
2122
Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval
2223
NOTIFY updateIntervalChanged)
2324

src/backend/nvidia/detector.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "system/commandrunner.h"
55
#include "system/sessionutil.h"
66

7-
#include <QFile>
87
#include <QDir>
8+
#include <QFile>
99
#include <QRegularExpression>
1010
#include <QTextStream>
1111
#include <QtGlobal>
@@ -211,11 +211,10 @@ QString NvidiaDetector::detectDriverPackageVersion() const {
211211
QStringLiteral("akmod-nvidia-open")};
212212
CommandRunner runner;
213213
for (const QString &packageName : packageNames) {
214-
const auto result =
215-
runner.run(QStringLiteral("rpm"),
216-
{QStringLiteral("-q"), QStringLiteral("--qf"),
217-
QStringLiteral("%{EPOCH}:%{VERSION}-%{RELEASE}"),
218-
packageName});
214+
const auto result = runner.run(
215+
QStringLiteral("rpm"),
216+
{QStringLiteral("-q"), QStringLiteral("--qf"),
217+
QStringLiteral("%{EPOCH}:%{VERSION}-%{RELEASE}"), packageName});
219218
if (result.success()) {
220219
const QString version = normalizedRpmDriverVersion(result.stdout);
221220
if (!version.isEmpty()) {

src/backend/nvidia/installer.cpp

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ void NvidiaInstaller::cancelOperation() {
270270
}
271271

272272
m_cancelRequested->store(true, std::memory_order_relaxed);
273-
emit progressMessage(tr("Cancel requested. Waiting for the active command to stop safely..."));
273+
emit progressMessage(
274+
tr("Cancel requested. Waiting for the active command to stop safely..."));
274275
}
275276

276277
void NvidiaInstaller::setProprietaryAgreement(bool required,
@@ -368,7 +369,8 @@ void NvidiaInstaller::installProprietary(bool agreementAccepted) {
368369
return;
369370
}
370371

371-
const SessionUtil::SessionInfo sessionInfo = SessionUtil::detectSessionInfo();
372+
const SessionUtil::SessionInfo sessionInfo =
373+
SessionUtil::detectSessionInfo();
372374
const QString sessionType = sessionInfo.type.trimmed().toLower();
373375
if (sessionType != QStringLiteral("wayland") &&
374376
sessionType != QStringLiteral("x11")) {
@@ -393,13 +395,12 @@ void NvidiaInstaller::installProprietary(bool agreementAccepted) {
393395
"Installing the closed-source NVIDIA driver with one privileged "
394396
"authorization..."));
395397
emitProgressAsync(
396-
guard,
397-
NvidiaInstaller::tr("Closed-source install packages for %1: %2")
398-
.arg(sessionType == QStringLiteral("wayland")
399-
? NvidiaInstaller::tr("Wayland")
400-
: NvidiaInstaller::tr("X11"))
401-
.arg(quotedList(buildDriverInstallTargets(
402-
QStringLiteral("akmod-nvidia"), sessionType))));
398+
guard, NvidiaInstaller::tr("Closed-source install packages for %1: %2")
399+
.arg(sessionType == QStringLiteral("wayland")
400+
? NvidiaInstaller::tr("Wayland")
401+
: NvidiaInstaller::tr("X11"))
402+
.arg(quotedList(buildDriverInstallTargets(
403+
QStringLiteral("akmod-nvidia"), sessionType))));
403404

404405
QStringList installArgs{QStringLiteral("install"), QStringLiteral("-y"),
405406
QStringLiteral("--refresh"),
@@ -423,21 +424,21 @@ void NvidiaInstaller::installProprietary(bool agreementAccepted) {
423424
{QStringLiteral("akmods"), {QStringLiteral("--force")}});
424425
rootCommands.append(buildSessionSpecificRootCommands(sessionType));
425426

426-
emitProgressAsync(
427-
guard, NvidiaInstaller::tr("Detected %1 session via %2.")
428-
.arg(sessionType == QStringLiteral("wayland")
429-
? NvidiaInstaller::tr("Wayland")
430-
: NvidiaInstaller::tr("X11"),
431-
sessionInfo.source.isEmpty()
432-
? NvidiaInstaller::tr("session probe")
433-
: sessionInfo.source));
427+
emitProgressAsync(guard, NvidiaInstaller::tr("Detected %1 session via %2.")
428+
.arg(sessionType == QStringLiteral("wayland")
429+
? NvidiaInstaller::tr("Wayland")
430+
: NvidiaInstaller::tr("X11"),
431+
sessionInfo.source.isEmpty()
432+
? NvidiaInstaller::tr("session probe")
433+
: sessionInfo.source));
434434

435435
auto result = runner.runAsRootBatch(rootCommands, runOptions);
436436
if (!result.success()) {
437-
const QString error = commandCanceled(result)
438-
? NvidiaInstaller::tr("Operation canceled by user.")
439-
: NvidiaInstaller::tr("Installation failed: ") +
440-
commandError(result);
437+
const QString error =
438+
commandCanceled(result)
439+
? NvidiaInstaller::tr("Operation canceled by user.")
440+
: NvidiaInstaller::tr("Installation failed: ") +
441+
commandError(result);
441442
QMetaObject::invokeMethod(
442443
guard,
443444
[guard, error]() {
@@ -493,7 +494,8 @@ void NvidiaInstaller::installOpenSource() {
493494
NvidiaInstaller::tr(
494495
"Switching to the community open-source graphics driver stack..."));
495496

496-
const SessionUtil::SessionInfo sessionInfo = SessionUtil::detectSessionInfo();
497+
const SessionUtil::SessionInfo sessionInfo =
498+
SessionUtil::detectSessionInfo();
497499
const QString sessionType = sessionInfo.type.trimmed().toLower();
498500
if (sessionType != QStringLiteral("wayland") &&
499501
sessionType != QStringLiteral("x11")) {
@@ -525,14 +527,13 @@ void NvidiaInstaller::installOpenSource() {
525527
QList<CommandRunner::RootCommand> rootCommands =
526528
buildCommunityNouveauRootCommands(sessionType);
527529

528-
emitProgressAsync(
529-
guard, NvidiaInstaller::tr("Detected %1 session via %2.")
530-
.arg(sessionType == QStringLiteral("wayland")
531-
? NvidiaInstaller::tr("Wayland")
532-
: NvidiaInstaller::tr("X11"),
533-
sessionInfo.source.isEmpty()
534-
? NvidiaInstaller::tr("session probe")
535-
: sessionInfo.source));
530+
emitProgressAsync(guard, NvidiaInstaller::tr("Detected %1 session via %2.")
531+
.arg(sessionType == QStringLiteral("wayland")
532+
? NvidiaInstaller::tr("Wayland")
533+
: NvidiaInstaller::tr("X11"),
534+
sessionInfo.source.isEmpty()
535+
? NvidiaInstaller::tr("session probe")
536+
: sessionInfo.source));
536537

537538
auto result = runner.runAsRootBatch(rootCommands, runOptions);
538539
if (!result.success()) {
@@ -598,12 +599,11 @@ void NvidiaInstaller::remove() {
598599

599600
const bool success = result.success();
600601
const QString message =
601-
success
602-
? NvidiaInstaller::tr("Driver removed successfully.")
603-
: (commandCanceled(result)
604-
? NvidiaInstaller::tr("Operation canceled by user.")
605-
: NvidiaInstaller::tr("Removal failed: ") +
606-
result.stderr.trimmed());
602+
success ? NvidiaInstaller::tr("Driver removed successfully.")
603+
: (commandCanceled(result)
604+
? NvidiaInstaller::tr("Operation canceled by user.")
605+
: NvidiaInstaller::tr("Removal failed: ") +
606+
result.stderr.trimmed());
607607
QMetaObject::invokeMethod(
608608
guard,
609609
[guard, success, message]() {
@@ -661,10 +661,9 @@ void NvidiaInstaller::deepClean() {
661661
return;
662662
}
663663

664-
const auto cleanResult =
665-
runner.runAsRoot(QStringLiteral("dnf"),
666-
{QStringLiteral("clean"), QStringLiteral("all")},
667-
runOptions);
664+
const auto cleanResult = runner.runAsRoot(
665+
QStringLiteral("dnf"), {QStringLiteral("clean"), QStringLiteral("all")},
666+
runOptions);
668667
if (!cleanResult.success()) {
669668
const QString error =
670669
commandCanceled(cleanResult)

0 commit comments

Comments
 (0)