diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml index e917d7f..5ab552a 100644 --- a/sources/awesome-widget/package/contents/ui/main.qml +++ b/sources/awesome-widget/package/contents/ui/main.qml @@ -63,6 +63,8 @@ Item { "notify": plasmoid.configuration.notify } + signal connectPlugin + signal disconnectPlugin signal dropSource(string sourceName) signal needTextUpdate(string newText) signal needToolTipUpdate(string newText) @@ -87,11 +89,6 @@ Item { connectedSources: systemmonitorDE.sources interval: plasmoid.configuration.interval - onNewData: { - if (debug) console.debug("Update source", sourceName) - awKeys.dataUpdateReceived(sourceName, data) - } - onSourceAdded: { if (debug) console.debug("Source", source) awKeys.addDevice(source) @@ -103,11 +100,6 @@ Item { engine: "extsysmon" connectedSources: extsysmonDE.sources interval: plasmoid.configuration.interval - - onNewData: { - if (debug) console.debug("Update source", sourceName) - awKeys.dataUpdateReceived(sourceName, data) - } } PlasmaCore.DataSource { @@ -115,11 +107,6 @@ Item { engine: "time" connectedSources: ["Local"] interval: 1000 - - onNewData: { - if (debug) console.debug("Update source", sourceName) - awKeys.dataUpdateReceived(sourceName, data) - } } @@ -173,6 +160,12 @@ Item { } } + Timer { + id: timer + interval: 5 * plasmoid.configuration.interval + onTriggered: connectPlugin() + } + Component.onCompleted: { if (debug) console.debug() @@ -184,13 +177,35 @@ Item { // init submodule Plasmoid.userConfiguringChanged(false) // connect data + awKeys.disconnectPlugin.connect(disconnectPlugin) awKeys.dropSourceFromDataengine.connect(dropSource) awKeys.needTextToBeUpdated.connect(needTextUpdate) awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate) + connectPlugin() // check updates if required if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false) } + onConnectPlugin: { + if (debug) console.debug() + + systemmonitorDE.newData.connect(awKeys.dataUpdateReceived) + extsysmonDE.newData.connect(awKeys.dataUpdateReceived) + timeDE.newData.connect(awKeys.dataUpdateReceived) + + return awKeys.unlock() + } + + onDisconnectPlugin: { + if (debug) console.debug() + + systemmonitorDE.newData.disconnect(awKeys.dataUpdateReceived) + extsysmonDE.newData.disconnect(awKeys.dataUpdateReceived) + timeDE.newData.disconnect(awKeys.dataUpdateReceived) + + return timer.start() + } + onDropSource: { if (debug) console.debug() if (debug) console.debug("Source", sourceName) diff --git a/sources/awesome-widget/plugin/awdataaggregator.cpp b/sources/awesome-widget/plugin/awdataaggregator.cpp index d19c695..dde47dd 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.cpp +++ b/sources/awesome-widget/plugin/awdataaggregator.cpp @@ -31,9 +31,8 @@ #include "awdebug.h" -AWDataAggregator::AWDataAggregator(QObject *parent, QThreadPool *pThreadPool) - : QObject(parent), - threadPool(pThreadPool) +AWDataAggregator::AWDataAggregator(QObject *parent) + : QObject(parent) { qCDebug(LOG_AW); // required by signals @@ -86,6 +85,7 @@ void AWDataAggregator::setParameters(QVariantMap settings) m_enablePopup = configuration[QString("notify")].toBool(); + counts = 0; counts += configuration[QString("cpuTooltip")].toInt(); counts += configuration[QString("cpuclTooltip")].toInt(); counts += configuration[QString("memTooltip")].toInt(); @@ -103,6 +103,7 @@ void AWDataAggregator::setParameters(QVariantMap settings) boundaries[QString("upTooltip")] = 1.0; boundaries[QString("batTooltip")] = 100.0; + requiredKeys.clear(); if (configuration[QString("cpuTooltip")].toBool()) requiredKeys.append(QString("cpuTooltip")); if (configuration[QString("cpuclTooltip")].toBool()) requiredKeys.append(QString("cpuclTooltip")); if (configuration[QString("memTooltip")].toBool()) requiredKeys.append(QString("memTooltip")); @@ -161,13 +162,7 @@ void AWDataAggregator::dataUpdate(const QHash values) { qCDebug(LOG_AW); -#ifdef BUILD_FUTURE - QtConcurrent::run(threadPool, [this, values]() { - setData(values); - }); -#else /* BUILD_FUTURE */ setData(values); -#endif /* BUILD_FUTURE */ emit(toolTipPainted(htmlImage(tooltipImage()))); } diff --git a/sources/awesome-widget/plugin/awdataaggregator.h b/sources/awesome-widget/plugin/awdataaggregator.h index c7f9539..6a66889 100644 --- a/sources/awesome-widget/plugin/awdataaggregator.h +++ b/sources/awesome-widget/plugin/awdataaggregator.h @@ -33,7 +33,7 @@ class AWDataAggregator : public QObject Q_OBJECT public: - explicit AWDataAggregator(QObject *parent = nullptr, QThreadPool *pThreadPool = nullptr); + explicit AWDataAggregator(QObject *parent = nullptr); virtual ~AWDataAggregator(); QList getData(const QString key) const; QString htmlImage(const QPixmap source) const; @@ -70,7 +70,6 @@ private: QHash> data; bool m_enablePopup = false; QStringList requiredKeys; - QThreadPool *threadPool = nullptr; }; diff --git a/sources/awesome-widget/plugin/awkeys.cpp b/sources/awesome-widget/plugin/awkeys.cpp index 89ee87a..11ced2a 100644 --- a/sources/awesome-widget/plugin/awkeys.cpp +++ b/sources/awesome-widget/plugin/awkeys.cpp @@ -50,11 +50,10 @@ AWKeys::AWKeys(QObject *parent) // thread pool queueLimit = QThread::idealThreadCount(); threadPool = new QThreadPool(this); - threadPool->setMaxThreadCount(queueLimit); #endif /* BUILD_FUTURE */ aggregator = new AWKeysAggregator(this); - dataAggregator = new AWDataAggregator(this, threadPool); + dataAggregator = new AWDataAggregator(this); // transfer signal from AWDataAggregator object to QML ui connect(dataAggregator, SIGNAL(toolTipPainted(const QString)), this, SIGNAL(needToolTipToBeUpdated(const QString))); @@ -126,6 +125,14 @@ void AWKeys::setWrapNewLines(const bool wrap) } +void AWKeys::unlock() +{ + qCDebug(LOG_AW); + + lock = false; +} + + void AWKeys::addDevice(const QString source) { qCDebug(LOG_AW); @@ -324,12 +331,11 @@ void AWKeys::dataUpdateReceived(const QString sourceName, const QVariantMap data qCDebug(LOG_AW) << "Source" << sourceName; qCDebug(LOG_AW) << "Data" << data; - // we will update text even if queue limit is reached + if (lock) return; if (sourceName == QString("update")) return emit(needToBeUpdated()); #ifdef BUILD_FUTURE // run concurrent data update - if ((lock = ((lock) && (queue > 0)))) return; QtConcurrent::run(threadPool, [this, sourceName, data]() { return setDataBySource(sourceName, data); }); @@ -682,6 +688,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data) if (++queue > queueLimit) { qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit; lock = true; + emit(disconnectPlugin()); return; } #endif /* BUILD_FUTURE */ diff --git a/sources/awesome-widget/plugin/awkeys.h b/sources/awesome-widget/plugin/awkeys.h index ff5d465..5cb311b 100644 --- a/sources/awesome-widget/plugin/awkeys.h +++ b/sources/awesome-widget/plugin/awkeys.h @@ -45,6 +45,7 @@ public: Q_INVOKABLE void initKeys(const QString currentPattern, const int limit); Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value); Q_INVOKABLE void setWrapNewLines(const bool wrap = false); + Q_INVOKABLE void unlock(); // keys Q_INVOKABLE void addDevice(const QString source); Q_INVOKABLE QStringList dictKeys(const bool sorted = false, @@ -58,6 +59,7 @@ public: Q_INVOKABLE void editItem(const QString type); signals: + void disconnectPlugin() const; void dropSourceFromDataengine(const QString source); void needTextToBeUpdated(const QString newText) const; void needToolTipToBeUpdated(const QString newText) const; @@ -89,8 +91,8 @@ private: QHash values; bool m_wrapNewLines = false; // queue and stream lock properties - bool lock = false; QThreadPool *threadPool = nullptr; + bool lock = true; int queueLimit, queue = 0; }; diff --git a/sources/desktop-panel/package/contents/ui/main.qml b/sources/desktop-panel/package/contents/ui/main.qml index 8bd1f87..a84311f 100644 --- a/sources/desktop-panel/package/contents/ui/main.qml +++ b/sources/desktop-panel/package/contents/ui/main.qml @@ -101,7 +101,7 @@ Item { } } - + Timer { id: timer interval: 1000