do not derive from qwidget in aggregates

This commit is contained in:
2024-03-21 18:08:19 +02:00
parent 33a41bb6c0
commit 67640cccdc
35 changed files with 428 additions and 444 deletions

View File

@ -59,13 +59,13 @@ KSysGuard::SensorInfo *SystemInfoSource::initialData(const QString &_source) con
qCDebug(LOG_ESS) << "Source" << _source;
auto data = new KSysGuard::SensorInfo();
if (_source == "system/brightness") {
if (_source == "brightness") {
data->min = 0.0;
data->max = 100.0;
data->name = "Screen brightness";
data->variantType = QVariant::Double;
data->unit = KSysGuard::UnitPercent;
} else if (_source == "system/volume") {
} else if (_source == "volume") {
data->min = 0.0;
data->max = 100.0;
data->name = "Master volume";
@ -79,16 +79,16 @@ KSysGuard::SensorInfo *SystemInfoSource::initialData(const QString &_source) con
void SystemInfoSource::run()
{
m_values["system/brightness"] = SystemInfoSource::getCurrentBrightness();
m_values["system/volume"] = SystemInfoSource::getCurrentVolume();
m_values["brightness"] = SystemInfoSource::getCurrentBrightness();
m_values["volume"] = SystemInfoSource::getCurrentVolume();
}
QStringList SystemInfoSource::sources() const
{
QStringList sources;
sources.append("system/brightness");
sources.append("system/volume");
sources.append("brightness");
sources.append("volume");
return sources;
}
@ -100,24 +100,24 @@ QVariant SystemInfoSource::fromDBusVariant(const QVariant &value)
}
float SystemInfoSource::getCurrentBrightness()
double SystemInfoSource::getCurrentBrightness()
{
qCDebug(LOG_ESS) << "Get current brightness";
auto maxBrightness
= sendDBusRequest("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
"org.kde.Solid.PowerManagement.Actions.BrightnessControl", "brightnessMax")
.toFloat();
.toDouble();
auto brightness
= sendDBusRequest("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
"org.kde.Solid.PowerManagement.Actions.BrightnessControl", "brightness")
.toFloat();
.toDouble();
return std::round(100.0f * brightness / maxBrightness);
return std::round(100.0 * brightness / maxBrightness);
}
float SystemInfoSource::getCurrentVolume()
double SystemInfoSource::getCurrentVolume()
{
qCDebug(LOG_ESS) << "Get current volume";
@ -129,7 +129,7 @@ float SystemInfoSource::getCurrentVolume()
if (currentMixer.isEmpty()) {
qCWarning(LOG_ESS) << "Mixer is empty";
return std::numeric_limits<float>::quiet_NaN();
return std::numeric_limits<double>::quiet_NaN();
}
currentMixer.replace(":", "_").replace(".", "_").replace("-", "_");
@ -140,14 +140,14 @@ float SystemInfoSource::getCurrentVolume()
.toString();
if (currentControl.isEmpty()) {
qCWarning(LOG_ESS) << "Control is empty";
return std::numeric_limits<float>::quiet_NaN();
return std::numeric_limits<double>::quiet_NaN();
}
currentControl.replace(":", "_").replace(".", "_").replace("-", "_");
auto path = QString("/Mixers/%1/%2").arg(currentMixer).arg(currentControl);
return fromDBusVariant(sendDBusRequest("org.kde.kmix", path, "org.freedesktop.DBus.Properties", "Get",
QVariantList({"org.kde.KMix.Control", "volume"})))
.toFloat();
.toDouble();
}