mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add lambda support
This commit is contained in:
parent
a5e9b32b28
commit
835eb00f0d
@ -26,6 +26,7 @@
|
|||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <QScriptEngine>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@ -131,6 +132,8 @@ QString AWKeys::parsePattern() const
|
|||||||
|
|
||||||
QString parsed = pattern;
|
QString parsed = pattern;
|
||||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||||
|
foreach(QString key, foundLambdas)
|
||||||
|
parsed.replace(QString("${{%1}}").arg(key), calculateLambda(key));
|
||||||
foreach(QString key, foundKeys)
|
foreach(QString key, foundKeys)
|
||||||
parsed.replace(QString("$%1").arg(key), htmlValue(key));
|
parsed.replace(QString("$%1").arg(key), htmlValue(key));
|
||||||
foreach(QString bar, foundBars)
|
foreach(QString bar, foundBars)
|
||||||
@ -820,6 +823,7 @@ void AWKeys::reinitKeys()
|
|||||||
keys = dictKeys();
|
keys = dictKeys();
|
||||||
foundBars = findGraphicalItems();
|
foundBars = findGraphicalItems();
|
||||||
foundKeys = findKeys();
|
foundKeys = findKeys();
|
||||||
|
foundLambdas = findLambdas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -868,6 +872,27 @@ void AWKeys::addKeyToCache(const QString type, const QString key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWKeys::calculateLambda(QString key) const
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Lambda key" << key;
|
||||||
|
|
||||||
|
QScriptEngine engine;
|
||||||
|
foreach(QString lambdaKey, foundKeys)
|
||||||
|
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Expression" << key;
|
||||||
|
|
||||||
|
QScriptValue result = engine.evaluate(key);
|
||||||
|
if (engine.hasUncaughtException()) {
|
||||||
|
int line = engine.uncaughtExceptionLineNumber();
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Uncaught exception at line"
|
||||||
|
<< line << ":" << result.toString();
|
||||||
|
return QString();
|
||||||
|
} else
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWKeys::htmlValue(QString key) const
|
QString AWKeys::htmlValue(QString key) const
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
@ -934,6 +959,8 @@ QStringList AWKeys::findGraphicalItems() const
|
|||||||
|
|
||||||
QStringList AWKeys::findKeys() const
|
QStringList AWKeys::findKeys() const
|
||||||
{
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QStringList selectedKeys;
|
QStringList selectedKeys;
|
||||||
foreach(QString key, keys) {
|
foreach(QString key, keys) {
|
||||||
if (key.startsWith(QString("bar"))) continue;
|
if (key.startsWith(QString("bar"))) continue;
|
||||||
@ -947,6 +974,31 @@ QStringList AWKeys::findKeys() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList AWKeys::findLambdas() const
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
QStringList selectedKeys;
|
||||||
|
// substring inside ${{ }} (with brackets) which should not contain ${{
|
||||||
|
QRegularExpression lambdaRegexp(QString("\\$\\{\\{((?!\\$\\{\\{).)*?\\}\\}"));
|
||||||
|
lambdaRegexp.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
|
||||||
|
|
||||||
|
QRegularExpressionMatchIterator it = lambdaRegexp.globalMatch(pattern);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QRegularExpressionMatch match = it.next();
|
||||||
|
QString lambda = match.captured();
|
||||||
|
// drop brakets
|
||||||
|
lambda.remove(QRegExp(QString("^\\$\\{\\{")));
|
||||||
|
lambda.remove(QRegExp(QString("\\}\\}$")));
|
||||||
|
// append
|
||||||
|
if (debug) qDebug() << PDEBUG << ":" << "Found lambda" << lambda;
|
||||||
|
selectedKeys.append(lambda);
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GraphicalItem *AWKeys::getItemByTag(const QString tag) const
|
GraphicalItem *AWKeys::getItemByTag(const QString tag) const
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
@ -75,12 +75,14 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
// methods
|
// methods
|
||||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||||
|
QString calculateLambda(QString key) const;
|
||||||
QString htmlValue(QString key) const;
|
QString htmlValue(QString key) const;
|
||||||
int numberCpus() const;
|
int numberCpus() const;
|
||||||
float temperature(const float temp, const QString units) const;
|
float temperature(const float temp, const QString units) const;
|
||||||
// find methods
|
// find methods
|
||||||
QStringList findGraphicalItems() const;
|
QStringList findGraphicalItems() const;
|
||||||
QStringList findKeys() const;
|
QStringList findKeys() const;
|
||||||
|
QStringList findLambdas() const;
|
||||||
// get methods
|
// get methods
|
||||||
GraphicalItem *getItemByTag(const QString tag) const;
|
GraphicalItem *getItemByTag(const QString tag) const;
|
||||||
QStringList getTimeKeys() const;
|
QStringList getTimeKeys() const;
|
||||||
@ -94,7 +96,7 @@ private:
|
|||||||
ExtItemAggregator<ExtUpgrade> *extUpgrade;
|
ExtItemAggregator<ExtUpgrade> *extUpgrade;
|
||||||
ExtItemAggregator<ExtWeather> *extWeather;
|
ExtItemAggregator<ExtWeather> *extWeather;
|
||||||
QString pattern;
|
QString pattern;
|
||||||
QStringList foundBars, foundKeys, keys;
|
QStringList foundBars, foundKeys, foundLambdas, keys;
|
||||||
QHash<QString, QString> values;
|
QHash<QString, QString> values;
|
||||||
QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;
|
QStringList diskDevices, hddDevices, mountDevices, networkDevices, tempDevices;
|
||||||
};
|
};
|
||||||
|
@ -67,21 +67,35 @@ public:
|
|||||||
m_items = getItems();
|
m_items = getItems();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
T *itemByTagNumber(const int _number) const
|
||||||
|
{
|
||||||
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
|
T *found = nullptr;
|
||||||
|
foreach(T *item, m_items) {
|
||||||
|
if (item->number() != _number) continue;
|
||||||
|
found = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
T *itemFromWidget() const
|
T *itemFromWidget() const
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
|
|
||||||
QListWidgetItem *item = widgetDialog->currentItem();
|
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
||||||
if (item == nullptr) return nullptr;
|
if (widgetItem == nullptr) return nullptr;
|
||||||
|
|
||||||
int originalItem = -1;
|
T *found = nullptr;
|
||||||
for (int i=0; i<m_items.count(); i++) {
|
foreach(T *item, m_items) {
|
||||||
if (m_items.at(i)->fileName() != item->text()) continue;
|
if (item->fileName() != widgetItem->text()) continue;
|
||||||
originalItem = i;
|
found = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return originalItem == -1 ? nullptr : m_items[originalItem];
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<T *> items() const
|
QList<T *> items() const
|
||||||
|
@ -29,7 +29,7 @@ Item {
|
|||||||
DPAdds {
|
DPAdds {
|
||||||
id: dpAdds;
|
id: dpAdds;
|
||||||
}
|
}
|
||||||
|
|
||||||
width: childrenRect.width
|
width: childrenRect.width
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
implicitWidth: pageColumn.implicitWidth
|
implicitWidth: pageColumn.implicitWidth
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
find_package(Gettext REQUIRED)
|
find_package(Gettext REQUIRED)
|
||||||
find_package(Qt5 REQUIRED COMPONENTS Core DBus Network Qml Widgets)
|
find_package(Qt5 REQUIRED COMPONENTS Core DBus Network Script Qml Widgets)
|
||||||
find_package(ECM 0.0.11 REQUIRED NO_MODULE)
|
find_package(ECM 0.0.11 REQUIRED NO_MODULE)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
|
||||||
find_package(KF5 REQUIRED COMPONENTS I18n Notifications Plasma Service WindowSystem)
|
find_package(KF5 REQUIRED COMPONENTS I18n Notifications Plasma Service WindowSystem)
|
||||||
@ -10,16 +10,16 @@ include(KDECompilerSettings)
|
|||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Network_DEFINITIONS}
|
||||||
${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
${Qt5Script_DEFINITIONS} ${Qt5Qml_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}
|
||||||
)
|
)
|
||||||
set(Qt_INCLUDE
|
set(Qt_INCLUDE
|
||||||
${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}
|
${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}
|
||||||
${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}
|
${Qt5Script_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
set(Kf5_INCLUDE ${I18n_INCLUDE_DIR} ${Notifications_INCLUDE_DIR} ${Plasma_INCLUDE_DIR})
|
set(Kf5_INCLUDE ${I18n_INCLUDE_DIR} ${Notifications_INCLUDE_DIR} ${Plasma_INCLUDE_DIR})
|
||||||
|
|
||||||
set(Qt_LIBRARIES
|
set(Qt_LIBRARIES
|
||||||
${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES}
|
${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Network_LIBRARIES}
|
||||||
${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES}
|
${Qt5Script_LIBRARIES} ${Qt5Qml_LIBRARIES} ${Qt5Widgets_LIBRARIES}
|
||||||
)
|
)
|
||||||
set(Kf5_LIBRARIES KF5::I18n KF5::Notifications KF5::Plasma KF5::WindowSystem)
|
set(Kf5_LIBRARIES KF5::I18n KF5::Notifications KF5::Plasma KF5::WindowSystem)
|
||||||
|
Loading…
Reference in New Issue
Block a user