refactor: remoove unsued code annd settings

This commit is contained in:
2024-04-19 03:58:54 +03:00
parent c608c40c97
commit 2f4f05b5af
10 changed files with 29 additions and 100 deletions

View File

@ -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();
}

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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;
};