massive refactoring

This commit is contained in:
2017-05-05 17:55:52 +03:00
parent 6e62ceaac7
commit d0c96ce829
152 changed files with 3041 additions and 3219 deletions

View File

@ -27,8 +27,8 @@
#include "awformatterhelper.h"
AWKeysAggregator::AWKeysAggregator(QObject *parent)
: QObject(parent)
AWKeysAggregator::AWKeysAggregator(QObject *_parent)
: QObject(_parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
@ -38,20 +38,20 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
// default formatters
// memory
m_formatter[QString("mem")] = FormatterType::Float;
m_formatter[QString("memtotmb")] = FormatterType::MemMBFormat;
m_formatter[QString("memtotgb")] = FormatterType::MemGBFormat;
m_formatter["mem"] = FormatterType::Float;
m_formatter["memtotmb"] = FormatterType::MemMBFormat;
m_formatter["memtotgb"] = FormatterType::MemGBFormat;
// network
m_formatter[QString("down")] = FormatterType::NetSmartFormat;
m_formatter[QString("downkb")] = FormatterType::Integer;
m_formatter[QString("downunits")] = FormatterType::NetSmartUnits;
m_formatter[QString("up")] = FormatterType::NetSmartFormat;
m_formatter[QString("upkb")] = FormatterType::Integer;
m_formatter[QString("upunits")] = FormatterType::NetSmartUnits;
m_formatter["down"] = FormatterType::NetSmartFormat;
m_formatter["downkb"] = FormatterType::Integer;
m_formatter["downunits"] = FormatterType::NetSmartUnits;
m_formatter["up"] = FormatterType::NetSmartFormat;
m_formatter["upkb"] = FormatterType::Integer;
m_formatter["upunits"] = FormatterType::NetSmartUnits;
// swap
m_formatter[QString("swap")] = FormatterType::Float;
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
m_formatter["swap"] = FormatterType::Float;
m_formatter["swaptotmb"] = FormatterType::MemMBFormat;
m_formatter["swaptotgb"] = FormatterType::MemGBFormat;
}
@ -71,42 +71,42 @@ void AWKeysAggregator::initFormatters()
}
QString AWKeysAggregator::formatter(const QVariant &data,
const QString &key) const
QString AWKeysAggregator::formatter(const QVariant &_data,
const QString &_key) const
{
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
qCDebug(LOG_AW) << "Data" << _data << "for key" << _key;
QString output;
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
// case block
switch (m_formatter[key]) {
switch (m_formatter[_key]) {
case FormatterType::Float:
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
output = QString("%1").arg(_data.toFloat(), 5, 'f', 1);
break;
case FormatterType::FloatTwoSymbols:
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
output = QString("%1").arg(_data.toFloat(), 5, 'f', 2);
break;
case FormatterType::Integer:
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
output = QString("%1").arg(_data.toFloat(), 4, 'f', 0);
break;
case FormatterType::IntegerFive:
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
output = QString("%1").arg(_data.toFloat(), 5, 'f', 0);
break;
case FormatterType::IntegerThree:
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
output = QString("%1").arg(_data.toFloat(), 3, 'f', 0);
break;
case FormatterType::List:
output = data.toStringList().join(QChar(','));
output = _data.toStringList().join(',');
break;
case FormatterType::ACFormat:
output = data.toBool() ? m_acOnline : m_acOffline;
output = _data.toBool() ? m_acOnline : m_acOffline;
break;
case FormatterType::MemGBFormat:
output
= QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
= QString("%1").arg(_data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
break;
case FormatterType::MemMBFormat:
output = QString("%1").arg(data.toFloat() / 1024.0, 5, 'f', 0);
output = QString("%1").arg(_data.toFloat() / 1024.0, 5, 'f', 0);
break;
case FormatterType::NetSmartFormat:
output = [](const float value) {
@ -114,44 +114,44 @@ QString AWKeysAggregator::formatter(const QVariant &data,
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
else
return QString("%1").arg(value, 4, 'f', 0);
}(data.toFloat());
}(_data.toFloat());
break;
case FormatterType::NetSmartUnits:
if (data.toFloat() > 1024.0)
output = m_translate ? i18n("MB/s") : QString("MB/s");
if (_data.toFloat() > 1024.0)
output = m_translate ? i18n("MB/s") : "MB/s";
else
output = m_translate ? i18n("KB/s") : QString("KB/s");
output = m_translate ? i18n("KB/s") : "KB/s";
break;
case FormatterType::Quotes:
// first cast
output = QString("%1").arg(data.toDouble(), 0, 'f');
output = QString("%1").arg(_data.toDouble(), 0, 'f');
output = output.rightJustified(8, QLatin1Char(' '), true);
break;
case FormatterType::Temperature:
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
output = QString("%1").arg(temperature(_data.toFloat()), 5, 'f', 1);
break;
case FormatterType::Time:
output = data.toDateTime().toString();
output = _data.toDateTime().toString();
break;
case FormatterType::TimeCustom:
output = m_customTime;
[&output, loc, this](const QDateTime dt) {
for (auto &key : m_timeKeys)
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
}(data.toDateTime());
}(_data.toDateTime());
break;
case FormatterType::TimeISO:
output = data.toDateTime().toString(Qt::ISODate);
output = _data.toDateTime().toString(Qt::ISODate);
break;
case FormatterType::TimeLong:
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
output = loc.toString(_data.toDateTime(), QLocale::LongFormat);
break;
case FormatterType::TimeShort:
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
output = loc.toString(_data.toDateTime(), QLocale::ShortFormat);
break;
case FormatterType::Timestamp:
output = QString("%1").arg(
data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
_data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
break;
case FormatterType::Uptime:
case FormatterType::UptimeCustom:
@ -161,27 +161,26 @@ QString AWKeysAggregator::formatter(const QVariant &data,
int minutes = seconds / 60 % 60;
int hours = ((seconds / 60) - minutes) / 60 % 24;
int days = (((seconds / 60) - minutes) / 60 - hours) / 24;
source.replace(QString("$dd"),
source.replace("$dd",
QString("%1").arg(days, 3, 10, QChar('0')));
source.replace(QString("$d"), QString("%1").arg(days));
source.replace(QString("$hh"),
source.replace("$d", QString("%1").arg(days));
source.replace("$hh",
QString("%1").arg(hours, 2, 10, QChar('0')));
source.replace(QString("$h"), QString("%1").arg(hours));
source.replace(QString("$mm"),
source.replace("$h", QString("%1").arg(hours));
source.replace("$mm",
QString("%1").arg(minutes, 2, 10, QChar('0')));
source.replace(QString("$m"), QString("%1").arg(minutes));
source.replace("$m", QString("%1").arg(minutes));
return source;
}(m_formatter[key] == FormatterType::Uptime
? QString("$ddd$hhh$mmm")
: m_customUptime,
static_cast<int>(data.toFloat()));
}(m_formatter[_key] == FormatterType::Uptime ? "$ddd$hhh$mmm"
: m_customUptime,
static_cast<int>(_data.toFloat()));
break;
case FormatterType::NoFormat:
output = data.toString();
output = _data.toString();
break;
case FormatterType::Custom:
if (m_customFormatters)
output = m_customFormatters->convert(data, key);
output = m_customFormatters->convert(_data, _key);
break;
}
@ -189,176 +188,176 @@ QString AWKeysAggregator::formatter(const QVariant &data,
}
QStringList AWKeysAggregator::keysFromSource(const QString &source) const
QStringList AWKeysAggregator::keysFromSource(const QString &_source) const
{
qCDebug(LOG_AW) << "Search for source" << source;
qCDebug(LOG_AW) << "Search for source" << _source;
return m_map.values(source);
return m_map.values(_source);
}
void AWKeysAggregator::setAcOffline(const QString &inactive)
void AWKeysAggregator::setAcOffline(const QString &_inactive)
{
qCDebug(LOG_AW) << "Inactive AC string" << inactive;
qCDebug(LOG_AW) << "Inactive AC string" << _inactive;
m_acOffline = inactive;
m_acOffline = _inactive;
}
void AWKeysAggregator::setAcOnline(const QString &active)
void AWKeysAggregator::setAcOnline(const QString &_active)
{
qCDebug(LOG_AW) << "Active AC string" << active;
qCDebug(LOG_AW) << "Active AC string" << _active;
m_acOnline = active;
m_acOnline = _active;
}
void AWKeysAggregator::setCustomTime(const QString &customTime)
void AWKeysAggregator::setCustomTime(const QString &_customTime)
{
qCDebug(LOG_AW) << "Format" << customTime;
qCDebug(LOG_AW) << "Format" << _customTime;
m_customTime = customTime;
m_customTime = _customTime;
}
void AWKeysAggregator::setCustomUptime(const QString &customUptime)
void AWKeysAggregator::setCustomUptime(const QString &_customUptime)
{
qCDebug(LOG_AW) << "Format" << customUptime;
qCDebug(LOG_AW) << "Format" << _customUptime;
m_customUptime = customUptime;
m_customUptime = _customUptime;
}
void AWKeysAggregator::setDevices(const QHash<QString, QStringList> &devices)
void AWKeysAggregator::setDevices(const QHash<QString, QStringList> &_devices)
{
qCDebug(LOG_AW) << "Devices" << devices;
qCDebug(LOG_AW) << "Devices" << _devices;
m_devices = devices;
m_devices = _devices;
}
void AWKeysAggregator::setTempUnits(const QString &units)
void AWKeysAggregator::setTempUnits(const QString &_units)
{
qCDebug(LOG_AW) << "Units" << units;
qCDebug(LOG_AW) << "Units" << _units;
m_tempUnits = units;
m_tempUnits = _units;
}
void AWKeysAggregator::setTranslate(const bool translate)
void AWKeysAggregator::setTranslate(const bool _translate)
{
qCDebug(LOG_AW) << "Translate" << translate;
qCDebug(LOG_AW) << "Translate" << _translate;
m_translate = translate;
m_translate = _translate;
}
// HACK units required to define should the value be calculated as temperature
// or fan data
QStringList AWKeysAggregator::registerSource(const QString &source,
const QString &units,
const QStringList &keys)
QStringList AWKeysAggregator::registerSource(const QString &_source,
const QString &_units,
const QStringList &_keys)
{
qCDebug(LOG_AW) << "Source" << source << "with units" << units;
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
// regular expressions
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
QRegExp cpuclRegExp = QRegExp(QString("cpu/cpu.*/clock"));
QRegExp hddrRegExp = QRegExp(QString("disk/.*/Rate/rblk"));
QRegExp hddwRegExp = QRegExp(QString("disk/.*/Rate/wblk"));
QRegExp mountFillRegExp = QRegExp(QString("partitions/.*/filllevel"));
QRegExp mountFreeRegExp = QRegExp(QString("partitions/.*/freespace"));
QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace"));
QRegExp netRegExp = QRegExp(
QString("network/interfaces/.*/(receiver|transmitter)/data$"));
QRegExp netTotalRegExp = QRegExp(
QString("network/interfaces/.*/(receiver|transmitter)/dataTotal$"));
QRegExp cpuRegExp = QRegExp("cpu/cpu.*/TotalLoad");
QRegExp cpuclRegExp = QRegExp("cpu/cpu.*/clock");
QRegExp hddrRegExp = QRegExp("disk/.*/Rate/rblk");
QRegExp hddwRegExp = QRegExp("disk/.*/Rate/wblk");
QRegExp mountFillRegExp = QRegExp("partitions/.*/filllevel");
QRegExp mountFreeRegExp = QRegExp("partitions/.*/freespace");
QRegExp mountUsedRegExp = QRegExp("partitions/.*/usedspace");
QRegExp netRegExp
= QRegExp("network/interfaces/.*/(receiver|transmitter)/data$");
QRegExp netTotalRegExp
= QRegExp("network/interfaces/.*/(receiver|transmitter)/dataTotal$");
if (source == QString("battery/ac")) {
if (_source == "battery/ac") {
// AC
m_map[source] = QString("ac");
m_formatter[QString("ac")] = FormatterType::ACFormat;
} else if (source.startsWith(QString("battery/"))) {
m_map[_source] = "ac";
m_formatter["ac"] = FormatterType::ACFormat;
} else if (_source.startsWith("battery/")) {
// battery stats
QString key = source;
key.remove(QString("battery/"));
m_map[source] = key;
QString key = _source;
key.remove("battery/");
m_map[_source] = key;
m_formatter[key] = FormatterType::IntegerThree;
} else if (source == QString("cpu/system/TotalLoad")) {
} else if (_source == "cpu/system/TotalLoad") {
// cpu
m_map[source] = QString("cpu");
m_formatter[QString("cpu")] = FormatterType::Float;
} else if (source.contains(cpuRegExp)) {
m_map[_source] = "cpu";
m_formatter["cpu"] = FormatterType::Float;
} else if (_source.contains(cpuRegExp)) {
// cpus
QString key = source;
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
m_map[source] = key;
QString key = _source;
key.remove("cpu/").remove("/TotalLoad");
m_map[_source] = key;
m_formatter[key] = FormatterType::Float;
} else if (source == QString("cpu/system/AverageClock")) {
} else if (_source == "cpu/system/AverageClock") {
// cpucl
m_map[source] = QString("cpucl");
m_formatter[QString("cpucl")] = FormatterType::Integer;
} else if (source.contains(cpuclRegExp)) {
m_map[_source] = "cpucl";
m_formatter["cpucl"] = FormatterType::Integer;
} else if (_source.contains(cpuclRegExp)) {
// cpucls
QString key = source;
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
QString key = _source;
key.remove("cpu/cpu").remove("/clock");
key = QString("cpucl%1").arg(key);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Integer;
} else if (source.startsWith(QString("custom"))) {
} else if (_source.startsWith("custom")) {
// custom
QString key = source;
key.remove(QString("custom/"));
m_map[source] = key;
QString key = _source;
key.remove("custom/");
m_map[_source] = key;
m_formatter[key] = FormatterType::NoFormat;
} else if (source == QString("desktop/current/name")) {
} else if (_source == "desktop/current/name") {
// current desktop name
m_map[source] = QString("desktop");
m_formatter[QString("desktop")] = FormatterType::NoFormat;
} else if (source == QString("desktop/current/number")) {
m_map[_source] = "desktop";
m_formatter["desktop"] = FormatterType::NoFormat;
} else if (_source == "desktop/current/number") {
// current desktop number
m_map[source] = QString("ndesktop");
m_formatter[QString("ndesktop")] = FormatterType::NoFormat;
} else if (source == QString("desktop/total/number")) {
m_map[_source] = "ndesktop";
m_formatter["ndesktop"] = FormatterType::NoFormat;
} else if (_source == "desktop/total/number") {
// desktop count
m_map[source] = QString("tdesktops");
m_formatter[QString("tdesktops")] = FormatterType::NoFormat;
} else if (source.contains(hddrRegExp)) {
m_map[_source] = "tdesktops";
m_formatter["tdesktops"] = FormatterType::NoFormat;
} else if (_source.contains(hddrRegExp)) {
// read speed
QString device = source;
device.remove(QString("/Rate/rblk"));
int index = m_devices[QString("disk")].indexOf(device);
QString device = _source;
device.remove("/Rate/rblk");
int index = m_devices["disk"].indexOf(device);
if (index > -1) {
QString key = QString("hddr%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Integer;
}
} else if (source.contains(hddwRegExp)) {
} else if (_source.contains(hddwRegExp)) {
// write speed
QString device = source;
device.remove(QString("/Rate/wblk"));
int index = m_devices[QString("disk")].indexOf(device);
QString device = _source;
device.remove("/Rate/wblk");
int index = m_devices["disk"].indexOf(device);
if (index > -1) {
QString key = QString("hddw%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Integer;
}
} else if (source == QString("gpu/load")) {
} else if (_source == "gpu/load") {
// gpu load
m_map[source] = QString("gpu");
m_formatter[QString("gpu")] = FormatterType::Float;
} else if (source == QString("gpu/temperature")) {
m_map[_source] = "gpu";
m_formatter["gpu"] = FormatterType::Float;
} else if (_source == "gpu/temperature") {
// gpu temperature
m_map[source] = QString("gputemp");
m_formatter[QString("gputemp")] = FormatterType::Temperature;
} else if (source.contains(mountFillRegExp)) {
m_map[_source] = "gputemp";
m_formatter["gputemp"] = FormatterType::Temperature;
} else if (_source.contains(mountFillRegExp)) {
// fill level
QString device = source;
device.remove(QString("partitions")).remove(QString("/filllevel"));
int index = m_devices[QString("mount")].indexOf(device);
QString device = _source;
device.remove("partitions").remove("/filllevel");
int index = m_devices["mount"].indexOf(device);
if (index > -1) {
QString key = QString("hdd%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Float;
// additional keys
m_formatter[QString("hddtotmb%1").arg(index)]
@ -366,229 +365,224 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
m_formatter[QString("hddtotgb%1").arg(index)]
= FormatterType::MemGBFormat;
}
} else if (source.contains(mountFreeRegExp)) {
} else if (_source.contains(mountFreeRegExp)) {
// free space
QString device = source;
device.remove(QString("partitions")).remove(QString("/freespace"));
int index = m_devices[QString("mount")].indexOf(device);
QString device = _source;
device.remove("partitions").remove("/freespace");
int index = m_devices["mount"].indexOf(device);
if (index > -1) {
// mb
QString key = QString("hddfreemb%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::MemMBFormat;
// gb
key = QString("hddfreegb%1").arg(index);
m_map.insertMulti(source, key);
m_map.insertMulti(_source, key);
m_formatter[key] = FormatterType::MemGBFormat;
}
} else if (source.contains(mountUsedRegExp)) {
} else if (_source.contains(mountUsedRegExp)) {
// used
QString device = source;
device.remove(QString("partitions")).remove(QString("/usedspace"));
int index = m_devices[QString("mount")].indexOf(device);
QString device = _source;
device.remove("partitions").remove("/usedspace");
int index = m_devices["mount"].indexOf(device);
if (index > -1) {
// mb
QString key = QString("hddmb%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::MemMBFormat;
// gb
key = QString("hddgb%1").arg(index);
m_map.insertMulti(source, key);
m_map.insertMulti(_source, key);
m_formatter[key] = FormatterType::MemGBFormat;
}
} else if (source.startsWith(QString("hdd/temperature"))) {
} else if (_source.startsWith("hdd/temperature")) {
// hdd temperature
QString device = source;
device.remove(QString("hdd/temperature"));
int index = m_devices[QString("hdd")].indexOf(device);
QString device = _source;
device.remove("hdd/temperature");
int index = m_devices["hdd"].indexOf(device);
if (index > -1) {
QString key = QString("hddtemp%1").arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Temperature;
}
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
} else if (_source.startsWith("cpu/system/loadavg")) {
// load average
QString time = source;
time.remove(QString("cpu/system/loadavg"));
QString time = _source;
time.remove("cpu/system/loadavg");
QString key = QString("la%1").arg(time);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::FloatTwoSymbols;
} else if (source == QString("mem/physical/application")) {
} else if (_source == "mem/physical/application") {
// app memory
// mb
m_map[source] = QString("memmb");
m_formatter[QString("memmb")] = FormatterType::MemMBFormat;
m_map[_source] = "memmb";
m_formatter["memmb"] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memgb"));
m_formatter[QString("memgb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/physical/free")) {
m_map.insertMulti(_source, "memgb");
m_formatter["memgb"] = FormatterType::MemGBFormat;
} else if (_source == "mem/physical/free") {
// free memory
// mb
m_map[source] = QString("memfreemb");
m_formatter[QString("memfreemb")] = FormatterType::MemMBFormat;
m_map[_source] = "memfreemb";
m_formatter["memfreemb"] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memfreegb"));
m_formatter[QString("memfreegb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/physical/used")) {
m_map.insertMulti(_source, "memfreegb");
m_formatter["memfreegb"] = FormatterType::MemGBFormat;
} else if (_source == "mem/physical/used") {
// used memory
// mb
m_map[source] = QString("memusedmb");
m_formatter[QString("memusedmb")] = FormatterType::MemMBFormat;
m_map[_source] = "memusedmb";
m_formatter["memusedmb"] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memusedgb"));
m_formatter[QString("memusedgb")] = FormatterType::MemGBFormat;
} else if (source == QString("network/current/name")) {
m_map.insertMulti(_source, "memusedgb");
m_formatter["memusedgb"] = FormatterType::MemGBFormat;
} else if (_source == "network/current/name") {
// network device
m_map[source] = QString("netdev");
m_formatter[QString("netdev")] = FormatterType::NoFormat;
} else if (source.startsWith(QString("network/response"))) {
m_map[_source] = "netdev";
m_formatter["netdev"] = FormatterType::NoFormat;
} else if (_source.startsWith("network/response")) {
// network response
QString key = source;
key.remove(QString("network/"));
m_map[source] = key;
QString key = _source;
key.remove("network/");
m_map[_source] = key;
m_formatter[key] = FormatterType::NoFormat;
} else if (source.contains(netRegExp)) {
} else if (_source.contains(netRegExp)) {
// network speed
QString type = source.contains(QString("receiver")) ? QString("down")
: QString("up");
int index
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
QString type = _source.contains("receiver") ? "down" : "up";
int index = m_devices["net"].indexOf(_source.split('/')[2]);
if (index > -1) {
// kb
QString key = QString("%1kb%2").arg(type).arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Integer;
// smart
key = QString("%1%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_map.insertMulti(_source, key);
m_formatter[key] = FormatterType::NetSmartFormat;
// units
key = QString("%1units%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_map.insertMulti(_source, key);
m_formatter[key] = FormatterType::NetSmartUnits;
}
} else if (source.contains(netTotalRegExp)) {
} else if (_source.contains(netTotalRegExp)) {
// network data total
QString type = source.contains(QString("receiver")) ? QString("down")
: QString("up");
int index
= m_devices[QString("net")].indexOf(source.split(QChar('/'))[2]);
QString type = _source.contains("receiver") ? "down" : "up";
int index = m_devices["net"].indexOf(_source.split('/')[2]);
if (index > -1) {
// kb
QString key = QString("%1totalkb%2").arg(type).arg(index);
m_map[source] = key;
m_map[_source] = key;
m_formatter[key] = FormatterType::Integer;
// mb
key = QString("%1total%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_map.insertMulti(_source, key);
m_formatter[key] = FormatterType::MemMBFormat;
}
} else if (source.startsWith(QString("upgrade"))) {
} else if (_source.startsWith("upgrade")) {
// package manager
QString key = source;
key.remove(QString("upgrade/"));
m_map[source] = key;
QString key = _source;
key.remove("upgrade/");
m_map[_source] = key;
m_formatter[key] = FormatterType::IntegerThree;
} else if (source.startsWith(QString("player"))) {
} else if (_source.startsWith("player")) {
// player
QString key = source;
key.remove(QString("player/"));
m_map[source] = key;
QString key = _source;
key.remove("player/");
m_map[_source] = key;
m_formatter[key] = FormatterType::NoFormat;
} else if (source == QString("ps/running/count")) {
} else if (_source == "ps/running/count") {
// running processes count
m_map[source] = QString("pscount");
m_formatter[QString("pscount")] = FormatterType::NoFormat;
} else if (source == QString("ps/running/list")) {
m_map[_source] = "pscount";
m_formatter["pscount"] = FormatterType::NoFormat;
} else if (_source == "ps/running/list") {
// list of running processes
m_map[source] = QString("ps");
m_formatter[QString("ps")] = FormatterType::List;
} else if (source == QString("ps/total/count")) {
m_map[_source] = "ps";
m_formatter["ps"] = FormatterType::List;
} else if (_source == "ps/total/count") {
// total processes count
m_map[source] = QString("pstotal");
m_formatter[QString("pstotal")] = FormatterType::NoFormat;
} else if (source.startsWith(QString("quotes"))) {
m_map[_source] = "pstotal";
m_formatter["pstotal"] = FormatterType::NoFormat;
} else if (_source.startsWith("quotes")) {
// quotes
QString key = source;
key.remove(QString("quotes/"));
m_map[source] = key;
QString key = _source;
key.remove("quotes/");
m_map[_source] = key;
m_formatter[key] = FormatterType::Quotes;
} else if (source == QString("mem/swap/free")) {
} else if (_source == "mem/swap/free") {
// free swap
// mb
m_map[source] = QString("swapfreemb");
m_formatter[QString("swapfreemb")] = FormatterType::MemMBFormat;
m_map[_source] = "swapfreemb";
m_formatter["swapfreemb"] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapfreegb"));
m_formatter[QString("swapfreegb")] = FormatterType::MemGBFormat;
} else if (source == QString("mem/swap/used")) {
m_map.insertMulti(_source, "swapfreegb");
m_formatter["swapfreegb"] = FormatterType::MemGBFormat;
} else if (_source == "mem/swap/used") {
// used swap
// mb
m_map[source] = QString("swapmb");
m_formatter[QString("swapmb")] = FormatterType::MemMBFormat;
m_map[_source] = "swapmb";
m_formatter["swapmb"] = FormatterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapgb"));
m_formatter[QString("swapgb")] = FormatterType::MemGBFormat;
} else if (source.startsWith(QString("lmsensors/"))) {
m_map.insertMulti(_source, "swapgb");
m_formatter["swapgb"] = FormatterType::MemGBFormat;
} else if (_source.startsWith("lmsensors/")) {
// temperature
int index = m_devices[QString("temp")].indexOf(source);
int index = m_devices["temp"].indexOf(_source);
// HACK on DE initialization there are no units key
if (units.isEmpty())
return QStringList() << QString("temp%1").arg(index);
if (_units.isEmpty())
return QStringList({QString("temp%1").arg(index)});
if (index > -1) {
QString key = QString("temp%1").arg(index);
m_map[source] = key;
m_formatter[key] = units == QString("°C")
? FormatterType::Temperature
: FormatterType::Integer;
m_map[_source] = key;
m_formatter[key] = _units == "°C" ? FormatterType::Temperature
: FormatterType::Integer;
}
} else if (source == QString("Local")) {
} else if (_source == "Local") {
// time
m_map[source] = QString("time");
m_formatter[QString("time")] = FormatterType::Time;
m_map[_source] = "time";
m_formatter["time"] = FormatterType::Time;
// custom time
m_map.insertMulti(source, QString("ctime"));
m_formatter[QString("ctime")] = FormatterType::TimeCustom;
m_map.insertMulti(_source, "ctime");
m_formatter["ctime"] = FormatterType::TimeCustom;
// ISO time
m_map.insertMulti(source, QString("isotime"));
m_formatter[QString("isotime")] = FormatterType::TimeISO;
m_map.insertMulti(_source, "isotime");
m_formatter["isotime"] = FormatterType::TimeISO;
// long time
m_map.insertMulti(source, QString("longtime"));
m_formatter[QString("longtime")] = FormatterType::TimeLong;
m_map.insertMulti(_source, "longtime");
m_formatter["longtime"] = FormatterType::TimeLong;
// short time
m_map.insertMulti(source, QString("shorttime"));
m_formatter[QString("shorttime")] = FormatterType::TimeShort;
m_map.insertMulti(_source, "shorttime");
m_formatter["shorttime"] = FormatterType::TimeShort;
// timestamp
m_map.insertMulti(source, QString("tstime"));
m_formatter[QString("tstime")] = FormatterType::Timestamp;
} else if (source == QString("system/uptime")) {
m_map.insertMulti(_source, "tstime");
m_formatter["tstime"] = FormatterType::Timestamp;
} else if (_source == "system/uptime") {
// uptime
m_map[source] = QString("uptime");
m_formatter[QString("uptime")] = FormatterType::Uptime;
m_map[_source] = "uptime";
m_formatter["uptime"] = FormatterType::Uptime;
// custom uptime
m_map.insertMulti(source, QString("cuptime"));
m_formatter[QString("cuptime")] = FormatterType::UptimeCustom;
} else if (source.startsWith(QString("weather/temperature"))) {
m_map.insertMulti(_source, "cuptime");
m_formatter["cuptime"] = FormatterType::UptimeCustom;
} else if (_source.startsWith("weather/temperature")) {
// temperature
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
QString key = _source;
key.remove("weather/");
m_map[_source] = key;
m_formatter[key] = FormatterType::Temperature;
} else if (source.startsWith(QString("weather/"))) {
} else if (_source.startsWith("weather/")) {
// other weather
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
QString key = _source;
key.remove("weather/");
m_map[_source] = key;
m_formatter[key] = FormatterType::NoFormat;
} else if (source.startsWith(QString("load/load"))) {
} else if (_source.startsWith("load/load")) {
// load source
QString key = source;
key.remove(QString("load/"));
m_map[source] = key;
QString key = _source;
key.remove("load/");
m_map[_source] = key;
m_formatter[key] = FormatterType::Temperature;
}
QStringList foundKeys = keysFromSource(source);
QStringList foundKeys = keysFromSource(_source);
// rewrite formatters for custom ones
QStringList customFormattersKeys;
@ -603,19 +597,19 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
}
// drop key from dictionary if no one user requested key required it
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
bool required
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
[&keys](const QString &key) {
return keys.contains(key);
});
= _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
[&_keys](const QString &key) {
return _keys.contains(key);
});
if (!required) {
m_map.remove(source);
m_map.remove(_source);
for (auto &key : foundKeys)
m_formatter.remove(key);
}
return keysFromSource(source);
return keysFromSource(_source);
}
@ -624,18 +618,18 @@ float AWKeysAggregator::temperature(const float temp) const
qCDebug(LOG_AW) << "Temperature value" << temp;
float converted = temp;
if (m_tempUnits == QString("Celsius")) {
} else if (m_tempUnits == QString("Fahrenheit")) {
if (m_tempUnits == "Celsius") {
} else if (m_tempUnits == "Fahrenheit") {
converted = temp * 9.0f / 5.0f + 32.0f;
} else if (m_tempUnits == QString("Kelvin")) {
} else if (m_tempUnits == "Kelvin") {
converted = temp + 273.15f;
} else if (m_tempUnits == QString("Reaumur")) {
} else if (m_tempUnits == "Reaumur") {
converted = temp * 0.8f;
} else if (m_tempUnits == QString("cm^-1")) {
} else if (m_tempUnits == "cm^-1") {
converted = (temp + 273.15f) * 0.695f;
} else if (m_tempUnits == QString("kJ/mol")) {
} else if (m_tempUnits == "kJ/mol") {
converted = (temp + 273.15f) * 8.31f;
} else if (m_tempUnits == QString("kcal/mol")) {
} else if (m_tempUnits == "kcal/mol") {
converted = (temp + 273.15f) * 1.98f;
} else {
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;