mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-14 22:35:49 +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:
@ -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