mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-08-31 04:39:56 +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:
@ -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,8 +61,8 @@ QVariant GPULoadSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_device == QString("nvidia")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("<gpu_util>")))
|
||||
continue;
|
||||
QString load = str.remove(QString("<gpu_util>"))
|
||||
@ -72,8 +72,8 @@ QVariant GPULoadSource::data(QString source)
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("load")))
|
||||
continue;
|
||||
QString load
|
||||
|
@ -62,8 +62,8 @@ QVariant GPUTemperatureSource::data(QString source)
|
||||
QString qoutput
|
||||
= QTextCodec::codecForMib(106)->toUnicode(process.output).trimmed();
|
||||
if (m_device == QString("nvidia")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("<gpu_temp>")))
|
||||
continue;
|
||||
QString temp = str.remove(QString("<gpu_temp>"))
|
||||
@ -72,8 +72,8 @@ QVariant GPUTemperatureSource::data(QString source)
|
||||
break;
|
||||
}
|
||||
} else if (m_device == QString("ati")) {
|
||||
foreach (QString str,
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
for (auto str :
|
||||
qoutput.split(QChar('\n'), QString::SkipEmptyParts)) {
|
||||
if (!str.contains(QString("Temperature")))
|
||||
continue;
|
||||
QString temp
|
||||
|
@ -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(
|
||||
|
Reference in New Issue
Block a user