mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
change formating
* add *h.in to clang-format configuration * move static keys definition to header. Probably it may break something with key parsing
This commit is contained in:
parent
95a5eec108
commit
15d4d7667d
@ -94,47 +94,14 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(
|
||||
extWeather->activeItems().at(i)->tag(QString("timestamp")));
|
||||
}
|
||||
// time
|
||||
allKeys.append(QString("time"));
|
||||
allKeys.append(QString("isotime"));
|
||||
allKeys.append(QString("shorttime"));
|
||||
allKeys.append(QString("longtime"));
|
||||
allKeys.append(QString("ctime"));
|
||||
// uptime
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpuclock & cpu
|
||||
for (int i = QThread::idealThreadCount() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
}
|
||||
allKeys.append(QString("cpucl"));
|
||||
allKeys.append(QString("cpu"));
|
||||
// temperature
|
||||
for (int i = m_devices[QString("temp")].count() - 1; i >= 0; i--)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gputemp
|
||||
allKeys.append(QString("gputemp"));
|
||||
// gpu
|
||||
allKeys.append(QString("gpu"));
|
||||
// memory
|
||||
allKeys.append(QString("memmb"));
|
||||
allKeys.append(QString("memgb"));
|
||||
allKeys.append(QString("memfreemb"));
|
||||
allKeys.append(QString("memfreegb"));
|
||||
allKeys.append(QString("memtotmb"));
|
||||
allKeys.append(QString("memtotgb"));
|
||||
allKeys.append(QString("memusedmb"));
|
||||
allKeys.append(QString("memusedgb"));
|
||||
allKeys.append(QString("mem"));
|
||||
// swap
|
||||
allKeys.append(QString("swapmb"));
|
||||
allKeys.append(QString("swapgb"));
|
||||
allKeys.append(QString("swapfreemb"));
|
||||
allKeys.append(QString("swapfreegb"));
|
||||
allKeys.append(QString("swaptotmb"));
|
||||
allKeys.append(QString("swaptotgb"));
|
||||
allKeys.append(QString("swap"));
|
||||
// hdd
|
||||
for (int i = m_devices[QString("mount")].count() - 1; i >= 0; i--) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
@ -162,38 +129,13 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("upkb%1").arg(i));
|
||||
allKeys.append(QString("up%1").arg(i));
|
||||
}
|
||||
allKeys.append(QString("downunits"));
|
||||
allKeys.append(QString("upunits"));
|
||||
allKeys.append(QString("downkb"));
|
||||
allKeys.append(QString("down"));
|
||||
allKeys.append(QString("upkb"));
|
||||
allKeys.append(QString("up"));
|
||||
allKeys.append(QString("netdev"));
|
||||
// battery
|
||||
allKeys.append(QString("ac"));
|
||||
QStringList allBatteryDevices
|
||||
= QDir(QString("/sys/class/power_supply"))
|
||||
.entryList(QStringList() << QString("BAT*"),
|
||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
for (int i = allBatteryDevices.count() - 1; i >= 0; i--)
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("bat"));
|
||||
// player
|
||||
allKeys.append(QString("album"));
|
||||
allKeys.append(QString("artist"));
|
||||
allKeys.append(QString("duration"));
|
||||
allKeys.append(QString("progress"));
|
||||
allKeys.append(QString("title"));
|
||||
allKeys.append(QString("dalbum"));
|
||||
allKeys.append(QString("dartist"));
|
||||
allKeys.append(QString("dtitle"));
|
||||
allKeys.append(QString("salbum"));
|
||||
allKeys.append(QString("sartist"));
|
||||
allKeys.append(QString("stitle"));
|
||||
// ps
|
||||
allKeys.append(QString("pscount"));
|
||||
allKeys.append(QString("pstotal"));
|
||||
allKeys.append(QString("ps"));
|
||||
// package manager
|
||||
for (int i = extUpgrade->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
@ -217,18 +159,14 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
// custom
|
||||
for (int i = extScripts->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(extScripts->activeItems().at(i)->tag(QString("custom")));
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
allKeys.append(QString("ndesktop"));
|
||||
allKeys.append(QString("tdesktops"));
|
||||
// load average
|
||||
allKeys.append(QString("la15"));
|
||||
allKeys.append(QString("la5"));
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
for (int i = graphicalItems->activeItems().count() - 1; i >= 0; i--)
|
||||
allKeys.append(
|
||||
graphicalItems->activeItems().at(i)->tag(QString("bar")));
|
||||
// static keys
|
||||
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
|
||||
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
|
||||
[&allKeys](const QString &key) { allKeys.append(key); });
|
||||
|
||||
return allKeys;
|
||||
}
|
||||
|
@ -285,24 +285,8 @@ void AWKeys::calculateValues()
|
||||
|
||||
// lambdas
|
||||
for (auto key : m_foundLambdas)
|
||||
values[key] = [this](QString key) {
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
key.replace(QString("$this"), values[key].toString());
|
||||
for (auto lambdaKey : m_foundKeys)
|
||||
key.replace(QString("$%1").arg(lambdaKey),
|
||||
aggregator->formater(values[lambdaKey], lambdaKey));
|
||||
qCInfo(LOG_AW) << "Expression" << key;
|
||||
QJSValue result = engine.evaluate(key);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt()
|
||||
<< ":" << result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}(key);
|
||||
values[key] = AWPatternFunctions::expandLambdas(key, aggregator, values,
|
||||
m_foundKeys);
|
||||
}
|
||||
|
||||
|
||||
@ -329,31 +313,16 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
// bars
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
if (item->type() == GraphicalItem::Graph)
|
||||
if (item->type() == GraphicalItem::Graph) {
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(QVariant::fromValue<QList<float>>(
|
||||
dataAggregator->getData(item->bar()))));
|
||||
else {
|
||||
} else {
|
||||
if (item->isCustom())
|
||||
pattern.replace(
|
||||
QString("$%1").arg(bar),
|
||||
item->image([this, item](QString bar) {
|
||||
QJSEngine engine;
|
||||
for (auto key : item->usedKeys())
|
||||
bar.replace(QString("$%1").arg(key),
|
||||
aggregator->formater(values[key], key));
|
||||
qCInfo(LOG_AW) << "Expression" << bar;
|
||||
QJSValue result = engine.evaluate(bar);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW)
|
||||
<< "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}(item->bar())));
|
||||
item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), aggregator, values, item->usedKeys())));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(values[item->bar()]));
|
||||
|
@ -21,6 +21,69 @@
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awkeysaggregator.h"
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandLambdas(QString code,
|
||||
AWKeysAggregator *aggregator,
|
||||
const QVariantHash &metadata,
|
||||
const QStringList &usedKeys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand lamdas in" << code;
|
||||
|
||||
QJSEngine engine;
|
||||
// apply $this values
|
||||
code.replace(QString("$this"), metadata[code].toString());
|
||||
// parsed values
|
||||
for (auto lambdaKey : usedKeys)
|
||||
code.replace(QString("$%1").arg(lambdaKey),
|
||||
aggregator->formater(metadata[lambdaKey], lambdaKey));
|
||||
qCInfo(LOG_AW) << "Expression" << code;
|
||||
QJSValue result = engine.evaluate(code);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt() << ":"
|
||||
<< result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandTemplates(QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand templates in" << code;
|
||||
|
||||
// match the following construction $template{{some code here}}
|
||||
QRegularExpression templatesRegexp(
|
||||
QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
|
||||
templatesRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString body = match.captured(QString("body"));
|
||||
|
||||
QJSEngine engine;
|
||||
qCInfo(LOG_AW) << "Expression" << body;
|
||||
QJSValue result = engine.evaluate(body);
|
||||
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
|
||||
code.replace(match.captured(), templateResult);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
@ -68,41 +131,6 @@ QVariantList AWPatternFunctions::findFunctionCalls(const QString function,
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::expandTemplates(QString code)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Expand templates in" << code;
|
||||
|
||||
// match the following construction $template{{some code here}}
|
||||
QRegularExpression templatesRegexp(
|
||||
QString("\\$template\\{\\{(?<body>.*?)\\}\\}"));
|
||||
templatesRegexp.setPatternOptions(
|
||||
QRegularExpression::DotMatchesEverythingOption);
|
||||
|
||||
QRegularExpressionMatchIterator it = templatesRegexp.globalMatch(code);
|
||||
while (it.hasNext()) {
|
||||
QRegularExpressionMatch match = it.next();
|
||||
QString body = match.captured(QString("body"));
|
||||
|
||||
QJSEngine engine;
|
||||
qCInfo(LOG_AW) << "Expression" << body;
|
||||
QJSValue result = engine.evaluate(body);
|
||||
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
|
||||
code.replace(match.captured(), templateResult);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
QString AWPatternFunctions::insertAllKeys(QString code, const QStringList keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for keys in code" << code << "using list"
|
||||
|
@ -23,9 +23,14 @@
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class AWKeysAggregator;
|
||||
|
||||
namespace AWPatternFunctions
|
||||
{
|
||||
// insert methods
|
||||
QString expandLambdas(QString code, AWKeysAggregator *aggregator,
|
||||
const QVariantHash &metadata,
|
||||
const QStringList &usedKeys);
|
||||
QString expandTemplates(QString code);
|
||||
QVariantList findFunctionCalls(const QString function, const QString code);
|
||||
QString insertAllKeys(QString code, const QStringList keys);
|
||||
|
@ -1,7 +1,7 @@
|
||||
# additional target to perform clang-format run, requires clang-format
|
||||
|
||||
# get all project files
|
||||
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
|
||||
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.h.in)
|
||||
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
|
||||
string(FIND ${SOURCE_FILE} ${PROJECT_TRDPARTY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
|
||||
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
|
||||
|
@ -7,11 +7,19 @@
|
||||
#define VERSION "@PROJECT_VERSION@"
|
||||
#define COMMIT_SHA "@PROJECT_COMMIT_SHA@"
|
||||
#define AUTHOR "@PROJECT_AUTHOR@"
|
||||
#define TRANSLATORS "Ernesto Aviles Vzqz (Spanish), Mermouy (French), underr (Brazillian Portuguese), Viktor Slobodyan (Ukrainian), Lemueler (Chinese), Heimen Stoffels (Dutch)"
|
||||
#define TRANSLATORS \
|
||||
"Ernesto Aviles Vzqz (Spanish), Mermouy (French), underr (Brazillian " \
|
||||
"Portuguese), Viktor Slobodyan (Ukrainian), Lemueler (Chinese), Heimen " \
|
||||
"Stoffels (Dutch)"
|
||||
#define EMAIL "@PROJECT_CONTACT@"
|
||||
#define LICENSE "@PROJECT_LICENSE@"
|
||||
#define TRDPARTY_LICENSE "tasks,BSD,https://github.com/mhogomchungu/tasks;QReplyTimeout wrapper,no,http://codereview.stackexchange.com/questions/30031/qnetworkreply-network-reply-timeout-helper"
|
||||
#define SPECIAL_THANKS "Yahoo! Finance,https://finance.yahoo.com/;Yahoo! Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/"
|
||||
#define TRDPARTY_LICENSE \
|
||||
"tasks,BSD,https://github.com/mhogomchungu/tasks;QReplyTimeout " \
|
||||
"wrapper,no,http://codereview.stackexchange.com/questions/30031/" \
|
||||
"qnetworkreply-network-reply-timeout-helper"
|
||||
#define SPECIAL_THANKS \
|
||||
"Yahoo! Finance,https://finance.yahoo.com/;Yahoo! " \
|
||||
"Weather,https://weather.yahoo.com/;JetBrains,https://www.jetbrains.com/"
|
||||
#define CHANGELOG "@PROJECT_CHANGELOG@"
|
||||
|
||||
// configuraion
|
||||
@ -28,7 +36,16 @@
|
||||
// network requests timeout, ms
|
||||
#define REQUEST_TIMEOUT 5000
|
||||
// available time keys
|
||||
#define TIME_KEYS "dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A"
|
||||
#define TIME_KEYS \
|
||||
"dddd,ddd,dd,d,MMMM,MMM,MM,M,yyyy,yy,hh,h,HH,H,mm,m,ss,s,t,ap,a,AP,A"
|
||||
// static keys
|
||||
#define STATIC_KEYS \
|
||||
"time,isotime,shorttime,longtime,ctime,uptime,cuptime,cpucl,cpu,gputemp," \
|
||||
"gpu,memmb,memgb,memfreemb,memfreegb,memtotmb,memtotgb,memusedmb," \
|
||||
"memusedgb,mem,swapmb,swapgb,swapfreemb,swapfreegb,swaptotmb,swaptotgb," \
|
||||
"swap,downunits,upunits,downkb,down,upkb,up,netdev,ac,bat,album,artist," \
|
||||
"duration,progress,title,dalbum,dartist,dtitle,salbum,sartist,stitle," \
|
||||
"pscount,pstotal,ps,desktop,ndesktop,tdesktops,la15,la5,la1"
|
||||
#cmakedefine BUILD_FUTURE
|
||||
#cmakedefine BUILD_TESTING
|
||||
|
||||
@ -36,10 +53,12 @@
|
||||
#define HOMEPAGE "https://arcanis.name/projects/awesome-widgets/"
|
||||
#define REPOSITORY "https://github.com/arcan1s/awesome-widgets"
|
||||
#define RELEASES "https://github.com/arcan1s/awesome-widgets/releases/tag/V."
|
||||
#define VERSION_API "https://api.github.com/repos/arcan1s/awesome-widgets/releases"
|
||||
#define VERSION_API \
|
||||
"https://api.github.com/repos/arcan1s/awesome-widgets/releases"
|
||||
#define BUGTRACKER "https://github.com/arcan1s/awesome-widgets/issues"
|
||||
#define TRANSLATION "https://github.com/arcan1s/awesome-widgets/issues/14"
|
||||
#define AUR_PACKAGES "https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/"
|
||||
#define AUR_PACKAGES \
|
||||
"https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/"
|
||||
#define OPENSUSE_PACKAGES "http://software.opensuse.org/package/awesome-widgets"
|
||||
|
||||
// build information
|
||||
|
Loading…
Reference in New Issue
Block a user