mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
fix: handle memory units as bytes
This commit is contained in:
parent
4d01b87088
commit
b0df3535a5
@ -153,7 +153,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
if (index > -1) {
|
||||
QString key = QString("hddr%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat;
|
||||
}
|
||||
} else if (_source.contains(hddwRegExp)) {
|
||||
// write speed
|
||||
@ -163,7 +163,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
if (index > -1) {
|
||||
QString key = QString("hddw%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat;
|
||||
}
|
||||
} else if (_source == "gpu/all/usage") {
|
||||
// gpu load
|
||||
@ -285,7 +285,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
// kb
|
||||
auto key = QString("%1kb%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat;
|
||||
// smart
|
||||
key = QString("%1%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
@ -303,7 +303,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSy
|
||||
// kb
|
||||
auto key = QString("%1totkb%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemKBFormat;
|
||||
// mb
|
||||
key = QString("%1tot%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
|
@ -85,21 +85,24 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
output = _data.toBool() ? m_acOnline : m_acOffline;
|
||||
break;
|
||||
case FormatterType::MemGBFormat:
|
||||
output = QString("%1").arg(_data.toDouble() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toDouble() / GBinBytes, 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::MemMBFormat:
|
||||
output = QString("%1").arg(_data.toDouble() / 1024.0, 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble() / MBinBytes, 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::MemKBFormat:
|
||||
output = QString("%1").arg(_data.toDouble() / KBinBytes, 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::NetSmartFormat:
|
||||
output = [](const float value) {
|
||||
if (value > 1024.0)
|
||||
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
||||
output = [](const double value) {
|
||||
if (value > MBinBytes)
|
||||
return QString("%1").arg(value / MBinBytes, 4, 'f', 1);
|
||||
else
|
||||
return QString("%1").arg(value, 4, 'f', 0);
|
||||
return QString("%1").arg(value / KBinBytes, 4, 'f', 0);
|
||||
}(_data.toDouble());
|
||||
break;
|
||||
case FormatterType::NetSmartUnits:
|
||||
if (_data.toDouble() > 1024.0)
|
||||
if (_data.toDouble() > MBinBytes)
|
||||
output = m_translate ? i18n("MB/s") : "MB/s";
|
||||
else
|
||||
output = m_translate ? i18n("KB/s") : "KB/s";
|
||||
@ -234,7 +237,7 @@ void AWKeysAggregator::setTranslate(const bool _translate)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeysAggregator::registerSource(const QString &_source, const KSysGuard::Unit &_units,
|
||||
QStringList AWKeysAggregator::registerSource(const QString &_source, const KSysGuard::Unit _units,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
@ -243,24 +246,24 @@ QStringList AWKeysAggregator::registerSource(const QString &_source, const KSysG
|
||||
}
|
||||
|
||||
|
||||
float AWKeysAggregator::temperature(const float temp) const
|
||||
double AWKeysAggregator::temperature(const double temp) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Temperature value" << temp;
|
||||
|
||||
float converted = temp;
|
||||
auto converted = temp;
|
||||
if (m_tempUnits == "Celsius") {
|
||||
} else if (m_tempUnits == "Fahrenheit") {
|
||||
converted = temp * 9.0f / 5.0f + 32.0f;
|
||||
converted = temp * 9.0f / 5.0 + 32.0;
|
||||
} else if (m_tempUnits == "Kelvin") {
|
||||
converted = temp + 273.15f;
|
||||
converted = temp + 273.15;
|
||||
} else if (m_tempUnits == "Reaumur") {
|
||||
converted = temp * 0.8f;
|
||||
converted = temp * 0.8;
|
||||
} else if (m_tempUnits == "cm^-1") {
|
||||
converted = (temp + 273.15f) * 0.695f;
|
||||
converted = (temp + 273.15) * 0.695;
|
||||
} else if (m_tempUnits == "kJ/mol") {
|
||||
converted = (temp + 273.15f) * 8.31f;
|
||||
converted = (temp + 273.15) * 8.31;
|
||||
} else if (m_tempUnits == "kcal/mol") {
|
||||
converted = (temp + 273.15f) * 1.98f;
|
||||
converted = (temp + 273.15) * 1.98;
|
||||
} else {
|
||||
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
ACFormat,
|
||||
MemGBFormat,
|
||||
MemMBFormat,
|
||||
MemKBFormat,
|
||||
NetSmartFormat,
|
||||
NetSmartUnits,
|
||||
Quotes,
|
||||
@ -67,6 +68,10 @@ public:
|
||||
UptimeCustom
|
||||
};
|
||||
|
||||
static constexpr double KBinBytes = 1024.0;
|
||||
static constexpr double MBinBytes = 1024.0 * KBinBytes;
|
||||
static constexpr double GBinBytes = 1024.0 * MBinBytes;
|
||||
|
||||
explicit AWKeysAggregator(QObject *_parent = nullptr);
|
||||
~AWKeysAggregator() override;
|
||||
void initFormatters();
|
||||
@ -83,10 +88,10 @@ public:
|
||||
void setTranslate(bool _translate);
|
||||
|
||||
public slots:
|
||||
QStringList registerSource(const QString &_source, const KSysGuard::Unit &_units, const QStringList &_keys);
|
||||
QStringList registerSource(const QString &_source, const KSysGuard::Unit _units, const QStringList &_keys);
|
||||
|
||||
private:
|
||||
[[nodiscard]] float temperature(float temp) const;
|
||||
[[nodiscard]] double temperature(double temp) const;
|
||||
AWFormatterHelper *m_customFormatters = nullptr;
|
||||
AWDataEngineMapper *m_mapper = nullptr;
|
||||
QStringList m_timeKeys;
|
||||
|
Loading…
Reference in New Issue
Block a user