mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +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.
|
||||
* 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**.
|
||||
* 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.
|
||||
* C-like casts, use `const_cast`, `static_cast`, `dymanic_Cast` instead. Using
|
||||
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.:
|
||||
|
||||
```
|
||||
@ -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.
|
||||
* `else if` construction is allowed and recommended.
|
||||
* '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.
|
||||
|
||||
Comments
|
||||
|
@ -28,12 +28,6 @@
|
||||
"category}][%{function}] %{message}"
|
||||
#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_DP)
|
||||
|
@ -61,7 +61,7 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
QQmlPropertyMap *configuration
|
||||
= static_cast<QQmlPropertyMap *>(nativeConfig);
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach (QString key, configuration->keys()) {
|
||||
for (auto key : configuration->keys()) {
|
||||
QVariant value = configuration->value(key);
|
||||
if (!value.isValid())
|
||||
continue;
|
||||
@ -70,13 +70,13 @@ bool AWConfigHelper::exportConfiguration(QObject *nativeConfig,
|
||||
settings.endGroup();
|
||||
|
||||
// extensions
|
||||
foreach (QString item, m_dirs) {
|
||||
for (auto item : m_dirs) {
|
||||
QStringList items
|
||||
= QDir(QString("%1/%2").arg(m_baseDir).arg(item))
|
||||
.entryList(QStringList() << QString("*.desktop"),
|
||||
QDir::Files);
|
||||
settings.beginGroup(item);
|
||||
foreach (QString it, items)
|
||||
for (auto it : items)
|
||||
copyExtensions(it, item, settings, false);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -112,9 +112,9 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
|
||||
// extensions
|
||||
if (importExtensions) {
|
||||
foreach (QString item, m_dirs) {
|
||||
for (auto item : m_dirs) {
|
||||
settings.beginGroup(item);
|
||||
foreach (QString it, settings.childGroups())
|
||||
for (auto it : settings.childGroups())
|
||||
copyExtensions(it, item, settings, true);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -137,7 +137,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString fileName,
|
||||
// plasmoid configuration
|
||||
if (importPlasmoid) {
|
||||
settings.beginGroup(QString("plasmoid"));
|
||||
foreach (QString key, settings.childKeys())
|
||||
for (auto key : settings.childKeys())
|
||||
configuration[key] = settings.value(key);
|
||||
settings.endGroup();
|
||||
}
|
||||
@ -239,7 +239,7 @@ void AWConfigHelper::copyExtensions(const QString item, const QString type,
|
||||
|
||||
void AWConfigHelper::copySettings(QSettings &from, QSettings &to) const
|
||||
{
|
||||
foreach (QString key, from.childKeys())
|
||||
for (auto key : from.childKeys())
|
||||
to.setValue(key, from.value(key));
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ QPixmap AWDataAggregator::tooltipImage()
|
||||
toolTipScene->clear();
|
||||
QPen pen;
|
||||
bool down = false;
|
||||
foreach (QString key, requiredKeys) {
|
||||
for (auto key : requiredKeys) {
|
||||
// create frame
|
||||
float normX = 100.0 / static_cast<float>(data[key].count());
|
||||
float normY = 100.0 / (1.5 * boundaries[key]);
|
||||
|
@ -45,8 +45,8 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
|
||||
void AWDataEngineAggregator::disconnectSources()
|
||||
{
|
||||
foreach (QString dataengine, m_dataEngines.keys())
|
||||
foreach (QString source, m_dataEngines[dataengine]->sources())
|
||||
for (auto dataengine : m_dataEngines.keys())
|
||||
for (auto source : m_dataEngines[dataengine]->sources())
|
||||
m_dataEngines[dataengine]->disconnectSource(source, parent());
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,11 @@ AWKeys::AWKeys(QObject *parent)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_AW) << metadata;
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// thread pool
|
||||
m_threadPool = new QThreadPool(this);
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
aggregator = new AWKeysAggregator(this);
|
||||
dataAggregator = new AWDataAggregator(this);
|
||||
@ -103,10 +101,8 @@ void AWKeys::initKeys(const QString currentPattern, const int interval,
|
||||
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||
} else
|
||||
dataEngineAggregator->setInterval(interval);
|
||||
#ifdef BUILD_FUTURE
|
||||
m_threadPool->setMaxThreadCount(limit == 0 ? QThread::idealThreadCount()
|
||||
: limit);
|
||||
#endif /* BUILD_FUTURE */
|
||||
updateCache();
|
||||
|
||||
return dataEngineAggregator->reconnectSources();
|
||||
@ -292,7 +288,7 @@ QStringList AWKeys::dictKeys(const bool sorted, const QString regexp) const
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
QStringList graphicalItemsKeys;
|
||||
foreach (GraphicalItem *item, graphicalItems->items())
|
||||
for (auto item : graphicalItems->items())
|
||||
graphicalItemsKeys.append(item->tag());
|
||||
graphicalItemsKeys.sort();
|
||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||
@ -430,13 +426,9 @@ void AWKeys::dataUpdated(const QString &sourceName,
|
||||
return emit(needToBeUpdated());
|
||||
}
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, sourceName,
|
||||
data);
|
||||
#else /* BUILD_FUTURE */
|
||||
return setDataBySource(sourceName, data);
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
|
||||
|
||||
@ -448,10 +440,10 @@ void AWKeys::loadKeysFromCache()
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
||||
foreach (QString group, cache.childGroups()) {
|
||||
for (auto group : cache.childGroups()) {
|
||||
cache.beginGroup(group);
|
||||
m_devices.remove(group);
|
||||
foreach (QString key, cache.allKeys())
|
||||
for (auto key : cache.allKeys())
|
||||
m_devices[group].append(cache.value(key).toString());
|
||||
cache.endGroup();
|
||||
}
|
||||
@ -489,17 +481,24 @@ void AWKeys::reinitKeys()
|
||||
// not documented feature - place all available tags
|
||||
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
||||
QStringList strings;
|
||||
foreach (QString tag, allKeys)
|
||||
for (auto tag : allKeys)
|
||||
strings.append(QString("%1: $%1").arg(tag));
|
||||
return strings.join(QString(" | "));
|
||||
}());
|
||||
#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
|
||||
// bars
|
||||
m_foundBars = [allKeys](QString pattern) {
|
||||
m_foundBars = [allKeys](const QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
foreach (QString key, allKeys)
|
||||
for (auto key : allKeys)
|
||||
if ((key.startsWith(QString("bar")))
|
||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found bar" << key;
|
||||
@ -511,9 +510,9 @@ void AWKeys::reinitKeys()
|
||||
}(m_pattern);
|
||||
|
||||
// main key list
|
||||
m_foundKeys = [allKeys](QString pattern) {
|
||||
m_foundKeys = [allKeys](const QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
foreach (QString key, allKeys)
|
||||
for (auto key : allKeys)
|
||||
if ((!key.startsWith(QString("bar")))
|
||||
&& (pattern.contains(QString("$%1").arg(key)))) {
|
||||
qCInfo(LOG_AW) << "Found key" << key;
|
||||
@ -525,7 +524,7 @@ void AWKeys::reinitKeys()
|
||||
}(m_pattern);
|
||||
|
||||
// lambdas
|
||||
m_foundLambdas = [](QString pattern) {
|
||||
m_foundLambdas = [](const QString pattern) {
|
||||
QStringList selectedKeys;
|
||||
// substring inside ${{ }} (with brackets) which should not contain ${{
|
||||
QRegularExpression lambdaRegexp(
|
||||
@ -556,15 +555,10 @@ void AWKeys::reinitKeys()
|
||||
|
||||
void AWKeys::updateTextData()
|
||||
{
|
||||
#ifdef BUILD_FUTURE
|
||||
QFuture<QString> text = QtConcurrent::run(m_threadPool, [this]() {
|
||||
calculateValues();
|
||||
return parsePattern(m_pattern);
|
||||
});
|
||||
#else /* BUILD_FUTURE */
|
||||
calculateValues();
|
||||
QString text = parsePattern(m_pattern);
|
||||
#endif /* BUILD_FUTURE */
|
||||
|
||||
emit(needTextToBeUpdated(text));
|
||||
emit(dataAggregator->updateData(values));
|
||||
@ -584,7 +578,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||
|
||||
cache.beginGroup(type);
|
||||
QStringList cachedValues;
|
||||
foreach (QString key, cache.allKeys())
|
||||
for (auto key : cache.allKeys())
|
||||
cachedValues.append(cache.value(key).toString());
|
||||
|
||||
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);
|
||||
QStringList devices
|
||||
= allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
foreach (QString dev, devices) {
|
||||
for (auto dev : devices) {
|
||||
QString device = QString("/dev/%1").arg(dev);
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
@ -604,7 +598,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||
} else if (type == QString("net")) {
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
||||
for (auto interface : rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
@ -632,7 +626,7 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
foreach (QString device, m_devices[QString("mount")]) {
|
||||
for (auto device : m_devices[QString("mount")]) {
|
||||
int index = m_devices[QString("mount")].indexOf(device);
|
||||
values[QString("hddtotmb%1").arg(index)] = QString("%1").arg(
|
||||
values[QString("hddfreemb%1").arg(index)].toFloat()
|
||||
@ -684,12 +678,12 @@ void AWKeys::calculateValues()
|
||||
5, 'f', 1);
|
||||
|
||||
// lambdas
|
||||
foreach (QString key, m_foundLambdas)
|
||||
for (auto key : m_foundLambdas)
|
||||
values[key] = [this](QString key) {
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
key.replace(QString("$this"), values[key]);
|
||||
foreach (QString lambdaKey, m_foundKeys)
|
||||
for (auto lambdaKey : m_foundKeys)
|
||||
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
||||
qCInfo(LOG_AW) << "Expression" << 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
|
||||
{
|
||||
// screen sign
|
||||
pattern.replace(QString("$$"), QString("$\\$\\"));
|
||||
|
||||
// lambdas
|
||||
foreach (QString key, m_foundLambdas)
|
||||
for (auto key : m_foundLambdas)
|
||||
pattern.replace(QString("${{%1}}").arg(key), values[key]);
|
||||
|
||||
// main keys
|
||||
foreach (QString key, m_foundKeys)
|
||||
for (auto key : m_foundKeys)
|
||||
pattern.replace(QString("$%1").arg(key),
|
||||
[](QString key, QString value) {
|
||||
if ((!key.startsWith(QString("custom")))
|
||||
@ -725,7 +849,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
}(key, values[key]));
|
||||
|
||||
// bars
|
||||
foreach (QString bar, m_foundBars) {
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = graphicalItems->itemByTag(bar);
|
||||
QString key = bar;
|
||||
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";
|
||||
emit(dropSourceFromDataengine(sourceName));
|
||||
} else {
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.lock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
// HACK workaround for time values which are stored in the different
|
||||
// path
|
||||
QVariant value = sourceName == QString("Local")
|
||||
@ -775,8 +897,6 @@ void AWKeys::setDataBySource(const QString &sourceName, const QVariantMap &data)
|
||||
[this, value](const QString tag) {
|
||||
values[tag] = aggregator->formater(value, tag);
|
||||
});
|
||||
#ifdef BUILD_FUTURE
|
||||
m_mutex.unlock();
|
||||
#endif /* BUILD_FUTURE */
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,10 @@ private:
|
||||
// methods
|
||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||
void calculateValues();
|
||||
void expandTemplates();
|
||||
QString insertKeyCount(QString code) const;
|
||||
QString insertKeyNames(QString code) const;
|
||||
QString insertKeys(QString code) const;
|
||||
QString parsePattern(QString pattern) const;
|
||||
void setDataBySource(const QString &sourceName, const QVariantMap &data);
|
||||
// objects
|
||||
|
@ -102,7 +102,7 @@ QString AWKeysAggregator::formater(const QVariant &data,
|
||||
case TimeCustom:
|
||||
output = m_customTime;
|
||||
[&output, loc, this](const QDateTime dt) {
|
||||
foreach (QString key, timeKeys)
|
||||
for (auto key : timeKeys)
|
||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||
}(data.toDateTime());
|
||||
break;
|
||||
|
@ -193,14 +193,14 @@ void AbstractExtItem::readConfiguration()
|
||||
|
||||
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));
|
||||
qCInfo(LOG_LIB) << "Remove file"
|
||||
<< QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
||||
}
|
||||
|
||||
// check if exists
|
||||
foreach (QString dir, m_dirs)
|
||||
for (auto dir : m_dirs)
|
||||
if (QFile::exists(QString("%1/%2").arg(dir).arg(m_fileName)))
|
||||
return false;
|
||||
return true;
|
||||
|
@ -188,7 +188,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << _value;
|
||||
|
||||
foreach (QString filt, m_filters) {
|
||||
for (auto filt : m_filters) {
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
@ -196,7 +196,7 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
<< "in the json";
|
||||
continue;
|
||||
}
|
||||
foreach (QString f, filter.keys())
|
||||
for (auto f : filter.keys())
|
||||
_value.replace(f, filter[f].toString());
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ DPAdds::DPAdds(QObject *parent)
|
||||
{
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_DP) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_DP) << metadata;
|
||||
|
||||
connect(KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)), this,
|
||||
@ -137,7 +137,7 @@ QString DPAdds::toolTipImage(const int desktop) const
|
||||
QPen pen = QPen();
|
||||
pen.setWidthF(2.0 * info.desktop.width() / 400.0);
|
||||
pen.setColor(QColor(m_tooltipColor));
|
||||
foreach (WindowData data, info.windowsData) {
|
||||
for (auto data : info.windowsData) {
|
||||
QRect rect = data.rect;
|
||||
toolTipScene->addLine(rect.left() + margin, rect.bottom() + margin,
|
||||
rect.left() + margin, rect.top() + margin,
|
||||
@ -196,7 +196,7 @@ QString DPAdds::parsePattern(const QString pattern, const int desktop) const
|
||||
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
foreach (QString key, dictKeys())
|
||||
for (auto key : dictKeys())
|
||||
parsed.replace(QString("$%1").arg(key), valueByKey(key, desktop));
|
||||
parsed.replace(QString("$\\$\\"), QString("$$"));
|
||||
|
||||
@ -363,7 +363,7 @@ DPAdds::DesktopWindowsInfo DPAdds::getInfoByDesktop(const int desktop) const
|
||||
DesktopWindowsInfo info;
|
||||
info.desktop = KWindowSystem::workArea(desktop);
|
||||
|
||||
foreach (WId id, KWindowSystem::windows()) {
|
||||
for (auto id : KWindowSystem::windows()) {
|
||||
KWindowInfo winInfo = KWindowInfo(
|
||||
id, NET::Property::WMDesktop | NET::Property::WMGeometry
|
||||
| NET::Property::WMState | NET::Property::WMWindowType
|
||||
|
@ -34,7 +34,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||
Q_UNUSED(args)
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
|
||||
foreach (const QString metadata, getBuildData())
|
||||
for (auto metadata : getBuildData())
|
||||
qCDebug(LOG_ESM) << metadata;
|
||||
|
||||
setMinimumPollingInterval(333);
|
||||
@ -42,7 +42,7 @@ ExtendedSysMon::ExtendedSysMon(QObject *parent, const QVariantList &args)
|
||||
|
||||
// init aggregator
|
||||
aggregator = new ExtSysMonAggregator(this, configuration);
|
||||
foreach (QString source, aggregator->sources())
|
||||
for (auto source : aggregator->sources())
|
||||
setData(source, aggregator->initialData(source));
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
QChar(','), QString::SkipEmptyParts);
|
||||
QStringList devices;
|
||||
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
|
||||
foreach (QString device, deviceList)
|
||||
for (auto device : deviceList)
|
||||
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
|
||||
devices.append(device);
|
||||
if (devices.isEmpty())
|
||||
@ -194,7 +194,7 @@ ExtendedSysMon::updateConfiguration(QHash<QString, QString> rawConfig) const
|
||||
if (rawConfig[QString("PLAYERSYMBOLS")].toInt() <= 0)
|
||||
rawConfig[QString("PLAYERSYMBOLS")] = QString("10");
|
||||
|
||||
foreach (QString key, rawConfig.keys())
|
||||
for (auto key : rawConfig.keys())
|
||||
qCInfo(LOG_ESM) << key << "=" << rawConfig[key];
|
||||
return rawConfig;
|
||||
}
|
||||
|
@ -91,37 +91,37 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
||||
// battery
|
||||
AbstractExtSysMonSource *batteryItem
|
||||
= new BatterySource(this, QStringList() << config[QString("ACPIPATH")]);
|
||||
foreach (QString source, batteryItem->sources())
|
||||
for (auto source : batteryItem->sources())
|
||||
m_map[source] = batteryItem;
|
||||
// custom
|
||||
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
|
||||
foreach (QString source, customItem->sources())
|
||||
for (auto source : customItem->sources())
|
||||
m_map[source] = customItem;
|
||||
// desktop
|
||||
AbstractExtSysMonSource *desktopItem
|
||||
= new DesktopSource(this, QStringList());
|
||||
foreach (QString source, desktopItem->sources())
|
||||
for (auto source : desktopItem->sources())
|
||||
m_map[source] = desktopItem;
|
||||
// gpu load
|
||||
AbstractExtSysMonSource *gpuLoadItem
|
||||
= new GPULoadSource(this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuLoadItem->sources())
|
||||
for (auto source : gpuLoadItem->sources())
|
||||
m_map[source] = gpuLoadItem;
|
||||
// gpu temperature
|
||||
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(
|
||||
this, QStringList() << config[QString("GPUDEV")]);
|
||||
foreach (QString source, gpuTempItem->sources())
|
||||
for (auto source : gpuTempItem->sources())
|
||||
m_map[source] = gpuTempItem;
|
||||
// hdd temperature
|
||||
AbstractExtSysMonSource *hddTempItem = new HDDTemperatureSource(
|
||||
this, QStringList() << config[QString("HDDDEV")]
|
||||
<< config[QString("HDDTEMPCMD")]);
|
||||
foreach (QString source, hddTempItem->sources())
|
||||
for (auto source : hddTempItem->sources())
|
||||
m_map[source] = hddTempItem;
|
||||
// network
|
||||
AbstractExtSysMonSource *networkItem
|
||||
= new NetworkSource(this, QStringList());
|
||||
foreach (QString source, networkItem->sources())
|
||||
for (auto source : networkItem->sources())
|
||||
m_map[source] = networkItem;
|
||||
// player
|
||||
AbstractExtSysMonSource *playerItem = new PlayerSource(
|
||||
@ -129,35 +129,35 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> config)
|
||||
<< config[QString("PLAYER")] << config[QString("MPDADDRESS")]
|
||||
<< config[QString("MPDPORT")] << config[QString("MPRIS")]
|
||||
<< config[QString("PLAYERSYMBOLS")]);
|
||||
foreach (QString source, playerItem->sources())
|
||||
for (auto source : playerItem->sources())
|
||||
m_map[source] = playerItem;
|
||||
// processes
|
||||
AbstractExtSysMonSource *processesItem
|
||||
= new ProcessesSource(this, QStringList());
|
||||
foreach (QString source, processesItem->sources())
|
||||
for (auto source : processesItem->sources())
|
||||
m_map[source] = processesItem;
|
||||
// quotes
|
||||
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
|
||||
foreach (QString source, quotesItem->sources())
|
||||
for (auto source : quotesItem->sources())
|
||||
m_map[source] = quotesItem;
|
||||
// update
|
||||
AbstractExtSysMonSource *updateItem = new UpdateSource(this, QStringList());
|
||||
foreach (QString source, updateItem->sources())
|
||||
for (auto source : updateItem->sources())
|
||||
m_map[source] = updateItem;
|
||||
// upgrade
|
||||
AbstractExtSysMonSource *upgradeItem
|
||||
= new UpgradeSource(this, QStringList());
|
||||
foreach (QString source, upgradeItem->sources())
|
||||
for (auto source : upgradeItem->sources())
|
||||
m_map[source] = upgradeItem;
|
||||
// weather
|
||||
AbstractExtSysMonSource *weatherItem
|
||||
= new WeatherSource(this, QStringList());
|
||||
foreach (QString source, weatherItem->sources())
|
||||
for (auto source : weatherItem->sources())
|
||||
m_map[source] = weatherItem;
|
||||
#ifdef BUILD_TESTING
|
||||
// additional load source
|
||||
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
|
||||
foreach (QString source, loadItem->sources())
|
||||
for (auto source : loadItem->sources())
|
||||
m_map[source] = loadItem;
|
||||
#endif /* BUILD_TESTING */
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ QStringList CustomSource::sources() const
|
||||
QStringList CustomSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
foreach (ExtScript *item, extScripts->activeItems())
|
||||
for (auto item : extScripts->activeItems())
|
||||
sources.append(QString("custom/%1").arg(item->tag(QString("custom"))));
|
||||
|
||||
return sources;
|
||||
|
@ -61,7 +61,7 @@ QVariant GPULoadSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_device == QString("nvidia")) {
|
||||
foreach (QString str,
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("<gpu_util>")))
|
||||
continue;
|
||||
@ -72,7 +72,7 @@ QVariant GPULoadSource::data(QString source)
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
foreach (QString str,
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("load")))
|
||||
continue;
|
||||
|
@ -62,7 +62,7 @@ QVariant GPUTemperatureSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_device == QString("nvidia")) {
|
||||
foreach (QString str,
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("<gpu_temp>")))
|
||||
continue;
|
||||
@ -72,7 +72,7 @@ QVariant GPUTemperatureSource::data(QString source)
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
foreach (QString str,
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("Temperature")))
|
||||
continue;
|
||||
|
@ -61,8 +61,7 @@ QVariant HDDTemperatureSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_smartctl) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str : qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.startsWith(QString("194")))
|
||||
continue;
|
||||
if (str.split(QChar(' '), QString::SkipEmptyParts).count() < 9)
|
||||
@ -104,7 +103,7 @@ QVariantMap HDDTemperatureSource::initialData(QString source) const
|
||||
QStringList HDDTemperatureSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
foreach (QString device, m_devices)
|
||||
for (auto device : m_devices)
|
||||
sources.append(QString("hdd/temperature%1").arg(device));
|
||||
|
||||
return sources;
|
||||
|
@ -46,7 +46,7 @@ QVariant NetworkSource::data(QString source)
|
||||
QList<QNetworkInterface> rawInterfaceList
|
||||
= QNetworkInterface::allInterfaces();
|
||||
qCInfo(LOG_ESM) << "Devices" << rawInterfaceList;
|
||||
foreach (QNetworkInterface interface, rawInterfaceList) {
|
||||
for (auto interface : rawInterfaceList) {
|
||||
if ((interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
||||
|| (interface.flags().testFlag(
|
||||
QNetworkInterface::IsPointToPoint)))
|
||||
|
@ -150,13 +150,13 @@ void PlayerSource::run()
|
||||
if (m_player == QString("mpd")) {
|
||||
// mpd
|
||||
QHash<QString, QVariant> data = getPlayerMpdInfo(m_mpdAddress);
|
||||
foreach (QString key, data.keys())
|
||||
for (auto key : data.keys())
|
||||
values[key] = data[key];
|
||||
} else if (m_player == QString("mpris")) {
|
||||
// players which supports mpris
|
||||
QString mpris = m_mpris == QString("auto") ? getAutoMpris() : m_mpris;
|
||||
QHash<QString, QVariant> data = getPlayerMprisInfo(mpris);
|
||||
foreach (QString key, data.keys())
|
||||
for (auto key : data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ QString PlayerSource::getAutoMpris() const
|
||||
return QString();
|
||||
QStringList arguments = listServices.arguments().first().toStringList();
|
||||
|
||||
foreach (QString arg, arguments) {
|
||||
for (auto arg : arguments) {
|
||||
if (!arg.startsWith(QString("org.mpris.MediaPlayer2.")))
|
||||
continue;
|
||||
qCInfo(LOG_ESM) << "Service found" << arg;
|
||||
@ -251,7 +251,7 @@ QVariantHash PlayerSource::getPlayerMpdInfo(const QString mpdAddress) const
|
||||
|
||||
QString qoutput
|
||||
= 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) {
|
||||
// "Metadata: data"
|
||||
QString metadata = str.split(QString(": "), QString::SkipEmptyParts)
|
||||
|
@ -84,7 +84,7 @@ void ProcessesSource::run()
|
||||
QStringList directories = allDirectories.filter(QRegExp(QString("(\\d+)")));
|
||||
QStringList running;
|
||||
|
||||
foreach (QString dir, directories) {
|
||||
for (auto dir : directories) {
|
||||
QFile statusFile(QString("/proc/%1/status").arg(dir));
|
||||
if (!statusFile.open(QIODevice::ReadOnly))
|
||||
continue;
|
||||
|
@ -47,7 +47,7 @@ QVariant QuotesSource::data(QString source)
|
||||
|
||||
if (source.startsWith(QString("quotes/percpricechg"))) {
|
||||
QVariantHash data = extQuotes->itemByTagNumber(index(source))->run();
|
||||
foreach (QString key, data.keys())
|
||||
for (auto key : data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
QString key = QString(source).remove(QString("quotes/"));
|
||||
@ -148,7 +148,7 @@ QStringList QuotesSource::sources() const
|
||||
QStringList QuotesSource::getSources()
|
||||
{
|
||||
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("askchg"))));
|
||||
sources.append(
|
||||
|
@ -76,7 +76,7 @@ QStringList UpgradeSource::sources() const
|
||||
QStringList UpgradeSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
foreach (ExtUpgrade *item, extUpgrade->activeItems())
|
||||
for (auto item : extUpgrade->activeItems())
|
||||
sources.append(
|
||||
QString("upgrade/%1").arg(item->tag(QString("pkgcount"))));
|
||||
|
||||
|
@ -47,7 +47,7 @@ QVariant WeatherSource::data(QString source)
|
||||
|
||||
if (source.startsWith(QString("weather/weatherId"))) {
|
||||
QVariantHash data = extWeather->itemByTagNumber(index(source))->run();
|
||||
foreach (QString key, data.keys())
|
||||
for (auto key : data.keys())
|
||||
values[key] = data[key];
|
||||
}
|
||||
QString key = QString(source).remove(QString("weather/"));
|
||||
@ -124,7 +124,7 @@ QStringList WeatherSource::sources() const
|
||||
QStringList WeatherSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
foreach (ExtWeather *item, extWeather->activeItems()) {
|
||||
for (auto item : extWeather->activeItems()) {
|
||||
sources.append(
|
||||
QString("weather/%1").arg(item->tag(QString("weatherId"))));
|
||||
sources.append(
|
||||
|
Loading…
Reference in New Issue
Block a user