mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
Initial support of templates and so on (#71)
* Initial syntax is the following: * $template{{ some JS code here }} - simple template based on JS code inside. It works the same as lambda functions, but calculates only once. * aw_count(regex) - keys count found for given regex * aw_keys(regex, [separator]) - keys found for given regex and joined by using given separator * aw_names(regex, [separator]) - key names found for given regex and joined by using given separator (the same as previous but w\o $) The template and function syntax may be changed before release. * replace `foreach` to `for (auto foo : bar)` and update CONTRIBUTING.md accordingly
This commit is contained in:
parent
fba58c27e8
commit
1c78e0d779
@ -36,14 +36,15 @@ for more details. To avoid manual labor there is automatic cmake target named
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
|
* `Q_PROPERTY` macro is allowed and recommended for QObject based classes.
|
||||||
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed.
|
* Qt macros (e.g. `signals`, `slots`, `Q_OBJECT`, etc) are allowed. In other hand
|
||||||
|
`Q_FOREACH` (`foreach`) is not allowed use `for (auto foo : bar)` instead.
|
||||||
* Current project standard is **C++11**.
|
* Current project standard is **C++11**.
|
||||||
* Do not use C-like code:
|
* Do not use C-like code:
|
||||||
* C-like style iteration if possible. Use `Q_FOREACH` (`foreach`) and
|
* C-like style iteration if possible. Use `for (auto foo : bar)` and
|
||||||
`std::for_each` instead if possible. It is also recommended to use iterators.
|
`std::for_each` instead if possible. It is also recommended to use iterators.
|
||||||
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
|
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
|
||||||
of `reinterpret_cast` is not recommended. It is highly recommended to use
|
of `reinterpret_cast` is not recommended. It is highly recommended to use
|
||||||
`dynamic_Cast` with the exception catching. It is also possible to use
|
`dynamic_cast` with the exception catching. It is also possible to use
|
||||||
`qvariant_cast` if required. Exception is class constructors, e.g.:
|
`qvariant_cast` if required. Exception is class constructors, e.g.:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -81,7 +82,7 @@ for more details. To avoid manual labor there is automatic cmake target named
|
|||||||
* Create one file (source and header) per class.
|
* Create one file (source and header) per class.
|
||||||
* `else if` construction is allowed and recommended.
|
* `else if` construction is allowed and recommended.
|
||||||
* 'true ? foo : bar' construction is allowed and recommended for one-line assignment.
|
* 'true ? foo : bar' construction is allowed and recommended for one-line assignment.
|
||||||
* any global pointer should be assign to `nullptr` after deletion and before
|
* Any global pointer should be assign to `nullptr` after deletion and before
|
||||||
initialization. Exception: if object is deleted into class destructor.
|
initialization. Exception: if object is deleted into class destructor.
|
||||||
|
|
||||||
Comments
|
Comments
|
||||||
|
@ -28,12 +28,6 @@
|
|||||||
"category}][%{function}] %{message}"
|
"category}][%{function}] %{message}"
|
||||||
#endif /* LOG_FORMAT */
|
#endif /* LOG_FORMAT */
|
||||||
|
|
||||||
// redefine info because it doesn't log properly
|
|
||||||
#ifdef qCInfo
|
|
||||||
#undef qCInfo
|
|
||||||
#endif /* qCInfo */
|
|
||||||
#define qCInfo qCDebug
|
|
||||||
|
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
|
||||||
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
|
||||||
|
@ -61,7 +61,7 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
|||||||
QQmlPropertyMap *configuration
|
QQmlPropertyMap *configuration
|
||||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||||
settings.beginGroup(QString("plasmoid"));
|
settings.beginGroup(QString("plasmoid"));
|
||||||
foreach (QString key, configuration->keys()) {
|
for (auto key : configuration->keys()) {
|
||||||
QVariant value = configuration->value(key);
|
QVariant value = configuration->value(key);
|
||||||
if (!value.isValid())
|
if (!value.isValid())
|
||||||
continue;
|
continue;
|
||||||
@ -70,13 +70,13 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
foreach (QString item, m_dirs) {
|
for (auto item : m_dirs) {
|
||||||
QStringList items
|
QStringList items
|
||||||
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
|
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
|
||||||
.entryList(QStringList() << QString("*.desktop"),
|
.entryList(QStringList() << QString("*.desktop"),
|
||||||
QDir::Files);
|
QDir::Files);
|
||||||
settings.beginGroup(item);
|
settings.beginGroup(item);
|
||||||
foreach (QString it, items)
|
for (auto it : items)
|
||||||
copyExtensions(it, item, settings, false);
|
copyExtensions(it, item, settings, false);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
@ -112,9 +112,9 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
|||||||
|
|
||||||
// extensions
|
// extensions
|
||||||
if (importExtensions) {
|
if (importExtensions) {
|
||||||
foreach (QString item, m_dirs) {
|
for (auto item : m_dirs) {
|
||||||
settings.beginGroup(item);
|
settings.beginGroup(item);
|
||||||
foreach (QString it, settings.childGroups())
|
for (auto it : settings.childGroups())
|
||||||
copyExtensions(it, item, settings, true);
|
copyExtensions(it, item, settings, true);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
|||||||
// plasmoid configuration
|
// plasmoid configuration
|
||||||
if (importPlasmoid) {
|
if (importPlasmoid) {
|
||||||
settings.beginGroup(QString("plasmoid"));
|
settings.beginGroup(QString("plasmoid"));
|
||||||
foreach (QString key, settings.childKeys())
|
for (auto key : settings.childKeys())
|
||||||
configuration[key] = settings.value(key);
|
configuration[key] = settings.value(key);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
|||||||
|
|
||||||
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||||
{
|
{
|
||||||
foreach (QString key, from.childKeys())
|
for (auto key : from.childKeys())
|
||||||
to.setValue(key, from.value(key));
|
to.setValue(key, from.value(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
|||||||
toolTipScene->clear();
|
toolTipScene->clear();
|
||||||
QPen pen;
|
QPen pen;
|
||||||
bool down = false;
|
bool down = false;
|
||||||
foreach (QString key, requiredKeys) {
|
for (auto key : requiredKeys) {
|
||||||
// create frame
|
// create frame
|
||||||
float normX = 100.0 / static_cast<float>(data[key].count());
|
float normX = 100.0 / static_cast<float>(data[key].count());
|
||||||
float normY = 100.0 / (1.5 * boundaries[key]);
|
float normY = 100.0 / (1.5 * boundaries[key]);
|
||||||
|
@ -45,8 +45,8 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
|||||||
|
|
||||||
void AWDataEngineAggregator::disconnectSources()
|
void AWDataEngineAggregator::disconnectSources()
|
||||||
{
|
{
|
||||||
foreach (QString dataengine, m_dataEngines.keys())
|
for (auto dataengine : m_dataEngines.keys())
|
||||||
foreach (QString source, m_dataEngines[dataengine]->sources())
|
for (auto source : m_dataEngines[dataengine]->sources())
|
||||||
m_dataEngines[dataengine]->disconnectSource(source, parent());
|
m_dataEngines[dataengine]->disconnectSource(source, parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +44,11 @@ AWKeys::AWKeys(QObject *parent)
|
|||||||
{
|
{
|
||||||
qSetMessagePattern(LOG_FORMAT);
|
qSetMessagePattern(LOG_FORMAT);
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
foreach (const QString metadata, getBuildData())
|
for (auto metadata : getBuildData())
|
||||||
qCDebug(LOG_AW) << metadata;
|
qCDebug(LOG_AW) << metadata;
|
||||||
|
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
// thread pool
|
// thread pool
|
||||||
m_threadPool = new QThreadPool(this);
|
m_threadPool = new QThreadPool(this);
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
|
|
||||||
aggregator = new AWKeysAggregator(this);
|
aggregator = new AWKeysAggregator(this);
|
||||||
dataAggregator = new AWDataAggregator(this);
|
dataAggregator = new AWDataAggregator(this);
|
||||||
@ -103,10 +101,8 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
|
|||||||
dataEngineAggregator, SLOT(dropSource(QString)));
|
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||||
} else
|
} else
|
||||||
dataEngineAggregator->setInterval(interval);
|
dataEngineAggregator->setInterval(interval);
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||||
: limit);
|
: limit);
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
updateCache();
|
updateCache();
|
||||||
|
|
||||||
return dataEngineAggregator->reconnectSources();
|
return dataEngineAggregator->reconnectSources();
|
||||||
@ -292,7 +288,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
|||||||
allKeys.append(QString("la1"));
|
allKeys.append(QString("la1"));
|
||||||
// bars
|
// bars
|
||||||
QStringList graphicalItemsKeys;
|
QStringList graphicalItemsKeys;
|
||||||
foreach (GraphicalItem *item, graphicalItems->items())
|
for (auto item : graphicalItems->items())
|
||||||
graphicalItemsKeys.append(item->tag());
|
graphicalItemsKeys.append(item->tag());
|
||||||
graphicalItemsKeys.sort();
|
graphicalItemsKeys.sort();
|
||||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||||
@ -430,13 +426,9 @@ void AWKeys::dataUpdated(const QString &sourceName,
|
|||||||
return emit(needToBeUpdated());
|
return emit(needToBeUpdated());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
// run concurrent data update
|
// run concurrent data update
|
||||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||||
data);
|
data);
|
||||||
#else /* BUILD_FUTURE */
|
|
||||||
return setDataBySource(sourceName, data);
|
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -448,10 +440,10 @@ void AWKeys::loadKeysFromCache()
|
|||||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||||
QSettings cache(fileName, QSettings::IniFormat);
|
QSettings cache(fileName, QSettings::IniFormat);
|
||||||
|
|
||||||
foreach (QString group, cache.childGroups()) {
|
for (auto group : cache.childGroups()) {
|
||||||
cache.beginGroup(group);
|
cache.beginGroup(group);
|
||||||
m_devices.remove(group);
|
m_devices.remove(group);
|
||||||
foreach (QString key, cache.allKeys())
|
for (auto key : cache.allKeys())
|
||||||
m_devices[group].append(cache.value(key).toString());
|
m_devices[group].append(cache.value(key).toString());
|
||||||
cache.endGroup();
|
cache.endGroup();
|
||||||
}
|
}
|
||||||
@ -489,17 +481,24 @@ void AWKeys::reinitKeys()
|
|||||||
// not documented feature - place all available tags
|
// not documented feature - place all available tags
|
||||||
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
||||||
QStringList strings;
|
QStringList strings;
|
||||||
foreach (QString tag, allKeys)
|
for (auto tag : allKeys)
|
||||||
strings.append(QString("%1: $%1").arg(tag));
|
strings.append(QString("%1: $%1").arg(tag));
|
||||||
return strings.join(QString(" | "));
|
return strings.join(QString(" | "));
|
||||||
}());
|
}());
|
||||||
#endif /* BUILD_TESTING */
|
#endif /* BUILD_TESTING */
|
||||||
|
|
||||||
|
// apply aw_* functions
|
||||||
|
m_pattern = insertKeyCount(m_pattern);
|
||||||
|
m_pattern = insertKeyNames(m_pattern);
|
||||||
|
m_pattern = insertKeys(m_pattern);
|
||||||
|
// wrap templates
|
||||||
|
expandTemplates();
|
||||||
|
|
||||||
// append lists
|
// append lists
|
||||||
// bars
|
// bars
|
||||||
m_foundBars = [allKeys](QString pattern) {
|
m_foundBars = [allKeys](const QString pattern) {
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
foreach (QString key, allKeys)
|
for (auto key : allKeys)
|
||||||
if ((key.startsWith(QString("bar")))
|
if ((key.startsWith(QString("bar")))
|
||||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||||
qCInfo(LOG_AW) << "Found bar" << key;
|
qCInfo(LOG_AW) << "Found bar" << key;
|
||||||
@ -511,9 +510,9 @@ void AWKeys::reinitKeys()
|
|||||||
}(m_pattern);
|
}(m_pattern);
|
||||||
|
|
||||||
// main key list
|
// main key list
|
||||||
m_foundKeys = [allKeys](QString pattern) {
|
m_foundKeys = [allKeys](const QString pattern) {
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
foreach (QString key, allKeys)
|
for (auto key : allKeys)
|
||||||
if ((!key.startsWith(QString("bar")))
|
if ((!key.startsWith(QString("bar")))
|
||||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||||
qCInfo(LOG_AW) << "Found key" << key;
|
qCInfo(LOG_AW) << "Found key" << key;
|
||||||
@ -525,7 +524,7 @@ void AWKeys::reinitKeys()
|
|||||||
}(m_pattern);
|
}(m_pattern);
|
||||||
|
|
||||||
// lambdas
|
// lambdas
|
||||||
m_foundLambdas = [](QString pattern) {
|
m_foundLambdas = [](const QString pattern) {
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
// substring inside ${{ }} (with brackets) which should not contain ${{
|
// substring inside ${{ }} (with brackets) which should not contain ${{
|
||||||
QRegularExpression lambdaRegexp(
|
QRegularExpression lambdaRegexp(
|
||||||
@ -556,15 +555,10 @@ void AWKeys::reinitKeys()
|
|||||||
|
|
||||||
void AWKeys::updateTextData()
|
void AWKeys::updateTextData()
|
||||||
{
|
{
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
|
QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
|
||||||
calculateValues();
|
calculateValues();
|
||||||
return parsePattern(m_pattern);
|
return parsePattern(m_pattern);
|
||||||
});
|
});
|
||||||
#else /* BUILD_FUTURE */
|
|
||||||
calculateValues();
|
|
||||||
QString text = parsePattern(m_pattern);
|
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
|
|
||||||
emit(needTextToBeUpdated(text));
|
emit(needTextToBeUpdated(text));
|
||||||
emit(dataAggregator->updateData(values));
|
emit(dataAggregator->updateData(values));
|
||||||
@ -584,7 +578,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
|||||||
|
|
||||||
cache.beginGroup(type);
|
cache.beginGroup(type);
|
||||||
QStringList cachedValues;
|
QStringList cachedValues;
|
||||||
foreach (QString key, cache.allKeys())
|
for (auto key : cache.allKeys())
|
||||||
cachedValues.append(cache.value(key).toString());
|
cachedValues.append(cache.value(key).toString());
|
||||||
|
|
||||||
if (type == QString("hdd")) {
|
if (type == QString("hdd")) {
|
||||||
@ -592,7 +586,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
|||||||
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
= QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||||
QStringList devices
|
QStringList devices
|
||||||
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||||
foreach (QString dev, devices) {
|
for (auto dev : devices) {
|
||||||
QString device = QString("/dev/%1").arg(dev);
|
QString device = QString("/dev/%1").arg(dev);
|
||||||
if (cachedValues.contains(device))
|
if (cachedValues.contains(device))
|
||||||
continue;
|
continue;
|
||||||
@ -604,7 +598,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
|||||||
} else if (type == QString("net")) {
|
} else if (type == QString("net")) {
|
||||||
QList<QNetworkInterface> rawInterfaceList
|
QList<QNetworkInterface> rawInterfaceList
|
||||||
= QNetworkInterface::allInterfaces();
|
= QNetworkInterface::allInterfaces();
|
||||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
for (auto interface : rawInterfaceList) {
|
||||||
QString device = interface.name();
|
QString device = interface.name();
|
||||||
if (cachedValues.contains(device))
|
if (cachedValues.contains(device))
|
||||||
continue;
|
continue;
|
||||||
@ -632,7 +626,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
|||||||
void AWKeys::calculateValues()
|
void AWKeys::calculateValues()
|
||||||
{
|
{
|
||||||
// hddtot*
|
// hddtot*
|
||||||
foreach (QString device, m_devices[QString("mount")]) {
|
for (auto device : m_devices[QString("mount")]) {
|
||||||
int index = m_devices[QString("mount")].indexOf(device);
|
int index = m_devices[QString("mount")].indexOf(device);
|
||||||
values[QString("hddtotmb%1").arg(index)] = QString("%1").arg(
|
values[QString("hddtotmb%1").arg(index)] = QString("%1").arg(
|
||||||
values[QString("hddfreemb%1").arg(index)].toFloat()
|
values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||||
@ -684,12 +678,12 @@ void AWKeys::calculateValues()
|
|||||||
5, 'f', 1);
|
5, 'f', 1);
|
||||||
|
|
||||||
// lambdas
|
// lambdas
|
||||||
foreach (QString key, m_foundLambdas)
|
for (auto key : m_foundLambdas)
|
||||||
values[key] = [this](QString key) {
|
values[key] = [this](QString key) {
|
||||||
QJSEngine engine;
|
QJSEngine engine;
|
||||||
// apply $this values
|
// apply $this values
|
||||||
key.replace(QString("$this"), values[key]);
|
key.replace(QString("$this"), values[key]);
|
||||||
foreach (QString lambdaKey, m_foundKeys)
|
for (auto lambdaKey : m_foundKeys)
|
||||||
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
||||||
qCInfo(LOG_AW) << "Expression" << key;
|
qCInfo(LOG_AW) << "Expression" << key;
|
||||||
QJSValue result = engine.evaluate(key);
|
QJSValue result = engine.evaluate(key);
|
||||||
@ -705,17 +699,147 @@ void AWKeys::calculateValues()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWKeys::expandTemplates()
|
||||||
|
{
|
||||||
|
// match the following construction $template{{some code here}}
|
||||||
|
QRegularExpression templatesRegexp(
|
||||||
|
QString("\\$template\\{\\{((?!\\$template\\{\\{).)*?\\}\\}"));
|
||||||
|
templatesRegexp.setPatternOptions(
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(m_pattern);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
QString fullTemplate = match.captured();
|
||||||
|
|
||||||
|
// drop additional markers
|
||||||
|
QString templ = fullTemplate;
|
||||||
|
templ.remove(QRegExp(QString("^\\$template\\{\\{")));
|
||||||
|
templ.remove(QRegExp(QString("\\}\\}$")));
|
||||||
|
|
||||||
|
QJSEngine engine;
|
||||||
|
qCInfo(LOG_AW) << "Expression" << templ;
|
||||||
|
QJSValue result = engine.evaluate(templ);
|
||||||
|
QString templateResult = QString("");
|
||||||
|
if (result.isError()) {
|
||||||
|
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||||
|
<< result.property("lineNumber").toInt() << ":"
|
||||||
|
<< result.toString();
|
||||||
|
} else {
|
||||||
|
templateResult = result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace template
|
||||||
|
m_pattern.replace(fullTemplate, templateResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWKeys::insertKeyCount(QString code) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Looking for count in code" << code;
|
||||||
|
|
||||||
|
QRegularExpression countRegexp(QString("aw_count\\(((?!\\aw_count\\().)*?\\)"));
|
||||||
|
countRegexp.setPatternOptions(
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator it = countRegexp.globalMatch(code);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
QString count = match.captured();
|
||||||
|
|
||||||
|
// get regexp to search
|
||||||
|
QString regex = count;
|
||||||
|
regex.remove(QRegExp(QString("^aw_count\\(")));
|
||||||
|
regex.remove(QRegExp(QString("\\)$")));
|
||||||
|
qCInfo(LOG_AW) << "Looking for" << regex;
|
||||||
|
|
||||||
|
code.replace(count, QString::number(dictKeys(false, regex).count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWKeys::insertKeyNames(QString code) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Looking for keys in code" << code;
|
||||||
|
|
||||||
|
QRegularExpression keysRegexp(QString("aw_names\\(((?!\\aw_names\\().)*?\\)"));
|
||||||
|
keysRegexp.setPatternOptions(
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator it = keysRegexp.globalMatch(code);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
QString keys = match.captured();
|
||||||
|
|
||||||
|
// get regexp to search
|
||||||
|
QString condition = keys;
|
||||||
|
condition.remove(QRegExp(QString("^aw_names\\(")));
|
||||||
|
condition.remove(QRegExp(QString("\\)$")));
|
||||||
|
QStringList conditionList = condition.split(QChar(','));
|
||||||
|
// regexp
|
||||||
|
QString regex = conditionList.at(0);
|
||||||
|
// separator to join
|
||||||
|
QString separator = conditionList.size() == 1 ? QString("") : conditionList.at(1);
|
||||||
|
qCInfo(LOG_AW) << "Looking for" << regex << "with separator" << separator;
|
||||||
|
|
||||||
|
code.replace(keys, dictKeys(true, regex).join(separator));
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWKeys::insertKeys(QString code) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Looking for keys in code" << code;
|
||||||
|
|
||||||
|
QRegularExpression keysRegexp(QString("aw_keys\\(((?!\\aw_keys\\().)*?\\)"));
|
||||||
|
keysRegexp.setPatternOptions(
|
||||||
|
QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator it = keysRegexp.globalMatch(code);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
QString keys = match.captured();
|
||||||
|
|
||||||
|
// get regexp to search
|
||||||
|
QString condition = keys;
|
||||||
|
condition.remove(QRegExp(QString("^aw_keys\\(")));
|
||||||
|
condition.remove(QRegExp(QString("\\)$")));
|
||||||
|
QStringList conditionList = condition.split(QChar(','));
|
||||||
|
// regexp
|
||||||
|
QString regex = conditionList.at(0);
|
||||||
|
// separator to join
|
||||||
|
QString separator = conditionList.size() == 1 ? QString("") : conditionList.at(1);
|
||||||
|
qCInfo(LOG_AW) << "Looking for" << regex << "with separator" << separator;
|
||||||
|
|
||||||
|
// find keys and add $ at the beginning of the line
|
||||||
|
QStringList foundKeys = dictKeys(true, regex);
|
||||||
|
std::for_each(foundKeys.begin(), foundKeys.end(), [](QString &value) {
|
||||||
|
value = QString("$%1").arg(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
code.replace(keys, foundKeys.join(separator));
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWKeys::parsePattern(QString pattern) const
|
QString AWKeys::parsePattern(QString pattern) const
|
||||||
{
|
{
|
||||||
// screen sign
|
// screen sign
|
||||||
pattern.replace(QString("$$"), QString("$\\$\\"));
|
pattern.replace(QString("$$"), QString("$\\$\\"));
|
||||||
|
|
||||||
// lambdas
|
// lambdas
|
||||||
foreach (QString key, m_foundLambdas)
|
for (auto key : m_foundLambdas)
|
||||||
pattern.replace(QString("${{%1}}").arg(key), values[key]);
|
pattern.replace(QString("${{%1}}").arg(key), values[key]);
|
||||||
|
|
||||||
// main keys
|
// main keys
|
||||||
foreach (QString key, m_foundKeys)
|
for (auto key : m_foundKeys)
|
||||||
pattern.replace(QString("$%1").arg(key),
|
pattern.replace(QString("$%1").arg(key),
|
||||||
[](QString key, QString value) {
|
[](QString key, QString value) {
|
||||||
if ((!key.startsWith(QString("custom")))
|
if ((!key.startsWith(QString("custom")))
|
||||||
@ -725,7 +849,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
|||||||
}(key, values[key]));
|
}(key, values[key]));
|
||||||
|
|
||||||
// bars
|
// bars
|
||||||
foreach (QString bar, m_foundBars) {
|
for (auto bar : m_foundBars) {
|
||||||
GraphicalItem *item = graphicalItems->itemByTag(bar);
|
GraphicalItem *item = graphicalItems->itemByTag(bar);
|
||||||
QString key = bar;
|
QString key = bar;
|
||||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||||
@ -763,9 +887,7 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
|||||||
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
|
qCDebug(LOG_AW) << "Source" << sourceName << "not found";
|
||||||
emit(dropSourceFromDataengine(sourceName));
|
emit(dropSourceFromDataengine(sourceName));
|
||||||
} else {
|
} else {
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
m_mutex.lock();
|
m_mutex.lock();
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
// HACK workaround for time values which are stored in the different
|
// HACK workaround for time values which are stored in the different
|
||||||
// path
|
// path
|
||||||
QVariant value = sourceName == QString("Local")
|
QVariant value = sourceName == QString("Local")
|
||||||
@ -775,8 +897,6 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
|||||||
[this, value](const QString tag) {
|
[this, value](const QString tag) {
|
||||||
values[tag] = aggregator->formater(value, tag);
|
values[tag] = aggregator->formater(value, tag);
|
||||||
});
|
});
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,10 @@ private:
|
|||||||
// methods
|
// methods
|
||||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||||
void calculateValues();
|
void calculateValues();
|
||||||
|
void expandTemplates();
|
||||||
|
QString insertKeyCount(QString code) const;
|
||||||
|
QString insertKeyNames(QString code) const;
|
||||||
|
QString insertKeys(QString code) const;
|
||||||
QString parsePattern(QString pattern) const;
|
QString parsePattern(QString pattern) const;
|
||||||
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
||||||
// objects
|
// objects
|
||||||
|
@ -102,7 +102,7 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
|||||||
case TimeCustom:
|
case TimeCustom:
|
||||||
output = m_customTime;
|
output = m_customTime;
|
||||||
[&output, loc, this](const QDateTime dt) {
|
[&output, loc, this](const QDateTime dt) {
|
||||||
foreach (QString 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;
|
||||||
|
@ -193,14 +193,14 @@ void AbstractExtItem::readConfiguration()
|
|||||||
|
|
||||||
bool AbstractExtItem::tryDelete() const
|
bool AbstractExtItem::tryDelete() const
|
||||||
{
|
{
|
||||||
foreach (QString dir, m_dirs) {
|
for (auto dir : m_dirs) {
|
||||||
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
|
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
|
||||||
qCInfo(LOG_LIB) << "Remove file"
|
qCInfo(LOG_LIB) << "Remove file"
|
||||||
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if exists
|
// check if exists
|
||||||
foreach (QString dir, m_dirs)
|
for (auto dir : m_dirs)
|
||||||
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -188,7 +188,7 @@ QString ExtScript::applyFilters(QString _value) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Value" << _value;
|
qCDebug(LOG_LIB) << "Value" << _value;
|
||||||
|
|
||||||
foreach (QString filt, m_filters) {
|
for (auto filt : m_filters) {
|
||||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||||
QVariantMap filter = jsonFilters[filt].toMap();
|
QVariantMap filter = jsonFilters[filt].toMap();
|
||||||
if (filter.isEmpty()) {
|
if (filter.isEmpty()) {
|
||||||
@ -196,7 +196,7 @@ QString ExtScript::applyFilters(QString _value) const
|
|||||||
<< "in the json";
|
<< "in the json";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach (QString f, filter.keys())
|
for (auto f : filter.keys())
|
||||||
_value.replace(f, filter[f].toString());
|
_value.replace(f, filter[f].toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ DPAdds::DPAdds(QObject *parent)
|
|||||||
{
|
{
|
||||||
qSetMessagePattern(LOG_FORMAT);
|
qSetMessagePattern(LOG_FORMAT);
|
||||||
qCDebug(LOG_DP) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DP) << __PRETTY_FUNCTION__;
|
||||||
foreach (const QString metadata, getBuildData())
|
for (auto metadata : getBuildData())
|
||||||
qCDebug(LOG_DP) << metadata;
|
qCDebug(LOG_DP) << metadata;
|
||||||
|
|
||||||
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this,
|
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this,
|
||||||
@ -137,7 +137,7 @@ QString DPAdds::toolTipImage(const int desktop) const
|
|||||||
QPen pen = QPen();
|
QPen pen = QPen();
|
||||||
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||||
pen.setColor(QColor(m_tooltipColor));
|
pen.setColor(QColor(m_tooltipColor));
|
||||||
foreach (WindowData data, info.windowsData) {
|
for (auto data : info.windowsData) {
|
||||||
QRect rect = data.rect;
|
QRect rect = data.rect;
|
||||||
toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
|
toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
|
||||||
rect.left() + margin, rect.top() + margin,
|
rect.left() + margin, rect.top() + margin,
|
||||||
@ -196,7 +196,7 @@ QString DPAdds::parsePattern(const QString pattern, const int desktop) const
|
|||||||
|
|
||||||
QString parsed = pattern;
|
QString parsed = pattern;
|
||||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||||
foreach (QString key, dictKeys())
|
for (auto key : dictKeys())
|
||||||
parsed.replace(QString("$%1").arg(key), valueByKey(key, desktop));
|
parsed.replace(QString("$%1").arg(key), valueByKey(key, desktop));
|
||||||
parsed.replace(QString("$\\$\\"), QString("$$"));
|
parsed.replace(QString("$\\$\\"), QString("$$"));
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) const
|
|||||||
DesktopWindowsInfo info;
|
DesktopWindowsInfo info;
|
||||||
info.desktop = KWindowSystem::workArea(desktop);
|
info.desktop = KWindowSystem::workArea(desktop);
|
||||||
|
|
||||||
foreach (WId id, KWindowSystem::windows()) {
|
for (auto id : KWindowSystem::windows()) {
|
||||||
KWindowInfo winInfo = KWindowInfo(
|
KWindowInfo winInfo = KWindowInfo(
|
||||||
id, NET::Property::WMDesktop | NET::Property::WMGeometry
|
id, NET::Property::WMDesktop | NET::Property::WMGeometry
|
||||||
| NET::Property::WMState | NET::Property::WMWindowType
|
| NET::Property::WMState | NET::Property::WMWindowType
|
||||||
|
@ -34,7 +34,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
|||||||
Q_UNUSED(args)
|
Q_UNUSED(args)
|
||||||
qSetMessagePattern(LOG_FORMAT);
|
qSetMessagePattern(LOG_FORMAT);
|
||||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||||
foreach (const QString metadata, getBuildData())
|
for (auto metadata : getBuildData())
|
||||||
qCDebug(LOG_ESM) << metadata;
|
qCDebug(LOG_ESM) << metadata;
|
||||||
|
|
||||||
setMinimumPollingInterval(333);
|
setMinimumPollingInterval(333);
|
||||||
@ -42,7 +42,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
|||||||
|
|
||||||
// init aggregator
|
// init aggregator
|
||||||
aggregator = new ExtSysMonAggregator(this, configuration);
|
aggregator = new ExtSysMonAggregator(this, configuration);
|
||||||
foreach (QString source, aggregator->sources())
|
for (auto source : aggregator->sources())
|
||||||
setData(source, aggregator->initialData(source));
|
setData(source, aggregator->initialData(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
|||||||
QChar(','), QString::SkipEmptyParts);
|
QChar(','), QString::SkipEmptyParts);
|
||||||
QStringList devices;
|
QStringList devices;
|
||||||
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
|
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
|
||||||
foreach (QString device, deviceList)
|
for (auto device : deviceList)
|
||||||
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
|
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
|
||||||
devices.append(device);
|
devices.append(device);
|
||||||
if (devices.isEmpty())
|
if (devices.isEmpty())
|
||||||
@ -194,7 +194,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
|||||||
if (rawConfig[QString("PLAYERSYMBOLS")].toInt() <= 0)
|
if (rawConfig[QString("PLAYERSYMBOLS")].toInt() <= 0)
|
||||||
rawConfig[QString("PLAYERSYMBOLS")] = QString("10");
|
rawConfig[QString("PLAYERSYMBOLS")] = QString("10");
|
||||||
|
|
||||||
foreach (QString key, rawConfig.keys())
|
for (auto key : rawConfig.keys())
|
||||||
qCInfo(LOG_ESM) << key << "=" << rawConfig[key];
|
qCInfo(LOG_ESM) << key << "=" << rawConfig[key];
|
||||||
return rawConfig;
|
return rawConfig;
|
||||||
}
|
}
|
||||||
|
@ -91,37 +91,37 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
|||||||
// battery
|
// battery
|
||||||
AbstractExtSysMonSource *batteryItem
|
AbstractExtSysMonSource *batteryItem
|
||||||
= new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
= new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
||||||
foreach (QString source, batteryItem->sources())
|
for (auto source : batteryItem->sources())
|
||||||
m_map[source] = batteryItem;
|
m_map[source] = batteryItem;
|
||||||
// custom
|
// custom
|
||||||
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
|
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
|
||||||
foreach (QString source, customItem->sources())
|
for (auto source : customItem->sources())
|
||||||
m_map[source] = customItem;
|
m_map[source] = customItem;
|
||||||
// desktop
|
// desktop
|
||||||
AbstractExtSysMonSource *desktopItem
|
AbstractExtSysMonSource *desktopItem
|
||||||
= new DesktopSource(this, QStringList());
|
= new DesktopSource(this, QStringList());
|
||||||
foreach (QString source, desktopItem->sources())
|
for (auto source : desktopItem->sources())
|
||||||
m_map[source] = desktopItem;
|
m_map[source] = desktopItem;
|
||||||
// gpu load
|
// gpu load
|
||||||
AbstractExtSysMonSource *gpuLoadItem
|
AbstractExtSysMonSource *gpuLoadItem
|
||||||
= new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
= new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||||
foreach (QString source, gpuLoadItem->sources())
|
for (auto source : gpuLoadItem->sources())
|
||||||
m_map[source] = gpuLoadItem;
|
m_map[source] = gpuLoadItem;
|
||||||
// gpu temperature
|
// gpu temperature
|
||||||
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(
|
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(
|
||||||
this, QStringList() << config[QString("GPUDEV")]);
|
this, QStringList() << config[QString("GPUDEV")]);
|
||||||
foreach (QString source, gpuTempItem->sources())
|
for (auto source : gpuTempItem->sources())
|
||||||
m_map[source] = gpuTempItem;
|
m_map[source] = gpuTempItem;
|
||||||
// hdd temperature
|
// hdd temperature
|
||||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
||||||
this, QStringList() << config[QString("HDDDEV")]
|
this, QStringList() << config[QString("HDDDEV")]
|
||||||
<< config[QString("HDDTEMPCMD")]);
|
<< config[QString("HDDTEMPCMD")]);
|
||||||
foreach (QString source, hddTempItem->sources())
|
for (auto source : hddTempItem->sources())
|
||||||
m_map[source] = hddTempItem;
|
m_map[source] = hddTempItem;
|
||||||
// network
|
// network
|
||||||
AbstractExtSysMonSource *networkItem
|
AbstractExtSysMonSource *networkItem
|
||||||
= new NetworkSource(this, QStringList());
|
= new NetworkSource(this, QStringList());
|
||||||
foreach (QString source, networkItem->sources())
|
for (auto source : networkItem->sources())
|
||||||
m_map[source] = networkItem;
|
m_map[source] = networkItem;
|
||||||
// player
|
// player
|
||||||
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
||||||
@ -129,35 +129,35 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
|||||||
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
||||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
||||||
<< config[QString("PLAYERSYMBOLS")]);
|
<< config[QString("PLAYERSYMBOLS")]);
|
||||||
foreach (QString source, playerItem->sources())
|
for (auto source : playerItem->sources())
|
||||||
m_map[source] = playerItem;
|
m_map[source] = playerItem;
|
||||||
// processes
|
// processes
|
||||||
AbstractExtSysMonSource *processesItem
|
AbstractExtSysMonSource *processesItem
|
||||||
= new ProcessesSource(this, QStringList());
|
= new ProcessesSource(this, QStringList());
|
||||||
foreach (QString source, processesItem->sources())
|
for (auto source : processesItem->sources())
|
||||||
m_map[source] = processesItem;
|
m_map[source] = processesItem;
|
||||||
// quotes
|
// quotes
|
||||||
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
|
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
|
||||||
foreach (QString source, quotesItem->sources())
|
for (auto source : quotesItem->sources())
|
||||||
m_map[source] = quotesItem;
|
m_map[source] = quotesItem;
|
||||||
// update
|
// update
|
||||||
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
|
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
|
||||||
foreach (QString source, updateItem->sources())
|
for (auto source : updateItem->sources())
|
||||||
m_map[source] = updateItem;
|
m_map[source] = updateItem;
|
||||||
// upgrade
|
// upgrade
|
||||||
AbstractExtSysMonSource *upgradeItem
|
AbstractExtSysMonSource *upgradeItem
|
||||||
= new UpgradeSource(this, QStringList());
|
= new UpgradeSource(this, QStringList());
|
||||||
foreach (QString source, upgradeItem->sources())
|
for (auto source : upgradeItem->sources())
|
||||||
m_map[source] = upgradeItem;
|
m_map[source] = upgradeItem;
|
||||||
// weather
|
// weather
|
||||||
AbstractExtSysMonSource *weatherItem
|
AbstractExtSysMonSource *weatherItem
|
||||||
= new WeatherSource(this, QStringList());
|
= new WeatherSource(this, QStringList());
|
||||||
foreach (QString source, weatherItem->sources())
|
for (auto source : weatherItem->sources())
|
||||||
m_map[source] = weatherItem;
|
m_map[source] = weatherItem;
|
||||||
#ifdef BUILD_TESTING
|
#ifdef BUILD_TESTING
|
||||||
// additional load source
|
// additional load source
|
||||||
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
||||||
foreach (QString source, loadItem->sources())
|
for (auto source : loadItem->sources())
|
||||||
m_map[source] = loadItem;
|
m_map[source] = loadItem;
|
||||||
#endif /* BUILD_TESTING */
|
#endif /* BUILD_TESTING */
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ QStringList CustomSource::sources() const
|
|||||||
QStringList CustomSource::getSources()
|
QStringList CustomSource::getSources()
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
foreach (ExtScript *item, extScripts->activeItems())
|
for (auto item : extScripts->activeItems())
|
||||||
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
|
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
|
||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
|
@ -61,7 +61,7 @@ QVariant GPULoadSource::data(QString source)
|
|||||||
QString qoutput
|
QString qoutput
|
||||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||||
if (m_device == QString("nvidia")) {
|
if (m_device == QString("nvidia")) {
|
||||||
foreach (QString str,
|
for (auto str :
|
||||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
if (!str.contains(QString("<gpu_util>")))
|
if (!str.contains(QString("<gpu_util>")))
|
||||||
continue;
|
continue;
|
||||||
@ -72,7 +72,7 @@ QVariant GPULoadSource::data(QString source)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (m_device == QString("ati")) {
|
} else if (m_device == QString("ati")) {
|
||||||
foreach (QString str,
|
for (auto str :
|
||||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
if (!str.contains(QString("load")))
|
if (!str.contains(QString("load")))
|
||||||
continue;
|
continue;
|
||||||
|
@ -62,7 +62,7 @@ QVariant GPUTemperatureSource::data(QString source)
|
|||||||
QString qoutput
|
QString qoutput
|
||||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||||
if (m_device == QString("nvidia")) {
|
if (m_device == QString("nvidia")) {
|
||||||
foreach (QString str,
|
for (auto str :
|
||||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
if (!str.contains(QString("<gpu_temp>")))
|
if (!str.contains(QString("<gpu_temp>")))
|
||||||
continue;
|
continue;
|
||||||
@ -72,7 +72,7 @@ QVariant GPUTemperatureSource::data(QString source)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (m_device == QString("ati")) {
|
} else if (m_device == QString("ati")) {
|
||||||
foreach (QString str,
|
for (auto str :
|
||||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
if (!str.contains(QString("Temperature")))
|
if (!str.contains(QString("Temperature")))
|
||||||
continue;
|
continue;
|
||||||
|
@ -61,8 +61,7 @@ QVariant HDDTemperatureSource::data(QString source)
|
|||||||
QString qoutput
|
QString qoutput
|
||||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||||
if (m_smartctl) {
|
if (m_smartctl) {
|
||||||
foreach (QString str,
|
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
|
||||||
if (!str.startsWith(QString("194")))
|
if (!str.startsWith(QString("194")))
|
||||||
continue;
|
continue;
|
||||||
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
|
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
|
||||||
@ -104,7 +103,7 @@ QVariantMap HDDTemperatureSource::initialData(QString source) const
|
|||||||
QStringList HDDTemperatureSource::sources() const
|
QStringList HDDTemperatureSource::sources() const
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
foreach (QString device, m_devices)
|
for (auto device : m_devices)
|
||||||
sources.append(QString("hdd/temperature%1").arg(device));
|
sources.append(QString("hdd/temperature%1").arg(device));
|
||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
|
@ -46,7 +46,7 @@ QVariant NetworkSource::data(QString source)
|
|||||||
QList<QNetworkInterface> rawInterfaceList
|
QList<QNetworkInterface> rawInterfaceList
|
||||||
= QNetworkInterface::allInterfaces();
|
= QNetworkInterface::allInterfaces();
|
||||||
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
|
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
|
||||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
for (auto interface : rawInterfaceList) {
|
||||||
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
||||||
|| (interface.flags().testFlag(
|
|| (interface.flags().testFlag(
|
||||||
QNetworkInterface::IsPointToPoint)))
|
QNetworkInterface::IsPointToPoint)))
|
||||||
|
@ -150,13 +150,13 @@ void PlayerSource::run()
|
|||||||
if (m_player == QString("mpd")) {
|
if (m_player == QString("mpd")) {
|
||||||
// mpd
|
// mpd
|
||||||
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
|
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
|
||||||
foreach (QString key, data.keys())
|
for (auto key : data.keys())
|
||||||
values[key] = data[key];
|
values[key] = data[key];
|
||||||
} else if (m_player == QString("mpris")) {
|
} else if (m_player == QString("mpris")) {
|
||||||
// players which supports mpris
|
// players which supports mpris
|
||||||
QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris;
|
QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris;
|
||||||
QHash<QString, QVariant> data = getPlayerMprisInfo(mpris);
|
QHash<QString, QVariant> data = getPlayerMprisInfo(mpris);
|
||||||
foreach (QString key, data.keys())
|
for (auto key : data.keys())
|
||||||
values[key] = data[key];
|
values[key] = data[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ QString PlayerSource::getAutoMpris() const
|
|||||||
return QString();
|
return QString();
|
||||||
QStringList arguments = listServices.arguments().first().toStringList();
|
QStringList arguments = listServices.arguments().first().toStringList();
|
||||||
|
|
||||||
foreach (QString arg, arguments) {
|
for (auto arg : arguments) {
|
||||||
if (!arg.startsWith(QString("org.mpris.MediaPlayer2.")))
|
if (!arg.startsWith(QString("org.mpris.MediaPlayer2.")))
|
||||||
continue;
|
continue;
|
||||||
qCInfo(LOG_ESM) << "Service found" << arg;
|
qCInfo(LOG_ESM) << "Service found" << arg;
|
||||||
@ -251,7 +251,7 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
|
|||||||
|
|
||||||
QString qoutput
|
QString qoutput
|
||||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||||
foreach (QString str, qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||||
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
|
if (str.split(QString(": "), QString::SkipEmptyParts).count() == 2) {
|
||||||
// "Metadata: data"
|
// "Metadata: data"
|
||||||
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
|
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
|
||||||
|
@ -84,7 +84,7 @@ void ProcessesSource::run()
|
|||||||
QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)")));
|
QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)")));
|
||||||
QStringList running;
|
QStringList running;
|
||||||
|
|
||||||
foreach (QString dir, directories) {
|
for (auto dir : directories) {
|
||||||
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
||||||
if (!statusFile.open(QIODevice::ReadOnly))
|
if (!statusFile.open(QIODevice::ReadOnly))
|
||||||
continue;
|
continue;
|
||||||
|
@ -47,7 +47,7 @@ QVariant QuotesSource::data(QString source)
|
|||||||
|
|
||||||
if (source.startsWith(QString("quotes/percpricechg"))) {
|
if (source.startsWith(QString("quotes/percpricechg"))) {
|
||||||
QVariantHash data = extQuotes->itemByTagNumber(index(source))->run();
|
QVariantHash data = extQuotes->itemByTagNumber(index(source))->run();
|
||||||
foreach (QString key, data.keys())
|
for (auto key : data.keys())
|
||||||
values[key] = data[key];
|
values[key] = data[key];
|
||||||
}
|
}
|
||||||
QString key = QString(source).remove(QString("quotes/"));
|
QString key = QString(source).remove(QString("quotes/"));
|
||||||
@ -148,7 +148,7 @@ QStringList QuotesSource::sources() const
|
|||||||
QStringList QuotesSource::getSources()
|
QStringList QuotesSource::getSources()
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
foreach (ExtQuotes *item, extQuotes->activeItems()) {
|
for (auto item : extQuotes->activeItems()) {
|
||||||
sources.append(QString("quotes/%1").arg(item->tag(QString("ask"))));
|
sources.append(QString("quotes/%1").arg(item->tag(QString("ask"))));
|
||||||
sources.append(QString("quotes/%1").arg(item->tag(QString("askchg"))));
|
sources.append(QString("quotes/%1").arg(item->tag(QString("askchg"))));
|
||||||
sources.append(
|
sources.append(
|
||||||
|
@ -76,7 +76,7 @@ QStringList UpgradeSource::sources() const
|
|||||||
QStringList UpgradeSource::getSources()
|
QStringList UpgradeSource::getSources()
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
foreach (ExtUpgrade *item, extUpgrade->activeItems())
|
for (auto item : extUpgrade->activeItems())
|
||||||
sources.append(
|
sources.append(
|
||||||
QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
|
QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ QVariant WeatherSource::data(QString source)
|
|||||||
|
|
||||||
if (source.startsWith(QString("weather/weatherId"))) {
|
if (source.startsWith(QString("weather/weatherId"))) {
|
||||||
QVariantHash data = extWeather->itemByTagNumber(index(source))->run();
|
QVariantHash data = extWeather->itemByTagNumber(index(source))->run();
|
||||||
foreach (QString key, data.keys())
|
for (auto key : data.keys())
|
||||||
values[key] = data[key];
|
values[key] = data[key];
|
||||||
}
|
}
|
||||||
QString key = QString(source).remove(QString("weather/"));
|
QString key = QString(source).remove(QString("weather/"));
|
||||||
@ -124,7 +124,7 @@ QStringList WeatherSource::sources() const
|
|||||||
QStringList WeatherSource::getSources()
|
QStringList WeatherSource::getSources()
|
||||||
{
|
{
|
||||||
QStringList sources;
|
QStringList sources;
|
||||||
foreach (ExtWeather *item, extWeather->activeItems()) {
|
for (auto item : extWeather->activeItems()) {
|
||||||
sources.append(
|
sources.append(
|
||||||
QString("weather/%1").arg(item->tag(QString("weatherId"))));
|
QString("weather/%1").arg(item->tag(QString("weatherId"))));
|
||||||
sources.append(
|
sources.append(
|
||||||
|
Loading…
Reference in New Issue
Block a user