mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
refactor: remoove unsued code annd settings
This commit is contained in:
parent
c608c40c97
commit
2f4f05b5af
@ -44,9 +44,6 @@
|
||||
<entry name="interval" type="Int">
|
||||
<default>1000</default>
|
||||
</entry>
|
||||
<entry name="queueLimit" type="Int">
|
||||
<default>0</default>
|
||||
</entry>
|
||||
<entry name="tempUnits" type="String">
|
||||
<default>Celsius</default>
|
||||
</entry>
|
||||
@ -62,15 +59,9 @@
|
||||
<entry name="acOffline" type="String">
|
||||
<default>( )</default>
|
||||
</entry>
|
||||
<entry name="telemetryCount" type="Int">
|
||||
<entry name="historyCount" type="Int">
|
||||
<default>100</default>
|
||||
</entry>
|
||||
<entry name="telemetryRemote" type="Bool">
|
||||
<default>false</default>
|
||||
</entry>
|
||||
<entry name="telemetryId" type="String">
|
||||
<default></default>
|
||||
</entry>
|
||||
</group>
|
||||
|
||||
<group name="Tooltip">
|
||||
|
@ -41,15 +41,12 @@ KCM.SimpleKCM {
|
||||
property alias cfg_height: widgetHeight.value
|
||||
property alias cfg_width: widgetWidth.value
|
||||
property alias cfg_interval: update.value
|
||||
property alias cfg_queueLimit: queueLimit.value
|
||||
property string cfg_tempUnits: tempUnits.value
|
||||
property alias cfg_customTime: customTime.value
|
||||
property alias cfg_customUptime: customUptime.value
|
||||
property alias cfg_acOnline: acOnline.value
|
||||
property alias cfg_acOffline: acOffline.value
|
||||
property alias cfg_telemetryCount: telemetryCount.value
|
||||
property alias cfg_telemetryRemote: telemetryRemote.checked
|
||||
property alias cfg_telemetryId: telemetryId.value
|
||||
property alias cfg_historyCount: historyCount.value
|
||||
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
@ -116,15 +113,6 @@ KCM.SimpleKCM {
|
||||
value: plasmoid.configuration.interval
|
||||
}
|
||||
|
||||
IntegerSelector {
|
||||
id: queueLimit
|
||||
maximumValue: 99
|
||||
minimumValue: 0
|
||||
stepSize: 1
|
||||
text: i18n("Messages queue limit")
|
||||
value: plasmoid.configuration.queueLimit
|
||||
}
|
||||
|
||||
ComboBoxSelector {
|
||||
id: tempUnits
|
||||
model: [
|
||||
@ -226,30 +214,19 @@ KCM.SimpleKCM {
|
||||
GroupBox {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
title: i18n("Telemetry")
|
||||
title: i18n("History")
|
||||
|
||||
Column {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
|
||||
CheckBoxSelector {
|
||||
id: telemetryRemote
|
||||
text: i18n("Enable remote telemetry")
|
||||
}
|
||||
|
||||
IntegerSelector {
|
||||
id: telemetryCount
|
||||
id: historyCount
|
||||
maximumValue: 10000
|
||||
minimumValue: 0
|
||||
stepSize: 50
|
||||
text: i18n("History count")
|
||||
value: plasmoid.configuration.telemetryCount
|
||||
}
|
||||
|
||||
LineSelector {
|
||||
id: telemetryId
|
||||
text: i18n("Telemetry ID")
|
||||
value: plasmoid.configuration.telemetryId
|
||||
value: plasmoid.configuration.historyCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,8 +168,7 @@ PlasmoidItem {
|
||||
|
||||
// init submodule
|
||||
awKeys.initDataAggregator(tooltipSettings)
|
||||
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
|
||||
plasmoid.configuration.queueLimit, plasmoid.configuration.optimize)
|
||||
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval, plasmoid.configuration.optimize)
|
||||
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
|
||||
// configure aggregator
|
||||
awKeys.setAggregatorProperty("acOffline", plasmoid.configuration.acOffline)
|
||||
@ -178,20 +177,8 @@ PlasmoidItem {
|
||||
awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime)
|
||||
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
||||
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
||||
// update telemetry ID
|
||||
if (plasmoid.configuration.telemetryId.length === 0)
|
||||
plasmoid.configuration.telemetryId = generateUuid()
|
||||
// save telemetry
|
||||
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
||||
plasmoid.configuration.telemetryId)
|
||||
awTelemetryHandler.init(plasmoid.configuration.historyCount)
|
||||
awTelemetryHandler.put("awwidgetconfig", plasmoid.configuration.text)
|
||||
}
|
||||
|
||||
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||
function generateUuid() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
let r = Math.random() * 16 | 0, v = c === "x" ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
#include <QThread>
|
||||
#include <QRegularExpression>
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
@ -42,9 +41,6 @@ AWKeys::AWKeys(QObject *_parent)
|
||||
for (auto &metadata : AWDebug::getBuildData())
|
||||
qCDebug(LOG_AW) << metadata;
|
||||
|
||||
// thread pool
|
||||
m_threadPool = new QThreadPool(this);
|
||||
|
||||
m_aggregator = new AWKeysAggregator(this);
|
||||
m_dataAggregator = new AWDataAggregator(this);
|
||||
m_dataEngineAggregator = new AWDataEngineAggregator(this);
|
||||
@ -91,14 +87,12 @@ void AWKeys::initDataAggregator(const QVariantMap &_tooltipParams)
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString &_currentPattern, const int _interval, const int _limit, const bool _optimize)
|
||||
void AWKeys::initKeys(const QString &_currentPattern, const int _interval, const bool _optimize)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Pattern" << _currentPattern << "with interval" << _interval << "and queue limit" << _limit
|
||||
<< "with optimization" << _optimize;
|
||||
qCDebug(LOG_AW) << "Pattern" << _currentPattern << "with interval" << _interval << "with optimization" << _optimize;
|
||||
|
||||
// init
|
||||
m_optimize = _optimize;
|
||||
m_threadPool->setMaxThreadCount(_limit == 0 ? QThread::idealThreadCount() : _limit);
|
||||
// child objects
|
||||
m_aggregator->initFormatters();
|
||||
m_keyOperator->setPattern(_currentPattern);
|
||||
@ -184,15 +178,11 @@ void AWKeys::dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors,
|
||||
{
|
||||
qCDebug(LOG_AW) << "Update data for" << _data.count() << "items";
|
||||
|
||||
// though it is better to use QtConcurrent::map here, but it might cause stack corruption
|
||||
for (auto &data : _data) {
|
||||
if (!_sensors.contains(data.sensorProperty))
|
||||
continue;
|
||||
auto sensor = _sensors[data.sensorProperty];
|
||||
setDataBySource(data.sensorProperty, sensor, data.payload);
|
||||
// std::ignore = QtConcurrent::run(m_threadPool, &AWKeys::setDataBySource, this, data.sensorProperty,
|
||||
// sensor,
|
||||
// data.payload);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,7 +198,7 @@ void AWKeys::reinitKeys(const QStringList &_currentKeys)
|
||||
// generate list of required keys for bars
|
||||
QStringList barKeys;
|
||||
for (auto &bar : m_foundBars) {
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
auto item = m_keyOperator->giByKey(bar);
|
||||
if (item->isCustom())
|
||||
item->setUsedKeys(AWPatternFunctions::findKeys(item->bar(), _currentKeys, false));
|
||||
else
|
||||
@ -228,12 +218,10 @@ void AWKeys::reinitKeys(const QStringList &_currentKeys)
|
||||
void AWKeys::updateTextData()
|
||||
{
|
||||
// do not do it in parallel to avoid race condition
|
||||
m_mutex.lock();
|
||||
calculateValues();
|
||||
auto text = parsePattern(m_keyOperator->pattern());
|
||||
// update tooltip values under lock
|
||||
m_dataAggregator->dataUpdate(m_values);
|
||||
m_mutex.unlock();
|
||||
|
||||
emit(needTextToBeUpdated(text));
|
||||
}
|
||||
@ -244,9 +232,9 @@ void AWKeys::updateTextData()
|
||||
void AWKeys::calculateValues()
|
||||
{
|
||||
// hddtot*
|
||||
QStringList mountDevices = m_keyOperator->devices("mount");
|
||||
auto mountDevices = m_keyOperator->devices("mount");
|
||||
for (auto &device : mountDevices) {
|
||||
int index = mountDevices.indexOf(device);
|
||||
auto index = mountDevices.indexOf(device);
|
||||
m_values[QString("hddtotmb%1").arg(index)] = m_values[QString("hddfreemb%1").arg(index)].toDouble()
|
||||
+ m_values[QString("hddmb%1").arg(index)].toDouble();
|
||||
m_values[QString("hddtotgb%1").arg(index)] = m_values[QString("hddfreegb%1").arg(index)].toDouble()
|
||||
@ -260,7 +248,7 @@ void AWKeys::calculateValues()
|
||||
m_values["mem"] = 100.0 * m_values["memmb"].toDouble() / m_values["memtotmb"].toDouble();
|
||||
|
||||
// up, down, upkb, downkb, upunits, downunits
|
||||
int netIndex = m_keyOperator->devices("net").indexOf(m_values["netdev"].toString());
|
||||
auto netIndex = m_keyOperator->devices("net").indexOf(m_values["netdev"].toString());
|
||||
m_values["down"] = m_values[QString("down%1").arg(netIndex)];
|
||||
m_values["downkb"] = m_values[QString("downkb%1").arg(netIndex)];
|
||||
m_values["downtot"] = m_values[QString("downtot%1").arg(netIndex)];
|
||||
@ -294,7 +282,7 @@ void AWKeys::createDBusInterface()
|
||||
auto id = reinterpret_cast<qlonglong>(this);
|
||||
|
||||
// create session
|
||||
QDBusConnection instanceBus = QDBusConnection::sessionBus();
|
||||
auto instanceBus = QDBusConnection::sessionBus();
|
||||
// HACK we are going to use different services because it binds to
|
||||
// application
|
||||
if (instanceBus.registerService(QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id))) {
|
||||
@ -305,7 +293,7 @@ void AWKeys::createDBusInterface()
|
||||
}
|
||||
|
||||
// and same instance but for id independent service
|
||||
QDBusConnection commonBus = QDBusConnection::sessionBus();
|
||||
auto commonBus = QDBusConnection::sessionBus();
|
||||
if (commonBus.registerService(AWDBUS_SERVICE))
|
||||
commonBus.registerObject(AWDBUS_PATH, new AWDBusAdaptor(this), QDBusConnection::ExportAllContents);
|
||||
}
|
||||
@ -326,10 +314,10 @@ QString AWKeys::parsePattern(QString _pattern) const
|
||||
|
||||
// bars
|
||||
for (auto &bar : m_foundBars) {
|
||||
GraphicalItem *item = m_keyOperator->giByKey(bar);
|
||||
QString image = item->isCustom() ? item->image(
|
||||
AWPatternFunctions::expandLambdas(item->bar(), m_aggregator, m_values, item->usedKeys()))
|
||||
: item->image(m_values[item->bar()]);
|
||||
auto item = m_keyOperator->giByKey(bar);
|
||||
auto image = item->isCustom() ? item->image(
|
||||
AWPatternFunctions::expandLambdas(item->bar(), m_aggregator, m_values, item->usedKeys()))
|
||||
: item->image(m_values[item->bar()]);
|
||||
_pattern.replace(QString("$%1").arg(bar), image);
|
||||
}
|
||||
|
||||
@ -357,7 +345,5 @@ void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo
|
||||
return emit(dropSourceFromDataengine(_source));
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, _value](const QString &tag) { m_values[tag] = _value; });
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
@ -27,7 +26,6 @@ class AWDataAggregator;
|
||||
class AWDataEngineAggregator;
|
||||
class AWKeyOperations;
|
||||
class AWKeysAggregator;
|
||||
class QThreadPool;
|
||||
class QTimer;
|
||||
|
||||
class AWKeys : public QObject
|
||||
@ -38,7 +36,7 @@ public:
|
||||
explicit AWKeys(QObject *_parent = nullptr);
|
||||
~AWKeys() override;
|
||||
Q_INVOKABLE void initDataAggregator(const QVariantMap &_tooltipParams);
|
||||
Q_INVOKABLE void initKeys(const QString &_currentPattern, int _interval, int _limit, bool _optimize);
|
||||
Q_INVOKABLE void initKeys(const QString &_currentPattern, int _interval, bool _optimize);
|
||||
Q_INVOKABLE void setAggregatorProperty(const QString &_key, const QVariant &_value);
|
||||
Q_INVOKABLE void setWrapNewLines(bool _wrap);
|
||||
// additional method to force load keys from Qml UI. Used in some
|
||||
@ -80,7 +78,4 @@ private:
|
||||
QVariantHash m_values;
|
||||
bool m_optimize = false;
|
||||
bool m_wrapNewLines = false;
|
||||
// multithread features
|
||||
QThreadPool *m_threadPool = nullptr;
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
@ -25,17 +25,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWTelemetryHandler::AWTelemetryHandler(QObject *_parent, const QString &_clientId)
|
||||
AWTelemetryHandler::AWTelemetryHandler(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_localFile = QString("%1/awesomewidgets/telemetry.ini")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
|
||||
|
||||
// override client id if any
|
||||
if (!_clientId.isEmpty())
|
||||
m_clientId = _clientId;
|
||||
}
|
||||
|
||||
|
||||
@ -63,12 +59,11 @@ QString AWTelemetryHandler::getLast(const QString &_group) const
|
||||
}
|
||||
|
||||
|
||||
void AWTelemetryHandler::init(const int _count, const QString &_clientId)
|
||||
void AWTelemetryHandler::init(const int _count)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Init telemetry with count" << _count << "client ID" << _clientId;
|
||||
qCDebug(LOG_AW) << "Init telemetry with count" << _count;
|
||||
|
||||
m_storeCount = _count;
|
||||
m_clientId = _clientId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,16 +25,15 @@ class AWTelemetryHandler : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWTelemetryHandler(QObject *_parent = nullptr, const QString &_clientId = "");
|
||||
explicit AWTelemetryHandler(QObject *_parent = nullptr);
|
||||
~AWTelemetryHandler() override = default;
|
||||
Q_INVOKABLE [[nodiscard]] QStringList get(const QString &_group) const;
|
||||
Q_INVOKABLE [[nodiscard]] QString getLast(const QString &_group) const;
|
||||
Q_INVOKABLE void init(int _count, const QString &_clientId);
|
||||
Q_INVOKABLE void init(int _count);
|
||||
Q_INVOKABLE [[nodiscard]] bool put(const QString &_group, const QString &_value) const;
|
||||
|
||||
private:
|
||||
static QString getKey(int _count);
|
||||
QString m_clientId;
|
||||
QString m_localFile;
|
||||
int m_storeCount = 0;
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ void TestAWKeys::initTestCase()
|
||||
plugin->setAggregatorProperty("tempUnits", "Celsius");
|
||||
plugin->setAggregatorProperty("translate", false);
|
||||
|
||||
plugin->initKeys(pattern, interval, 0, false);
|
||||
plugin->initKeys(pattern, interval, false);
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@ void TestAWKeys::test_dictKeys()
|
||||
|
||||
void TestAWKeys::test_pattern()
|
||||
{
|
||||
plugin->initKeys(pattern, interval, 0, false);
|
||||
plugin->initKeys(pattern, interval, false);
|
||||
QSignalSpy spy(plugin, SIGNAL(needTextToBeUpdated(const QString)));
|
||||
|
||||
QVERIFY(spy.wait(5 * interval));
|
||||
|
@ -27,7 +27,7 @@ void TestAWTelemetryHandler::initTestCase()
|
||||
{
|
||||
AWTestLibrary::init();
|
||||
plugin = new AWTelemetryHandler(this);
|
||||
plugin->init(1, telemetryId);
|
||||
plugin->init(1);
|
||||
telemetryData = AWTestLibrary::randomString();
|
||||
telemetryGroup = AWTestLibrary::randomString();
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ private:
|
||||
AWTelemetryHandler *plugin = nullptr;
|
||||
QString telemetryData;
|
||||
QString telemetryGroup;
|
||||
QString telemetryId = "autotest";
|
||||
QString telemetryStatus = "saved";
|
||||
QString telemetryValidGroup = "awwidgetconfig";
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user