mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-10-31 13:13:41 +00:00 
			
		
		
		
	return back stream lock which will be disabled from qml by the timer. In
other case there is possibe plasma crash
This commit is contained in:
		| @ -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) | ||||
|  | ||||
| @ -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<QString, QString> 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()))); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -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<float> getData(const QString key) const; | ||||
|     QString htmlImage(const QPixmap source) const; | ||||
| @ -70,7 +70,6 @@ private: | ||||
|     QHash<QString, QList<float>> data; | ||||
|     bool m_enablePopup = false; | ||||
|     QStringList requiredKeys; | ||||
|     QThreadPool *threadPool = nullptr; | ||||
| }; | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -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 */ | ||||
|  | ||||
| @ -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<QString, QString> values; | ||||
|     bool m_wrapNewLines = false; | ||||
|     // queue and stream lock properties | ||||
|     bool lock = false; | ||||
|     QThreadPool *threadPool = nullptr; | ||||
|     bool lock = true; | ||||
|     int queueLimit, queue = 0; | ||||
| }; | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user