mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-10-31 05:13:40 +00:00 
			
		
		
		
	* better extensions update
* prepare dataaggregator to graph data * add ability to wrap text * move tag selection dialog to ui
This commit is contained in:
		| @ -50,6 +50,9 @@ | ||||
|     <entry name="translateStrings" type="bool"> | ||||
|       <default>true</default> | ||||
|     </entry> | ||||
|     <entry name="wrapText" type="bool"> | ||||
|       <default>false</default> | ||||
|     </entry> | ||||
|   </group> | ||||
|  | ||||
|   <group name="Tooltip"> | ||||
|  | ||||
| @ -47,6 +47,7 @@ Item { | ||||
|     property alias cfg_acOffline: acOffline.text | ||||
|     property alias cfg_checkUpdates: updates.checked | ||||
|     property alias cfg_translateStrings: translate.checked | ||||
|     property alias cfg_wrapText: wordWrap.checked | ||||
|  | ||||
|  | ||||
|     Column { | ||||
| @ -120,6 +121,20 @@ Item { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Row { | ||||
|             height: implicitHeight | ||||
|             width: parent.width | ||||
|             QtControls.Label { | ||||
|                 height: parent.heigth | ||||
|                 width: parent.width * 2 / 5 | ||||
|             } | ||||
|             QtControls.CheckBox { | ||||
|                 id: wordWrap | ||||
|                 width: parent.width * 3 / 5 | ||||
|                 text: i18n("Enable word wrap") | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Row { | ||||
|             height: implicitHeight | ||||
|             width: parent.width | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
|  | ||||
| import QtQuick 2.4 | ||||
| import QtQuick.Controls 1.3 as QtControls | ||||
| import QtQuick.Dialogs 1.2 as QtDialogs | ||||
| import QtQuick.Layouts 1.1 | ||||
| import org.kde.plasma.plasmoid 2.0 | ||||
| import org.kde.plasma.core 2.0 as PlasmaCore | ||||
| @ -37,13 +38,6 @@ Item { | ||||
|     } | ||||
|  | ||||
|     property bool debug: awActions.isDebugEnabled() | ||||
|     property variant settings: { | ||||
|         "customTime": plasmoid.configuration.customTime, | ||||
|         "customUptime": plasmoid.configuration.customUptime, | ||||
|         "tempUnits": plasmoid.configuration.tempUnits, | ||||
|         "acOnline": plasmoid.configuration.acOnline, | ||||
|         "acOffline": plasmoid.configuration.acOffline | ||||
|     } | ||||
|     property variant tooltipSettings: { | ||||
|         "tooltipNumber": plasmoid.configuration.tooltipNumber, | ||||
|         "useTooltipBackground": plasmoid.configuration.useTooltipBackground, | ||||
| @ -63,8 +57,10 @@ Item { | ||||
|         "upTooltipColor": plasmoid.configuration.upTooltipColor, | ||||
|         "batTooltipColor": plasmoid.configuration.batTooltipColor, | ||||
|         "batInTooltipColor": plasmoid.configuration.batInTooltipColor, | ||||
|         // additinal field to parse AC status | ||||
|         "acOnline": plasmoid.configuration.acOnline | ||||
|         // additional field to parse AC status | ||||
|         "acOnline": plasmoid.configuration.acOnline, | ||||
|         // additional field to send notifications | ||||
|         "notify": plasmoid.configuration.notify | ||||
|     } | ||||
|  | ||||
|     signal dropSource(string sourceName) | ||||
| @ -93,7 +89,7 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|  | ||||
|         onSourceAdded: { | ||||
| @ -110,8 +106,7 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
| //             extsysmonDE.interval = plasmoid.configuration.interval | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -123,7 +118,7 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -134,7 +129,7 @@ Item { | ||||
|         anchors.fill: parent | ||||
|         renderType: Text.NativeRendering | ||||
|         textFormat: Text.RichText | ||||
|         wrapMode: Text.NoWrap | ||||
|         wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap | ||||
|  | ||||
|         horizontalAlignment: general.align[plasmoid.configuration.textAlign] | ||||
|         verticalAlignment: Text.AlignVCenter | ||||
| @ -157,6 +152,27 @@ Item { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     QtDialogs.Dialog { | ||||
|         id: tagSelector | ||||
|         title: i18n("Select tag") | ||||
|  | ||||
|         QtControls.ComboBox { | ||||
|             id: tagSelectorBox | ||||
|             width: parent.width | ||||
|             editable: true | ||||
|         } | ||||
|  | ||||
|         onAccepted: { | ||||
|             var tag = tagSelectorBox.editText | ||||
|             var message = i18n("Tag: %1", tag) | ||||
|             message += "<br>" | ||||
|             message += i18n("Value: %1", awKeys.valueByKey(tag)) | ||||
|             message += "<br>" | ||||
|             message += i18n("Info: %1", awKeys.infoByKey(tag)) | ||||
|             awActions.sendNotification("tag", message) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     Component.onCompleted: { | ||||
|         if (debug) console.debug() | ||||
|  | ||||
| @ -221,10 +237,15 @@ Item { | ||||
|  | ||||
|         // init submodule | ||||
|         awKeys.initKeys(plasmoid.configuration.text) | ||||
|         awKeys.initTooltip(tooltipSettings) | ||||
|         awKeys.setPopupEnabled(plasmoid.configuration.notify) | ||||
|         awKeys.setTranslateStrings(plasmoid.configuration.translateStrings) | ||||
|         awKeys.initDataAggregator(tooltipSettings) | ||||
|         awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines) | ||||
|         // configure aggregator | ||||
|         awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline) | ||||
|         awKeys.setAggregatorProperty("acOnline", plasmoid.configuration.acOnline) | ||||
|         awKeys.setAggregatorProperty("customTime", plasmoid.configuration.customTime) | ||||
|         awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime) | ||||
|         awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits) | ||||
|         awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings) | ||||
|     } | ||||
|  | ||||
|     function action_checkUpdates() { | ||||
| @ -242,6 +263,7 @@ Item { | ||||
|     function action_requestKey() { | ||||
|         if (debug) console.debug() | ||||
|  | ||||
|         return awKeys.graphicalValueByKey() | ||||
|         tagSelectorBox.model = awKeys.dictKeys(true) | ||||
|         return tagSelector.open() | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -38,33 +38,6 @@ Item { | ||||
|     implicitHeight: pageColumn.implicitHeight | ||||
|  | ||||
|     property bool debug: awActions.isDebugEnabled() | ||||
|     property variant settings: { | ||||
|         "customTime": plasmoid.configuration.customTime, | ||||
|         "customUptime": plasmoid.configuration.customUptime, | ||||
|         "tempUnits": plasmoid.configuration.tempUnits, | ||||
|         "acOnline": plasmoid.configuration.acOnline, | ||||
|         "acOffline": plasmoid.configuration.acOffline | ||||
|     } | ||||
|     property variant tooltipSettings: { | ||||
|         "tooltipNumber": plasmoid.configuration.tooltipNumber, | ||||
|         "useTooltipBackground": plasmoid.configuration.useTooltipBackground, | ||||
|         "tooltipBackgroung": plasmoid.configuration.tooltipBackgroung, | ||||
|         "cpuTooltip": plasmoid.configuration.cpuTooltip, | ||||
|         "cpuclTooltip": plasmoid.configuration.cpuclTooltip, | ||||
|         "memTooltip": plasmoid.configuration.memTooltip, | ||||
|         "swapTooltip": plasmoid.configuration.swapTooltip, | ||||
|         "downTooltip": plasmoid.configuration.downTooltip, | ||||
|         "upTooltip": plasmoid.configuration.downTooltip, | ||||
|         "batTooltip": plasmoid.configuration.batTooltip, | ||||
|         "cpuTooltipColor": plasmoid.configuration.cpuTooltipColor, | ||||
|         "cpuclTooltipColor": plasmoid.configuration.cpuclTooltipColor, | ||||
|         "memTooltipColor": plasmoid.configuration.memTooltipColor, | ||||
|         "swapTooltipColor": plasmoid.configuration.swapTooltipColor, | ||||
|         "downTooltipColor": plasmoid.configuration.downTooltipColor, | ||||
|         "upTooltipColor": plasmoid.configuration.upTooltipColor, | ||||
|         "batTooltipColor": plasmoid.configuration.batTooltipColor, | ||||
|         "batInTooltipColor": plasmoid.configuration.batInTooltipColor | ||||
|     } | ||||
|  | ||||
|     property alias cfg_text: textPattern.text | ||||
|  | ||||
| @ -362,7 +335,7 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -374,7 +347,7 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -386,16 +359,24 @@ Item { | ||||
|  | ||||
|         onNewData: { | ||||
|             if (debug) console.debug("Update source", sourceName) | ||||
|             awKeys.dataUpdateReceived(sourceName, data, settings) | ||||
|             awKeys.dataUpdateReceived(sourceName, data) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     Component.onCompleted: { | ||||
|         if (debug) console.debug() | ||||
|  | ||||
|         // drop "update" source which does not required by this page | ||||
|         extsysmonDE.disconnectSource("update") | ||||
|         awKeys.dropSourceFromDataengine.connect(dropSource) | ||||
|         // init submodule | ||||
|         awKeys.initKeys(plasmoid.configuration.text) | ||||
|         awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline) | ||||
|         awKeys.setAggregatorProperty("acOnline", plasmoid.configuration.acOnline) | ||||
|         awKeys.setAggregatorProperty("customTime", plasmoid.configuration.customTime) | ||||
|         awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime) | ||||
|         awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits) | ||||
|         awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings) | ||||
|     } | ||||
|  | ||||
|     onDropSource: { | ||||
|  | ||||
| @ -20,25 +20,69 @@ | ||||
| #include <KI18n/KLocalizedString> | ||||
|  | ||||
| #include <QBuffer> | ||||
|  | ||||
| #include <math.h> | ||||
|  | ||||
| #include "awactions.h" | ||||
| #include "awdebug.h" | ||||
|  | ||||
|  | ||||
| AWDataAggregator::AWDataAggregator(QObject *parent, QVariantMap settings) | ||||
|     : QObject(parent), | ||||
|       configuration(qvariant_cast<QVariantHash>(settings)) | ||||
| AWDataAggregator::AWDataAggregator(QObject *parent) | ||||
|     : QObject(parent) | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     toolTipScene = new QGraphicsScene(nullptr); | ||||
|     toolTipView = new QGraphicsView(toolTipScene); | ||||
|     toolTipView->setStyleSheet(QString("background: transparent")); | ||||
|     toolTipView->setContentsMargins(0, 0, 0, 0); | ||||
|     toolTipView->setFrameShape(QFrame::NoFrame); | ||||
|     toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
|     toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
|     initScene(); | ||||
|  | ||||
|     connect(this, SIGNAL(updateData(QHash<QString, QString>)), | ||||
|             this, SLOT(dataUpdate(QHash<QString, QString>))); | ||||
| } | ||||
|  | ||||
|  | ||||
| AWDataAggregator::~AWDataAggregator() | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     delete toolTipScene; | ||||
| } | ||||
|  | ||||
|  | ||||
| QList<float> AWDataAggregator::getData(const QString key) const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|     qCDebug(LOG_AW) << "Key" << key; | ||||
|  | ||||
|     return data[QString("%1Tooltip").arg(key)]; | ||||
| } | ||||
|  | ||||
|  | ||||
| QSize AWDataAggregator::getTooltipSize() const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     return size; | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWDataAggregator::htmlImage(const QPixmap source) const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     QByteArray byteArray; | ||||
|     QBuffer buffer(&byteArray); | ||||
|     source.save(&buffer, "PNG"); | ||||
|  | ||||
|     return byteArray.isEmpty() ? QString() : | ||||
|            QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64())); | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataAggregator::setParameters(QVariantMap settings) | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|     qCDebug(LOG_AW) << "Settings" << settings; | ||||
|  | ||||
|     configuration = qvariant_cast<QVariantHash>(settings); | ||||
|  | ||||
|     enablePopup = configuration[QString("notify")].toBool(); | ||||
|  | ||||
| @ -67,66 +111,10 @@ AWDataAggregator::AWDataAggregator(QObject *parent, QVariantMap settings) | ||||
|     if (configuration[QString("upTooltip")].toBool()) requiredKeys.append(QString("upTooltip")); | ||||
|     if (configuration[QString("batTooltip")].toBool()) requiredKeys.append(QString("batTooltip")); | ||||
|  | ||||
|     connect(this, SIGNAL(updateData(QHash<QString, QString>)), | ||||
|             this, SLOT(dataUpdate(QHash<QString, QString>))); | ||||
| } | ||||
|  | ||||
|  | ||||
| AWDataAggregator::~AWDataAggregator() | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     delete toolTipScene; | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataAggregator::dataUpdate(QHash<QString, QString> values) | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     // battery update requires info is AC online or not | ||||
|     setData(values[QString("ac")] == configuration[QString("acOnline")], | ||||
|             QString("batTooltip"), values[QString("bat")].toFloat()); | ||||
|     // usual case | ||||
|     setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0); | ||||
|     setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat()); | ||||
|     setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0); | ||||
|     setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0); | ||||
|     setData(QString("downTooltip"), values[QString("downkb")].toFloat()); | ||||
|     setData(QString("upTooltip"), values[QString("upkb")].toFloat()); | ||||
|     // additional check for network device | ||||
|     [this](const QString value) { | ||||
|         checkValue(QString("netdev"), currentNetworkDevice, value); | ||||
|         currentNetworkDevice = value; | ||||
|     }(values[QString("netdev")]); | ||||
|     // additional check for GPU load | ||||
|     [this](const float value) { | ||||
|         checkValue(QString("gpu"), value, 90.0); | ||||
|         currentGPULoad = value; | ||||
|     }(values[QString("gpu")].toFloat()); | ||||
|  | ||||
|     emit(toolTipPainted(htmlImage(tooltipImage()))); | ||||
| } | ||||
|  | ||||
|  | ||||
| QSize AWDataAggregator::getTooltipSize() const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     return size; | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWDataAggregator::htmlImage(const QPixmap source) | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     QByteArray byteArray; | ||||
|     QBuffer buffer(&byteArray); | ||||
|     source.save(&buffer, "PNG"); | ||||
|  | ||||
|     return byteArray.isEmpty() ? QString() : | ||||
|            QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64())); | ||||
|     // background | ||||
|     toolTipScene->setBackgroundBrush(configuration[QString("useTooltipBackground")].toBool() ? | ||||
|                                      QBrush(QColor(configuration[QString("tooltipBackground")].toString())) : | ||||
|                                      QBrush(Qt::NoBrush)); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -138,10 +126,6 @@ QPixmap AWDataAggregator::tooltipImage() | ||||
|     // create image | ||||
|     toolTipScene->clear(); | ||||
|     QPen pen = QPen(); | ||||
|     // background | ||||
|     toolTipScene->setBackgroundBrush(configuration[QString("useTooltipBackground")].toBool() ? | ||||
|                                      QBrush(QColor(configuration[QString("tooltipBackground")].toString())) : | ||||
|                                      QBrush(Qt::NoBrush)); | ||||
|     bool down = false; | ||||
|     foreach(QString key, requiredKeys) { | ||||
|         // create frame | ||||
| @ -174,6 +158,35 @@ QPixmap AWDataAggregator::tooltipImage() | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataAggregator::dataUpdate(QHash<QString, QString> values) | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     // battery update requires info is AC online or not | ||||
|     setData(values[QString("ac")] == configuration[QString("acOnline")], | ||||
|             QString("batTooltip"), values[QString("bat")].toFloat()); | ||||
|     // usual case | ||||
|     setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0); | ||||
|     setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat()); | ||||
|     setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0); | ||||
|     setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0); | ||||
|     setData(QString("downTooltip"), values[QString("downkb")].toFloat()); | ||||
|     setData(QString("upTooltip"), values[QString("upkb")].toFloat()); | ||||
|     // additional check for network device | ||||
|     [this](const QString value) { | ||||
|         checkValue(QString("netdev"), currentNetworkDevice, value); | ||||
|         currentNetworkDevice = value; | ||||
|     }(values[QString("netdev")]); | ||||
|     // additional check for GPU load | ||||
|     [this](const float value) { | ||||
|         checkValue(QString("gpu"), value, 90.0); | ||||
|         currentGPULoad = value; | ||||
|     }(values[QString("gpu")].toFloat()); | ||||
|  | ||||
|     emit(toolTipPainted(htmlImage(tooltipImage()))); | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataAggregator::checkValue(const QString source, const float value, const float extremum) const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
| @ -181,8 +194,13 @@ void AWDataAggregator::checkValue(const QString source, const float value, const | ||||
|     qCDebug(LOG_AW) << "Value" << value; | ||||
|     qCDebug(LOG_AW) << "Called with extremum" << extremum; | ||||
|  | ||||
|     if ((enablePopup) && (value > extremum) && (data[source].last() < extremum)) | ||||
|         return AWActions::sendNotification(QString("event"), notificationText(source, value)); | ||||
|     if (value >= 0.0) { | ||||
|         if ((enablePopup) && (value > extremum) && (data[source].last() < extremum)) | ||||
|             return AWActions::sendNotification(QString("event"), notificationText(source, value)); | ||||
|     } else { | ||||
|         if ((enablePopup) && (value < extremum) && (data[source].last() > extremum)) | ||||
|             return AWActions::sendNotification(QString("event"), notificationText(source, value)); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -198,6 +216,20 @@ void AWDataAggregator::checkValue(const QString source, const QString current, c | ||||
| } | ||||
|  | ||||
|  | ||||
| void AWDataAggregator::initScene() | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     toolTipScene = new QGraphicsScene(nullptr); | ||||
|     toolTipView = new QGraphicsView(toolTipScene); | ||||
|     toolTipView->setStyleSheet(QString("background: transparent")); | ||||
|     toolTipView->setContentsMargins(0, 0, 0, 0); | ||||
|     toolTipView->setFrameShape(QFrame::NoFrame); | ||||
|     toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
|     toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||||
| } | ||||
|  | ||||
|  | ||||
| QString AWDataAggregator::notificationText(const QString source, const float value) const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
| @ -32,10 +32,12 @@ class AWDataAggregator : public QObject | ||||
|     Q_OBJECT | ||||
|  | ||||
| public: | ||||
|     explicit AWDataAggregator(QObject *parent = nullptr, QVariantMap settings = QVariantMap()); | ||||
|     explicit AWDataAggregator(QObject *parent = nullptr); | ||||
|     virtual ~AWDataAggregator(); | ||||
|     QList<float> getData(const QString key) const; | ||||
|     QSize getTooltipSize() const; | ||||
|     QString htmlImage(const QPixmap source); | ||||
|     QString htmlImage(const QPixmap source) const; | ||||
|     void setParameters(QVariantMap settings); | ||||
|     QPixmap tooltipImage(); | ||||
|  | ||||
| signals: | ||||
| @ -50,7 +52,8 @@ private: | ||||
|     QGraphicsScene *toolTipScene = nullptr; | ||||
|     QGraphicsView *toolTipView = nullptr; | ||||
|     void checkValue(const QString source, const float value, const float extremum) const; | ||||
|     void checkValue(const QString source,  const QString current, const QString received) const; | ||||
|     void checkValue(const QString source, const QString current, const QString received) const; | ||||
|     void initScene(); | ||||
|     QString notificationText(const QString source, const float value) const; | ||||
|     QString notificationText(const QString source, const QString value) const; | ||||
|     void setData(const QString source, float value, const float extremum = -1.0); | ||||
| @ -60,7 +63,7 @@ private: | ||||
|     int counts = 0; | ||||
|     QVariantHash configuration; | ||||
|     float currentGPULoad = 0.0; | ||||
|     QString currentNetworkDevice; | ||||
|     QString currentNetworkDevice = QString("lo"); | ||||
|     QHash<QString, float> boundaries; | ||||
|     QHash<QString, QList<float>> data; | ||||
|     bool enablePopup = false; | ||||
|  | ||||
| @ -46,14 +46,11 @@ AWKeys::AWKeys(QObject *parent) | ||||
|     qSetMessagePattern(LOG_FORMAT); | ||||
|  | ||||
|     aggregator = new AWKeysAggregator(this); | ||||
|  | ||||
|     // backend | ||||
|     graphicalItems = new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops")); | ||||
|     extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes")); | ||||
|     extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts")); | ||||
|     extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade")); | ||||
|     extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather")); | ||||
|     dataAggregator = new AWDataAggregator(this); | ||||
|     connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate())); | ||||
|     // transfer signal from AWDataAggregator object to QML ui | ||||
|     connect(dataAggregator, SIGNAL(toolTipPainted(QString)), | ||||
|             this, SIGNAL(needToolTipToBeUpdated(QString))); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -61,14 +58,14 @@ AWKeys::~AWKeys() | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     if (dataAggregator != nullptr)  delete dataAggregator; | ||||
|     if (graphicalItems != nullptr) delete graphicalItems; | ||||
|     if (extQuotes != nullptr) delete extQuotes; | ||||
|     if (extScripts != nullptr) delete extScripts; | ||||
|     if (extUpgrade != nullptr) delete extUpgrade; | ||||
|     if (extWeather != nullptr) delete extWeather; | ||||
|  | ||||
|     delete aggregator; | ||||
|     delete graphicalItems; | ||||
|     delete extQuotes; | ||||
|     delete extScripts; | ||||
|     delete extUpgrade; | ||||
|     delete extWeather; | ||||
|     delete dataAggregator; | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -77,16 +74,7 @@ void AWKeys::initDataAggregator(const QVariantMap tooltipParams) | ||||
|     qCDebug(LOG_AW); | ||||
|     qCDebug(LOG_AW) << "Tooltip parameters" << tooltipParams; | ||||
|  | ||||
|     if (dataAggregator != nullptr) { | ||||
|         disconnect(dataAggregator, SIGNAL(toolTipPainted(QString)), | ||||
|                    this, SIGNAL(needToolTipToBeUpdated(QString))); | ||||
|         delete dataAggregator; | ||||
|     } | ||||
|  | ||||
|     dataAggregator = new AWDataAggregator(this, tooltipParams); | ||||
|     // transfer signal from AWDataAggregator object to QML ui | ||||
|     connect(dataAggregator, SIGNAL(toolTipPainted(QString)), | ||||
|             this, SIGNAL(needToolTipToBeUpdated(QString))); | ||||
|     dataAggregator->setParameters(tooltipParams); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -134,7 +122,6 @@ void AWKeys::setWrapNewLines(const bool wrap) | ||||
| QSize AWKeys::toolTipSize() const | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|     if (dataAggregator == nullptr) return QSize(); | ||||
|  | ||||
|     return dataAggregator->getTooltipSize(); | ||||
| } | ||||
| @ -418,7 +405,7 @@ void AWKeys::dataUpdate() | ||||
|     calculateValues(); | ||||
|     calculateLambdas(); | ||||
|     emit(needTextToBeUpdated(parsePattern())); | ||||
|     if (dataAggregator != nullptr) emit(dataAggregator->updateData(values)); | ||||
|     emit(dataAggregator->updateData(values)); | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -469,6 +456,20 @@ void AWKeys::reinitKeys() | ||||
| { | ||||
|     qCDebug(LOG_AW); | ||||
|  | ||||
|     // renew extensions | ||||
|     // delete them if any | ||||
|     if (graphicalItems != nullptr) delete graphicalItems; | ||||
|     if (extQuotes != nullptr) delete extQuotes; | ||||
|     if (extScripts != nullptr) delete extScripts; | ||||
|     if (extUpgrade != nullptr) delete extUpgrade; | ||||
|     if (extWeather != nullptr) delete extWeather; | ||||
|     // create | ||||
|     graphicalItems = new ExtItemAggregator<GraphicalItem>(nullptr, QString("desktops")); | ||||
|     extQuotes = new ExtItemAggregator<ExtQuotes>(nullptr, QString("quotes")); | ||||
|     extScripts = new ExtItemAggregator<ExtScript>(nullptr, QString("scripts")); | ||||
|     extUpgrade = new ExtItemAggregator<ExtUpgrade>(nullptr, QString("upgrade")); | ||||
|     extWeather = new ExtItemAggregator<ExtWeather>(nullptr, QString("weather")); | ||||
|  | ||||
|     // init | ||||
|     QStringList allKeys = dictKeys(); | ||||
|  | ||||
| @ -678,9 +679,18 @@ QString AWKeys::parsePattern() const | ||||
|         }(key, values[key])); | ||||
|  | ||||
|     // bars | ||||
|     foreach(QString bar, foundBars) | ||||
|         parsed.replace(QString("$%1").arg(bar), | ||||
|                        graphicalItems->itemByTag(bar)->image(valueByKey(bar).toFloat())); | ||||
|     foreach(QString bar, foundBars) { | ||||
|         GraphicalItem *item = graphicalItems->itemByTag(bar); | ||||
|         QString key = bar; | ||||
|         key.remove(QRegExp(QString("^bar[0-9]{1,}"))); | ||||
|         if (item->type() == GraphicalItem::Graph) | ||||
|             parsed.replace(QString("$%1").arg(bar), item->image([](const QList<float> data) { | ||||
|                 return QVariant::fromValue<QList<float>>(data); | ||||
|             }(dataAggregator->getData(key)))); | ||||
|         else | ||||
|             parsed.replace(QString("$%1").arg(bar), item->image(values[key])); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     // prepare strings | ||||
|     parsed.replace(QString("$\\$\\"), QString("$$")); | ||||
|  | ||||
| @ -82,11 +82,11 @@ private: | ||||
|     AWDataAggregator *dataAggregator = nullptr; | ||||
|     bool enablePopup = false; | ||||
|     bool wrapNewLines = false; | ||||
|     ExtItemAggregator<GraphicalItem> *graphicalItems; | ||||
|     ExtItemAggregator<ExtQuotes> *extQuotes; | ||||
|     ExtItemAggregator<ExtScript> *extScripts; | ||||
|     ExtItemAggregator<ExtUpgrade> *extUpgrade; | ||||
|     ExtItemAggregator<ExtWeather> *extWeather; | ||||
|     ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr; | ||||
|     ExtItemAggregator<ExtQuotes> *extQuotes = nullptr; | ||||
|     ExtItemAggregator<ExtScript> *extScripts = nullptr; | ||||
|     ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr; | ||||
|     ExtItemAggregator<ExtWeather> *extWeather = nullptr; | ||||
|     bool lock = false; | ||||
|     int queue = 0; | ||||
|     QString pattern; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user