mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
move dataengine control to plugin part (ref to #66)
This commit is contained in:
parent
228d6500d3
commit
c4612d84ed
@ -118,16 +118,6 @@ Item {
|
|||||||
QtControls.ComboBox {
|
QtControls.ComboBox {
|
||||||
id: hdd
|
id: hdd
|
||||||
width: parent.width * 3 / 5
|
width: parent.width * 3 / 5
|
||||||
model: awKeys.getHddDevices(true)
|
|
||||||
Component.onCompleted: {
|
|
||||||
if (debug) console.debug()
|
|
||||||
for (var i=0; i<model.length; i++) {
|
|
||||||
if (model[i] == cfg_dataengine["HDDDEV"]) {
|
|
||||||
if (debug) console.info("Found", model[i], "on", i)
|
|
||||||
hdd.currentIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +335,16 @@ Item {
|
|||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
|
|
||||||
// init submodule
|
// init submodule
|
||||||
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.queueLimit)
|
awKeys.updateCache()
|
||||||
|
|
||||||
|
// update hdd model
|
||||||
|
hdd.model = awKeys.getHddDevices()
|
||||||
|
for (var i=0; i<model.length; i++) {
|
||||||
|
if (model[i] == cfg_dataengine["HDDDEV"]) {
|
||||||
|
if (debug) console.info("Found", model[i], "on", i)
|
||||||
|
hdd.currentIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onDestruction: {
|
Component.onDestruction: {
|
||||||
|
@ -63,9 +63,6 @@ Item {
|
|||||||
"notify": plasmoid.configuration.notify
|
"notify": plasmoid.configuration.notify
|
||||||
}
|
}
|
||||||
|
|
||||||
signal connectPlugin
|
|
||||||
signal disconnectPlugin
|
|
||||||
signal dropSource(string sourceName)
|
|
||||||
signal needTextUpdate(string newText)
|
signal needTextUpdate(string newText)
|
||||||
signal needToolTipUpdate(string newText)
|
signal needToolTipUpdate(string newText)
|
||||||
signal sizeUpdate
|
signal sizeUpdate
|
||||||
@ -83,32 +80,6 @@ Item {
|
|||||||
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
||||||
Plasmoid.associatedApplication: "ksysguard"
|
Plasmoid.associatedApplication: "ksysguard"
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: systemmonitorDE
|
|
||||||
engine: "systemmonitor"
|
|
||||||
connectedSources: systemmonitorDE.sources
|
|
||||||
interval: plasmoid.configuration.interval
|
|
||||||
|
|
||||||
onSourceAdded: {
|
|
||||||
if (debug) console.debug("Source", source)
|
|
||||||
awKeys.addDevice(source)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: extsysmonDE
|
|
||||||
engine: "extsysmon"
|
|
||||||
connectedSources: extsysmonDE.sources
|
|
||||||
interval: plasmoid.configuration.interval
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: timeDE
|
|
||||||
engine: "time"
|
|
||||||
connectedSources: ["Local"]
|
|
||||||
interval: 1000
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ui
|
// ui
|
||||||
Text {
|
Text {
|
||||||
@ -160,12 +131,6 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: timer
|
|
||||||
interval: 5 * plasmoid.configuration.interval
|
|
||||||
onTriggered: connectPlugin()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
@ -177,42 +142,12 @@ Item {
|
|||||||
// init submodule
|
// init submodule
|
||||||
Plasmoid.userConfiguringChanged(false)
|
Plasmoid.userConfiguringChanged(false)
|
||||||
// connect data
|
// connect data
|
||||||
awKeys.disconnectPlugin.connect(disconnectPlugin)
|
|
||||||
awKeys.dropSourceFromDataengine.connect(dropSource)
|
|
||||||
awKeys.needTextToBeUpdated.connect(needTextUpdate)
|
awKeys.needTextToBeUpdated.connect(needTextUpdate)
|
||||||
awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate)
|
awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate)
|
||||||
connectPlugin()
|
|
||||||
// check updates if required
|
// check updates if required
|
||||||
if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false)
|
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)
|
|
||||||
|
|
||||||
systemmonitorDE.disconnectSource(sourceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
onNeedTextUpdate: {
|
onNeedTextUpdate: {
|
||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
|
|
||||||
@ -252,7 +187,8 @@ Item {
|
|||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
|
|
||||||
// init submodule
|
// init submodule
|
||||||
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.queueLimit)
|
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
|
||||||
|
plasmoid.configuration.queueLimit)
|
||||||
awKeys.initDataAggregator(tooltipSettings)
|
awKeys.initDataAggregator(tooltipSettings)
|
||||||
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
|
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
|
||||||
// configure aggregator
|
// configure aggregator
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import QtQuick.Controls 1.3 as QtControls
|
import QtQuick.Controls 1.3 as QtControls
|
||||||
import QtQuick.Dialogs 1.2 as QtDialogs
|
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
||||||
|
|
||||||
import org.kde.plasma.private.awesomewidget 1.0
|
import org.kde.plasma.private.awesomewidget 1.0
|
||||||
|
|
||||||
@ -41,8 +40,8 @@ Item {
|
|||||||
property bool debug: awActions.isDebugEnabled()
|
property bool debug: awActions.isDebugEnabled()
|
||||||
|
|
||||||
property alias cfg_text: textPattern.text
|
property alias cfg_text: textPattern.text
|
||||||
|
property bool lock: true
|
||||||
|
|
||||||
signal dropSource(string sourceName)
|
|
||||||
signal needTextUpdate(string newText)
|
signal needTextUpdate(string newText)
|
||||||
|
|
||||||
|
|
||||||
@ -320,7 +319,9 @@ Item {
|
|||||||
width: parent.width * 2 / 5
|
width: parent.width * 2 / 5
|
||||||
text: i18n("Preview")
|
text: i18n("Preview")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
awKeys.initKeys(textPattern.text, plasmoid.configuration.queueLimit)
|
lock = false
|
||||||
|
awKeys.initKeys(textPattern.text, plasmoid.configuration.interval,
|
||||||
|
plasmoid.configuration.queueLimit)
|
||||||
awKeys.needToBeUpdated()
|
awKeys.needToBeUpdated()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,67 +343,27 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// we need to initializate DataEngines here too
|
|
||||||
// because we need to get keys and values
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: systemmonitorDE
|
|
||||||
engine: "systemmonitor"
|
|
||||||
connectedSources: systemmonitorDE.sources
|
|
||||||
interval: 5000
|
|
||||||
onNewData: awKeys.dataUpdateReceived(sourceName, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: extsysmonDE
|
|
||||||
engine: "extsysmon"
|
|
||||||
connectedSources: extsysmonDE.sources
|
|
||||||
interval: 5000
|
|
||||||
|
|
||||||
onNewData: {
|
|
||||||
// even after a disconnect it is possible that we'll receive an update
|
|
||||||
if (sourceName == "update") return
|
|
||||||
awKeys.dataUpdateReceived(sourceName, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
|
||||||
id: timeDE
|
|
||||||
engine: "time"
|
|
||||||
connectedSources: ["Local"]
|
|
||||||
interval: 5000
|
|
||||||
onNewData: awKeys.dataUpdateReceived(sourceName, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
|
|
||||||
// drop "update" source which does not required by this page
|
|
||||||
extsysmonDE.disconnectSource("update")
|
|
||||||
awKeys.dropSourceFromDataengine.connect(dropSource)
|
|
||||||
awKeys.needTextToBeUpdated.connect(needTextUpdate)
|
awKeys.needTextToBeUpdated.connect(needTextUpdate)
|
||||||
// init submodule
|
// init submodule
|
||||||
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.queueLimit)
|
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
|
||||||
|
plasmoid.configuration.queueLimit)
|
||||||
awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline)
|
awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline)
|
||||||
awKeys.setAggregatorProperty("acOnline", plasmoid.configuration.acOnline)
|
awKeys.setAggregatorProperty("acOnline", plasmoid.configuration.acOnline)
|
||||||
awKeys.setAggregatorProperty("customTime", plasmoid.configuration.customTime)
|
awKeys.setAggregatorProperty("customTime", plasmoid.configuration.customTime)
|
||||||
awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime)
|
awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime)
|
||||||
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
||||||
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
||||||
awKeys.unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
onDropSource: {
|
|
||||||
if (debug) console.debug()
|
|
||||||
if (debug) console.debug("Source", sourceName)
|
|
||||||
|
|
||||||
systemmonitorDE.disconnectSource(sourceName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onNeedTextUpdate: {
|
onNeedTextUpdate: {
|
||||||
|
if (lock) return
|
||||||
if (debug) console.debug()
|
if (debug) console.debug()
|
||||||
|
|
||||||
compiledText.text = newText.replace(/ /g, " ")
|
compiledText.text = newText.replace(/ /g, " ")
|
||||||
compiledText.open()
|
compiledText.open()
|
||||||
|
lock = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,9 @@ include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||||
file(GLOB SUBPROJECT_UI *.ui)
|
|
||||||
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||||
|
|
||||||
qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
|
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
|
||||||
add_library(${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
|
|
||||||
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
target_link_libraries(${PLUGIN_NAME} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||||
|
|
||||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||||
|
123
sources/awesome-widget/plugin/awdataengineaggregator.cpp
Normal file
123
sources/awesome-widget/plugin/awdataengineaggregator.cpp
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "awdataengineaggregator.h"
|
||||||
|
|
||||||
|
#include <Plasma/DataEngineConsumer>
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "awdebug.h"
|
||||||
|
#include "awkeys.h"
|
||||||
|
|
||||||
|
|
||||||
|
AWDataEngineAggregator::AWDataEngineAggregator(QObject *parent, const int interval)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
setInterval(interval);
|
||||||
|
initDataEngines();
|
||||||
|
connectVisualization();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
m_dataEngines.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::setInterval(const int _interval)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
qCDebug(LOG_AW) << "Interval" << _interval;
|
||||||
|
|
||||||
|
m_interval = _interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::connectVisualization()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(updateData(QString, QVariantHash)),
|
||||||
|
parent(), SLOT(dataUpdated(QString, QVariantHash)));
|
||||||
|
|
||||||
|
return static_cast<AWKeys *>(parent())->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::disconnectVisualization()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
disconnect(this, SIGNAL(updateData(QString, QVariantHash)),
|
||||||
|
parent(), SLOT(dataUpdated(QString, QVariantHash)));
|
||||||
|
|
||||||
|
return QTimer::singleShot(5 * m_interval, this, SLOT(connectVisualization()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::dropSource(const QString source)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
qCDebug(LOG_AW) << "Source" << source;
|
||||||
|
|
||||||
|
// this method is only used for systemmonitor dataengine
|
||||||
|
m_dataEngines[QString("systemmonitor")]->disconnectSource(source, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::reconnectSources()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
m_dataEngines[QString("systemmonitor")]->connectAllSources(this, m_interval);
|
||||||
|
m_dataEngines[QString("extsysmon")]->connectAllSources(this, m_interval);
|
||||||
|
m_dataEngines[QString("time")]->connectSource(QString("Local"), this, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::dataUpdated(const QString sourceName, const Plasma::DataEngine::Data data)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||||
|
qCDebug(LOG_AW) << "Data" << data;
|
||||||
|
|
||||||
|
return emit(updateData(QString(sourceName), qvariant_cast<QVariantHash>(data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWDataEngineAggregator::initDataEngines()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
Plasma::DataEngineConsumer *deConsumer = new Plasma::DataEngineConsumer();
|
||||||
|
m_dataEngines[QString("systemmonitor")] = deConsumer->dataEngine(QString("systemmonitor"));
|
||||||
|
m_dataEngines[QString("extsysmon")] = deConsumer->dataEngine(QString("extsysmon"));
|
||||||
|
m_dataEngines[QString("time")] = deConsumer->dataEngine(QString("time"));
|
||||||
|
|
||||||
|
// additional method required by systemmonitor structure
|
||||||
|
connect(m_dataEngines[QString("systemmonitor")], &Plasma::DataEngine::sourceAdded,
|
||||||
|
[this](const QString source) {
|
||||||
|
static_cast<AWKeys *>(parent())->addDevice(source);
|
||||||
|
m_dataEngines[QString("systemmonitor")]->connectSource(source, this, m_interval);
|
||||||
|
});
|
||||||
|
}
|
58
sources/awesome-widget/plugin/awdataengineaggregator.h
Normal file
58
sources/awesome-widget/plugin/awdataengineaggregator.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of awesome-widgets *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef AWDATAENGINEAGGREGATOR_H
|
||||||
|
#define AWDATAENGINEAGGREGATOR_H
|
||||||
|
|
||||||
|
#include <Plasma/DataEngine>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class AWDataEngineAggregator : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int interval MEMBER m_interval WRITE setInterval);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AWDataEngineAggregator(QObject *parent = nullptr, const int interval = 1000);
|
||||||
|
virtual ~AWDataEngineAggregator();
|
||||||
|
// properties
|
||||||
|
void setInterval(const int _interval);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void updateData(const QString sourceName, const QVariantHash sdata);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// additional methods to control this and visualization
|
||||||
|
void connectVisualization();
|
||||||
|
void disconnectVisualization();
|
||||||
|
void dropSource(const QString source);
|
||||||
|
void reconnectSources();
|
||||||
|
// data engines operations
|
||||||
|
void dataUpdated(const QString sourceName, const Plasma::DataEngine::Data data);
|
||||||
|
// dummy method required by DataEngine connections
|
||||||
|
void modelChanged(QString, QAbstractItemModel *) {};
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initDataEngines();
|
||||||
|
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||||
|
int m_interval;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* AWDATAENGINEAGGREGATOR_H */
|
@ -27,9 +27,10 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#include "awdataaggregator.h"
|
||||||
|
#include "awdataengineaggregator.h"
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "awkeysaggregator.h"
|
#include "awkeysaggregator.h"
|
||||||
#include "awdataaggregator.h"
|
|
||||||
#include "extquotes.h"
|
#include "extquotes.h"
|
||||||
#include "extscript.h"
|
#include "extscript.h"
|
||||||
#include "extupgrade.h"
|
#include "extupgrade.h"
|
||||||
@ -57,7 +58,7 @@ AWKeys::AWKeys(QObject *parent)
|
|||||||
// transfer signal from AWDataAggregator object to QML ui
|
// transfer signal from AWDataAggregator object to QML ui
|
||||||
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)),
|
connect(dataAggregator, SIGNAL(toolTipPainted(const QString)),
|
||||||
this, SIGNAL(needToolTipToBeUpdated(const QString)));
|
this, SIGNAL(needToolTipToBeUpdated(const QString)));
|
||||||
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate()));
|
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(updateTextData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -73,12 +74,21 @@ AWKeys::~AWKeys()
|
|||||||
if (extWeather != nullptr) delete extWeather;
|
if (extWeather != nullptr) delete extWeather;
|
||||||
|
|
||||||
// core
|
// core
|
||||||
|
if (dataEngineAggregator != nullptr) delete dataEngineAggregator;
|
||||||
if (threadPool != nullptr) delete threadPool;
|
if (threadPool != nullptr) delete threadPool;
|
||||||
delete aggregator;
|
delete aggregator;
|
||||||
delete dataAggregator;
|
delete dataAggregator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWKeys::unlock()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
@ -88,13 +98,21 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::initKeys(const QString currentPattern, const int limit)
|
void AWKeys::initKeys(const QString currentPattern, const int interval, const int limit)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
qCDebug(LOG_AW) << "Pattern" << currentPattern;
|
qCDebug(LOG_AW) << "Pattern" << currentPattern;
|
||||||
|
qCDebug(LOG_AW) << "Interval" << interval;
|
||||||
|
qCDebug(LOG_AW) << "Queue limit" << limit;
|
||||||
|
|
||||||
// init
|
// init
|
||||||
m_pattern = currentPattern;
|
m_pattern = currentPattern;
|
||||||
|
if (dataEngineAggregator == nullptr) {
|
||||||
|
dataEngineAggregator = new AWDataEngineAggregator(this, interval);
|
||||||
|
connect(this, SIGNAL(dropSourceFromDataengine(QString)),
|
||||||
|
dataEngineAggregator, SLOT(dropSource(QString)));
|
||||||
|
} else
|
||||||
|
dataEngineAggregator->setInterval(interval);
|
||||||
#ifdef BUILD_FUTURE
|
#ifdef BUILD_FUTURE
|
||||||
// queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag.
|
// queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag.
|
||||||
// In other hand since I'm using global thread pool, it makes sense to limit
|
// In other hand since I'm using global thread pool, it makes sense to limit
|
||||||
@ -102,9 +120,9 @@ void AWKeys::initKeys(const QString currentPattern, const int limit)
|
|||||||
queueLimit = limit == 0 ? QThread::idealThreadCount() : limit;
|
queueLimit = limit == 0 ? QThread::idealThreadCount() : limit;
|
||||||
threadPool->setMaxThreadCount(queueLimit);
|
threadPool->setMaxThreadCount(queueLimit);
|
||||||
#endif /* BUILD_FUTURE */
|
#endif /* BUILD_FUTURE */
|
||||||
// update network and hdd list
|
updateCache();
|
||||||
addKeyToCache(QString("hdd"));
|
|
||||||
addKeyToCache(QString("net"));
|
return dataEngineAggregator->reconnectSources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -125,33 +143,13 @@ void AWKeys::setWrapNewLines(const bool wrap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::unlock()
|
void AWKeys::updateCache()
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
lock = false;
|
// update network and hdd list
|
||||||
}
|
addKeyToCache(QString("hdd"));
|
||||||
|
addKeyToCache(QString("net"));
|
||||||
|
|
||||||
void AWKeys::addDevice(const QString source)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW);
|
|
||||||
qCDebug(LOG_AW) << "Source" << source;
|
|
||||||
|
|
||||||
QRegExp diskRegexp = QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
|
||||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
|
||||||
|
|
||||||
if (source.contains(diskRegexp)) {
|
|
||||||
QString device = source;
|
|
||||||
device.remove(QString("/Rate/rblk"));
|
|
||||||
addKeyToCache(QString("disk"), device);
|
|
||||||
} else if (source.contains(mountRegexp)) {
|
|
||||||
QString device = source;
|
|
||||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
|
||||||
addKeyToCache(QString("mount"), device);
|
|
||||||
} else if (source.startsWith(QString("lmsensors"))) {
|
|
||||||
addKeyToCache(QString("temp"), source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -325,26 +323,6 @@ QStringList AWKeys::getHddDevices() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::dataUpdateReceived(const QString sourceName, const QVariantMap data)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW);
|
|
||||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
|
||||||
qCDebug(LOG_AW) << "Data" << data;
|
|
||||||
|
|
||||||
if (lock) return;
|
|
||||||
if (sourceName == QString("update")) return emit(needToBeUpdated());
|
|
||||||
|
|
||||||
#ifdef BUILD_FUTURE
|
|
||||||
// run concurrent data update
|
|
||||||
QtConcurrent::run(threadPool, [this, sourceName, data]() {
|
|
||||||
return setDataBySource(sourceName, data);
|
|
||||||
});
|
|
||||||
#else /* BUILD_FUTURE */
|
|
||||||
return setDataBySource(sourceName, data);
|
|
||||||
#endif /* BUILD_FUTURE */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWKeys::infoByKey(QString key) const
|
QString AWKeys::infoByKey(QString key) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
@ -404,21 +382,45 @@ void AWKeys::editItem(const QString type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::dataUpdate()
|
void AWKeys::addDevice(const QString source)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
|
qCDebug(LOG_AW) << "Source" << source;
|
||||||
|
|
||||||
|
QRegExp diskRegexp = QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||||
|
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||||
|
|
||||||
|
if (source.contains(diskRegexp)) {
|
||||||
|
QString device = source;
|
||||||
|
device.remove(QString("/Rate/rblk"));
|
||||||
|
addKeyToCache(QString("disk"), device);
|
||||||
|
} else if (source.contains(mountRegexp)) {
|
||||||
|
QString device = source;
|
||||||
|
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||||
|
addKeyToCache(QString("mount"), device);
|
||||||
|
} else if (source.startsWith(QString("lmsensors"))) {
|
||||||
|
addKeyToCache(QString("temp"), source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWKeys::dataUpdated(const QString sourceName, const QVariantHash data)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||||
|
qCDebug(LOG_AW) << "Data" << data;
|
||||||
|
|
||||||
|
if (lock) return;
|
||||||
|
if (sourceName == QString("update")) return emit(needToBeUpdated());
|
||||||
|
|
||||||
#ifdef BUILD_FUTURE
|
#ifdef BUILD_FUTURE
|
||||||
QFuture<QString> text = QtConcurrent::run(threadPool, [this]() {
|
// run concurrent data update
|
||||||
calculateValues();
|
QtConcurrent::run(threadPool, [this, sourceName, data]() {
|
||||||
return parsePattern(m_pattern);
|
return setDataBySource(sourceName, data);
|
||||||
});
|
});
|
||||||
#else /* BUILD_FUTURE */
|
#else /* BUILD_FUTURE */
|
||||||
calculateValues();
|
return setDataBySource(sourceName, data);
|
||||||
QString text = parsePattern(m_pattern);
|
|
||||||
#endif /* BUILD_FUTURE */
|
#endif /* BUILD_FUTURE */
|
||||||
emit(needTextToBeUpdated(text));
|
|
||||||
emit(dataAggregator->updateData(values));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -464,7 +466,7 @@ void AWKeys::reinitKeys()
|
|||||||
// init
|
// init
|
||||||
QStringList allKeys = dictKeys();
|
QStringList allKeys = dictKeys();
|
||||||
|
|
||||||
#ifdef BUILD_TEST
|
#ifdef BUILD_TESTING
|
||||||
// not documented feature - place all available tags
|
// not documented feature - place all available tags
|
||||||
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
m_pattern = m_pattern.replace(QString("$ALL"), [allKeys]() {
|
||||||
QStringList strings;
|
QStringList strings;
|
||||||
@ -472,7 +474,7 @@ void AWKeys::reinitKeys()
|
|||||||
strings.append(QString("%1: $%1").arg(tag));
|
strings.append(QString("%1: $%1").arg(tag));
|
||||||
return strings.join(QString(" | "));
|
return strings.join(QString(" | "));
|
||||||
}());
|
}());
|
||||||
#endif /* BUILD_TEST */
|
#endif /* BUILD_TESTING */
|
||||||
|
|
||||||
// append lists
|
// append lists
|
||||||
// bars
|
// bars
|
||||||
@ -528,6 +530,24 @@ void AWKeys::reinitKeys()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWKeys::updateTextData()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW);
|
||||||
|
|
||||||
|
#ifdef BUILD_FUTURE
|
||||||
|
QFuture<QString> text = QtConcurrent::run(threadPool, [this]() {
|
||||||
|
calculateValues();
|
||||||
|
return parsePattern(m_pattern);
|
||||||
|
});
|
||||||
|
#else /* BUILD_FUTURE */
|
||||||
|
calculateValues();
|
||||||
|
QString text = parsePattern(m_pattern);
|
||||||
|
#endif /* BUILD_FUTURE */
|
||||||
|
emit(needTextToBeUpdated(text));
|
||||||
|
emit(dataAggregator->updateData(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::addKeyToCache(const QString type, const QString key)
|
void AWKeys::addKeyToCache(const QString type, const QString key)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
@ -679,7 +699,7 @@ QString AWKeys::parsePattern(QString pattern) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
|
void AWKeys::setDataBySource(const QString sourceName, const QVariantHash data)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW);
|
qCDebug(LOG_AW);
|
||||||
qCDebug(LOG_AW) << "Source" << sourceName;
|
qCDebug(LOG_AW) << "Source" << sourceName;
|
||||||
@ -690,8 +710,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
|
|||||||
if (++queue > queueLimit) {
|
if (++queue > queueLimit) {
|
||||||
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit;
|
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit;
|
||||||
lock = true;
|
lock = true;
|
||||||
emit(disconnectPlugin());
|
return dataEngineAggregator->disconnectVisualization();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif /* BUILD_FUTURE */
|
#endif /* BUILD_FUTURE */
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class AWDataAggregator;
|
class AWDataAggregator;
|
||||||
|
class AWDataEngineAggregator;
|
||||||
class AWKeysAggregator;
|
class AWKeysAggregator;
|
||||||
class ExtQuotes;
|
class ExtQuotes;
|
||||||
class ExtScript;
|
class ExtScript;
|
||||||
@ -40,45 +41,48 @@ class AWKeys : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit AWKeys(QObject *parent = nullptr);
|
explicit AWKeys(QObject *parent = nullptr);
|
||||||
virtual ~AWKeys();
|
virtual ~AWKeys();
|
||||||
|
|
||||||
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
|
Q_INVOKABLE void initDataAggregator(const QVariantMap tooltipParams);
|
||||||
Q_INVOKABLE void initKeys(const QString currentPattern, const int limit);
|
Q_INVOKABLE void initKeys(const QString currentPattern, const int interval,
|
||||||
|
const int limit);
|
||||||
Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value);
|
Q_INVOKABLE void setAggregatorProperty(const QString key, const QVariant value);
|
||||||
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
|
||||||
Q_INVOKABLE void unlock();
|
Q_INVOKABLE void unlock();
|
||||||
|
Q_INVOKABLE void updateCache();
|
||||||
// keys
|
// keys
|
||||||
Q_INVOKABLE void addDevice(const QString source);
|
|
||||||
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
Q_INVOKABLE QStringList dictKeys(const bool sorted = false,
|
||||||
const QString regexp = QString()) const;
|
const QString regexp = QString()) const;
|
||||||
Q_INVOKABLE QStringList getHddDevices() const;
|
Q_INVOKABLE QStringList getHddDevices() const;
|
||||||
Q_INVOKABLE void dataUpdateReceived(const QString sourceName, const QVariantMap data);
|
|
||||||
// values
|
// values
|
||||||
Q_INVOKABLE QString infoByKey(QString key) const;
|
Q_INVOKABLE QString infoByKey(QString key) const;
|
||||||
Q_INVOKABLE QString valueByKey(QString key) const;
|
Q_INVOKABLE QString valueByKey(QString key) const;
|
||||||
// configuration
|
// configuration
|
||||||
Q_INVOKABLE void editItem(const QString type);
|
Q_INVOKABLE void editItem(const QString type);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void addDevice(const QString source);
|
||||||
|
void dataUpdated(const QString sourceName, const QVariantHash data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void disconnectPlugin() const;
|
|
||||||
void dropSourceFromDataengine(const QString source);
|
void dropSourceFromDataengine(const QString source);
|
||||||
void needTextToBeUpdated(const QString newText) const;
|
void needTextToBeUpdated(const QString newText) const;
|
||||||
void needToolTipToBeUpdated(const QString newText) const;
|
void needToolTipToBeUpdated(const QString newText) const;
|
||||||
void needToBeUpdated();
|
void needToBeUpdated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void dataUpdate();
|
|
||||||
void loadKeysFromCache();
|
void loadKeysFromCache();
|
||||||
void reinitKeys();
|
void reinitKeys();
|
||||||
|
void updateTextData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods
|
// methods
|
||||||
void addKeyToCache(const QString type, const QString key = QString(""));
|
void addKeyToCache(const QString type, const QString key = QString(""));
|
||||||
void calculateValues();
|
void calculateValues();
|
||||||
QString parsePattern(QString pattern) const;
|
QString parsePattern(QString pattern) const;
|
||||||
void setDataBySource(const QString sourceName, const QVariantMap data);
|
void setDataBySource(const QString sourceName, const QVariantHash data);
|
||||||
// objects
|
// objects
|
||||||
AWKeysAggregator *aggregator = nullptr;
|
|
||||||
AWDataAggregator *dataAggregator = nullptr;
|
AWDataAggregator *dataAggregator = nullptr;
|
||||||
|
AWDataEngineAggregator *dataEngineAggregator = nullptr;
|
||||||
|
AWKeysAggregator *aggregator = nullptr;
|
||||||
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
|
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
|
||||||
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
|
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
|
||||||
ExtItemAggregator<ExtScript> *extScripts = nullptr;
|
ExtItemAggregator<ExtScript> *extScripts = nullptr;
|
||||||
@ -92,8 +96,8 @@ private:
|
|||||||
bool m_wrapNewLines = false;
|
bool m_wrapNewLines = false;
|
||||||
// queue and stream lock properties
|
// queue and stream lock properties
|
||||||
QThreadPool *threadPool = nullptr;
|
QThreadPool *threadPool = nullptr;
|
||||||
bool lock = true;
|
|
||||||
int queueLimit, queue = 0;
|
int queueLimit, queue = 0;
|
||||||
|
bool lock = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user