mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 23:29:58 +00:00
possible fix #75
I've added 'optimize' option (by default true). If it options is set then sources will be checked if they are required (with dependencies if any). And if they are not required they will be dropped by using common mechanism. Please note that if this option enabled the following features (at the moment) will be unavailable: * key request from context menu (from configuration interface it still works) * notifications event if sources on which notification is not connected I suppose this commit will increase performance in about 4-5 times.
This commit is contained in:
@ -87,7 +87,7 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
counts += configuration[QString("cpuclTooltip")].toInt();
|
||||
counts += configuration[QString("memTooltip")].toInt();
|
||||
counts += configuration[QString("swapTooltip")].toInt();
|
||||
counts += configuration[QString("downTooltip")].toInt();
|
||||
counts += configuration[QString("downkbTooltip")].toInt();
|
||||
counts += configuration[QString("batTooltip")].toInt();
|
||||
// resize tooltip image
|
||||
toolTipView->resize(100 * counts, 105);
|
||||
@ -96,8 +96,8 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
boundaries[QString("cpuclTooltip")] = 4000.0;
|
||||
boundaries[QString("memTooltip")] = 100.0;
|
||||
boundaries[QString("swapTooltip")] = 100.0;
|
||||
boundaries[QString("downTooltip")] = 1.0;
|
||||
boundaries[QString("upTooltip")] = 1.0;
|
||||
boundaries[QString("downkbTooltip")] = 1.0;
|
||||
boundaries[QString("upkbTooltip")] = 1.0;
|
||||
boundaries[QString("batTooltip")] = 100.0;
|
||||
|
||||
requiredKeys.clear();
|
||||
@ -109,10 +109,10 @@ void AWDataAggregator::setParameters(QVariantMap settings)
|
||||
requiredKeys.append(QString("memTooltip"));
|
||||
if (configuration[QString("swapTooltip")].toBool())
|
||||
requiredKeys.append(QString("swapTooltip"));
|
||||
if (configuration[QString("downTooltip")].toBool())
|
||||
requiredKeys.append(QString("downTooltip"));
|
||||
if (configuration[QString("upTooltip")].toBool())
|
||||
requiredKeys.append(QString("upTooltip"));
|
||||
if (configuration[QString("downkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("downkbTooltip"));
|
||||
if (configuration[QString("upkbTooltip")].toBool())
|
||||
requiredKeys.append(QString("upkbTooltip"));
|
||||
if (configuration[QString("batTooltip")].toBool())
|
||||
requiredKeys.append(QString("batTooltip"));
|
||||
|
||||
@ -133,9 +133,9 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
bool down = false;
|
||||
for (auto key : requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0 / static_cast<float>(data[key].count());
|
||||
float normY = 100.0 / (1.5 * boundaries[key]);
|
||||
float shift = requiredKeys.indexOf(key) * 100.0;
|
||||
float normX = 100.0f / static_cast<float>(data[key].count());
|
||||
float normY = 100.0f / (1.5f * boundaries[key]);
|
||||
float shift = requiredKeys.indexOf(key) * 100.0f;
|
||||
if (down)
|
||||
shift -= 100.0;
|
||||
// apply pen color
|
||||
@ -146,9 +146,9 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
for (int j = 0; j < data[key].count() - 1; j++) {
|
||||
// some magic here
|
||||
float x1 = j * normX + shift;
|
||||
float y1 = -fabs(data[key].at(j)) * normY + 5.0;
|
||||
float y1 = -fabs(data[key].at(j)) * normY + 5.0f;
|
||||
float x2 = (j + 1) * normX + shift;
|
||||
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0;
|
||||
float y2 = -fabs(data[key].at(j + 1)) * normY + 5.0f;
|
||||
if (key == QString("batTooltip")) {
|
||||
if (data[key].at(j + 1) > 0)
|
||||
pen.setColor(QColor(
|
||||
@ -160,7 +160,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
}
|
||||
toolTipScene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
if (key == QString("downTooltip"))
|
||||
if (key == QString("downkbTooltip"))
|
||||
down = true;
|
||||
}
|
||||
|
||||
@ -265,8 +265,8 @@ void AWDataAggregator::setData(const QHash<QString, QString> &values)
|
||||
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
|
||||
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0);
|
||||
setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0);
|
||||
setData(QString("downTooltip"), values[QString("downkb")].toFloat());
|
||||
setData(QString("upTooltip"), values[QString("upkb")].toFloat());
|
||||
setData(QString("downkbTooltip"), values[QString("downkb")].toFloat());
|
||||
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
||||
// additional check for network device
|
||||
[this](const QString value) {
|
||||
checkValue(QString("netdev"), currentNetworkDevice, value);
|
||||
@ -298,12 +298,13 @@ void AWDataAggregator::setData(const QString &source, float value,
|
||||
checkValue(source, value, extremum);
|
||||
|
||||
data[source].append(value);
|
||||
if (source == QString("downTooltip")) {
|
||||
if (source == QString("downkbTooltip")) {
|
||||
QList<float> netValues
|
||||
= data[QString("downTooltip")] + data[QString("upTooltip")];
|
||||
boundaries[QString("downTooltip")]
|
||||
= data[QString("downkbTooltip")] + data[QString("upkbTooltip")];
|
||||
boundaries[QString("downkbTooltip")]
|
||||
= 1.2 * *std::max_element(netValues.cbegin(), netValues.cend());
|
||||
boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")];
|
||||
boundaries[QString("upkbTooltip")]
|
||||
= boundaries[QString("downkbTooltip")];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,14 +21,10 @@
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent,
|
||||
const int interval)
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
setInterval(interval);
|
||||
initDataEngines();
|
||||
}
|
||||
|
||||
|
||||
@ -36,10 +32,17 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::clear()
|
||||
{
|
||||
// disconnect sources first
|
||||
disconnectSources();
|
||||
m_dataEngines.clear();
|
||||
delete m_consumer;
|
||||
m_consumer = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -51,11 +54,27 @@ void AWDataEngineAggregator::disconnectSources()
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::setInterval(const int _interval)
|
||||
void AWDataEngineAggregator::initDataEngines(const int interval)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Interval" << _interval;
|
||||
qCDebug(LOG_AW) << "Init dataengines with interval" << interval;
|
||||
|
||||
m_interval = _interval;
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines[QString("systemmonitor")]
|
||||
= m_consumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")]
|
||||
= m_consumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = m_consumer->dataEngine(QString("time"));
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
connect(m_dataEngines[QString("systemmonitor")],
|
||||
&Plasma::DataEngine::sourceAdded,
|
||||
[this, interval](const QString source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(
|
||||
source, parent(), interval);
|
||||
});
|
||||
|
||||
return reconnectSources(interval);
|
||||
}
|
||||
|
||||
|
||||
@ -70,31 +89,13 @@ void AWDataEngineAggregator::dropSource(const QString source)
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::reconnectSources()
|
||||
void AWDataEngineAggregator::reconnectSources(const int interval)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Reconnect sources with interval" << interval;
|
||||
|
||||
m_dataEngines[QString("systemmonitor")]->connectAllSources(parent(),
|
||||
m_interval);
|
||||
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(),
|
||||
m_interval);
|
||||
interval);
|
||||
m_dataEngines[QString("extsysmon")]->connectAllSources(parent(), interval);
|
||||
m_dataEngines[QString("time")]->connectSource(QString("Local"), parent(),
|
||||
1000);
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::initDataEngines()
|
||||
{
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines[QString("systemmonitor")]
|
||||
= m_consumer->dataEngine(QString("systemmonitor"));
|
||||
m_dataEngines[QString("extsysmon")]
|
||||
= m_consumer->dataEngine(QString("extsysmon"));
|
||||
m_dataEngines[QString("time")] = m_consumer->dataEngine(QString("time"));
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
connect(m_dataEngines[QString("systemmonitor")],
|
||||
&Plasma::DataEngine::sourceAdded, [this](const QString source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines[QString("systemmonitor")]->connectSource(
|
||||
source, parent(), m_interval);
|
||||
});
|
||||
}
|
||||
|
@ -28,28 +28,24 @@
|
||||
class AWDataEngineAggregator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int interval MEMBER m_interval WRITE setInterval);
|
||||
|
||||
public:
|
||||
explicit AWDataEngineAggregator(QObject *parent = nullptr,
|
||||
const int interval = 1000);
|
||||
explicit AWDataEngineAggregator(QObject *parent = nullptr);
|
||||
virtual ~AWDataEngineAggregator();
|
||||
void clear();
|
||||
void disconnectSources();
|
||||
// properties
|
||||
void setInterval(const int _interval);
|
||||
void initDataEngines(const int interval);
|
||||
|
||||
signals:
|
||||
void deviceAdded(const QString &source);
|
||||
|
||||
public slots:
|
||||
void dropSource(const QString source);
|
||||
void reconnectSources();
|
||||
void reconnectSources(const int interval);
|
||||
|
||||
private:
|
||||
void initDataEngines();
|
||||
Plasma::DataEngineConsumer *m_consumer = nullptr;
|
||||
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||
int m_interval;
|
||||
};
|
||||
|
||||
|
||||
|
@ -81,6 +81,93 @@ bool AWKeyCache::addKeyToCache(const QString type, const QString key)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeyCache::getRequiredKeys(const QStringList &keys,
|
||||
const QStringList &bars,
|
||||
const QVariantMap &tooltip,
|
||||
const QStringList &allKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for required keys in" << keys << bars
|
||||
<< "using tooltip settings" << tooltip;
|
||||
|
||||
// initial copy
|
||||
QSet<QString> used = QSet<QString>::fromList(keys);
|
||||
// insert bars
|
||||
for (auto bar : bars) {
|
||||
bar.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
used << bar;
|
||||
}
|
||||
// insert keys from tooltip
|
||||
for (auto key : tooltip.keys()) {
|
||||
if ((key.endsWith(QString("Tooltip"))) && (tooltip[key].toBool())) {
|
||||
key.remove(QString("Tooltip"));
|
||||
used << key;
|
||||
}
|
||||
}
|
||||
|
||||
// insert depending keys, refer to AWKeys::calculateValues()
|
||||
// hddtotmb*
|
||||
for (auto key : allKeys.filter(QRegExp(QString("^hddtotmb")))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove(QString("hddtotmb"));
|
||||
int index = key.toInt();
|
||||
used << QString("hddfreemb%1").arg(index)
|
||||
<< QString("hddmb%1").arg(index);
|
||||
}
|
||||
// hddtotgb*
|
||||
for (auto key : allKeys.filter(QRegExp(QString("^hddtotgb")))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove(QString("hddtotgb"));
|
||||
int index = key.toInt();
|
||||
used << QString("hddfreegb%1").arg(index)
|
||||
<< QString("hddgb%1").arg(index);
|
||||
}
|
||||
// mem
|
||||
if (used.contains(QString("mem")))
|
||||
used << QString("memmb") << QString("memtotmb");
|
||||
// memtotmb
|
||||
if (used.contains(QString("memtotmb")))
|
||||
used << QString("memusedmb") << QString("memfreemb");
|
||||
// memtotgb
|
||||
if (used.contains(QString("memtotgb")))
|
||||
used << QString("memusedgb") << QString("memfreegb");
|
||||
// swap
|
||||
if (used.contains(QString("swap")))
|
||||
used << QString("swapmb") << QString("swaptotmb");
|
||||
// swaptotmb
|
||||
if (used.contains(QString("swaptotmb")))
|
||||
used << QString("swapmb") << QString("swapfreemb");
|
||||
// memtotgb
|
||||
if (used.contains(QString("swaptotgb")))
|
||||
used << QString("swapgb") << QString("swapfreegb");
|
||||
// network keys
|
||||
QStringList netKeys(QStringList() << QString("up") << QString("upkb")
|
||||
<< QString("upunits") << QString("down")
|
||||
<< QString("downkb")
|
||||
<< QString("downunits"));
|
||||
for (auto key : netKeys) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
QStringList filt
|
||||
= allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
|
||||
for (auto filtered : filt)
|
||||
used << filtered;
|
||||
}
|
||||
// netdev key
|
||||
if (std::any_of(netKeys.cbegin(), netKeys.cend(),
|
||||
[&used](const QString &key) { return used.contains(key); }))
|
||||
used << QString("netdev");
|
||||
|
||||
// HACK append dummy if there are no other keys. This hack is required
|
||||
// because empty list leads to the same behaviour as skip checking
|
||||
if (used.isEmpty())
|
||||
used << QString("dummy");
|
||||
|
||||
return used.toList();
|
||||
}
|
||||
|
||||
|
||||
QHash<QString, QStringList> AWKeyCache::loadKeysFromCache()
|
||||
{
|
||||
QString fileName = QString("%1/awesomewidgets.ndx")
|
||||
|
@ -21,11 +21,15 @@
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
namespace AWKeyCache
|
||||
{
|
||||
bool addKeyToCache(const QString type, const QString key = QString(""));
|
||||
QStringList getRequiredKeys(const QStringList &keys, const QStringList &bars,
|
||||
const QVariantMap &tooltip,
|
||||
const QStringList &allKeys);
|
||||
QHash<QString, QStringList> loadKeysFromCache();
|
||||
};
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
#include "awdebug.h"
|
||||
#include "awkeycache.h"
|
||||
#include "awkeyoperations.h"
|
||||
#include "awkeysaggregator.h"
|
||||
#include "awpatternfunctions.h"
|
||||
@ -45,7 +46,9 @@ AWKeys::AWKeys(QObject *parent)
|
||||
|
||||
aggregator = new AWKeysAggregator(this);
|
||||
dataAggregator = new AWDataAggregator(this);
|
||||
dataEngineAggregator = new AWDataEngineAggregator(this);
|
||||
keyOperator = new AWKeyOperations(this);
|
||||
|
||||
// update key data if required
|
||||
connect(keyOperator, SIGNAL(updateKeys(QStringList)), this,
|
||||
SLOT(reinitKeys(QStringList)));
|
||||
@ -53,6 +56,11 @@ AWKeys::AWKeys(QObject *parent)
|
||||
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(updateTextData()));
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
|
||||
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
keyOperator, SLOT(addDevice(const QString &)));
|
||||
}
|
||||
|
||||
|
||||
@ -73,32 +81,29 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Tooltip parameters" << tooltipParams;
|
||||
|
||||
dataAggregator->setParameters(tooltipParams);
|
||||
// store parameters to generate m_requiredKeys
|
||||
m_tooltipParams = tooltipParams;
|
||||
dataAggregator->setParameters(m_tooltipParams);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
const int limit)
|
||||
const int limit, const bool optimize)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Pattern" << currentPattern << "with interval"
|
||||
<< interval << "and queue limit" << limit;
|
||||
<< interval << "and queue limit" << limit
|
||||
<< "with optimization" << optimize;
|
||||
|
||||
// init
|
||||
keyOperator->setPattern(currentPattern);
|
||||
if (dataEngineAggregator == nullptr) {
|
||||
dataEngineAggregator = new AWDataEngineAggregator(this, interval);
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
|
||||
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(dataEngineAggregator, SIGNAL(deviceAdded(const QString &)),
|
||||
keyOperator, SLOT(addDevice(const QString &)));
|
||||
} else
|
||||
dataEngineAggregator->setInterval(interval);
|
||||
m_optimize = optimize;
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
// child objects
|
||||
keyOperator->setPattern(currentPattern);
|
||||
keyOperator->updateCache();
|
||||
dataEngineAggregator->clear();
|
||||
|
||||
return dataEngineAggregator->reconnectSources();
|
||||
return dataEngineAggregator->initDataEngines(interval);
|
||||
}
|
||||
|
||||
|
||||
@ -200,6 +205,11 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
m_foundKeys
|
||||
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
||||
// get required keys
|
||||
m_requiredKeys
|
||||
= m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, m_foundBars,
|
||||
m_tooltipParams, currentKeys)
|
||||
: QStringList();
|
||||
|
||||
// set key data to aggregator
|
||||
aggregator->setDevices(keyOperator->devices());
|
||||
@ -347,8 +357,8 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
// first list init
|
||||
QStringList tags = aggregator->keysFromSource(sourceName);
|
||||
if (tags.isEmpty())
|
||||
tags = aggregator->registerSource(sourceName,
|
||||
data[QString("units")].toString());
|
||||
tags = aggregator->registerSource(
|
||||
sourceName, data[QString("units")].toString(), m_requiredKeys);
|
||||
|
||||
// update data or drop source if there are no matches and exit
|
||||
if (tags.isEmpty()) {
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
virtual ~AWKeys();
|
||||
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
|
||||
Q_INVOKABLE void initKeys(const QString currentPattern, const int interval,
|
||||
const int limit);
|
||||
const int limit, const bool optimize);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString key,
|
||||
const QVariant value);
|
||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||
@ -84,8 +84,10 @@ private:
|
||||
AWKeysAggregator *aggregator = nullptr;
|
||||
AWKeyOperations *keyOperator = nullptr;
|
||||
// variables
|
||||
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
|
||||
QVariantMap m_tooltipParams;
|
||||
QStringList m_foundBars, m_foundKeys, m_foundLambdas, m_requiredKeys;
|
||||
QHash<QString, QString> values;
|
||||
bool m_optimize = false;
|
||||
bool m_wrapNewLines = false;
|
||||
// multithread features
|
||||
QThreadPool *m_threadPool = nullptr;
|
||||
|
@ -154,15 +154,6 @@ QStringList AWKeysAggregator::keysFromSource(const QString &source) const
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
AWKeysAggregator::requiredByKeysFromSource(const QString &source) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Search for source" << source;
|
||||
|
||||
return m_requiredByMap.values(source);
|
||||
}
|
||||
|
||||
|
||||
void AWKeysAggregator::setAcOffline(const QString inactive)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Inactive AC string" << inactive;
|
||||
@ -222,7 +213,8 @@ void AWKeysAggregator::setTranslate(const bool 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 QString &units,
|
||||
const QStringList &keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << source << "with units" << units;
|
||||
|
||||
@ -338,11 +330,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
key = QString("hddfreegb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotmb%1").arg(index));
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotgb%1").arg(index));
|
||||
}
|
||||
} else if (source.contains(mountUsedRegExp)) {
|
||||
// used
|
||||
@ -358,11 +345,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
key = QString("hddgb%1").arg(index);
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotmb%1").arg(index));
|
||||
m_requiredByMap.insertMulti(source,
|
||||
QString("hddtotgb%1").arg(index));
|
||||
}
|
||||
} else if (source.startsWith(QString("hdd/temperature"))) {
|
||||
// hdd temperature
|
||||
@ -389,8 +371,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memgb"));
|
||||
m_formater[QString("memgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("mem/physical/free")) {
|
||||
// free memory
|
||||
// mb
|
||||
@ -399,10 +379,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memfreegb"));
|
||||
m_formater[QString("memfreegb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("memtotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("memtotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("mem/physical/used")) {
|
||||
// used memory
|
||||
// mb
|
||||
@ -411,21 +387,10 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("memusedgb"));
|
||||
m_formater[QString("memusedgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("memtotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("memtotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("mem"));
|
||||
} else if (source == QString("network/current/name")) {
|
||||
// network device
|
||||
m_map[source] = QString("netdev");
|
||||
m_formater[QString("netdev")] = NoFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("down"));
|
||||
m_requiredByMap.insertMulti(source, QString("downkb"));
|
||||
m_requiredByMap.insertMulti(source, QString("downunits"));
|
||||
m_requiredByMap.insertMulti(source, QString("up"));
|
||||
m_requiredByMap.insertMulti(source, QString("upkb"));
|
||||
m_requiredByMap.insertMulti(source, QString("upunits"));
|
||||
} else if (source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = source.contains(QString("receiver")) ? QString("down")
|
||||
@ -446,13 +411,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
m_map.insertMulti(source, key);
|
||||
m_formater[key] = NetSmartUnits;
|
||||
}
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("%1").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1kb").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1units").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1kb").arg(type));
|
||||
m_requiredByMap.insertMulti(source, QString("%1units").arg(type));
|
||||
} else if (source.startsWith(QString("upgrade"))) {
|
||||
// package manager
|
||||
QString key = source;
|
||||
@ -491,10 +449,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapfreegb"));
|
||||
m_formater[QString("swapfreegb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swap"));
|
||||
} else if (source == QString("mem/swap/used")) {
|
||||
// used swap
|
||||
// mb
|
||||
@ -503,10 +457,6 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// gb
|
||||
m_map.insertMulti(source, QString("swapgb"));
|
||||
m_formater[QString("swapgb")] = MemGBFormat;
|
||||
// fill required by list
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotmb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swaptotgb"));
|
||||
m_requiredByMap.insertMulti(source, QString("swap"));
|
||||
} else if (source.startsWith(QString("lmsensors/"))) {
|
||||
// temperature
|
||||
int index = m_devices[QString("temp")].indexOf(source);
|
||||
@ -561,6 +511,18 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
m_formater[key] = Temperature;
|
||||
}
|
||||
|
||||
// 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;
|
||||
// let required if key list is empty no one use it
|
||||
bool required
|
||||
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||
[&keys](const QString &key) {
|
||||
return keys.contains(key);
|
||||
});
|
||||
if (!required)
|
||||
m_map.remove(source);
|
||||
|
||||
return keysFromSource(source);
|
||||
}
|
||||
|
||||
@ -572,17 +534,17 @@ float AWKeysAggregator::temperature(const float temp) const
|
||||
float converted = temp;
|
||||
if (m_tempUnits == QString("Celsius")) {
|
||||
} else if (m_tempUnits == QString("Fahrenheit")) {
|
||||
converted = temp * 9.0 / 5.0 + 32.0;
|
||||
converted = temp * 9.0f / 5.0f + 32.0f;
|
||||
} else if (m_tempUnits == QString("Kelvin")) {
|
||||
converted = temp + 273.15;
|
||||
converted = temp + 273.15f;
|
||||
} else if (m_tempUnits == QString("Reaumur")) {
|
||||
converted = temp * 0.8;
|
||||
converted = temp * 0.8f;
|
||||
} else if (m_tempUnits == QString("cm^-1")) {
|
||||
converted = (temp + 273.15) * 0.695;
|
||||
converted = (temp + 273.15f) * 0.695f;
|
||||
} else if (m_tempUnits == QString("kJ/mol")) {
|
||||
converted = (temp + 273.15) * 8.31;
|
||||
converted = (temp + 273.15f) * 8.31f;
|
||||
} else if (m_tempUnits == QString("kcal/mol")) {
|
||||
converted = (temp + 273.15) * 1.98;
|
||||
converted = (temp + 273.15f) * 1.98f;
|
||||
} else {
|
||||
qCWarning(LOG_AW) << "Invalid units" << m_tempUnits;
|
||||
}
|
||||
|
@ -67,7 +67,6 @@ public:
|
||||
// get methods
|
||||
QString formater(const QVariant &data, const QString &key) const;
|
||||
QStringList keysFromSource(const QString &source) const;
|
||||
QStringList requiredByKeysFromSource(const QString &source) const;
|
||||
// set methods
|
||||
void setAcOffline(const QString inactive);
|
||||
void setAcOnline(const QString active);
|
||||
@ -78,7 +77,8 @@ public:
|
||||
void setTranslate(const bool translate);
|
||||
|
||||
public slots:
|
||||
QStringList registerSource(const QString &source, const QString &units);
|
||||
QStringList registerSource(const QString &source, const QString &units,
|
||||
const QStringList &keys = QStringList());
|
||||
|
||||
private:
|
||||
float temperature(const float temp) const;
|
||||
@ -91,7 +91,6 @@ private:
|
||||
QHash<QString, QStringList> m_devices;
|
||||
QHash<QString, FormaterType> m_formater;
|
||||
QHash<QString, QString> m_map;
|
||||
QHash<QString, QString> m_requiredByMap;
|
||||
QString m_tempUnits;
|
||||
bool m_translate = false;
|
||||
};
|
||||
|
Reference in New Issue
Block a user