mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 07:09:58 +00:00
initial plasma6 support
This commit is contained in:
@ -7,17 +7,17 @@ include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE}
|
||||
${Kf6_INCLUDE}
|
||||
)
|
||||
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/fontdialog/*.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB SUBPROJECT_UI *.ui)
|
||||
file(GLOB SUBPROJECT_NOTIFY *.notifyrc)
|
||||
|
||||
qt5_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
|
||||
qt6_wrap_ui(SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
|
||||
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} ${Kf6_LIBRARIES})
|
||||
|
||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||
install(FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})
|
||||
install(TARGETS ${PLUGIN_NAME} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/awesomewidget)
|
||||
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/awesomewidget)
|
||||
install(FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR})
|
||||
|
@ -71,13 +71,6 @@ QString AWActions::getFileContent(const QString &_path)
|
||||
}
|
||||
|
||||
|
||||
// HACK: since QML could not use QLoggingCategory I need this hack
|
||||
bool AWActions::isDebugEnabled()
|
||||
{
|
||||
return LOG_AW().isDebugEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool AWActions::runCmd(const QString &_cmd, const QStringList &_args)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Cmd" << _cmd << "args" << _args;
|
||||
|
@ -34,7 +34,6 @@ public:
|
||||
~AWActions() override;
|
||||
Q_INVOKABLE void checkUpdates(bool _showAnyway = false);
|
||||
Q_INVOKABLE static QString getFileContent(const QString &_path);
|
||||
Q_INVOKABLE static bool isDebugEnabled();
|
||||
Q_INVOKABLE static bool runCmd(const QString &_cmd, const QStringList &_args);
|
||||
Q_INVOKABLE static void showLegacyInfo();
|
||||
Q_INVOKABLE static void showReadme();
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <QQmlPropertyMap>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
@ -171,9 +170,6 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration()
|
||||
|
||||
settings.beginGroup("Configuration");
|
||||
configuration["ACPIPATH"] = settings.value("ACPIPATH", "/sys/class/power_supply/");
|
||||
configuration["GPUDEV"] = settings.value("GPUDEV", "auto");
|
||||
configuration["HDDDEV"] = settings.value("HDDDEV", "all");
|
||||
configuration["HDDTEMPCMD"] = settings.value("HDDTEMPCMD", "sudo smartctl -a");
|
||||
configuration["MPDADDRESS"] = settings.value("MPDADDRESS", "localhost");
|
||||
configuration["MPDPORT"] = settings.value("MPDPORT", "6600");
|
||||
configuration["MPRIS"] = settings.value("MPRIS", "auto");
|
||||
@ -198,9 +194,6 @@ bool AWConfigHelper::writeDataEngineConfiguration(const QVariantMap &_configurat
|
||||
|
||||
settings.beginGroup("Configuration");
|
||||
settings.setValue("ACPIPATH", _configuration["ACPIPATH"]);
|
||||
settings.setValue("GPUDEV", _configuration["GPUDEV"]);
|
||||
settings.setValue("HDDDEV", _configuration["HDDDEV"]);
|
||||
settings.setValue("HDDTEMPCMD", _configuration["HDDTEMPCMD"]);
|
||||
settings.setValue("MPDADDRESS", _configuration["MPDADDRESS"]);
|
||||
settings.setValue("MPDPORT", _configuration["MPDPORT"]);
|
||||
settings.setValue("MPRIS", _configuration["MPRIS"]);
|
||||
@ -285,7 +278,6 @@ void AWConfigHelper::writeFile(QSettings &_settings, const QString &_key, const
|
||||
QFile file(_fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out.setCodec("UTF-8");
|
||||
out << _settings.value(_key).toString().toUtf8();
|
||||
out.flush();
|
||||
file.close();
|
||||
|
@ -17,30 +17,35 @@
|
||||
|
||||
#include "awdataengineaggregator.h"
|
||||
|
||||
#include <Plasma/DataContainer>
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/DBusInterface.h>
|
||||
|
||||
#include <QDBusConnection>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWDataEngineAggregator::AWDataEngineAggregator(QObject *_parent)
|
||||
: QObject(_parent)
|
||||
, m_interface(new KSysGuard::SystemStats::DBusInterface())
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_consumer = new Plasma::DataEngineConsumer();
|
||||
m_dataEngines["systemmonitor"] = m_consumer->dataEngine("systemmonitor");
|
||||
m_dataEngines["extsysmon"] = m_consumer->dataEngine("extsysmon");
|
||||
m_dataEngines["time"] = m_consumer->dataEngine("time");
|
||||
qDBusRegisterMetaType<KSysGuard::SensorData>();
|
||||
qDBusRegisterMetaType<KSysGuard::SensorInfo>();
|
||||
qDBusRegisterMetaType<KSysGuard::SensorDataList>();
|
||||
qDBusRegisterMetaType<QHash<QString, KSysGuard::SensorInfo>>();
|
||||
|
||||
// additional method required by systemmonitor structure
|
||||
m_newSourceConnection
|
||||
= connect(m_dataEngines["systemmonitor"], &Plasma::DataEngine::sourceAdded, [this](const QString &source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines["systemmonitor"]->connectSource(source, parent(), 1000);
|
||||
});
|
||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::newSensorData, this,
|
||||
&AWDataEngineAggregator::updateData);
|
||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorMetaDataChanged, this,
|
||||
&AWDataEngineAggregator::updateSensors);
|
||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorAdded, this,
|
||||
&AWDataEngineAggregator::sensorAdded);
|
||||
connect(m_interface, &KSysGuard::SystemStats::DBusInterface::sensorRemoved, this,
|
||||
&AWDataEngineAggregator::sensorRemoved);
|
||||
|
||||
// required to define Qt::QueuedConnection for signal-slot connection
|
||||
qRegisterMetaType<Plasma::DataEngine::Data>("Plasma::DataEngine::Data");
|
||||
loadSources();
|
||||
}
|
||||
|
||||
|
||||
@ -49,67 +54,102 @@ AWDataEngineAggregator::~AWDataEngineAggregator()
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
disconnectSources();
|
||||
m_interface->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::connectSources()
|
||||
{
|
||||
auto keys = m_sensors.keys();
|
||||
auto newKeys = QSet(keys.cbegin(), keys.cend()) - m_subscribed;
|
||||
|
||||
m_interface->subscribe(newKeys.values()).waitForFinished();
|
||||
m_subscribed.unite(newKeys);
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::disconnectSources()
|
||||
{
|
||||
for (auto dataEngine : m_dataEngines.values())
|
||||
for (auto &source : dataEngine->sources())
|
||||
dataEngine->disconnectSource(source, parent());
|
||||
disconnect(m_newSourceConnection);
|
||||
m_interface->unsubscribe(m_subscribed.values()).waitForFinished();
|
||||
m_subscribed.clear();
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::reconnectSources(const int _interval)
|
||||
bool AWDataEngineAggregator::isValidSensor(const KSysGuard::SensorInfo &_sensor)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Reconnect sources with interval" << _interval;
|
||||
return _sensor.unit != KSysGuard::UnitInvalid;
|
||||
}
|
||||
|
||||
disconnectSources();
|
||||
|
||||
m_dataEngines["systemmonitor"]->connectAllSources(parent(), (uint)_interval);
|
||||
m_dataEngines["extsysmon"]->connectAllSources(parent(), (uint)_interval);
|
||||
m_dataEngines["time"]->connectSource("Local", parent(), 1000);
|
||||
void AWDataEngineAggregator::loadSources()
|
||||
{
|
||||
auto response = m_interface->allSensors();
|
||||
response.waitForFinished();
|
||||
|
||||
m_newSourceConnection = connect(
|
||||
m_dataEngines["systemmonitor"], &Plasma::DataEngine::sourceAdded, [this, _interval](const QString &source) {
|
||||
emit(deviceAdded(source));
|
||||
m_dataEngines["systemmonitor"]->connectSource(source, parent(), (uint)_interval);
|
||||
});
|
||||
auto sensors = response.value();
|
||||
updateSensors(sensors);
|
||||
connectSources();
|
||||
|
||||
#ifdef BUILD_FUTURE
|
||||
createQueuedConnection();
|
||||
#endif /* BUILD_FUTURE */
|
||||
for (auto &sensor : m_sensors.keys())
|
||||
emit(deviceAdded(sensor));
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::dropSource(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
qCDebug(LOG_AW) << "Disconnect sensor" << _source;
|
||||
|
||||
// HACK there is no possibility to check to which dataengine source
|
||||
// connected we will try to disconnect it from all engines
|
||||
for (auto dataEngine : m_dataEngines.values())
|
||||
dataEngine->disconnectSource(_source, parent());
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::createQueuedConnection()
|
||||
{
|
||||
// HACK additional method which forces QueuedConnection instead of Auto one
|
||||
// for more details refer to plasma-framework source code
|
||||
for (auto &dataEngine : m_dataEngines.keys()) {
|
||||
// different source set for different engines
|
||||
QStringList sources = dataEngine == "time" ? QStringList() << "Local" : m_dataEngines[dataEngine]->sources();
|
||||
// reconnect sources
|
||||
for (auto &source : sources) {
|
||||
Plasma::DataContainer *container = m_dataEngines[dataEngine]->containerForSource(source);
|
||||
// disconnect old connections first
|
||||
disconnect(container, SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data)), parent(),
|
||||
SLOT(dataUpdated(QString, Plasma::DataEngine::Data)));
|
||||
// and now reconnect with Qt::QueuedConnection type
|
||||
connect(container, SIGNAL(dataUpdated(QString, Plasma::DataEngine::Data)), parent(),
|
||||
SLOT(dataUpdated(QString, Plasma::DataEngine::Data)), Qt::QueuedConnection);
|
||||
}
|
||||
if (m_subscribed.contains(_source)) {
|
||||
m_interface->unsubscribe({_source}).waitForFinished();
|
||||
m_subscribed.remove(_source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::sensorAdded(const QString &_sensor)
|
||||
{
|
||||
qCDebug(LOG_AW) << "New sensor added" << _sensor;
|
||||
|
||||
// check if sensor is actually valid
|
||||
auto response = m_interface->sensors({_sensor});
|
||||
response.waitForFinished();
|
||||
|
||||
auto info = response.value().value(_sensor);
|
||||
if (!isValidSensor(info))
|
||||
return;
|
||||
|
||||
m_sensors[_sensor] = info;
|
||||
dropSource(_sensor); // force reconnect
|
||||
if (!m_subscribed.contains(_sensor)) {
|
||||
m_interface->subscribe({_sensor}).waitForFinished();
|
||||
m_subscribed.insert(_sensor);
|
||||
}
|
||||
|
||||
// notify about new device
|
||||
emit(deviceAdded(_sensor));
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::sensorRemoved(const QString &_sensor)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Sensor" << _sensor << "has been removed";
|
||||
|
||||
m_sensors.remove(_sensor);
|
||||
dropSource(_sensor);
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::updateData(KSysGuard::SensorDataList _data)
|
||||
{
|
||||
emit(dataUpdated(m_sensors, _data));
|
||||
}
|
||||
|
||||
|
||||
void AWDataEngineAggregator::updateSensors(const QHash<QString, KSysGuard::SensorInfo> &_sensors)
|
||||
{
|
||||
for (auto sensor = _sensors.cbegin(); sensor != _sensors.cend(); ++sensor) {
|
||||
if (!isValidSensor(sensor.value()))
|
||||
continue;
|
||||
m_sensors.insert(sensor.key(), sensor.value());
|
||||
}
|
||||
}
|
||||
|
@ -15,16 +15,20 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef AWDATAENGINEAGGREGATOR_H
|
||||
#define AWDATAENGINEAGGREGATOR_H
|
||||
|
||||
#include <Plasma/DataEngine>
|
||||
#include <Plasma/DataEngineConsumer>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
|
||||
|
||||
namespace KSysGuard::SystemStats
|
||||
{
|
||||
class DBusInterface;
|
||||
}
|
||||
|
||||
class AWDataEngineAggregator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -32,21 +36,24 @@ class AWDataEngineAggregator : public QObject
|
||||
public:
|
||||
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
||||
~AWDataEngineAggregator() override;
|
||||
void connectSources();
|
||||
void disconnectSources();
|
||||
void reconnectSources(int _interval);
|
||||
[[nodiscard]] static bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
|
||||
void loadSources();
|
||||
|
||||
signals:
|
||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||
void deviceAdded(const QString &_source);
|
||||
|
||||
public slots:
|
||||
void dropSource(const QString &_source);
|
||||
void sensorAdded(const QString &_sensor);
|
||||
void sensorRemoved(const QString &_sensor);
|
||||
void updateData(KSysGuard::SensorDataList _data);
|
||||
void updateSensors(const QHash<QString, KSysGuard::SensorInfo> &_sensors);
|
||||
|
||||
private:
|
||||
void createQueuedConnection();
|
||||
Plasma::DataEngineConsumer *m_consumer = nullptr;
|
||||
QHash<QString, Plasma::DataEngine *> m_dataEngines;
|
||||
QMetaObject::Connection m_newSourceConnection;
|
||||
KSysGuard::SystemStats::DBusInterface *m_interface = nullptr;
|
||||
QHash<QString, KSysGuard::SensorInfo> m_sensors;
|
||||
QSet<QString> m_subscribed;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWDATAENGINEAGGREGATOR_H */
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "awdataenginemapper.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awformatterhelper.h"
|
||||
@ -76,76 +76,80 @@ QStringList AWDataEngineMapper::keysFromSource(const QString &_source) const
|
||||
|
||||
// HACK units required to define should the value be calculated as temperature
|
||||
// or fan data
|
||||
QStringList AWDataEngineMapper::registerSource(const QString &_source, const QString &_units, const QStringList &_keys)
|
||||
QStringList AWDataEngineMapper::registerSource(const QString &_source, const KSysGuard::Unit _units,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
|
||||
// regular expressions
|
||||
QRegExp cpuRegExp = QRegExp("cpu/cpu.*/TotalLoad");
|
||||
QRegExp cpuclRegExp = QRegExp("cpu/cpu.*/clock");
|
||||
QRegExp hddrRegExp = QRegExp("disk/.*/Rate/rblk");
|
||||
QRegExp hddwRegExp = QRegExp("disk/.*/Rate/wblk");
|
||||
QRegExp mountFillRegExp = QRegExp("partitions/.*/filllevel");
|
||||
QRegExp mountFreeRegExp = QRegExp("partitions/.*/freespace");
|
||||
QRegExp mountUsedRegExp = QRegExp("partitions/.*/usedspace");
|
||||
QRegExp netRegExp = QRegExp("network/interfaces/.*/(receiver|transmitter)/data$");
|
||||
QRegExp netTotalRegExp = QRegExp("network/interfaces/.*/(receiver|transmitter)/dataTotal$");
|
||||
auto cpuRegExp = QRegularExpression("^cpu/cpu.*/usage$");
|
||||
auto cpuclRegExp = QRegularExpression("^cpu/cpu.*/frequency$");
|
||||
auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
auto gpuTempRegExp = QRegularExpression("^gpu/gpu.*/temperature$");
|
||||
auto hddrRegExp = QRegularExpression("^disk/.*/read$");
|
||||
auto hddwRegExp = QRegularExpression("^disk/.*/write$");
|
||||
auto mountFillRegExp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
auto mountFreeRegExp = QRegularExpression("^disk/.*/free$");
|
||||
auto mountUsedRegExp = QRegularExpression("^disk/.*/used$");
|
||||
auto netRegExp = QRegularExpression("^network/.*/(download|upload)$");
|
||||
auto netTotalRegExp = QRegularExpression("^network/.*/(totalDownload|totalUpload)$");
|
||||
|
||||
if (_source == "battery/ac") {
|
||||
if (_source == "extsysmon/battery/ac") {
|
||||
// AC
|
||||
m_map.insert(_source, "ac");
|
||||
m_formatter["ac"] = AWKeysAggregator::FormatterType::ACFormat;
|
||||
} else if (_source.startsWith("battery/")) {
|
||||
} else if (_source.startsWith("extsysmon/battery/")) {
|
||||
// battery stats
|
||||
QString key = _source;
|
||||
key.remove("battery/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/battery/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = _source.contains("rate") ? AWKeysAggregator::FormatterType::Float
|
||||
: AWKeysAggregator::FormatterType::IntegerThree;
|
||||
} else if (_source == "cpu/system/TotalLoad") {
|
||||
} else if (_source == "cpu/all/usage") {
|
||||
// cpu
|
||||
m_map.insert(_source, "cpu");
|
||||
m_formatter["cpu"] = AWKeysAggregator::FormatterType::Float;
|
||||
} else if (_source.contains(cpuRegExp)) {
|
||||
// cpus
|
||||
QString key = _source;
|
||||
key.remove("cpu/").remove("/TotalLoad");
|
||||
auto key = _source;
|
||||
key.remove("cpu/").remove("/usage");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Float;
|
||||
} else if (_source == "cpu/system/AverageClock") {
|
||||
} else if (_source == "cpu/all/averageFrequency") {
|
||||
// cpucl
|
||||
m_map.insert(_source, "cpucl");
|
||||
m_formatter["cpucl"] = AWKeysAggregator::FormatterType::Integer;
|
||||
} else if (_source.contains(cpuclRegExp)) {
|
||||
// cpucls
|
||||
QString key = _source;
|
||||
key.remove("cpu/cpu").remove("/clock");
|
||||
auto key = _source;
|
||||
key.remove("cpu/cpu").remove("/frequency");
|
||||
key = QString("cpucl%1").arg(key);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
} else if (_source.startsWith("custom")) {
|
||||
} else if (_source.startsWith("extsysmon/custom")) {
|
||||
// custom
|
||||
QString key = _source;
|
||||
key.remove("custom/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/custom/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "desktop/current/name") {
|
||||
} else if (_source == "extsysmon/desktop/name") {
|
||||
// current desktop name
|
||||
m_map.insert(_source, "desktop");
|
||||
m_formatter["desktop"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "desktop/current/number") {
|
||||
} else if (_source == "extsysmon/desktop/number") {
|
||||
// current desktop number
|
||||
m_map.insert(_source, "ndesktop");
|
||||
m_formatter["ndesktop"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "desktop/total/number") {
|
||||
} else if (_source == "extsysmon/desktop/count") {
|
||||
// desktop count
|
||||
m_map.insert(_source, "tdesktops");
|
||||
m_formatter["tdesktops"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.contains(hddrRegExp)) {
|
||||
// read speed
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/read");
|
||||
auto index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddr%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
@ -153,29 +157,45 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
}
|
||||
} else if (_source.contains(hddwRegExp)) {
|
||||
// write speed
|
||||
QString device = _source;
|
||||
device.remove("/Rate/wblk");
|
||||
int index = m_devices["disk"].indexOf(device);
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/write");
|
||||
auto index = m_devices["disk"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddw%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
}
|
||||
} else if (_source == "gpu/load") {
|
||||
} else if (_source == "gpu/all/usage") {
|
||||
// gpu load
|
||||
m_map.insert(_source, "gpu");
|
||||
m_formatter["gpu"] = AWKeysAggregator::FormatterType::Float;
|
||||
} else if (_source == "gpu/temperature") {
|
||||
// gpu temperature
|
||||
m_map.insert(_source, "gputemp");
|
||||
m_formatter["gputemp"] = AWKeysAggregator::FormatterType::Temperature;
|
||||
} else if (_source.contains(gpuRegExp)) {
|
||||
// gpus
|
||||
auto device = _source;
|
||||
device.remove("gpu/").remove("/usage");
|
||||
auto index = m_devices["gpu"].indexOf(device);
|
||||
if (index > -1) {
|
||||
auto key = QString("gpu%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Float;
|
||||
}
|
||||
} else if (_source.contains(gpuTempRegExp)) {
|
||||
// gpus temps
|
||||
auto device = _source;
|
||||
device.remove("gpu/").remove("/temperature");
|
||||
auto index = m_devices["gpu"].indexOf(device);
|
||||
if (index > -1) {
|
||||
auto key = QString("gputemp%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||
}
|
||||
} else if (_source.contains(mountFillRegExp)) {
|
||||
// fill level
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/usedPercent");
|
||||
auto index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hdd%1").arg(index);
|
||||
auto key = QString("hdd%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Float;
|
||||
// additional keys
|
||||
@ -184,9 +204,9 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
}
|
||||
} else if (_source.contains(mountFreeRegExp)) {
|
||||
// free space
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/freespace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/free");
|
||||
auto index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddfreemb%1").arg(index);
|
||||
@ -199,9 +219,9 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
}
|
||||
} else if (_source.contains(mountUsedRegExp)) {
|
||||
// used
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/usedspace");
|
||||
int index = m_devices["mount"].indexOf(device);
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/used");
|
||||
auto index = m_devices["mount"].indexOf(device);
|
||||
if (index > -1) {
|
||||
// mb
|
||||
QString key = QString("hddmb%1").arg(index);
|
||||
@ -212,24 +232,14 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
}
|
||||
} else if (_source.startsWith("hdd/temperature")) {
|
||||
// hdd temperature
|
||||
QString device = _source;
|
||||
device.remove("hdd/temperature");
|
||||
int index = m_devices["hdd"].indexOf(device);
|
||||
if (index > -1) {
|
||||
QString key = QString("hddtemp%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||
}
|
||||
} else if (_source.startsWith("cpu/system/loadavg")) {
|
||||
} else if (_source.startsWith("cpu/loadaverages/loadaverage")) {
|
||||
// load average
|
||||
QString time = _source;
|
||||
time.remove("cpu/system/loadavg");
|
||||
QString key = QString("la%1").arg(time);
|
||||
auto time = _source;
|
||||
time.remove("cpu/loadaverages/loadaverage");
|
||||
auto key = QString("la%1").arg(time);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::FloatTwoSymbols;
|
||||
} else if (_source == "mem/physical/application") {
|
||||
} else if (_source == "memory/physical/application") {
|
||||
// app memory
|
||||
// mb
|
||||
m_map.insert(_source, "memmb");
|
||||
@ -237,7 +247,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "memgb");
|
||||
m_formatter["memgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/free") {
|
||||
} else if (_source == "memory/physical/free") {
|
||||
// free memory
|
||||
// mb
|
||||
m_map.insert(_source, "memfreemb");
|
||||
@ -245,7 +255,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "memfreegb");
|
||||
m_formatter["memfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/physical/used") {
|
||||
} else if (_source == "memory/physical/used") {
|
||||
// used memory
|
||||
// mb
|
||||
m_map.insert(_source, "memusedmb");
|
||||
@ -253,27 +263,27 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "memusedgb");
|
||||
m_formatter["memusedgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "network/current/name") {
|
||||
} else if (_source == "extsysmon/network/device") {
|
||||
// network device
|
||||
m_map.insert(_source, "netdev");
|
||||
m_formatter["netdev"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "network/current/ssid") {
|
||||
} else if (_source == "extsysmon/network/ssid") {
|
||||
// current ssid
|
||||
m_map.insert(_source, "ssid");
|
||||
m_formatter["ssid"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.startsWith("network/response")) {
|
||||
} else if (_source.startsWith("extsysmon/requests/response")) {
|
||||
// network response
|
||||
QString key = _source;
|
||||
key.remove("network/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/requests/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.contains(netRegExp)) {
|
||||
// network speed
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
auto type = _source.endsWith("download") ? "down" : "up";
|
||||
auto index = m_devices["net"].indexOf(_source.split('/')[1]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1kb%2").arg(type).arg(index);
|
||||
auto key = QString("%1kb%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
// smart
|
||||
@ -287,11 +297,11 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
}
|
||||
} else if (_source.contains(netTotalRegExp)) {
|
||||
// network data total
|
||||
QString type = _source.contains("receiver") ? "down" : "up";
|
||||
int index = m_devices["net"].indexOf(_source.split('/')[2]);
|
||||
auto type = _source.endsWith("Download") ? "down" : "up";
|
||||
auto index = m_devices["net"].indexOf(_source.split('/')[1]);
|
||||
if (index > -1) {
|
||||
// kb
|
||||
QString key = QString("%1totkb%2").arg(type).arg(index);
|
||||
auto key = QString("%1totkb%2").arg(type).arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Integer;
|
||||
// mb
|
||||
@ -299,37 +309,37 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::MemMBFormat;
|
||||
}
|
||||
} else if (_source.startsWith("upgrade")) {
|
||||
} else if (_source.startsWith("extsysmon/upgrade")) {
|
||||
// package manager
|
||||
QString key = _source;
|
||||
key.remove("upgrade/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/upgrade/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::IntegerThree;
|
||||
} else if (_source.startsWith("player")) {
|
||||
} else if (_source.startsWith("extsysmon/player")) {
|
||||
// player
|
||||
QString key = _source;
|
||||
key.remove("player/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/player/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "ps/running/count") {
|
||||
} else if (_source == "extsysmon/ps/running") {
|
||||
// running processes count
|
||||
m_map.insert(_source, "pscount");
|
||||
m_formatter["pscount"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source == "ps/running/list") {
|
||||
} else if (_source == "extsysmon/ps/list") {
|
||||
// list of running processes
|
||||
m_map.insert(_source, "ps");
|
||||
m_formatter["ps"] = AWKeysAggregator::FormatterType::List;
|
||||
} else if (_source == "ps/total/count") {
|
||||
} else if (_source == "extsysmon/ps/count") {
|
||||
// total processes count
|
||||
m_map.insert(_source, "pstot");
|
||||
m_formatter["pstot"] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.startsWith("quotes")) {
|
||||
} else if (_source.startsWith("extsysmon/quotes")) {
|
||||
// quotes
|
||||
QString key = _source;
|
||||
key.remove("quotes/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/quotes/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Quotes;
|
||||
} else if (_source == "mem/swap/free") {
|
||||
} else if (_source == "memory/swap/free") {
|
||||
// free swap
|
||||
// mb
|
||||
m_map.insert(_source, "swapfreemb");
|
||||
@ -337,7 +347,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "swapfreegb");
|
||||
m_formatter["swapfreegb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source == "mem/swap/used") {
|
||||
} else if (_source == "memory/swap/used") {
|
||||
// used swap
|
||||
// mb
|
||||
m_map.insert(_source, "swapmb");
|
||||
@ -345,19 +355,20 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// gb
|
||||
m_map.insert(_source, "swapgb");
|
||||
m_formatter["swapgb"] = AWKeysAggregator::FormatterType::MemGBFormat;
|
||||
} else if (_source.startsWith("lmsensors/")) {
|
||||
} else if (_source.startsWith("lmsensors/") || _source.contains(cpuTempRegExp)
|
||||
|| _source == "cpu/all/averageTemperature") {
|
||||
// temperature
|
||||
int index = m_devices["temp"].indexOf(_source);
|
||||
auto index = m_devices["temp"].indexOf(_source);
|
||||
// HACK on DE initialization there are no units key
|
||||
if (_units.isEmpty())
|
||||
if (_units == KSysGuard::UnitInvalid)
|
||||
return QStringList({QString("temp%1").arg(index)});
|
||||
if (index > -1) {
|
||||
QString key = QString("temp%1").arg(index);
|
||||
auto key = QString("temp%1").arg(index);
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = _units == "°C" ? AWKeysAggregator::FormatterType::Temperature
|
||||
: AWKeysAggregator::FormatterType::Integer;
|
||||
m_formatter[key] = _units == KSysGuard::UnitCelsius ? AWKeysAggregator::FormatterType::Temperature
|
||||
: AWKeysAggregator::FormatterType::Integer;
|
||||
}
|
||||
} else if (_source == "Local") {
|
||||
} else if (_source == "extsysmon/time/now") {
|
||||
// time
|
||||
m_map.insert(_source, "time");
|
||||
m_formatter["time"] = AWKeysAggregator::FormatterType::Time;
|
||||
@ -376,40 +387,40 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
// timestamp
|
||||
m_map.insert(_source, "tstime");
|
||||
m_formatter["tstime"] = AWKeysAggregator::FormatterType::Timestamp;
|
||||
} else if (_source == "system/brightness") {
|
||||
} else if (_source == "extsysmon/system/brightness") {
|
||||
m_map.insert(_source, "brightness");
|
||||
m_formatter["brightness"] = AWKeysAggregator::FormatterType::IntegerThree;
|
||||
} else if (_source == "system/volume") {
|
||||
} else if (_source == "extsysmon/system/volume") {
|
||||
m_map.insert(_source, "volume");
|
||||
m_formatter["volume"] = AWKeysAggregator::FormatterType::IntegerThree;
|
||||
} else if (_source == "system/uptime") {
|
||||
} else if (_source == "os/system/uptime") {
|
||||
// uptime
|
||||
m_map.insert(_source, "uptime");
|
||||
m_formatter["uptime"] = AWKeysAggregator::FormatterType::Uptime;
|
||||
// custom uptime
|
||||
m_map.insert(_source, "cuptime");
|
||||
m_formatter["cuptime"] = AWKeysAggregator::FormatterType::UptimeCustom;
|
||||
} else if (_source.startsWith("weather/temperature")) {
|
||||
} else if (_source.startsWith("extsysmon/weather/temperature")) {
|
||||
// temperature
|
||||
QString key = _source;
|
||||
key.remove("weather/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/weather/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||
} else if (_source.startsWith("weather/")) {
|
||||
} else if (_source.startsWith("extsysmon/weather/")) {
|
||||
// other weather
|
||||
QString key = _source;
|
||||
key.remove("weather/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/weather/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::NoFormat;
|
||||
} else if (_source.startsWith("load/load")) {
|
||||
} else if (_source.startsWith("extsysmon/load/load")) {
|
||||
// load source
|
||||
QString key = _source;
|
||||
key.remove("load/");
|
||||
auto key = _source;
|
||||
key.remove("extsysmon/load/");
|
||||
m_map.insert(_source, key);
|
||||
m_formatter[key] = AWKeysAggregator::FormatterType::Temperature;
|
||||
}
|
||||
|
||||
QStringList foundKeys = keysFromSource(_source);
|
||||
auto foundKeys = keysFromSource(_source);
|
||||
|
||||
// rewrite formatters for custom ones
|
||||
QStringList customFormattersKeys;
|
||||
@ -424,7 +435,7 @@ QStringList AWDataEngineMapper::registerSource(const QString &_source, const QSt
|
||||
|
||||
// drop key from dictionary if no one user requested key required it
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << _keys;
|
||||
bool required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](const QString &key) {
|
||||
auto required = _keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(), [&_keys](const QString &key) {
|
||||
return _keys.contains(key);
|
||||
});
|
||||
if (!required) {
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef AWDATAENGINEMAPPER_H
|
||||
#define AWDATAENGINEMAPPER_H
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
|
||||
#include <QMultiHash>
|
||||
#include <QObject>
|
||||
|
||||
@ -38,7 +40,7 @@ public:
|
||||
[[nodiscard]] AWKeysAggregator::FormatterType formatter(const QString &_key) const;
|
||||
[[nodiscard]] QStringList keysFromSource(const QString &_source) const;
|
||||
// set methods
|
||||
QStringList registerSource(const QString &_source, const QString &_units, const QStringList &_keys);
|
||||
QStringList registerSource(const QString &_source, const KSysGuard::Unit _units, const QStringList &_keys);
|
||||
void setDevices(const QHash<QString, QStringList> &_devices);
|
||||
|
||||
private:
|
||||
|
@ -114,8 +114,7 @@ QStringList AWFormatterHelper::rightKeys()
|
||||
|
||||
void AWFormatterHelper::editItems()
|
||||
{
|
||||
repaintList();
|
||||
int ret = exec();
|
||||
auto ret = exec();
|
||||
qCInfo(LOG_AW) << "Dialog returns" << ret;
|
||||
}
|
||||
|
||||
@ -200,20 +199,20 @@ QPair<QString, AWAbstractFormatter::FormatterClass> AWFormatterHelper::readMetad
|
||||
|
||||
QSettings settings(_filePath, QSettings::IniFormat);
|
||||
settings.beginGroup("Desktop Entry");
|
||||
QString name = settings.value("Name", _filePath).toString();
|
||||
QString type = settings.value("X-AW-Type", "NoFormat").toString();
|
||||
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(type);
|
||||
auto name = settings.value("Name", _filePath).toString();
|
||||
auto type = settings.value("X-AW-Type", "NoFormat").toString();
|
||||
auto formatter = defineFormatterClass(type);
|
||||
settings.endGroup();
|
||||
|
||||
return QPair<QString, AWAbstractFormatter::FormatterClass>(name, formatter);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterHelper::doCreateItem()
|
||||
void AWFormatterHelper::doCreateItem(QListWidget *_widget)
|
||||
{
|
||||
QStringList selection = {"NoFormat", "DateTime", "Float", "List", "Script", "String", "Json"};
|
||||
bool ok;
|
||||
QString select = QInputDialog::getItem(this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||
auto select = QInputDialog::getItem(nullptr, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||
if (!ok) {
|
||||
qCWarning(LOG_AW) << "No type selected";
|
||||
return;
|
||||
@ -223,18 +222,18 @@ void AWFormatterHelper::doCreateItem()
|
||||
AWAbstractFormatter::FormatterClass formatter = defineFormatterClass(select);
|
||||
switch (formatter) {
|
||||
case AWAbstractFormatter::FormatterClass::DateTime:
|
||||
return createItem<AWDateTimeFormatter>();
|
||||
return createItem<AWDateTimeFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::Float:
|
||||
return createItem<AWFloatFormatter>();
|
||||
return createItem<AWFloatFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
return createItem<AWListFormatter>();
|
||||
return createItem<AWListFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
return createItem<AWScriptFormatter>();
|
||||
return createItem<AWScriptFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
return createItem<AWStringFormatter>();
|
||||
return createItem<AWStringFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::Json:
|
||||
return createItem<AWJsonFormatter>();
|
||||
return createItem<AWJsonFormatter>(_widget);
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
return createItem<AWNoFormatter>();
|
||||
return createItem<AWNoFormatter>(_widget);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ private:
|
||||
void initFormatters();
|
||||
[[nodiscard]] static QPair<QString, AWAbstractFormatter::FormatterClass> readMetadata(const QString &_filePath);
|
||||
// parent methods
|
||||
void doCreateItem() override;
|
||||
void doCreateItem(QListWidget *_widget) override;
|
||||
// properties
|
||||
QHash<QString, AWAbstractFormatter *> m_formatters;
|
||||
QHash<QString, AWAbstractFormatter *> m_formattersClasses;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QDir>
|
||||
#include <QNetworkInterface>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
@ -30,7 +31,7 @@ bool AWKeyCache::addKeyToCache(const QString &_type, const QString &_key)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Key" << _key << "with type" << _type;
|
||||
|
||||
QString fileName
|
||||
auto fileName
|
||||
= QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
@ -40,19 +41,8 @@ bool AWKeyCache::addKeyToCache(const QString &_type, const QString &_key)
|
||||
for (auto &number : cache.allKeys())
|
||||
cachedValues.append(cache.value(number).toString());
|
||||
|
||||
if (_type == "hdd") {
|
||||
QStringList allDevices = QDir("/dev").entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$"));
|
||||
for (auto &dev : devices) {
|
||||
QString device = QString("/dev/%1").arg(dev);
|
||||
if (cachedValues.contains(device))
|
||||
continue;
|
||||
qCInfo(LOG_AW) << "Found new key" << device << "for type" << _type;
|
||||
cachedValues.append(device);
|
||||
cache.setValue(QString("%1").arg(cache.allKeys().count(), 3, 10, QChar('0')), device);
|
||||
}
|
||||
} else if (_type == "net") {
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
if (_type == "net") {
|
||||
auto rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (auto &interface : rawInterfaceList) {
|
||||
QString device = interface.name();
|
||||
if (cachedValues.contains(device))
|
||||
@ -93,19 +83,19 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
|
||||
// insert depending keys, refer to AWKeys::calculateValues()
|
||||
// hddtotmb*
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotmb"))) {
|
||||
for (auto &key : _allKeys.filter(QRegularExpression("^hddtotmb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove("hddtotmb");
|
||||
int index = key.toInt();
|
||||
auto index = key.toInt();
|
||||
used << QString("hddfreemb%1").arg(index) << QString("hddmb%1").arg(index);
|
||||
}
|
||||
// hddtotgb*
|
||||
for (auto &key : _allKeys.filter(QRegExp("^hddtotgb"))) {
|
||||
for (auto &key : _allKeys.filter(QRegularExpression("^hddtotgb"))) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
key.remove("hddtotgb");
|
||||
int index = key.toInt();
|
||||
auto index = key.toInt();
|
||||
used << QString("hddfreegb%1").arg(index) << QString("hddgb%1").arg(index);
|
||||
}
|
||||
// mem
|
||||
@ -138,7 +128,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
for (auto &key : netKeys) {
|
||||
if (!used.contains(key))
|
||||
continue;
|
||||
QStringList filt = _allKeys.filter(QRegExp(QString("^%1[0-9]{1,}").arg(key)));
|
||||
auto filt = _allKeys.filter(QRegularExpression(QString("^%1[0-9]{1,}").arg(key)));
|
||||
for (auto &filtered : filt)
|
||||
used << filtered;
|
||||
}
|
||||
@ -157,7 +147,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &_keys, const QStringL
|
||||
|
||||
QHash<QString, QStringList> AWKeyCache::loadKeysFromCache()
|
||||
{
|
||||
QString fileName
|
||||
auto fileName
|
||||
= QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||
qCInfo(LOG_AW) << "Cache file" << fileName;
|
||||
QSettings cache(fileName, QSettings::IniFormat);
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "awkeyoperations.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QThread>
|
||||
|
||||
#include "awcustomkeyshelper.h"
|
||||
@ -72,7 +72,6 @@ QHash<QString, QStringList> AWKeyOperations::devices() const
|
||||
void AWKeyOperations::updateCache()
|
||||
{
|
||||
// update network and hdd list
|
||||
addKeyToCache("hdd");
|
||||
addKeyToCache("net");
|
||||
}
|
||||
|
||||
@ -90,15 +89,20 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(item->tag("timestamp"));
|
||||
}
|
||||
// cpuclock & cpu
|
||||
for (int i = 0; i < QThread::idealThreadCount(); i++) {
|
||||
for (auto i = 0; i < QThread::idealThreadCount(); i++) {
|
||||
allKeys.append(QString("cpucl%1").arg(i));
|
||||
allKeys.append(QString("cpu%1").arg(i));
|
||||
}
|
||||
// temperature
|
||||
for (int i = 0; i < m_devices["temp"].count(); i++)
|
||||
for (auto i = 0; i < m_devices["temp"].count(); i++)
|
||||
allKeys.append(QString("temp%1").arg(i));
|
||||
// gpu
|
||||
for (auto i = 0; i < m_devices["gpu"].count(); i++) {
|
||||
allKeys.append(QString("gpu%1").arg(i));
|
||||
allKeys.append(QString("gputemp%1").arg(i));
|
||||
}
|
||||
// hdd
|
||||
for (int i = 0; i < m_devices["mount"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["mount"].count(); i++) {
|
||||
allKeys.append(QString("hddmb%1").arg(i));
|
||||
allKeys.append(QString("hddgb%1").arg(i));
|
||||
allKeys.append(QString("hddfreemb%1").arg(i));
|
||||
@ -108,15 +112,12 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("hdd%1").arg(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (int i = 0; i < m_devices["disk"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["disk"].count(); i++) {
|
||||
allKeys.append(QString("hddr%1").arg(i));
|
||||
allKeys.append(QString("hddw%1").arg(i));
|
||||
}
|
||||
// hdd temp
|
||||
for (int i = 0; i < m_devices["hdd"].count(); i++)
|
||||
allKeys.append(QString("hddtemp%1").arg(i));
|
||||
// network
|
||||
for (int i = 0; i < m_devices["net"].count(); i++) {
|
||||
for (auto i = 0; i < m_devices["net"].count(); i++) {
|
||||
allKeys.append(QString("downunits%1").arg(i));
|
||||
allKeys.append(QString("upunits%1").arg(i));
|
||||
allKeys.append(QString("downtotkb%1").arg(i));
|
||||
@ -129,9 +130,8 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("up%1").arg(i));
|
||||
}
|
||||
// battery
|
||||
QStringList allBatteryDevices
|
||||
= QDir("/sys/class/power_supply")
|
||||
.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
auto allBatteryDevices = QDir("/sys/class/power_supply")
|
||||
.entryList(QStringList({"BAT*"}), QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
for (int i = 0; i < allBatteryDevices.count(); i++) {
|
||||
allKeys.append(QString("bat%1").arg(i));
|
||||
allKeys.append(QString("batleft%1").arg(i));
|
||||
@ -205,52 +205,48 @@ QString AWKeyOperations::infoByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << _key;
|
||||
|
||||
QString stripped = _key;
|
||||
stripped.remove(QRegExp("\\d+"));
|
||||
auto stripped = _key;
|
||||
stripped.remove(QRegularExpression("\\d+"));
|
||||
QString output;
|
||||
|
||||
if (_key.startsWith("bar")) {
|
||||
AbstractExtItem *item = m_graphicalItems->itemByTag(_key, stripped);
|
||||
auto *item = m_graphicalItems->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.startsWith("custom")) {
|
||||
AbstractExtItem *item = m_extScripts->itemByTag(_key, stripped);
|
||||
auto *item = m_extScripts->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("^hdd[rw]"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("hdd[rw]"));
|
||||
} else if (_key.contains(QRegularExpression("^hdd[rw]"))) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("hdd[rw]"));
|
||||
output = m_devices["disk"][index.toInt()];
|
||||
} else if (_key.contains(QRegExp("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^hdd(|mb|gb|freemb|freegb|totmb|totgb)"));
|
||||
} else if (_key.contains(QRegularExpression("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("^hdd(|mb|gb|freemb|freegb|totmb|totgb)"));
|
||||
output = m_devices["mount"][index.toInt()];
|
||||
} else if (_key.startsWith("hddtemp")) {
|
||||
QString index = _key;
|
||||
index.remove("hddtemp");
|
||||
output = m_devices["hdd"][index.toInt()];
|
||||
} else if (_key.contains(QRegExp("^(down|up)[0-9]"))) {
|
||||
QString index = _key;
|
||||
index.remove(QRegExp("^(down|up)"));
|
||||
} else if (_key.contains(QRegularExpression("^(down|up)[0-9]"))) {
|
||||
auto index = _key;
|
||||
index.remove(QRegularExpression("^(down|up)"));
|
||||
output = m_devices["net"][index.toInt()];
|
||||
} else if (_key.startsWith("pkgcount")) {
|
||||
AbstractExtItem *item = m_extUpgrade->itemByTag(_key, stripped);
|
||||
auto *item = m_extUpgrade->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
AbstractExtItem *item = m_extQuotes->itemByTag(_key, stripped);
|
||||
} else if (_key.contains(QRegularExpression("(^|perc)(ask|bid|price)(chg|)"))) {
|
||||
auto *item = m_extQuotes->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.contains(QRegExp("(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
AbstractExtItem *item = m_extWeather->itemByTag(_key, stripped);
|
||||
} else if (_key.contains(QRegularExpression("(weather|weatherId|humidity|pressure|temperature)"))) {
|
||||
auto *item = m_extWeather->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else if (_key.startsWith("temp")) {
|
||||
QString index = _key;
|
||||
auto index = _key;
|
||||
index.remove("temp");
|
||||
output = m_devices["temp"][index.toInt()];
|
||||
} else if (_key.startsWith("response")) {
|
||||
AbstractExtItem *item = m_extNetRequest->itemByTag(_key, stripped);
|
||||
auto *item = m_extNetRequest->itemByTag(_key, stripped);
|
||||
if (item)
|
||||
output = item->uniq();
|
||||
} else {
|
||||
@ -280,7 +276,7 @@ void AWKeyOperations::editItem(const QString &_type)
|
||||
qCDebug(LOG_AW) << "Item type" << _type;
|
||||
|
||||
if (_type == "graphicalitem") {
|
||||
QStringList keys = dictKeys().filter(QRegExp("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
QStringList keys = dictKeys().filter(QRegularExpression("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)"));
|
||||
keys.sort();
|
||||
m_graphicalItems->setConfigArgs(keys);
|
||||
return m_graphicalItems->editItems();
|
||||
@ -302,19 +298,26 @@ void AWKeyOperations::addDevice(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source;
|
||||
|
||||
QRegExp diskRegexp = QRegExp("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)");
|
||||
QRegExp mountRegexp = QRegExp("partitions/.*/filllevel");
|
||||
auto diskRegexp = QRegularExpression("^disk/.*/read$");
|
||||
auto mountRegexp = QRegularExpression("^disk/.*/usedPercent$");
|
||||
auto cpuTempRegExp = QRegularExpression("^cpu/cpu.*/temperature$");
|
||||
auto gpuRegExp = QRegularExpression("^gpu/gpu.*/usage$");
|
||||
|
||||
if (_source.contains(diskRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("/Rate/rblk");
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/read");
|
||||
addKeyToCache("disk", device);
|
||||
} else if (_source.contains(mountRegexp)) {
|
||||
QString device = _source;
|
||||
device.remove("partitions").remove("/filllevel");
|
||||
auto device = _source;
|
||||
device.remove("disk/").remove("/usedPercent");
|
||||
addKeyToCache("mount", device);
|
||||
} else if (_source.startsWith("lmsensors")) {
|
||||
} else if (_source.startsWith("lmsensors") || _source.contains(cpuTempRegExp)
|
||||
|| _source == "cpu/all/averageTemperature") {
|
||||
addKeyToCache("temp", _source);
|
||||
} else if (_source.contains(gpuRegExp)) {
|
||||
auto device = _source;
|
||||
device.remove("gpu/").remove("/usage");
|
||||
addKeyToCache("gpu", device);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,16 +56,17 @@ AWKeys::AWKeys(QObject *_parent)
|
||||
createDBusInterface();
|
||||
|
||||
// update key data if required
|
||||
connect(m_keyOperator, SIGNAL(updateKeys(const QStringList &)), this, SLOT(reinitKeys(const QStringList &)));
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTextData()));
|
||||
connect(m_keyOperator, &AWKeyOperations::updateKeys, this, &AWKeys::reinitKeys);
|
||||
connect(m_timer, &QTimer::timeout, this, &AWKeys::updateTextData);
|
||||
|
||||
// transfer signal from AWDataAggregator object to QML ui
|
||||
connect(m_dataAggregator, SIGNAL(toolTipPainted(const QString &)), this,
|
||||
SIGNAL(needToolTipToBeUpdated(const QString &)));
|
||||
connect(this, SIGNAL(dropSourceFromDataengine(const QString &)), m_dataEngineAggregator,
|
||||
SLOT(dropSource(const QString &)));
|
||||
connect(m_dataAggregator, &AWDataAggregator::toolTipPainted,
|
||||
[this](const QString &_tooltip) { emit(needToolTipToBeUpdated(_tooltip)); });
|
||||
|
||||
connect(this, &AWKeys::dropSourceFromDataengine, m_dataEngineAggregator, &AWDataEngineAggregator::dropSource);
|
||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::dataUpdated, this, &AWKeys::dataUpdated);
|
||||
// transfer signal from dataengine to update source list
|
||||
connect(m_dataEngineAggregator, SIGNAL(deviceAdded(const QString &)), m_keyOperator,
|
||||
SLOT(addDevice(const QString &)));
|
||||
connect(m_dataEngineAggregator, &AWDataEngineAggregator::deviceAdded, m_keyOperator, &AWKeyOperations::addDevice);
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +103,7 @@ void AWKeys::initKeys(const QString &_currentPattern, const int _interval, const
|
||||
m_aggregator->initFormatters();
|
||||
m_keyOperator->setPattern(_currentPattern);
|
||||
m_keyOperator->updateCache();
|
||||
m_dataEngineAggregator->reconnectSources(_interval);
|
||||
m_dataEngineAggregator->loadSources();
|
||||
|
||||
// timer
|
||||
m_timer->setInterval(_interval);
|
||||
@ -148,7 +149,7 @@ QStringList AWKeys::dictKeys(const bool _sorted, const QString &_regexp) const
|
||||
if (_sorted)
|
||||
allKeys.sort();
|
||||
|
||||
return allKeys.filter(QRegExp(_regexp));
|
||||
return allKeys.filter(QRegularExpression(_regexp));
|
||||
}
|
||||
|
||||
|
||||
@ -185,9 +186,9 @@ QString AWKeys::valueByKey(const QString &_key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested value for key" << _key;
|
||||
|
||||
QString trueKey = _key.startsWith("bar") ? m_keyOperator->infoByKey(_key) : _key;
|
||||
auto realKey = _key.startsWith("bar") ? m_keyOperator->infoByKey(_key) : _key;
|
||||
|
||||
return m_aggregator->formatter(m_values[trueKey], trueKey, true);
|
||||
return m_aggregator->formatter(m_values[realKey], realKey, true);
|
||||
}
|
||||
|
||||
|
||||
@ -199,10 +200,15 @@ void AWKeys::editItem(const QString &_type)
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::dataUpdated(const QString &_sourceName, const Plasma::DataEngine::Data &_data)
|
||||
void AWKeys::dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data)
|
||||
{
|
||||
// run concurrent data update
|
||||
QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, _sourceName, _data);
|
||||
for (auto &single : _data) {
|
||||
if (_sensors.contains(single.sensorProperty)) {
|
||||
setDataBySource(single.sensorProperty, _sensors.value(single.sensorProperty), single);
|
||||
}
|
||||
// TODO use QtConcurrent::map or something like that
|
||||
// QtConcurrent::run(m_threadPool, this, &AWKeys::setDataBySource, "ss", sensor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -239,7 +245,7 @@ void AWKeys::updateTextData()
|
||||
// do not do it in parallel to avoid race condition
|
||||
m_mutex.lock();
|
||||
calculateValues();
|
||||
QString text = parsePattern(m_keyOperator->pattern());
|
||||
auto text = parsePattern(m_keyOperator->pattern());
|
||||
// update tooltip values under lock
|
||||
m_dataAggregator->dataUpdate(m_values);
|
||||
m_mutex.unlock();
|
||||
@ -256,17 +262,17 @@ void AWKeys::calculateValues()
|
||||
QStringList mountDevices = m_keyOperator->devices("mount");
|
||||
for (auto &device : mountDevices) {
|
||||
int index = mountDevices.indexOf(device);
|
||||
m_values[QString("hddtotmb%1").arg(index)]
|
||||
= m_values[QString("hddfreemb%1").arg(index)].toFloat() + m_values[QString("hddmb%1").arg(index)].toFloat();
|
||||
m_values[QString("hddtotgb%1").arg(index)]
|
||||
= m_values[QString("hddfreegb%1").arg(index)].toFloat() + m_values[QString("hddgb%1").arg(index)].toFloat();
|
||||
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()
|
||||
+ m_values[QString("hddgb%1").arg(index)].toDouble();
|
||||
}
|
||||
|
||||
// memtot*
|
||||
m_values["memtotmb"] = m_values["memusedmb"].toInt() + m_values["memfreemb"].toInt();
|
||||
m_values["memtotgb"] = m_values["memusedgb"].toFloat() + m_values["memfreegb"].toFloat();
|
||||
m_values["memtotmb"] = m_values["memusedmb"].toLongLong() + m_values["memfreemb"].toLongLong();
|
||||
m_values["memtotgb"] = m_values["memusedgb"].toDouble() + m_values["memfreegb"].toDouble();
|
||||
// mem
|
||||
m_values["mem"] = 100.0f * m_values["memmb"].toFloat() / m_values["memtotmb"].toFloat();
|
||||
m_values["mem"] = 100.0f * 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());
|
||||
@ -282,10 +288,10 @@ void AWKeys::calculateValues()
|
||||
m_values["upunits"] = m_values[QString("upunits%1").arg(netIndex)];
|
||||
|
||||
// swaptot*
|
||||
m_values["swaptotmb"] = m_values["swapmb"].toInt() + m_values["swapfreemb"].toInt();
|
||||
m_values["swaptotgb"] = m_values["swapgb"].toFloat() + m_values["swapfreegb"].toFloat();
|
||||
m_values["swaptotmb"] = m_values["swapmb"].toLongLong() + m_values["swapfreemb"].toLongLong();
|
||||
m_values["swaptotgb"] = m_values["swapgb"].toDouble() + m_values["swapfreegb"].toDouble();
|
||||
// swap
|
||||
m_values["swap"] = 100.0f * m_values["swapmb"].toFloat() / m_values["swaptotmb"].toFloat();
|
||||
m_values["swap"] = 100.0f * m_values["swapmb"].toDouble() / m_values["swaptotmb"].toDouble();
|
||||
|
||||
// user defined keys
|
||||
for (auto &key : m_keyOperator->userKeys())
|
||||
@ -323,7 +329,7 @@ void AWKeys::createDBusInterface()
|
||||
QString AWKeys::parsePattern(QString _pattern) const
|
||||
{
|
||||
// screen sign
|
||||
_pattern.replace("$$", QString(0x1d));
|
||||
_pattern.replace("$$", QChar(0x1d));
|
||||
|
||||
// lambdas
|
||||
for (auto &key : m_foundLambdas)
|
||||
@ -343,7 +349,7 @@ QString AWKeys::parsePattern(QString _pattern) const
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
_pattern.replace(QString(0x1d), "$");
|
||||
_pattern.replace(QChar(0x1d), "$");
|
||||
if (m_wrapNewLines)
|
||||
_pattern.replace("\n", "<br>");
|
||||
|
||||
@ -351,25 +357,23 @@ QString AWKeys::parsePattern(QString _pattern) const
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setDataBySource(const QString &_sourceName, const QVariantMap &_data)
|
||||
void AWKeys::setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor,
|
||||
const KSysGuard::SensorData &_data)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _sourceName << "with data" << _data;
|
||||
qCDebug(LOG_AW) << "Source" << _source << _sensor.name << "with data" << _data.payload;
|
||||
|
||||
// first list init
|
||||
QStringList tags = m_aggregator->keysFromSource(_sourceName);
|
||||
auto tags = m_aggregator->keysFromSource(_source);
|
||||
if (tags.isEmpty())
|
||||
tags = m_aggregator->registerSource(_sourceName, _data["units"].toString(), m_requiredKeys);
|
||||
tags = m_aggregator->registerSource(_source, _sensor.unit, m_requiredKeys);
|
||||
|
||||
// update data or drop source if there are no matches and exit
|
||||
if (tags.isEmpty()) {
|
||||
qCInfo(LOG_AW) << "Source" << _sourceName << "not found";
|
||||
return emit(dropSourceFromDataengine(_sourceName));
|
||||
qCInfo(LOG_AW) << "Sensor" << _source << "not found";
|
||||
return emit(dropSourceFromDataengine(_source));
|
||||
}
|
||||
|
||||
m_mutex.lock();
|
||||
// HACK workaround for time values which are stored in the different path
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, &_data, &_sourceName](const QString &tag) {
|
||||
m_values[tag] = _sourceName == "Local" ? _data["DateTime"] : _data["value"];
|
||||
});
|
||||
std::for_each(tags.cbegin(), tags.cend(), [this, &_data](const QString &tag) { m_values[tag] = _data.payload; });
|
||||
m_mutex.unlock();
|
||||
}
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef AWKEYS_H
|
||||
#define AWKEYS_H
|
||||
|
||||
#include <Plasma/DataEngine>
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
|
||||
class AWDataAggregator;
|
||||
class AWDataEngineAggregator;
|
||||
@ -56,9 +56,7 @@ public:
|
||||
Q_INVOKABLE void editItem(const QString &_type);
|
||||
|
||||
public slots:
|
||||
void dataUpdated(const QString &_sourceName, const Plasma::DataEngine::Data &_data);
|
||||
// dummy method required by DataEngine connections
|
||||
static void modelChanged(const QString &, QAbstractItemModel *){};
|
||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||
|
||||
signals:
|
||||
void dropSourceFromDataengine(const QString &_source);
|
||||
@ -74,7 +72,8 @@ private:
|
||||
void calculateValues();
|
||||
void createDBusInterface();
|
||||
[[nodiscard]] QString parsePattern(QString _pattern) const;
|
||||
void setDataBySource(const QString &_sourceName, const QVariantMap &_data);
|
||||
void setDataBySource(const QString &_source, const KSysGuard::SensorInfo &_sensor,
|
||||
const KSysGuard::SensorData &_data);
|
||||
// objects
|
||||
AWDataAggregator *m_dataAggregator = nullptr;
|
||||
AWDataEngineAggregator *m_dataEngineAggregator = nullptr;
|
||||
|
@ -64,19 +64,19 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
// case block
|
||||
switch (m_mapper->formatter(_key)) {
|
||||
case FormatterType::Float:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::FloatTwoSymbols:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 2);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 2);
|
||||
break;
|
||||
case FormatterType::Integer:
|
||||
output = QString("%1").arg(_data.toFloat(), 4, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 4, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerFive:
|
||||
output = QString("%1").arg(_data.toFloat(), 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::IntegerThree:
|
||||
output = QString("%1").arg(_data.toFloat(), 3, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble(), 3, 'f', 0);
|
||||
break;
|
||||
case FormatterType::List:
|
||||
output = _data.toStringList().join(',');
|
||||
@ -85,10 +85,10 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
output = _data.toBool() ? m_acOnline : m_acOffline;
|
||||
break;
|
||||
case FormatterType::MemGBFormat:
|
||||
output = QString("%1").arg(_data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
output = QString("%1").arg(_data.toDouble() / (1024.0 * 1024.0), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::MemMBFormat:
|
||||
output = QString("%1").arg(_data.toFloat() / 1024.0, 5, 'f', 0);
|
||||
output = QString("%1").arg(_data.toDouble() / 1024.0, 5, 'f', 0);
|
||||
break;
|
||||
case FormatterType::NetSmartFormat:
|
||||
output = [](const float value) {
|
||||
@ -96,10 +96,10 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
|
||||
else
|
||||
return QString("%1").arg(value, 4, 'f', 0);
|
||||
}(_data.toFloat());
|
||||
}(_data.toDouble());
|
||||
break;
|
||||
case FormatterType::NetSmartUnits:
|
||||
if (_data.toFloat() > 1024.0)
|
||||
if (_data.toDouble() > 1024.0)
|
||||
output = m_translate ? i18n("MB/s") : "MB/s";
|
||||
else
|
||||
output = m_translate ? i18n("KB/s") : "KB/s";
|
||||
@ -110,29 +110,29 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
output = output.rightJustified(8, QLatin1Char(' '), true);
|
||||
break;
|
||||
case FormatterType::Temperature:
|
||||
output = QString("%1").arg(temperature(_data.toFloat()), 5, 'f', 1);
|
||||
output = QString("%1").arg(temperature(_data.toDouble()), 5, 'f', 1);
|
||||
break;
|
||||
case FormatterType::Time:
|
||||
output = _data.toDateTime().toString();
|
||||
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString();
|
||||
break;
|
||||
case FormatterType::TimeCustom:
|
||||
output = m_customTime;
|
||||
[&output, loc, this](const QDateTime &dt) {
|
||||
for (auto &key : m_timeKeys)
|
||||
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
|
||||
}(_data.toDateTime());
|
||||
}(QDateTime::fromSecsSinceEpoch(_data.toLongLong()));
|
||||
break;
|
||||
case FormatterType::TimeISO:
|
||||
output = _data.toDateTime().toString(Qt::ISODate);
|
||||
output = QDateTime::fromSecsSinceEpoch(_data.toLongLong()).toString(Qt::ISODate);
|
||||
break;
|
||||
case FormatterType::TimeLong:
|
||||
output = loc.toString(_data.toDateTime(), QLocale::LongFormat);
|
||||
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::LongFormat);
|
||||
break;
|
||||
case FormatterType::TimeShort:
|
||||
output = loc.toString(_data.toDateTime(), QLocale::ShortFormat);
|
||||
output = loc.toString(QDateTime::fromSecsSinceEpoch(_data.toLongLong()), QLocale::ShortFormat);
|
||||
break;
|
||||
case FormatterType::Timestamp:
|
||||
output = QString("%1").arg(_data.toDateTime().toMSecsSinceEpoch() / 1000.0, 10, 'f', 0);
|
||||
output = _data.toString();
|
||||
break;
|
||||
case FormatterType::Uptime:
|
||||
case FormatterType::UptimeCustom:
|
||||
@ -150,7 +150,7 @@ QString AWKeysAggregator::formatter(const QVariant &_data, const QString &_key,
|
||||
source.replace("$m", QString("%1").arg(minutes));
|
||||
return source;
|
||||
}(m_mapper->formatter(_key) == FormatterType::Uptime ? "$ddd$hhh$mmm" : m_customUptime,
|
||||
static_cast<int>(_data.toFloat()));
|
||||
static_cast<int>(_data.toDouble()));
|
||||
break;
|
||||
case FormatterType::NoFormat:
|
||||
output = _data.toString();
|
||||
@ -234,7 +234,8 @@ void AWKeysAggregator::setTranslate(const bool _translate)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeysAggregator::registerSource(const QString &_source, const QString &_units, const QStringList &_keys)
|
||||
QStringList AWKeysAggregator::registerSource(const QString &_source, const KSysGuard::Unit &_units,
|
||||
const QStringList &_keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Source" << _source << "with units" << _units;
|
||||
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef AWKEYSAGGREGATOR_H
|
||||
#define AWKEYSAGGREGATOR_H
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
|
||||
@ -81,7 +83,7 @@ public:
|
||||
void setTranslate(bool _translate);
|
||||
|
||||
public slots:
|
||||
QStringList registerSource(const QString &_source, const QString &_units, const QStringList &_keys);
|
||||
QStringList registerSource(const QString &_source, const KSysGuard::Unit &_units, const QStringList &_keys);
|
||||
|
||||
private:
|
||||
[[nodiscard]] float temperature(float temp) const;
|
||||
|
@ -105,9 +105,9 @@ QList<AWPatternFunctions::AWFunction> AWPatternFunctions::findFunctionCalls(cons
|
||||
metadata.args = QStringList();
|
||||
} else {
|
||||
// replace '$,' to 0x1d
|
||||
argsString.replace("$,", QString(0x1d));
|
||||
argsString.replace("$,", QChar(0x1d));
|
||||
QStringList args = argsString.split(',');
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) { arg.replace(QString(0x1d), ","); });
|
||||
std::for_each(args.begin(), args.end(), [](QString &arg) { arg.replace(QChar(0x1d), ","); });
|
||||
metadata.args = args;
|
||||
}
|
||||
// other variables
|
||||
@ -130,7 +130,7 @@ QString AWPatternFunctions::insertAllKeys(QString _code, const QStringList &_key
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_all", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("%1: $%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
@ -146,7 +146,7 @@ QString AWPatternFunctions::insertKeyCount(QString _code, const QStringList &_ke
|
||||
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_count", _code);
|
||||
for (auto &function : found) {
|
||||
int count = _keys.filter(QRegExp(function.body)).count();
|
||||
int count = _keys.filter(QRegularExpression(function.body)).count();
|
||||
|
||||
_code.replace(function.what, QString::number(count));
|
||||
}
|
||||
@ -162,7 +162,7 @@ QString AWPatternFunctions::insertKeyNames(QString _code, const QStringList &_ke
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_names", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
}
|
||||
@ -178,7 +178,7 @@ QString AWPatternFunctions::insertKeys(QString _code, const QStringList &_keys)
|
||||
QList<AWPatternFunctions::AWFunction> found = AWPatternFunctions::findFunctionCalls("aw_keys", _code);
|
||||
for (auto &function : found) {
|
||||
QString separator = function.args.isEmpty() ? "," : function.args.at(0);
|
||||
QStringList required = _keys.filter(QRegExp(function.body));
|
||||
QStringList required = _keys.filter(QRegularExpression(function.body));
|
||||
std::for_each(required.begin(), required.end(), [](QString &value) { value = QString("$%1").arg(value); });
|
||||
|
||||
_code.replace(function.what, required.join(separator));
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
Reference in New Issue
Block a user