mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-28 09:27:18 +00:00
rename forma_t_er to forma_tt_er
This commit is contained in:
parent
46db3fee4c
commit
3771ce6ec2
@ -179,7 +179,7 @@ QString AWKeys::valueByKey(QString key) const
|
|||||||
qCDebug(LOG_AW) << "Requested value for key" << key;
|
qCDebug(LOG_AW) << "Requested value for key" << key;
|
||||||
|
|
||||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||||
return aggregator->formater(values[key], key);
|
return aggregator->formatter(values[key], key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
|||||||
for (auto key : m_foundKeys)
|
for (auto key : m_foundKeys)
|
||||||
pattern.replace(QString("$%1").arg(key), [this](const QString &tag,
|
pattern.replace(QString("$%1").arg(key), [this](const QString &tag,
|
||||||
const QVariant &value) {
|
const QVariant &value) {
|
||||||
QString strValue = aggregator->formater(value, tag);
|
QString strValue = aggregator->formatter(value, tag);
|
||||||
if ((!tag.startsWith(QString("custom")))
|
if ((!tag.startsWith(QString("custom")))
|
||||||
&& (!tag.startsWith(QString("weather"))))
|
&& (!tag.startsWith(QString("weather"))))
|
||||||
strValue.replace(QString(" "), QString(" "));
|
strValue.replace(QString(" "), QString(" "));
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
#include "awformatterhelper.h"
|
||||||
|
|
||||||
|
|
||||||
AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
||||||
@ -31,69 +32,73 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
// default formaters
|
// default formatters
|
||||||
// memory
|
// memory
|
||||||
m_formater[QString("mem")] = FormaterType::Float;
|
m_formatter[QString("mem")] = FormatterType::Float;
|
||||||
m_formater[QString("memtotmb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("memtotmb")] = FormatterType::MemMBFormat;
|
||||||
m_formater[QString("memtotgb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("memtotgb")] = FormatterType::MemGBFormat;
|
||||||
// network
|
// network
|
||||||
m_formater[QString("down")] = FormaterType::NetSmartFormat;
|
m_formatter[QString("down")] = FormatterType::NetSmartFormat;
|
||||||
m_formater[QString("downkb")] = FormaterType::Integer;
|
m_formatter[QString("downkb")] = FormatterType::Integer;
|
||||||
m_formater[QString("downunits")] = FormaterType::NetSmartUnits;
|
m_formatter[QString("downunits")] = FormatterType::NetSmartUnits;
|
||||||
m_formater[QString("up")] = FormaterType::NetSmartFormat;
|
m_formatter[QString("up")] = FormatterType::NetSmartFormat;
|
||||||
m_formater[QString("upkb")] = FormaterType::Integer;
|
m_formatter[QString("upkb")] = FormatterType::Integer;
|
||||||
m_formater[QString("upunits")] = FormaterType::NetSmartUnits;
|
m_formatter[QString("upunits")] = FormatterType::NetSmartUnits;
|
||||||
// swap
|
// swap
|
||||||
m_formater[QString("swap")] = FormaterType::Float;
|
m_formatter[QString("swap")] = FormatterType::Float;
|
||||||
m_formater[QString("swaptotmb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
||||||
m_formater[QString("swaptotgb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
||||||
|
|
||||||
|
m_customFormatters = new AWFormatterHelper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWKeysAggregator::~AWKeysAggregator()
|
AWKeysAggregator::~AWKeysAggregator()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
delete m_customFormatters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWKeysAggregator::formater(const QVariant &data,
|
QString AWKeysAggregator::formatter(const QVariant &data,
|
||||||
const QString &key) const
|
const QString &key) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
|
qCDebug(LOG_AW) << "Data" << data << "for key" << key;
|
||||||
|
|
||||||
QString output;
|
QString output;
|
||||||
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
|
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
|
||||||
// case block
|
// case block
|
||||||
switch (m_formater[key]) {
|
switch (m_formatter[key]) {
|
||||||
case FormaterType::Float:
|
case FormatterType::Float:
|
||||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
|
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
|
||||||
break;
|
break;
|
||||||
case FormaterType::FloatTwoSymbols:
|
case FormatterType::FloatTwoSymbols:
|
||||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
|
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
|
||||||
break;
|
break;
|
||||||
case FormaterType::Integer:
|
case FormatterType::Integer:
|
||||||
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
|
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
|
||||||
break;
|
break;
|
||||||
case FormaterType::IntegerFive:
|
case FormatterType::IntegerFive:
|
||||||
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
|
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
|
||||||
break;
|
break;
|
||||||
case FormaterType::IntegerThree:
|
case FormatterType::IntegerThree:
|
||||||
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
|
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
|
||||||
break;
|
break;
|
||||||
case FormaterType::List:
|
case FormatterType::List:
|
||||||
output = data.toStringList().join(QChar(','));
|
output = data.toStringList().join(QChar(','));
|
||||||
break;
|
break;
|
||||||
case FormaterType::ACFormat:
|
case FormatterType::ACFormat:
|
||||||
output = data.toBool() ? m_acOnline : m_acOffline;
|
output = data.toBool() ? m_acOnline : m_acOffline;
|
||||||
break;
|
break;
|
||||||
case FormaterType::MemGBFormat:
|
case FormatterType::MemGBFormat:
|
||||||
output
|
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;
|
break;
|
||||||
case FormaterType::MemMBFormat:
|
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;
|
break;
|
||||||
case FormaterType::NetSmartFormat:
|
case FormatterType::NetSmartFormat:
|
||||||
output = [](const float value) {
|
output = [](const float value) {
|
||||||
if (value > 1024.0)
|
if (value > 1024.0)
|
||||||
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
||||||
@ -101,41 +106,41 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
|||||||
return QString("%1").arg(value, 4, 'f', 0);
|
return QString("%1").arg(value, 4, 'f', 0);
|
||||||
}(data.toFloat());
|
}(data.toFloat());
|
||||||
break;
|
break;
|
||||||
case FormaterType::NetSmartUnits:
|
case FormatterType::NetSmartUnits:
|
||||||
if (data.toFloat() > 1024.0)
|
if (data.toFloat() > 1024.0)
|
||||||
output = m_translate ? i18n("MB/s") : QString("MB/s");
|
output = m_translate ? i18n("MB/s") : QString("MB/s");
|
||||||
else
|
else
|
||||||
output = m_translate ? i18n("KB/s") : QString("KB/s");
|
output = m_translate ? i18n("KB/s") : QString("KB/s");
|
||||||
break;
|
break;
|
||||||
case FormaterType::Quotes:
|
case FormatterType::Quotes:
|
||||||
// first cast
|
// first cast
|
||||||
output = QString("%1").arg(data.toDouble(), 0, 'f');
|
output = QString("%1").arg(data.toDouble(), 0, 'f');
|
||||||
output = output.rightJustified(8, QLatin1Char(' '), true);
|
output = output.rightJustified(8, QLatin1Char(' '), true);
|
||||||
break;
|
break;
|
||||||
case FormaterType::Temperature:
|
case FormatterType::Temperature:
|
||||||
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
|
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
|
||||||
break;
|
break;
|
||||||
case FormaterType::Time:
|
case FormatterType::Time:
|
||||||
output = data.toDateTime().toString();
|
output = data.toDateTime().toString();
|
||||||
break;
|
break;
|
||||||
case FormaterType::TimeCustom:
|
case FormatterType::TimeCustom:
|
||||||
output = m_customTime;
|
output = m_customTime;
|
||||||
[&output, loc, this](const QDateTime dt) {
|
[&output, loc, this](const QDateTime dt) {
|
||||||
for (auto key : timeKeys)
|
for (auto key : timeKeys)
|
||||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||||
}(data.toDateTime());
|
}(data.toDateTime());
|
||||||
break;
|
break;
|
||||||
case FormaterType::TimeISO:
|
case FormatterType::TimeISO:
|
||||||
output = data.toDateTime().toString(Qt::ISODate);
|
output = data.toDateTime().toString(Qt::ISODate);
|
||||||
break;
|
break;
|
||||||
case FormaterType::TimeLong:
|
case FormatterType::TimeLong:
|
||||||
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
|
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
|
||||||
break;
|
break;
|
||||||
case FormaterType::TimeShort:
|
case FormatterType::TimeShort:
|
||||||
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
|
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
|
||||||
break;
|
break;
|
||||||
case FormaterType::Uptime:
|
case FormatterType::Uptime:
|
||||||
case FormaterType::UptimeCustom:
|
case FormatterType::UptimeCustom:
|
||||||
output =
|
output =
|
||||||
[](QString source, const int uptime) {
|
[](QString source, const int uptime) {
|
||||||
int seconds = uptime - uptime % 60;
|
int seconds = uptime - uptime % 60;
|
||||||
@ -152,13 +157,17 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
|||||||
QString("%1").arg(minutes, 2, 10, QChar('0')));
|
QString("%1").arg(minutes, 2, 10, QChar('0')));
|
||||||
source.replace(QString("$m"), QString("%1").arg(minutes));
|
source.replace(QString("$m"), QString("%1").arg(minutes));
|
||||||
return source;
|
return source;
|
||||||
}(m_formater[key] == FormaterType::Uptime ? QString("$ddd$hhh$mmm")
|
}(m_formatter[key] == FormatterType::Uptime
|
||||||
: m_customUptime,
|
? QString("$ddd$hhh$mmm")
|
||||||
|
: m_customUptime,
|
||||||
static_cast<int>(data.toFloat()));
|
static_cast<int>(data.toFloat()));
|
||||||
break;
|
break;
|
||||||
case FormaterType::NoFormat:
|
case FormatterType::NoFormat:
|
||||||
output = data.toString();
|
output = data.toString();
|
||||||
break;
|
break;
|
||||||
|
case FormatterType::Custom:
|
||||||
|
output = m_customFormatters->convert(data, key);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -253,52 +262,52 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (source == QString("battery/ac")) {
|
if (source == QString("battery/ac")) {
|
||||||
// AC
|
// AC
|
||||||
m_map[source] = QString("ac");
|
m_map[source] = QString("ac");
|
||||||
m_formater[QString("ac")] = FormaterType::ACFormat;
|
m_formatter[QString("ac")] = FormatterType::ACFormat;
|
||||||
} else if (source.startsWith(QString("battery/"))) {
|
} else if (source.startsWith(QString("battery/"))) {
|
||||||
// battery stats
|
// battery stats
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("battery/"));
|
key.remove(QString("battery/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::IntegerThree;
|
m_formatter[key] = FormatterType::IntegerThree;
|
||||||
} else if (source == QString("cpu/system/TotalLoad")) {
|
} else if (source == QString("cpu/system/TotalLoad")) {
|
||||||
// cpu
|
// cpu
|
||||||
m_map[source] = QString("cpu");
|
m_map[source] = QString("cpu");
|
||||||
m_formater[QString("cpu")] = FormaterType::Float;
|
m_formatter[QString("cpu")] = FormatterType::Float;
|
||||||
} else if (source.contains(cpuRegExp)) {
|
} else if (source.contains(cpuRegExp)) {
|
||||||
// cpus
|
// cpus
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
|
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Float;
|
m_formatter[key] = FormatterType::Float;
|
||||||
} else if (source == QString("cpu/system/AverageClock")) {
|
} else if (source == QString("cpu/system/AverageClock")) {
|
||||||
// cpucl
|
// cpucl
|
||||||
m_map[source] = QString("cpucl");
|
m_map[source] = QString("cpucl");
|
||||||
m_formater[QString("cpucl")] = FormaterType::Integer;
|
m_formatter[QString("cpucl")] = FormatterType::Integer;
|
||||||
} else if (source.contains(cpuclRegExp)) {
|
} else if (source.contains(cpuclRegExp)) {
|
||||||
// cpucls
|
// cpucls
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
|
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
|
||||||
key = QString("cpucl%1").arg(key);
|
key = QString("cpucl%1").arg(key);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Integer;
|
m_formatter[key] = FormatterType::Integer;
|
||||||
} else if (source.startsWith(QString("custom"))) {
|
} else if (source.startsWith(QString("custom"))) {
|
||||||
// custom
|
// custom
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("custom/"));
|
key.remove(QString("custom/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::NoFormat;
|
m_formatter[key] = FormatterType::NoFormat;
|
||||||
} else if (source == QString("desktop/current/name")) {
|
} else if (source == QString("desktop/current/name")) {
|
||||||
// current desktop name
|
// current desktop name
|
||||||
m_map[source] = QString("desktop");
|
m_map[source] = QString("desktop");
|
||||||
m_formater[QString("desktop")] = FormaterType::NoFormat;
|
m_formatter[QString("desktop")] = FormatterType::NoFormat;
|
||||||
} else if (source == QString("desktop/current/number")) {
|
} else if (source == QString("desktop/current/number")) {
|
||||||
// current desktop number
|
// current desktop number
|
||||||
m_map[source] = QString("ndesktop");
|
m_map[source] = QString("ndesktop");
|
||||||
m_formater[QString("ndesktop")] = FormaterType::NoFormat;
|
m_formatter[QString("ndesktop")] = FormatterType::NoFormat;
|
||||||
} else if (source == QString("desktop/total/number")) {
|
} else if (source == QString("desktop/total/number")) {
|
||||||
// desktop count
|
// desktop count
|
||||||
m_map[source] = QString("tdesktops");
|
m_map[source] = QString("tdesktops");
|
||||||
m_formater[QString("tdesktops")] = FormaterType::NoFormat;
|
m_formatter[QString("tdesktops")] = FormatterType::NoFormat;
|
||||||
} else if (source.contains(hddrRegExp)) {
|
} else if (source.contains(hddrRegExp)) {
|
||||||
// read speed
|
// read speed
|
||||||
QString device = source;
|
QString device = source;
|
||||||
@ -307,7 +316,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
QString key = QString("hddr%1").arg(index);
|
QString key = QString("hddr%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Integer;
|
m_formatter[key] = FormatterType::Integer;
|
||||||
}
|
}
|
||||||
} else if (source.contains(hddwRegExp)) {
|
} else if (source.contains(hddwRegExp)) {
|
||||||
// write speed
|
// write speed
|
||||||
@ -317,16 +326,16 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
QString key = QString("hddw%1").arg(index);
|
QString key = QString("hddw%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Integer;
|
m_formatter[key] = FormatterType::Integer;
|
||||||
}
|
}
|
||||||
} else if (source == QString("gpu/load")) {
|
} else if (source == QString("gpu/load")) {
|
||||||
// gpu load
|
// gpu load
|
||||||
m_map[source] = QString("gpu");
|
m_map[source] = QString("gpu");
|
||||||
m_formater[QString("gpu")] = FormaterType::Float;
|
m_formatter[QString("gpu")] = FormatterType::Float;
|
||||||
} else if (source == QString("gpu/temperature")) {
|
} else if (source == QString("gpu/temperature")) {
|
||||||
// gpu temperature
|
// gpu temperature
|
||||||
m_map[source] = QString("gputemp");
|
m_map[source] = QString("gputemp");
|
||||||
m_formater[QString("gputemp")] = FormaterType::Temperature;
|
m_formatter[QString("gputemp")] = FormatterType::Temperature;
|
||||||
} else if (source.contains(mountFillRegExp)) {
|
} else if (source.contains(mountFillRegExp)) {
|
||||||
// fill level
|
// fill level
|
||||||
QString device = source;
|
QString device = source;
|
||||||
@ -335,12 +344,12 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
QString key = QString("hdd%1").arg(index);
|
QString key = QString("hdd%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Float;
|
m_formatter[key] = FormatterType::Float;
|
||||||
// additional keys
|
// additional keys
|
||||||
m_formater[QString("hddtotmb%1").arg(index)]
|
m_formatter[QString("hddtotmb%1").arg(index)]
|
||||||
= FormaterType::MemMBFormat;
|
= FormatterType::MemMBFormat;
|
||||||
m_formater[QString("hddtotgb%1").arg(index)]
|
m_formatter[QString("hddtotgb%1").arg(index)]
|
||||||
= FormaterType::MemGBFormat;
|
= FormatterType::MemGBFormat;
|
||||||
}
|
}
|
||||||
} else if (source.contains(mountFreeRegExp)) {
|
} else if (source.contains(mountFreeRegExp)) {
|
||||||
// free space
|
// free space
|
||||||
@ -351,11 +360,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
// mb
|
// mb
|
||||||
QString key = QString("hddfreemb%1").arg(index);
|
QString key = QString("hddfreemb%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::MemMBFormat;
|
m_formatter[key] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
key = QString("hddfreegb%1").arg(index);
|
key = QString("hddfreegb%1").arg(index);
|
||||||
m_map.insertMulti(source, key);
|
m_map.insertMulti(source, key);
|
||||||
m_formater[key] = FormaterType::MemGBFormat;
|
m_formatter[key] = FormatterType::MemGBFormat;
|
||||||
}
|
}
|
||||||
} else if (source.contains(mountUsedRegExp)) {
|
} else if (source.contains(mountUsedRegExp)) {
|
||||||
// used
|
// used
|
||||||
@ -366,11 +375,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
// mb
|
// mb
|
||||||
QString key = QString("hddmb%1").arg(index);
|
QString key = QString("hddmb%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::MemMBFormat;
|
m_formatter[key] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
key = QString("hddgb%1").arg(index);
|
key = QString("hddgb%1").arg(index);
|
||||||
m_map.insertMulti(source, key);
|
m_map.insertMulti(source, key);
|
||||||
m_formater[key] = FormaterType::MemGBFormat;
|
m_formatter[key] = FormatterType::MemGBFormat;
|
||||||
}
|
}
|
||||||
} else if (source.startsWith(QString("hdd/temperature"))) {
|
} else if (source.startsWith(QString("hdd/temperature"))) {
|
||||||
// hdd temperature
|
// hdd temperature
|
||||||
@ -380,7 +389,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
QString key = QString("hddtemp%1").arg(index);
|
QString key = QString("hddtemp%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Temperature;
|
m_formatter[key] = FormatterType::Temperature;
|
||||||
}
|
}
|
||||||
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
|
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
|
||||||
// load average
|
// load average
|
||||||
@ -388,35 +397,35 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
time.remove(QString("cpu/system/loadavg"));
|
time.remove(QString("cpu/system/loadavg"));
|
||||||
QString key = QString("la%1").arg(time);
|
QString key = QString("la%1").arg(time);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::FloatTwoSymbols;
|
m_formatter[key] = FormatterType::FloatTwoSymbols;
|
||||||
} else if (source == QString("mem/physical/application")) {
|
} else if (source == QString("mem/physical/application")) {
|
||||||
// app memory
|
// app memory
|
||||||
// mb
|
// mb
|
||||||
m_map[source] = QString("memmb");
|
m_map[source] = QString("memmb");
|
||||||
m_formater[QString("memmb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("memmb")] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
m_map.insertMulti(source, QString("memgb"));
|
m_map.insertMulti(source, QString("memgb"));
|
||||||
m_formater[QString("memgb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("memgb")] = FormatterType::MemGBFormat;
|
||||||
} else if (source == QString("mem/physical/free")) {
|
} else if (source == QString("mem/physical/free")) {
|
||||||
// free memory
|
// free memory
|
||||||
// mb
|
// mb
|
||||||
m_map[source] = QString("memfreemb");
|
m_map[source] = QString("memfreemb");
|
||||||
m_formater[QString("memfreemb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("memfreemb")] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
m_map.insertMulti(source, QString("memfreegb"));
|
m_map.insertMulti(source, QString("memfreegb"));
|
||||||
m_formater[QString("memfreegb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("memfreegb")] = FormatterType::MemGBFormat;
|
||||||
} else if (source == QString("mem/physical/used")) {
|
} else if (source == QString("mem/physical/used")) {
|
||||||
// used memory
|
// used memory
|
||||||
// mb
|
// mb
|
||||||
m_map[source] = QString("memusedmb");
|
m_map[source] = QString("memusedmb");
|
||||||
m_formater[QString("memusedmb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("memusedmb")] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
m_map.insertMulti(source, QString("memusedgb"));
|
m_map.insertMulti(source, QString("memusedgb"));
|
||||||
m_formater[QString("memusedgb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("memusedgb")] = FormatterType::MemGBFormat;
|
||||||
} else if (source == QString("network/current/name")) {
|
} else if (source == QString("network/current/name")) {
|
||||||
// network device
|
// network device
|
||||||
m_map[source] = QString("netdev");
|
m_map[source] = QString("netdev");
|
||||||
m_formater[QString("netdev")] = FormaterType::NoFormat;
|
m_formatter[QString("netdev")] = FormatterType::NoFormat;
|
||||||
} else if (source.contains(netRegExp)) {
|
} else if (source.contains(netRegExp)) {
|
||||||
// network speed
|
// network speed
|
||||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||||
@ -427,15 +436,15 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
// kb
|
// kb
|
||||||
QString key = QString("%1kb%2").arg(type).arg(index);
|
QString key = QString("%1kb%2").arg(type).arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Integer;
|
m_formatter[key] = FormatterType::Integer;
|
||||||
// smart
|
// smart
|
||||||
key = QString("%1%2").arg(type).arg(index);
|
key = QString("%1%2").arg(type).arg(index);
|
||||||
m_map.insertMulti(source, key);
|
m_map.insertMulti(source, key);
|
||||||
m_formater[key] = FormaterType::NetSmartFormat;
|
m_formatter[key] = FormatterType::NetSmartFormat;
|
||||||
// units
|
// units
|
||||||
key = QString("%1units%2").arg(type).arg(index);
|
key = QString("%1units%2").arg(type).arg(index);
|
||||||
m_map.insertMulti(source, key);
|
m_map.insertMulti(source, key);
|
||||||
m_formater[key] = FormaterType::NetSmartUnits;
|
m_formatter[key] = FormatterType::NetSmartUnits;
|
||||||
}
|
}
|
||||||
} else if (source.contains(netTotalRegExp)) {
|
} else if (source.contains(netTotalRegExp)) {
|
||||||
// network data total
|
// network data total
|
||||||
@ -447,58 +456,58 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
// kb
|
// kb
|
||||||
QString key = QString("%1totalkb%2").arg(type).arg(index);
|
QString key = QString("%1totalkb%2").arg(type).arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Integer;
|
m_formatter[key] = FormatterType::Integer;
|
||||||
// mb
|
// mb
|
||||||
key = QString("%1total%2").arg(type).arg(index);
|
key = QString("%1total%2").arg(type).arg(index);
|
||||||
m_map.insertMulti(source, key);
|
m_map.insertMulti(source, key);
|
||||||
m_formater[key] = FormaterType::MemMBFormat;
|
m_formatter[key] = FormatterType::MemMBFormat;
|
||||||
}
|
}
|
||||||
} else if (source.startsWith(QString("upgrade"))) {
|
} else if (source.startsWith(QString("upgrade"))) {
|
||||||
// package manager
|
// package manager
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("upgrade/"));
|
key.remove(QString("upgrade/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::IntegerThree;
|
m_formatter[key] = FormatterType::IntegerThree;
|
||||||
} else if (source.startsWith(QString("player"))) {
|
} else if (source.startsWith(QString("player"))) {
|
||||||
// player
|
// player
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("player/"));
|
key.remove(QString("player/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::NoFormat;
|
m_formatter[key] = FormatterType::NoFormat;
|
||||||
} else if (source == QString("ps/running/count")) {
|
} else if (source == QString("ps/running/count")) {
|
||||||
// running processes count
|
// running processes count
|
||||||
m_map[source] = QString("pscount");
|
m_map[source] = QString("pscount");
|
||||||
m_formater[QString("pscount")] = FormaterType::NoFormat;
|
m_formatter[QString("pscount")] = FormatterType::NoFormat;
|
||||||
} else if (source == QString("ps/running/list")) {
|
} else if (source == QString("ps/running/list")) {
|
||||||
// list of running processes
|
// list of running processes
|
||||||
m_map[source] = QString("ps");
|
m_map[source] = QString("ps");
|
||||||
m_formater[QString("ps")] = FormaterType::List;
|
m_formatter[QString("ps")] = FormatterType::List;
|
||||||
} else if (source == QString("ps/total/count")) {
|
} else if (source == QString("ps/total/count")) {
|
||||||
// total processes count
|
// total processes count
|
||||||
m_map[source] = QString("pstotal");
|
m_map[source] = QString("pstotal");
|
||||||
m_formater[QString("pstotal")] = FormaterType::NoFormat;
|
m_formatter[QString("pstotal")] = FormatterType::NoFormat;
|
||||||
} else if (source.startsWith(QString("quotes"))) {
|
} else if (source.startsWith(QString("quotes"))) {
|
||||||
// quotes
|
// quotes
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("quotes/"));
|
key.remove(QString("quotes/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Quotes;
|
m_formatter[key] = FormatterType::Quotes;
|
||||||
} else if (source == QString("mem/swap/free")) {
|
} else if (source == QString("mem/swap/free")) {
|
||||||
// free swap
|
// free swap
|
||||||
// mb
|
// mb
|
||||||
m_map[source] = QString("swapfreemb");
|
m_map[source] = QString("swapfreemb");
|
||||||
m_formater[QString("swapfreemb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("swapfreemb")] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
m_map.insertMulti(source, QString("swapfreegb"));
|
m_map.insertMulti(source, QString("swapfreegb"));
|
||||||
m_formater[QString("swapfreegb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("swapfreegb")] = FormatterType::MemGBFormat;
|
||||||
} else if (source == QString("mem/swap/used")) {
|
} else if (source == QString("mem/swap/used")) {
|
||||||
// used swap
|
// used swap
|
||||||
// mb
|
// mb
|
||||||
m_map[source] = QString("swapmb");
|
m_map[source] = QString("swapmb");
|
||||||
m_formater[QString("swapmb")] = FormaterType::MemMBFormat;
|
m_formatter[QString("swapmb")] = FormatterType::MemMBFormat;
|
||||||
// gb
|
// gb
|
||||||
m_map.insertMulti(source, QString("swapgb"));
|
m_map.insertMulti(source, QString("swapgb"));
|
||||||
m_formater[QString("swapgb")] = FormaterType::MemGBFormat;
|
m_formatter[QString("swapgb")] = FormatterType::MemGBFormat;
|
||||||
} else if (source.startsWith(QString("lmsensors/"))) {
|
} else if (source.startsWith(QString("lmsensors/"))) {
|
||||||
// temperature
|
// temperature
|
||||||
int index = m_devices[QString("temp")].indexOf(source);
|
int index = m_devices[QString("temp")].indexOf(source);
|
||||||
@ -508,64 +517,77 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
QString key = QString("temp%1").arg(index);
|
QString key = QString("temp%1").arg(index);
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = units == QString("°C") ? FormaterType::Temperature
|
m_formatter[key] = units == QString("°C")
|
||||||
: FormaterType::Integer;
|
? FormatterType::Temperature
|
||||||
|
: FormatterType::Integer;
|
||||||
}
|
}
|
||||||
} else if (source == QString("Local")) {
|
} else if (source == QString("Local")) {
|
||||||
// time
|
// time
|
||||||
m_map[source] = QString("time");
|
m_map[source] = QString("time");
|
||||||
m_formater[QString("time")] = FormaterType::Time;
|
m_formatter[QString("time")] = FormatterType::Time;
|
||||||
// custom time
|
// custom time
|
||||||
m_map.insertMulti(source, QString("ctime"));
|
m_map.insertMulti(source, QString("ctime"));
|
||||||
m_formater[QString("ctime")] = FormaterType::TimeCustom;
|
m_formatter[QString("ctime")] = FormatterType::TimeCustom;
|
||||||
// ISO time
|
// ISO time
|
||||||
m_map.insertMulti(source, QString("isotime"));
|
m_map.insertMulti(source, QString("isotime"));
|
||||||
m_formater[QString("isotime")] = FormaterType::TimeISO;
|
m_formatter[QString("isotime")] = FormatterType::TimeISO;
|
||||||
// long time
|
// long time
|
||||||
m_map.insertMulti(source, QString("longtime"));
|
m_map.insertMulti(source, QString("longtime"));
|
||||||
m_formater[QString("longtime")] = FormaterType::TimeLong;
|
m_formatter[QString("longtime")] = FormatterType::TimeLong;
|
||||||
// short time
|
// short time
|
||||||
m_map.insertMulti(source, QString("shorttime"));
|
m_map.insertMulti(source, QString("shorttime"));
|
||||||
m_formater[QString("shorttime")] = FormaterType::TimeShort;
|
m_formatter[QString("shorttime")] = FormatterType::TimeShort;
|
||||||
} else if (source == QString("system/uptime")) {
|
} else if (source == QString("system/uptime")) {
|
||||||
// uptime
|
// uptime
|
||||||
m_map[source] = QString("uptime");
|
m_map[source] = QString("uptime");
|
||||||
m_formater[QString("uptime")] = FormaterType::Uptime;
|
m_formatter[QString("uptime")] = FormatterType::Uptime;
|
||||||
// custom uptime
|
// custom uptime
|
||||||
m_map.insertMulti(source, QString("cuptime"));
|
m_map.insertMulti(source, QString("cuptime"));
|
||||||
m_formater[QString("cuptime")] = FormaterType::UptimeCustom;
|
m_formatter[QString("cuptime")] = FormatterType::UptimeCustom;
|
||||||
} else if (source.startsWith(QString("weather/temperature"))) {
|
} else if (source.startsWith(QString("weather/temperature"))) {
|
||||||
// temperature
|
// temperature
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("weather/"));
|
key.remove(QString("weather/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Temperature;
|
m_formatter[key] = FormatterType::Temperature;
|
||||||
} else if (source.startsWith(QString("weather/"))) {
|
} else if (source.startsWith(QString("weather/"))) {
|
||||||
// other weather
|
// other weather
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("weather/"));
|
key.remove(QString("weather/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::NoFormat;
|
m_formatter[key] = FormatterType::NoFormat;
|
||||||
} else if (source.startsWith(QString("load/load"))) {
|
} else if (source.startsWith(QString("load/load"))) {
|
||||||
// load source
|
// load source
|
||||||
QString key = source;
|
QString key = source;
|
||||||
key.remove(QString("load/"));
|
key.remove(QString("load/"));
|
||||||
m_map[source] = key;
|
m_map[source] = key;
|
||||||
m_formater[key] = FormaterType::Temperature;
|
m_formatter[key] = FormatterType::Temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList foundKeys = keysFromSource(source);
|
||||||
|
|
||||||
|
// rewrite formatters for custom ones
|
||||||
|
QStringList customFormattersKeys = m_customFormatters->definedFormatters();
|
||||||
|
qCInfo(LOG_AW) << "Looking for fprmatters" << foundKeys << "in"
|
||||||
|
<< customFormattersKeys;
|
||||||
|
for (auto key : foundKeys) {
|
||||||
|
if (!customFormattersKeys.contains(key))
|
||||||
|
continue;
|
||||||
|
m_formatter[key] = FormatterType::Custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop key from dictionary if no one user requested key required it
|
// drop key from dictionary if no one user requested key required it
|
||||||
QStringList foundKeys = keysFromSource(source);
|
|
||||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
|
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
|
||||||
// this source is required if list is empty (which means skip checking)
|
|
||||||
// or if key in required key list
|
|
||||||
bool required
|
bool required
|
||||||
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||||
[&keys](const QString &key) {
|
[&keys](const QString &key) {
|
||||||
return keys.contains(key);
|
return keys.contains(key);
|
||||||
});
|
});
|
||||||
if (!required)
|
if (!required) {
|
||||||
m_map.remove(source);
|
m_map.remove(source);
|
||||||
|
for (auto key : foundKeys)
|
||||||
|
m_formatter.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
return keysFromSource(source);
|
return keysFromSource(source);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
|
||||||
|
class AWFormatterHelper;
|
||||||
|
|
||||||
class AWKeysAggregator : public QObject
|
class AWKeysAggregator : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -36,16 +38,17 @@ class AWKeysAggregator : public QObject
|
|||||||
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits);
|
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits);
|
||||||
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate);
|
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate);
|
||||||
|
|
||||||
enum class FormaterType {
|
enum class FormatterType {
|
||||||
// general formaters
|
// general formatters
|
||||||
NoFormat = 0,
|
Custom,
|
||||||
|
NoFormat,
|
||||||
Float,
|
Float,
|
||||||
FloatTwoSymbols,
|
FloatTwoSymbols,
|
||||||
Integer,
|
Integer,
|
||||||
IntegerFive,
|
IntegerFive,
|
||||||
IntegerThree,
|
IntegerThree,
|
||||||
List,
|
List,
|
||||||
// unit specific formaters
|
// unit specific formatters
|
||||||
ACFormat,
|
ACFormat,
|
||||||
MemGBFormat,
|
MemGBFormat,
|
||||||
MemMBFormat,
|
MemMBFormat,
|
||||||
@ -66,7 +69,7 @@ public:
|
|||||||
explicit AWKeysAggregator(QObject *parent = nullptr);
|
explicit AWKeysAggregator(QObject *parent = nullptr);
|
||||||
virtual ~AWKeysAggregator();
|
virtual ~AWKeysAggregator();
|
||||||
// get methods
|
// get methods
|
||||||
QString formater(const QVariant &data, const QString &key) const;
|
QString formatter(const QVariant &data, const QString &key) const;
|
||||||
QStringList keysFromSource(const QString &source) const;
|
QStringList keysFromSource(const QString &source) const;
|
||||||
// set methods
|
// set methods
|
||||||
void setAcOffline(const QString inactive);
|
void setAcOffline(const QString inactive);
|
||||||
@ -83,6 +86,7 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
float temperature(const float temp) const;
|
float temperature(const float temp) const;
|
||||||
|
AWFormatterHelper *m_customFormatters = nullptr;
|
||||||
QStringList timeKeys = QString(TIME_KEYS).split(QChar(','));
|
QStringList timeKeys = QString(TIME_KEYS).split(QChar(','));
|
||||||
// variables
|
// variables
|
||||||
QString m_acOffline;
|
QString m_acOffline;
|
||||||
@ -90,7 +94,7 @@ private:
|
|||||||
QString m_customTime;
|
QString m_customTime;
|
||||||
QString m_customUptime;
|
QString m_customUptime;
|
||||||
QHash<QString, QStringList> m_devices;
|
QHash<QString, QStringList> m_devices;
|
||||||
QHash<QString, FormaterType> m_formater;
|
QHash<QString, FormatterType> m_formatter;
|
||||||
QHash<QString, QString> m_map;
|
QHash<QString, QString> m_map;
|
||||||
QString m_tempUnits;
|
QString m_tempUnits;
|
||||||
bool m_translate = false;
|
bool m_translate = false;
|
||||||
|
@ -37,7 +37,7 @@ QString AWPatternFunctions::expandLambdas(QString code,
|
|||||||
// parsed values
|
// parsed values
|
||||||
for (auto lambdaKey : usedKeys)
|
for (auto lambdaKey : usedKeys)
|
||||||
code.replace(QString("$%1").arg(lambdaKey),
|
code.replace(QString("$%1").arg(lambdaKey),
|
||||||
aggregator->formater(metadata[lambdaKey], lambdaKey));
|
aggregator->formatter(metadata[lambdaKey], lambdaKey));
|
||||||
qCInfo(LOG_AW) << "Expression" << code;
|
qCInfo(LOG_AW) << "Expression" << code;
|
||||||
QJSValue result = engine.evaluate(code);
|
QJSValue result = engine.evaluate(code);
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
|
@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem
|
|||||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
|
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
|
||||||
|
|
||||||
explicit ExtScript(QWidget *parent = nullptr,
|
explicit ExtScript(QWidget *parent = nullptr,
|
||||||
const QString scriptName = QString(),
|
const QString scriptName = QString(),
|
||||||
|
@ -50,7 +50,7 @@ class GraphicalItem : public AbstractExtItem
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||||
enum class Type { Horizontal = 0, Vertical, Circle, Graph, Bars };
|
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
|
||||||
|
|
||||||
explicit GraphicalItem(QWidget *parent = nullptr,
|
explicit GraphicalItem(QWidget *parent = nullptr,
|
||||||
const QString desktopName = QString(),
|
const QString desktopName = QString(),
|
||||||
|
Loading…
Reference in New Issue
Block a user