From 7218defe196086012253f96d9e6a9bd39acb3702 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Thu, 3 Sep 2015 00:30:10 +0300 Subject: [PATCH] add '$this' feature to lambda functions fix large size on startup fix invalid key parsing --- .../package/contents/ui/main.qml | 4 --- .../awesome-widget/package/contents/ui/qmldir | 2 +- sources/awesome-widget/plugin/awkeys.cpp | 28 +++++++++++++------ sources/awesome-widget/plugin/awkeys.h | 3 +- sources/awesome-widget/plugin/qmldir | 1 - sources/awesomewidgets/extitemaggregator.h | 4 +++ .../desktop-panel/package/contents/ui/qmldir | 2 +- sources/desktop-panel/plugin/qmldir | 1 - sources/extsysmon/extsysmon.cpp | 2 +- 9 files changed, 29 insertions(+), 18 deletions(-) diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml index 52c1147..dfbf3c5 100644 --- a/sources/awesome-widget/package/contents/ui/main.qml +++ b/sources/awesome-widget/package/contents/ui/main.qml @@ -150,8 +150,6 @@ Item { font.pointSize: plasmoid.configuration.fontSize font.weight: general.fontWeight[plasmoid.configuration.fontWeight] - text: plasmoid.configuration.text - PlasmaCore.ToolTipArea { height: tooltip.height width: tooltip.width @@ -233,8 +231,6 @@ Item { awKeys.setPopupEnabled(plasmoid.configuration.notify) awKeys.setTranslateStrings(plasmoid.configuration.translateStrings) awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines) - - needTextUpdate(plasmoid.configuration.text) } function action_checkUpdates() { diff --git a/sources/awesome-widget/package/contents/ui/qmldir b/sources/awesome-widget/package/contents/ui/qmldir index dda3998..c5315a3 100644 --- a/sources/awesome-widget/package/contents/ui/qmldir +++ b/sources/awesome-widget/package/contents/ui/qmldir @@ -1 +1 @@ -singleton general general.qml +singleton general 1.0 general.qml diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 5ed2c40..9236e08 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -724,10 +724,11 @@ void AWKeys::editItem(const QString type) } -void AWKeys::dataUpdate() const +void AWKeys::dataUpdate() { qCDebug(LOG_AW); + calculateLambdas(); emit(needTextToBeUpdated(parsePattern())); if (toolTip != nullptr) emit(toolTip->updateData(values)); } @@ -877,17 +878,15 @@ void AWKeys::addKeyToCache(const QString type, const QString key) } -QString AWKeys::parsePattern() const +void AWKeys::calculateLambdas() { qCDebug(LOG_AW); - QString parsed = pattern; - parsed.replace(QString("$$"), QString("$\\$\\")); - - // lambdas foreach(QString key, foundLambdas) - parsed.replace(QString("${{%1}}").arg(key), [this](QString key) { + values[key] = [this](QString key) { QScriptEngine engine; + // apply $this values + key.replace(QString("$this"), values[key]); foreach(QString lambdaKey, foundKeys) key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]); qCInfo(LOG_AW) << "Expression" << key; @@ -898,7 +897,20 @@ QString AWKeys::parsePattern() const return QString(); } else return result.toString(); - }(key)); + }(key); +} + + +QString AWKeys::parsePattern() const +{ + qCDebug(LOG_AW); + + QString parsed = pattern; + parsed.replace(QString("$$"), QString("$\\$\\")); + + // lambdas + foreach(QString key, foundLambdas) + parsed.replace(QString("${{%1}}").arg(key), values[key]); // main keys foreach(QString key, foundKeys) diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index e138403..8653fc5 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -70,13 +70,14 @@ signals: void needToBeUpdated(); private slots: - void dataUpdate() const; + void dataUpdate(); void loadKeysFromCache(); void reinitKeys(); private: // methods void addKeyToCache(const QString type, const QString key = QString("")); + void calculateLambdas(); QString parsePattern() const; float temperature(const float temp, const QString units) const; // get methods diff --git a/sources/awesome-widget/plugin/qmldir b/sources/awesome-widget/plugin/qmldir index 8a3ed27..504d781 100644 --- a/sources/awesome-widget/plugin/qmldir +++ b/sources/awesome-widget/plugin/qmldir @@ -1,3 +1,2 @@ module org.kde.plasma.private.awesomewidget - plugin awplugin diff --git a/sources/awesomewidgets/extitemaggregator.h b/sources/awesomewidgets/extitemaggregator.h index 93f77e4..1eddfbc 100644 --- a/sources/awesomewidgets/extitemaggregator.h +++ b/sources/awesomewidgets/extitemaggregator.h @@ -174,6 +174,10 @@ private: } } + // sort items + std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs){ + return lhs->number() < rhs->number(); + }); return items; }; diff --git a/sources/desktop-panel/package/contents/ui/qmldir b/sources/desktop-panel/package/contents/ui/qmldir index dda3998..c5315a3 100644 --- a/sources/desktop-panel/package/contents/ui/qmldir +++ b/sources/desktop-panel/package/contents/ui/qmldir @@ -1 +1 @@ -singleton general general.qml +singleton general 1.0 general.qml diff --git a/sources/desktop-panel/plugin/qmldir b/sources/desktop-panel/plugin/qmldir index b49440a..2629c46 100644 --- a/sources/desktop-panel/plugin/qmldir +++ b/sources/desktop-panel/plugin/qmldir @@ -1,3 +1,2 @@ module org.kde.plasma.private.desktoppanel - plugin dpplugin diff --git a/sources/extsysmon/extsysmon.cpp b/sources/extsysmon/extsysmon.cpp index 73cdebf..232a6c4 100644 --- a/sources/extsysmon/extsysmon.cpp +++ b/sources/extsysmon/extsysmon.cpp @@ -533,7 +533,7 @@ QString ExtendedSysMon::buildString(const QString current, const QString value, qCDebug(LOG_ESM) << "Strip after" << s; int index = value.indexOf(current); - if ((index == -1) || ((index + s + 1) > value.count())) + if ((current.isEmpty()) || ((index + s + 1) > value.count())) return QString("%1").arg(value.left(s), s, QLatin1Char(' ')); else return QString("%1").arg(value.mid(index + 1, s), s, QLatin1Char(' '));