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:
@ -8,11 +8,11 @@ include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Kf5_INCLUDE}
|
||||
${Kf6_INCLUDE}
|
||||
)
|
||||
|
||||
file(GLOB SUBPROJECT_SOURCE *.cpp)
|
||||
file(GLOB SUBPROJECT_HEADER *.h)
|
||||
|
||||
add_library(${SUBPROJECT} STATIC ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
|
||||
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
target_link_libraries(${SUBPROJECT} ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Kf6_LIBRARIES})
|
||||
|
@ -19,10 +19,15 @@
|
||||
#define ABSTRACTEXTSYSMONSOURCE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
namespace KSysGuard
|
||||
{
|
||||
class SensorInfo;
|
||||
}
|
||||
|
||||
class AbstractExtSysMonSource : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -32,15 +37,14 @@ public:
|
||||
: QObject(_parent){};
|
||||
~AbstractExtSysMonSource() override = default;
|
||||
virtual QVariant data(const QString &_source) = 0;
|
||||
[[nodiscard]] virtual QVariantMap initialData(const QString &_source) const = 0;
|
||||
[[nodiscard]] virtual KSysGuard::SensorInfo *initialData(const QString &_source) const = 0;
|
||||
virtual void run() = 0;
|
||||
[[nodiscard]] virtual QStringList sources() const = 0;
|
||||
// used by extensions
|
||||
static int index(const QString &_source)
|
||||
{
|
||||
QRegExp rx("\\d+");
|
||||
rx.indexIn(_source);
|
||||
return rx.cap().toInt();
|
||||
QRegularExpression rx("\\d+");
|
||||
return rx.match(_source).captured().toInt();
|
||||
}
|
||||
|
||||
signals:
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "batterysource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <cmath>
|
||||
@ -45,12 +48,12 @@ BatterySource::~BatterySource()
|
||||
QStringList BatterySource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("battery/ac");
|
||||
sources.append("battery/bat");
|
||||
sources.append("battery/batleft");
|
||||
sources.append("battery/batnow");
|
||||
sources.append("battery/batrate");
|
||||
sources.append("battery/battotal");
|
||||
sources.append("ac");
|
||||
sources.append("bat");
|
||||
sources.append("batleft");
|
||||
sources.append("batnow");
|
||||
sources.append("batrate");
|
||||
sources.append("battotal");
|
||||
|
||||
auto directory = QDir(m_acpiPath);
|
||||
|
||||
@ -60,11 +63,11 @@ QStringList BatterySource::getSources()
|
||||
qCInfo(LOG_ESS) << "Init batteries count as" << m_batteriesCount;
|
||||
|
||||
for (int i = 0; i < m_batteriesCount; i++) {
|
||||
sources.append(QString("battery/bat%1").arg(i));
|
||||
sources.append(QString("battery/batleft%1").arg(i));
|
||||
sources.append(QString("battery/batnow%1").arg(i));
|
||||
sources.append(QString("battery/batrate%1").arg(i));
|
||||
sources.append(QString("battery/battotal%1").arg(i));
|
||||
sources.append(QString("bat%1").arg(i));
|
||||
sources.append(QString("batleft%1").arg(i));
|
||||
sources.append(QString("batnow%1").arg(i));
|
||||
sources.append(QString("batrate%1").arg(i));
|
||||
sources.append(QString("battotal%1").arg(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,82 +82,79 @@ QVariant BatterySource::data(const QString &_source)
|
||||
|
||||
if (!m_values.contains(_source))
|
||||
run();
|
||||
QVariant value = m_values.take(_source);
|
||||
return value;
|
||||
return m_values.take(_source);
|
||||
}
|
||||
|
||||
|
||||
QVariantMap BatterySource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *BatterySource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "battery/ac") {
|
||||
data["min"] = false;
|
||||
data["max"] = true;
|
||||
data["name"] = "Is AC online or not";
|
||||
data["type"] = "bool";
|
||||
data["units"] = "";
|
||||
} else if (_source == "battery/bat") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 100;
|
||||
data["name"] = "Average battery usage";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "%";
|
||||
} else if (_source == "battery/batleft") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Battery discharge time";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "s";
|
||||
} else if (_source == "battery/batnow") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Current battery capacity";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source == "battery/batrate") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Average battery discharge rate";
|
||||
data["type"] = "float";
|
||||
data["units"] = "1/s";
|
||||
} else if (_source == "battery/battotal") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Full battery capacity";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("battery/batleft")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Battery %1 discharge time").arg(index(_source));
|
||||
data["type"] = "integer";
|
||||
data["units"] = "s";
|
||||
} else if (_source.startsWith("battery/batnow")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Battery %1 capacity").arg(index(_source));
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("battery/battotal")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Battery %1 full capacity").arg(index(_source));
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("battery/batrate")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Battery %1 discharge rate").arg(index(_source));
|
||||
data["type"] = "float";
|
||||
data["units"] = "1/s";
|
||||
} else if (_source.startsWith("battery/bat")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 100;
|
||||
data["name"] = QString("Battery %1 usage").arg(index(_source));
|
||||
data["type"] = "integer";
|
||||
data["units"] = "%";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "ac") {
|
||||
data->name = "Is AC online or not";
|
||||
data->variantType = QVariant::Bool;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "bat") {
|
||||
data->min = 0;
|
||||
data->max = 100;
|
||||
data->name = "Average battery usage";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
} else if (_source == "batleft") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Battery discharge time";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitSecond;
|
||||
} else if (_source == "batnow") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Current battery capacity";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "batrate") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Average battery discharge rate";
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitRate;
|
||||
} else if (_source == "battotal") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Full battery capacity";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("batleft")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Battery %1 discharge time").arg(index(_source));
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitSecond;
|
||||
} else if (_source.startsWith("batnow")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Battery %1 capacity").arg(index(_source));
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("battotal")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Battery %1 full capacity").arg(index(_source));
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("batrate")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Battery %1 discharge rate").arg(index(_source));
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitRate;
|
||||
} else if (_source.startsWith("bat")) {
|
||||
data->min = 0;
|
||||
data->max = 100;
|
||||
data->name = QString("Battery %1 usage").arg(index(_source));
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -166,7 +166,7 @@ void BatterySource::run()
|
||||
// adaptor
|
||||
QFile acFile(QString("%1/AC/online").arg(m_acpiPath));
|
||||
if (acFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
m_values["battery/ac"] = (QString(acFile.readLine()).trimmed().toInt() == 1);
|
||||
m_values["ac"] = (QString(acFile.readLine()).trimmed().toInt() == 1);
|
||||
acFile.close();
|
||||
|
||||
// batteries
|
||||
@ -177,28 +177,27 @@ void BatterySource::run()
|
||||
if (currentLevelFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
auto value = QString(currentLevelFile.readLine()).toInt();
|
||||
m_trend[i + 1].append(value);
|
||||
m_values[QString("battery/batnow%1").arg(i)] = value;
|
||||
m_values[QString("batnow%1").arg(i)] = value;
|
||||
}
|
||||
currentLevelFile.close();
|
||||
// total
|
||||
QFile fullLevelFile(QString("%1/BAT%2/energy_full").arg(m_acpiPath).arg(i));
|
||||
if (fullLevelFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
m_values[QString("battery/battotal%1").arg(i)] = QString(fullLevelFile.readLine()).toInt();
|
||||
m_values[QString("battotal%1").arg(i)] = QString(fullLevelFile.readLine()).toInt();
|
||||
fullLevelFile.close();
|
||||
|
||||
m_values[QString("battery/bat%1").arg(i)]
|
||||
= static_cast<int>(100 * m_values[QString("battery/batnow%1").arg(i)].toFloat()
|
||||
/ m_values[QString("battery/battotal%1").arg(i)].toFloat());
|
||||
m_values[QString("bat%1").arg(i)] = static_cast<int>(100 * m_values[QString("batnow%1").arg(i)].toFloat()
|
||||
/ m_values[QString("battotal%1").arg(i)].toFloat());
|
||||
// accumulate
|
||||
currentLevel += m_values[QString("battery/batnow%1").arg(i)].toFloat();
|
||||
fullLevel += m_values[QString("battery/battotal%1").arg(i)].toFloat();
|
||||
currentLevel += m_values[QString("batnow%1").arg(i)].toFloat();
|
||||
fullLevel += m_values[QString("battotal%1").arg(i)].toFloat();
|
||||
}
|
||||
|
||||
// total
|
||||
m_trend[0].append(static_cast<int>(currentLevel));
|
||||
m_values["battery/batnow"] = static_cast<int>(currentLevel);
|
||||
m_values["battery/battotal"] = static_cast<int>(fullLevel);
|
||||
m_values["battery/bat"] = static_cast<int>(100 * currentLevel / fullLevel);
|
||||
m_values["batnow"] = static_cast<int>(currentLevel);
|
||||
m_values["battotal"] = static_cast<int>(fullLevel);
|
||||
m_values["bat"] = static_cast<int>(100 * currentLevel / fullLevel);
|
||||
|
||||
calculateRates();
|
||||
}
|
||||
@ -244,15 +243,14 @@ void BatterySource::calculateRates()
|
||||
|
||||
for (int i = 0; i < m_batteriesCount; i++) {
|
||||
auto approx = approximate(m_trend[i + 1]);
|
||||
m_values[QString("battery/batrate%1").arg(i)] = approx / interval;
|
||||
m_values[QString("battery/batleft%1").arg(i)]
|
||||
= interval * m_values[QString("battery/batnow%1").arg(i)].toFloat() / approx;
|
||||
m_values[QString("batrate%1").arg(i)] = approx / interval;
|
||||
m_values[QString("batleft%1").arg(i)] = interval * m_values[QString("batnow%1").arg(i)].toFloat() / approx;
|
||||
}
|
||||
|
||||
// total
|
||||
auto approx = approximate(m_trend[0]);
|
||||
m_values["battery/batrate"] = approx / interval;
|
||||
m_values["battery/batleft"] = interval * m_values["battery/batnow"].toFloat() / approx;
|
||||
m_values["batrate"] = approx / interval;
|
||||
m_values["batleft"] = interval * m_values["batnow"].toFloat() / approx;
|
||||
|
||||
// old data cleanup
|
||||
for (auto &trend : m_trend.keys()) {
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
~BatterySource() override;
|
||||
QStringList getSources();
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -15,9 +15,11 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "customsource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extscript.h"
|
||||
|
||||
@ -49,16 +51,14 @@ QVariant CustomSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap CustomSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *CustomSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Custom command '%1' output").arg(m_extScripts->itemByTagNumber(index(_source))->uniq());
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
data->name = QString("Custom command '%1' output").arg(m_extScripts->itemByTagNumber(index(_source))->uniq());
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -74,7 +74,7 @@ QStringList CustomSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &item : m_extScripts->activeItems())
|
||||
sources.append(QString("custom/%1").arg(item->tag("custom")));
|
||||
sources.append(item->tag("custom"));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
explicit CustomSource(QObject *_parent, const QStringList &_args);
|
||||
~CustomSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -15,10 +15,11 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "desktopsource.h"
|
||||
|
||||
#include <KWindowSystem/KWindowSystem>
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
#include <taskmanager/virtualdesktopinfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
@ -50,13 +51,13 @@ QVariant DesktopSource::data(const QString &_source)
|
||||
auto decrement = KWindowSystem::isPlatformX11() ? 1 : 0;
|
||||
auto current = nativeIndex - decrement;
|
||||
|
||||
if (_source == "desktop/current/name") {
|
||||
if (_source == "name") {
|
||||
return m_vdi->desktopNames().at(current);
|
||||
} else if (_source == "desktop/current/number") {
|
||||
} else if (_source == "number") {
|
||||
return current + 1;
|
||||
} else if (_source == "desktop/total/name") {
|
||||
} else if (_source == "names") {
|
||||
return m_vdi->desktopNames();
|
||||
} else if (_source == "desktop/total/number") {
|
||||
} else if (_source == "count") {
|
||||
return m_vdi->numberOfDesktops();
|
||||
}
|
||||
|
||||
@ -64,35 +65,29 @@ QVariant DesktopSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap DesktopSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *DesktopSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "desktop/current/name") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current desktop name";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "desktop/current/number") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Current desktop number";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source == "desktop/total/name") {
|
||||
data["min"] = QStringList();
|
||||
data["max"] = QStringList();
|
||||
data["name"] = "All desktops by name";
|
||||
data["type"] = "QStringList";
|
||||
data["units"] = "";
|
||||
} else if (_source == "desktop/total/number") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Desktops count";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "name") {
|
||||
data->name = "Current desktop name";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "number") {
|
||||
data->min = 0;
|
||||
data->name = "Current desktop number";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "names") {
|
||||
data->name = "All desktops by name";
|
||||
data->variantType = QVariant::StringList;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "count") {
|
||||
data->min = 0;
|
||||
data->name = "Desktops count";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -102,10 +97,10 @@ QVariantMap DesktopSource::initialData(const QString &_source) const
|
||||
QStringList DesktopSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("desktop/current/name");
|
||||
sources.append("desktop/current/number");
|
||||
sources.append("desktop/total/name");
|
||||
sources.append("desktop/total/number");
|
||||
sources.append("name");
|
||||
sources.append("number");
|
||||
sources.append("names");
|
||||
sources.append("count");
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
explicit DesktopSource(QObject *_parent, const QStringList &_args);
|
||||
~DesktopSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
89
sources/extsysmonsources/extsysmonsensor.cpp
Normal file
89
sources/extsysmonsources/extsysmonsensor.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "extsysmonsensor.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
ExtSysMonSensor::ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QString &_id, const QString &_name,
|
||||
AbstractExtSysMonSource *_source)
|
||||
: KSysGuard::SensorObject(_id, _name, _parent)
|
||||
, m_source(_source)
|
||||
, m_timer(new QTimer(this))
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
loadProperties();
|
||||
|
||||
connect(this, &SensorObject::subscribedChanged, [this](bool _state) { changeSubscription(_state); });
|
||||
connect(m_timer, &QTimer::timeout, [this]() { update(); });
|
||||
}
|
||||
|
||||
|
||||
ExtSysMonSensor::~ExtSysMonSensor()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_timer->stop();
|
||||
m_timer->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void ExtSysMonSensor::changeSubscription(bool _subscribed)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Subscription changed to" << _subscribed;
|
||||
|
||||
if (_subscribed) {
|
||||
m_timer->start(1000);
|
||||
} else {
|
||||
m_timer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExtSysMonSensor::update()
|
||||
{
|
||||
for (auto &source : m_source->sources()) {
|
||||
auto property = sensor(source);
|
||||
if (!property->isSubscribed())
|
||||
continue; // skip properties which are not explicitly subscribed
|
||||
|
||||
auto value = m_source->data(source);
|
||||
property->setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ExtSysMonSensor::loadProperties()
|
||||
{
|
||||
for (auto &source : m_source->sources()) {
|
||||
auto info = m_source->initialData(source);
|
||||
auto property = new KSysGuard::SensorProperty(source, info->name, this);
|
||||
|
||||
property->setUnit(info->unit);
|
||||
property->setVariantType(info->variantType);
|
||||
|
||||
property->setMin(info->min);
|
||||
property->setMax(info->max);
|
||||
|
||||
addProperty(property);
|
||||
}
|
||||
}
|
@ -15,38 +15,31 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GPULOADSOURCE_H
|
||||
#define GPULOADSOURCE_H
|
||||
#ifndef EXTSYSMONSENSOR_H
|
||||
#define EXTSYSMONSENSOR_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
#include <ksysguard/systemstats/SensorObject.h>
|
||||
|
||||
|
||||
class QProcess;
|
||||
class AbstractExtSysMonSource;
|
||||
class QTimer;
|
||||
|
||||
class GPULoadSource : public AbstractExtSysMonSource
|
||||
class ExtSysMonSensor : public KSysGuard::SensorObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GPULoadSource(QObject *_parent, const QStringList &_args);
|
||||
~GPULoadSource() override;
|
||||
static QString autoGpu();
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
private slots:
|
||||
void updateValue();
|
||||
explicit ExtSysMonSensor(KSysGuard::SensorContainer *_parent, const QString &_id, const QString &_name,
|
||||
AbstractExtSysMonSource *_source);
|
||||
~ExtSysMonSensor() override;
|
||||
void changeSubscription(bool _subscribed);
|
||||
void update();
|
||||
|
||||
private:
|
||||
// configuration and values
|
||||
QString m_device;
|
||||
QProcess *m_process = nullptr;
|
||||
QVariantHash m_values;
|
||||
void loadProperties();
|
||||
AbstractExtSysMonSource *m_source = nullptr;
|
||||
QTimer *m_timer = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* GPULOADSOURCE_H */
|
||||
#endif /* EXTSYSMONSENSOR_H */
|
@ -1,151 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "gpuloadsource.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
GPULoadSource::GPULoadSource(QObject *_parent, const QStringList &_args)
|
||||
: AbstractExtSysMonSource(_parent, _args)
|
||||
{
|
||||
Q_ASSERT(_args.count() == 1);
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_device = _args.at(0);
|
||||
|
||||
m_process = new QProcess(nullptr);
|
||||
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
|
||||
connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[this](int, QProcess::ExitStatus) { return updateValue(); });
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
GPULoadSource::~GPULoadSource()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
QString GPULoadSource::autoGpu()
|
||||
{
|
||||
QString gpu = "disable";
|
||||
QFile moduleFile("/proc/modules");
|
||||
if (!moduleFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCWarning(LOG_AW) << "Could not open file as text" << moduleFile.fileName();
|
||||
return gpu;
|
||||
}
|
||||
|
||||
QString output = moduleFile.readAll();
|
||||
moduleFile.close();
|
||||
if (output.contains("fglrx"))
|
||||
gpu = "ati";
|
||||
else if (output.contains("nvidia"))
|
||||
gpu = "nvidia";
|
||||
|
||||
qCInfo(LOG_ESM) << "Device" << gpu;
|
||||
return gpu;
|
||||
}
|
||||
|
||||
|
||||
QVariant GPULoadSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
if (_source == "gpu/load")
|
||||
run();
|
||||
|
||||
return m_values[_source];
|
||||
}
|
||||
|
||||
|
||||
QVariantMap GPULoadSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "gpu/load") {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 100.0;
|
||||
data["name"] = "GPU usage";
|
||||
data["type"] = "float";
|
||||
data["units"] = "%";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void GPULoadSource::run()
|
||||
{
|
||||
if ((m_device != "nvidia") && (m_device != "ati"))
|
||||
return;
|
||||
// build cmd
|
||||
QString cmd = m_device == "nvidia" ? "nvidia-smi" : "aticonfig";
|
||||
auto args = m_device == "nvidia" ? QStringList({"-q", "-x"}) : QStringList({"--od-getclocks"});
|
||||
qCInfo(LOG_ESS) << "cmd" << cmd;
|
||||
|
||||
m_process->start(cmd, args);
|
||||
}
|
||||
|
||||
|
||||
QStringList GPULoadSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("gpu/load");
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
void GPULoadSource::updateValue()
|
||||
{
|
||||
qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardError()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||
|
||||
if (m_device == "nvidia") {
|
||||
for (auto &str : qoutput.split('\n', Qt::SkipEmptyParts)) {
|
||||
if (!str.contains("<gpu_util>"))
|
||||
continue;
|
||||
auto load = str.remove("<gpu_util>").remove("</gpu_util>").remove('%');
|
||||
m_values["gpu/load"] = load.toFloat();
|
||||
break;
|
||||
}
|
||||
} else if (m_device == "ati") {
|
||||
for (auto &str : qoutput.split('\n', Qt::SkipEmptyParts)) {
|
||||
if (!str.contains("load"))
|
||||
continue;
|
||||
QString load = str.split(' ', Qt::SkipEmptyParts)[3].remove('%');
|
||||
m_values["gpu/load"] = load.toFloat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "gputempsource.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
GPUTemperatureSource::GPUTemperatureSource(QObject *_parent, const QStringList &_args)
|
||||
: AbstractExtSysMonSource(_parent, _args)
|
||||
{
|
||||
Q_ASSERT(_args.count() == 1);
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_device = _args.at(0);
|
||||
|
||||
m_process = new QProcess(nullptr);
|
||||
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
|
||||
connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[this](int, QProcess::ExitStatus) { return updateValue(); });
|
||||
m_process->waitForFinished(0);
|
||||
}
|
||||
|
||||
|
||||
GPUTemperatureSource::~GPUTemperatureSource()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_process->kill();
|
||||
m_process->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
QVariant GPUTemperatureSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
if (_source == "gpu/temperature")
|
||||
run();
|
||||
|
||||
return m_values[_source];
|
||||
}
|
||||
|
||||
|
||||
QVariantMap GPUTemperatureSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "gpu/temperature") {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 0.0;
|
||||
data["name"] = "GPU temperature";
|
||||
data["type"] = "float";
|
||||
data["units"] = "°C";
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void GPUTemperatureSource::run()
|
||||
{
|
||||
if ((m_device != "nvidia") && (m_device != "ati"))
|
||||
return;
|
||||
// build cmd
|
||||
QString cmd = m_device == "nvidia" ? "nvidia-smi" : "aticonfig";
|
||||
auto args = m_device == "nvidia" ? QStringList({"-q", "-x"}) : QStringList({"--od-gettemperature"});
|
||||
qCInfo(LOG_ESS) << "cmd" << cmd;
|
||||
|
||||
m_process->start(cmd, args);
|
||||
}
|
||||
|
||||
|
||||
QStringList GPUTemperatureSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("gpu/temperature");
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
void GPUTemperatureSource::updateValue()
|
||||
{
|
||||
qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardError()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||
|
||||
if (m_device == "nvidia") {
|
||||
for (auto &str : qoutput.split('\n', Qt::SkipEmptyParts)) {
|
||||
if (!str.contains("<gpu_temp>"))
|
||||
continue;
|
||||
QString temp = str.remove("<gpu_temp>").remove("C</gpu_temp>");
|
||||
m_values["gpu/temperature"] = temp.toFloat();
|
||||
break;
|
||||
}
|
||||
} else if (m_device == "ati") {
|
||||
for (auto &str : qoutput.split('\n', Qt::SkipEmptyParts)) {
|
||||
if (!str.contains("Temperature"))
|
||||
continue;
|
||||
QString temp = str.split(' ', Qt::SkipEmptyParts).at(4);
|
||||
m_values["gpu/temperature"] = temp.toFloat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "hddtempsource.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
HDDTemperatureSource::HDDTemperatureSource(QObject *_parent, const QStringList &_args)
|
||||
: AbstractExtSysMonSource(_parent, _args)
|
||||
{
|
||||
Q_ASSERT(_args.count() == 2);
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
m_devices = _args.at(0).split(',', Qt::SkipEmptyParts);
|
||||
m_cmd = _args.at(1).split(' '); // lets hope no one put cmd with spaces here lol
|
||||
|
||||
m_smartctl = m_cmd.contains("smartctl");
|
||||
qCInfo(LOG_ESS) << "Parse as smartctl" << m_smartctl;
|
||||
|
||||
for (auto &device : m_devices) {
|
||||
m_processes[device] = new QProcess(nullptr);
|
||||
// fucking magic from http://doc.qt.io/qt-5/qprocess.html#finished
|
||||
connect(m_processes[device], QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[this, &device](int, QProcess::ExitStatus) { return updateValue(device); });
|
||||
m_processes[device]->waitForFinished(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HDDTemperatureSource::~HDDTemperatureSource()
|
||||
{
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
|
||||
for (auto &device : m_devices) {
|
||||
m_processes[device]->kill();
|
||||
m_processes[device]->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QStringList HDDTemperatureSource::allHdd()
|
||||
{
|
||||
QStringList allDevices = QDir("/dev").entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp("^[hms]d[a-z]$"));
|
||||
for (int i = 0; i < devices.count(); i++)
|
||||
devices[i] = QString("/dev/%1").arg(devices.at(i));
|
||||
|
||||
qCInfo(LOG_ESS) << "Device list" << devices;
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
QVariant HDDTemperatureSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QString device = _source;
|
||||
device.remove("hdd/temperature");
|
||||
// run cmd
|
||||
if (m_processes[device]->state() == QProcess::NotRunning) {
|
||||
auto cmd = m_cmd.first();
|
||||
auto args = m_cmd.mid(1);
|
||||
args.append(device);
|
||||
m_processes[device]->start(cmd, args);
|
||||
}
|
||||
|
||||
return m_values[device];
|
||||
}
|
||||
|
||||
|
||||
QVariantMap HDDTemperatureSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QString device = _source;
|
||||
device.remove("hdd/temperature");
|
||||
QVariantMap data;
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 0.0;
|
||||
data["name"] = QString("HDD '%1' temperature").arg(device);
|
||||
data["type"] = "float";
|
||||
data["units"] = "°C";
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
QStringList HDDTemperatureSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &device : m_devices)
|
||||
sources.append(QString("hdd/temperature%1").arg(device));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
|
||||
void HDDTemperatureSource::updateValue(const QString &_device)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Called with device" << _device;
|
||||
|
||||
qCInfo(LOG_ESS) << "Cmd returns" << m_processes[_device]->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(m_processes[_device]->readAllStandardError()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_processes[_device]->readAllStandardOutput()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||
|
||||
// parse
|
||||
if (m_smartctl) {
|
||||
QStringList lines = qoutput.split('\n', Qt::SkipEmptyParts);
|
||||
for (auto &str : lines) {
|
||||
if (!str.startsWith("194"))
|
||||
continue;
|
||||
if (str.split(' ', Qt::SkipEmptyParts).count() < 9)
|
||||
continue;
|
||||
m_values[_device] = str.split(' ', Qt::SkipEmptyParts).at(9).toFloat();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
QStringList lines = qoutput.split(':', Qt::SkipEmptyParts);
|
||||
if (lines.count() >= 3) {
|
||||
QString temp = lines.at(2);
|
||||
temp.remove(QChar(0260)).remove('C');
|
||||
m_values[_device] = temp.toFloat();
|
||||
}
|
||||
}
|
||||
|
||||
emit(dataReceived(m_values));
|
||||
}
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "loadsource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#include "awdebug.h"
|
||||
@ -45,17 +48,17 @@ QVariant LoadSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap LoadSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *LoadSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source.startsWith("load/load")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Simple sources for load tests";
|
||||
data["type"] = "int";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source.startsWith("load")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Simple sources for load tests";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -66,7 +69,7 @@ QStringList LoadSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
sources.append(QString("load/load%1").arg(i));
|
||||
sources.append(QString("load%1").arg(i));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
explicit LoadSource(QObject *_parent, const QStringList &_args);
|
||||
~LoadSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
};
|
||||
|
@ -18,9 +18,11 @@
|
||||
|
||||
#include "networksource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
@ -58,23 +60,19 @@ QVariant NetworkSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap NetworkSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *NetworkSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "network/current/name") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current network device name";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "network/current/ssid") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current SSID name";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "device") {
|
||||
data->name = "Current network device name";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "ssid") {
|
||||
data->name = "Current SSID name";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -83,16 +81,18 @@ QVariantMap NetworkSource::initialData(const QString &_source) const
|
||||
|
||||
void NetworkSource::run()
|
||||
{
|
||||
m_values["network/current/name"] = NetworkSource::getCurrentDevice();
|
||||
m_process->start("iwgetid", QStringList() << "-r");
|
||||
m_values["device"] = NetworkSource::getCurrentDevice();
|
||||
if (m_process->state() == QProcess::ProcessState::NotRunning) {
|
||||
m_process->start("iwgetid", {"-r"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QStringList NetworkSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("network/current/name");
|
||||
sources.append("network/current/ssid");
|
||||
sources.append("device");
|
||||
sources.append("ssid");
|
||||
|
||||
return sources;
|
||||
}
|
||||
@ -101,12 +101,12 @@ QStringList NetworkSource::sources() const
|
||||
void NetworkSource::updateSsid()
|
||||
{
|
||||
qCInfo(LOG_ESS) << "Cmd returns" << m_process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardError()).trimmed();
|
||||
QString qdebug = QString::fromUtf8(m_process->readAllStandardError()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_process->readAllStandardOutput()).trimmed();
|
||||
QString qoutput = QString::fromUtf8(m_process->readAllStandardOutput()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||
|
||||
m_values["network/current/ssid"] = qoutput;
|
||||
m_values["ssid"] = qoutput;
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
explicit NetworkSource(QObject *_parent, const QStringList &_args);
|
||||
~NetworkSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -18,12 +18,14 @@
|
||||
|
||||
#include "playersource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
@ -88,77 +90,59 @@ QString PlayerSource::getAutoMpris()
|
||||
}
|
||||
|
||||
|
||||
QVariantMap PlayerSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *PlayerSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "player/album") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current song album";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/salbum") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song album (%1 symbols)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/dalbum") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song album (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/artist") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current song artist";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/sartist") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song artist (%1 symbols)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/dartist") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song artist (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/duration") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Current song duration";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "s";
|
||||
} else if (_source == "player/progress") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Current song progress";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "s";
|
||||
} else if (_source == "player/title") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = "Current song title";
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/stitle") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song title (%1 symbols)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source == "player/dtitle") {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Current song title (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "album") {
|
||||
data->name = "Current song album";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "salbum") {
|
||||
data->name = QString("Current song album (%1 symbols)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "dalbum") {
|
||||
data->name = QString("Current song album (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "artist") {
|
||||
data->name = "Current song artist";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "sartist") {
|
||||
data->name = QString("Current song artist (%1 symbols)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "dartist") {
|
||||
data->name = QString("Current song artist (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "duration") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Current song duration";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitSecond;
|
||||
} else if (_source == "progress") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Current song progress";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitSecond;
|
||||
} else if (_source == "title") {
|
||||
data->name = "Current song title";
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "stitle") {
|
||||
data->name = QString("Current song title (%1 symbols)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "dtitle") {
|
||||
data->name = QString("Current song title (%1 symbols, dynamic)").arg(m_symbols);
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -182,33 +166,30 @@ void PlayerSource::run()
|
||||
|
||||
// dymanic properties
|
||||
// solid
|
||||
m_values["player/salbum"] = stripString(m_values["player/album"].toString(), m_symbols);
|
||||
m_values["player/sartist"] = stripString(m_values["player/artist"].toString(), m_symbols);
|
||||
m_values["player/stitle"] = stripString(m_values["player/title"].toString(), m_symbols);
|
||||
m_values["salbum"] = stripString(m_values["album"].toString(), m_symbols);
|
||||
m_values["sartist"] = stripString(m_values["artist"].toString(), m_symbols);
|
||||
m_values["stitle"] = stripString(m_values["title"].toString(), m_symbols);
|
||||
// dynamic
|
||||
m_values["player/dalbum"]
|
||||
= buildString(m_values["player/dalbum"].toString(), m_values["player/album"].toString(), m_symbols);
|
||||
m_values["player/dartist"]
|
||||
= buildString(m_values["player/dartist"].toString(), m_values["player/artist"].toString(), m_symbols);
|
||||
m_values["player/dtitle"]
|
||||
= buildString(m_values["player/dtitle"].toString(), m_values["player/title"].toString(), m_symbols);
|
||||
m_values["dalbum"] = buildString(m_values["dalbum"].toString(), m_values["album"].toString(), m_symbols);
|
||||
m_values["dartist"] = buildString(m_values["dartist"].toString(), m_values["artist"].toString(), m_symbols);
|
||||
m_values["dtitle"] = buildString(m_values["dtitle"].toString(), m_values["title"].toString(), m_symbols);
|
||||
}
|
||||
|
||||
|
||||
QStringList PlayerSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("player/album");
|
||||
sources.append("player/dalbum");
|
||||
sources.append("player/salbum");
|
||||
sources.append("player/artist");
|
||||
sources.append("player/dartist");
|
||||
sources.append("player/sartist");
|
||||
sources.append("player/duration");
|
||||
sources.append("player/progress");
|
||||
sources.append("player/title");
|
||||
sources.append("player/dtitle");
|
||||
sources.append("player/stitle");
|
||||
sources.append("album");
|
||||
sources.append("dalbum");
|
||||
sources.append("salbum");
|
||||
sources.append("artist");
|
||||
sources.append("dartist");
|
||||
sources.append("sartist");
|
||||
sources.append("duration");
|
||||
sources.append("progress");
|
||||
sources.append("title");
|
||||
sources.append("dtitle");
|
||||
sources.append("stitle");
|
||||
|
||||
return sources;
|
||||
}
|
||||
@ -219,7 +200,7 @@ QString PlayerSource::buildString(const QString &_current, const QString &_value
|
||||
qCDebug(LOG_ESS) << "Current value" << _current << "received" << _value << "will be stripped after" << _s;
|
||||
|
||||
int index = _value.indexOf(_current);
|
||||
if ((_current.isEmpty()) || ((index + _s + 1) > _value.count()))
|
||||
if ((_current.isEmpty()) || ((index + _s + 1) > _value.length()))
|
||||
return QString("%1").arg(_value.left(_s), -_s, QLatin1Char(' '));
|
||||
else
|
||||
return QString("%1").arg(_value.mid(index + 1, _s), -_s, QLatin1Char(' '));
|
||||
@ -230,8 +211,8 @@ QString PlayerSource::stripString(const QString &_value, const int _s)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "New value" << _value << "will be stripped after" << _s;
|
||||
|
||||
return _value.count() > _s ? QString("%1\u2026").arg(_value.left(_s - 1))
|
||||
: _value.leftJustified(_s, QLatin1Char(' '));
|
||||
return _value.length() > _s ? QString("%1\u2026").arg(_value.left(_s - 1))
|
||||
: _value.leftJustified(_s, QLatin1Char(' '));
|
||||
}
|
||||
|
||||
|
||||
@ -249,7 +230,7 @@ void PlayerSource::mpdSocketConnected()
|
||||
|
||||
void PlayerSource::mpdSocketReadyRead()
|
||||
{
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(m_mpdSocket.readAll()).trimmed();
|
||||
QString qoutput = QString::fromUtf8(m_mpdSocket.readAll()).trimmed();
|
||||
qCInfo(LOG_ESS) << "Output" << qoutput;
|
||||
|
||||
// parse
|
||||
@ -261,10 +242,10 @@ void PlayerSource::mpdSocketReadyRead()
|
||||
// there are one more time...
|
||||
if ((metadata == "time") && (data.contains(':'))) {
|
||||
QStringList times = data.split(':');
|
||||
m_mpdCached["player/duration"] = times.at(0).toInt();
|
||||
m_mpdCached["player/progress"] = times.at(1).toInt();
|
||||
m_mpdCached["duration"] = times.at(0).toInt();
|
||||
m_mpdCached["progress"] = times.at(1).toInt();
|
||||
} else if (m_metadata.contains(metadata)) {
|
||||
m_mpdCached[QString("player/%1").arg(metadata)] = data;
|
||||
m_mpdCached[metadata] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,11 +263,11 @@ void PlayerSource::mpdSocketWritten(const qint64 _bytes)
|
||||
QVariantHash PlayerSource::defaultInfo()
|
||||
{
|
||||
QVariantHash info;
|
||||
info["player/album"] = "unknown";
|
||||
info["player/artist"] = "unknown";
|
||||
info["player/duration"] = 0;
|
||||
info["player/progress"] = 0;
|
||||
info["player/title"] = "unknown";
|
||||
info["album"] = "unknown";
|
||||
info["artist"] = "unknown";
|
||||
info["duration"] = 0;
|
||||
info["progress"] = 0;
|
||||
info["title"] = "unknown";
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -337,11 +318,11 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString &_mpris)
|
||||
// another portion of dirty magic
|
||||
auto map = qdbus_cast<QVariantHash>(
|
||||
response.arguments().first().value<QDBusVariant>().variant().value<QDBusArgument>());
|
||||
info["player/album"] = map.value("xesam:album", "unknown");
|
||||
info["album"] = map.value("xesam:album", "unknown");
|
||||
// artist is array
|
||||
info["player/artist"] = map.value("xesam:artist", "unknown").toString();
|
||||
info["player/duration"] = map.value("mpris:length", 0).toInt() / (1000 * 1000);
|
||||
info["player/title"] = map.value("xesam:title", "unknown");
|
||||
info["artist"] = map.value("xesam:artist", "unknown").toString();
|
||||
info["duration"] = map.value("mpris:length", 0).toInt() / (1000 * 1000);
|
||||
info["title"] = map.value("xesam:title", "unknown");
|
||||
}
|
||||
|
||||
// position
|
||||
@ -352,8 +333,7 @@ QVariantHash PlayerSource::getPlayerMprisInfo(const QString &_mpris)
|
||||
qCWarning(LOG_ESS) << "Error message" << response.errorMessage();
|
||||
} else {
|
||||
// this cast is simpler than the previous one ;)
|
||||
info["player/progress"]
|
||||
= response.arguments().first().value<QDBusVariant>().variant().toLongLong() / (1000 * 1000);
|
||||
info["progress"] = response.arguments().first().value<QDBusVariant>().variant().toLongLong() / (1000 * 1000);
|
||||
}
|
||||
|
||||
return info;
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
~PlayerSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
static QString getAutoMpris();
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
// additional method to build dynamic tags
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "processessource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include "awdebug.h"
|
||||
@ -48,29 +51,27 @@ QVariant ProcessesSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap ProcessesSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *ProcessesSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "ps/running/count") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Count of running processes";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source == "ps/running/list") {
|
||||
data["min"] = QStringList();
|
||||
data["max"] = QStringList();
|
||||
data["name"] = "All running processes list";
|
||||
data["type"] = "QStringList";
|
||||
data["units"] = "";
|
||||
} else if (_source == "ps/total/count") {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = "Total count of processes";
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "running") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Count of running processes";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "list") {
|
||||
data->name = "All running processes list";
|
||||
data->variantType = QVariant::StringList;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source == "count") {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = "Total count of processes";
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -80,7 +81,7 @@ QVariantMap ProcessesSource::initialData(const QString &_source) const
|
||||
void ProcessesSource::run()
|
||||
{
|
||||
QStringList allDirectories = QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||
QStringList directories = allDirectories.filter(QRegExp("(\\d+)"));
|
||||
QStringList directories = allDirectories.filter(QRegularExpression("(\\d+)"));
|
||||
QStringList running;
|
||||
|
||||
for (auto &dir : directories) {
|
||||
@ -98,18 +99,18 @@ void ProcessesSource::run()
|
||||
cmdFile.close();
|
||||
}
|
||||
|
||||
m_values["ps/running/count"] = running.count();
|
||||
m_values["ps/running/list"] = running;
|
||||
m_values["ps/total/count"] = directories.count();
|
||||
m_values["running"] = running.count();
|
||||
m_values["list"] = running;
|
||||
m_values["count"] = directories.count();
|
||||
}
|
||||
|
||||
|
||||
QStringList ProcessesSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("ps/running/count");
|
||||
sources.append("ps/running/list");
|
||||
sources.append("ps/total/count");
|
||||
sources.append("running");
|
||||
sources.append("list");
|
||||
sources.append("count");
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
explicit ProcessesSource(QObject *_parent, const QStringList &_args);
|
||||
~ProcessesSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "quotessource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extquotes.h"
|
||||
|
||||
@ -45,60 +48,58 @@ QVariant QuotesSource::data(const QString &_source)
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
auto service = _source;
|
||||
service.remove("quotes/");
|
||||
if (!m_values.contains(service)) {
|
||||
if (!m_values.contains(_source)) {
|
||||
QVariantHash data = m_extQuotes->itemByTagNumber(ind)->run();
|
||||
for (auto &key : data.keys())
|
||||
m_values[key] = data[key];
|
||||
}
|
||||
QVariant value = m_values.take(service);
|
||||
QVariant value = m_values.take(_source);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap QuotesSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *QuotesSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
QVariantMap data;
|
||||
if (_source.startsWith("quotes/pricechg")) {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 0.0;
|
||||
data["name"] = QString("Absolute prie changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "double";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("quotes/price")) {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 0.0;
|
||||
data["name"] = QString("Price for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "double";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("quotes/percpricechg")) {
|
||||
data["min"] = -100.0;
|
||||
data["max"] = 100.0;
|
||||
data["name"] = QString("Price changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "double";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("quotes/volumechg")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Absolute volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "int";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("quotes/volume")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Volume for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "int";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("quotes/percvolumechg")) {
|
||||
data["min"] = -100.0;
|
||||
data["max"] = 100.0;
|
||||
data["name"] = QString("Volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "double";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo;
|
||||
if (_source.startsWith("pricechg")) {
|
||||
data->min = 0.0;
|
||||
data->max = 0.0;
|
||||
data->name = QString("Absolute price changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("price")) {
|
||||
data->min = 0.0;
|
||||
data->max = 0.0;
|
||||
data->name = QString("Price for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("percpricechg")) {
|
||||
data->min = -100.0;
|
||||
data->max = 100.0;
|
||||
data->name = QString("Price changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
} else if (_source.startsWith("volumechg")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Absolute volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("volume")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Volume for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("percvolumechg")) {
|
||||
data->min = -100.0;
|
||||
data->max = 100.0;
|
||||
data->name = QString("Volume changes for '%1'").arg(m_extQuotes->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -115,12 +116,12 @@ QStringList QuotesSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &item : m_extQuotes->activeItems()) {
|
||||
sources.append(QString("quotes/%1").arg(item->tag("price")));
|
||||
sources.append(QString("quotes/%1").arg(item->tag("pricechg")));
|
||||
sources.append(QString("quotes/%1").arg(item->tag("percpricechg")));
|
||||
sources.append(QString("quotes/%1").arg(item->tag("volume")));
|
||||
sources.append(QString("quotes/%1").arg(item->tag("volumechg")));
|
||||
sources.append(QString("quotes/%1").arg(item->tag("percvolumechg")));
|
||||
sources.append(item->tag("price"));
|
||||
sources.append(item->tag("pricechg"));
|
||||
sources.append(item->tag("percpricechg"));
|
||||
sources.append(item->tag("volume"));
|
||||
sources.append(item->tag("volumechg"));
|
||||
sources.append(item->tag("percvolumechg"));
|
||||
}
|
||||
|
||||
return sources;
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
explicit QuotesSource(QObject *_parent, const QStringList &_args);
|
||||
~QuotesSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "requestsource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extnetworkrequest.h"
|
||||
|
||||
@ -45,30 +48,26 @@ QVariant RequestSource::data(const QString &_source)
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
auto service = _source;
|
||||
service.remove("network/");
|
||||
if (!m_values.contains(service)) {
|
||||
if (!m_values.contains(_source)) {
|
||||
QVariantHash data = m_extNetRequest->itemByTagNumber(ind)->run();
|
||||
for (auto &key : data.keys())
|
||||
m_values[key] = data[key];
|
||||
}
|
||||
QVariant value = m_values.take(service);
|
||||
QVariant value = m_values.take(_source);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap RequestSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *RequestSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
QVariantMap data;
|
||||
if (_source.startsWith("network/response")) {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Network response for %1").arg(m_extNetRequest->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source.startsWith("response")) {
|
||||
data->name = QString("Network response for %1").arg(m_extNetRequest->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -85,7 +84,7 @@ QStringList RequestSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &item : m_extNetRequest->activeItems())
|
||||
sources.append(QString("network/%1").arg(item->tag("response")));
|
||||
sources.append(item->tag("response"));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
explicit RequestSource(QObject *_parent, const QStringList &_args);
|
||||
~RequestSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "systeminfosource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusVariant>
|
||||
@ -51,23 +54,23 @@ QVariant SystemInfoSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap SystemInfoSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *SystemInfoSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
if (_source == "system/brightness") {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 100.0;
|
||||
data["name"] = "Screen brightness";
|
||||
data["type"] = "float";
|
||||
data["units"] = "%";
|
||||
} else if (_source == "system/volume") {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 100.0;
|
||||
data["name"] = "Master volume";
|
||||
data["type"] = "float";
|
||||
data["units"] = "%";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source == "brightness") {
|
||||
data->min = 0.0;
|
||||
data->max = 100.0;
|
||||
data->name = "Screen brightness";
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
} else if (_source == "volume") {
|
||||
data->min = 0.0;
|
||||
data->max = 100.0;
|
||||
data->name = "Master volume";
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -76,16 +79,16 @@ QVariantMap SystemInfoSource::initialData(const QString &_source) const
|
||||
|
||||
void SystemInfoSource::run()
|
||||
{
|
||||
m_values["system/brightness"] = SystemInfoSource::getCurrentBrightness();
|
||||
m_values["system/volume"] = SystemInfoSource::getCurrentVolume();
|
||||
m_values["brightness"] = SystemInfoSource::getCurrentBrightness();
|
||||
m_values["volume"] = SystemInfoSource::getCurrentVolume();
|
||||
}
|
||||
|
||||
|
||||
QStringList SystemInfoSource::sources() const
|
||||
{
|
||||
QStringList sources;
|
||||
sources.append("system/brightness");
|
||||
sources.append("system/volume");
|
||||
sources.append("brightness");
|
||||
sources.append("volume");
|
||||
|
||||
return sources;
|
||||
}
|
||||
@ -97,24 +100,24 @@ QVariant SystemInfoSource::fromDBusVariant(const QVariant &value)
|
||||
}
|
||||
|
||||
|
||||
float SystemInfoSource::getCurrentBrightness()
|
||||
double SystemInfoSource::getCurrentBrightness()
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Get current brightness";
|
||||
|
||||
auto maxBrightness
|
||||
= sendDBusRequest("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
|
||||
"org.kde.Solid.PowerManagement.Actions.BrightnessControl", "brightnessMax")
|
||||
.toFloat();
|
||||
.toDouble();
|
||||
auto brightness
|
||||
= sendDBusRequest("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
|
||||
"org.kde.Solid.PowerManagement.Actions.BrightnessControl", "brightness")
|
||||
.toFloat();
|
||||
.toDouble();
|
||||
|
||||
return std::round(100.0f * brightness / maxBrightness);
|
||||
return std::round(100.0 * brightness / maxBrightness);
|
||||
}
|
||||
|
||||
|
||||
float SystemInfoSource::getCurrentVolume()
|
||||
double SystemInfoSource::getCurrentVolume()
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Get current volume";
|
||||
|
||||
@ -126,7 +129,7 @@ float SystemInfoSource::getCurrentVolume()
|
||||
|
||||
if (currentMixer.isEmpty()) {
|
||||
qCWarning(LOG_ESS) << "Mixer is empty";
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
currentMixer.replace(":", "_").replace(".", "_").replace("-", "_");
|
||||
|
||||
@ -137,14 +140,14 @@ float SystemInfoSource::getCurrentVolume()
|
||||
.toString();
|
||||
if (currentControl.isEmpty()) {
|
||||
qCWarning(LOG_ESS) << "Control is empty";
|
||||
return std::numeric_limits<float>::quiet_NaN();
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
currentControl.replace(":", "_").replace(".", "_").replace("-", "_");
|
||||
|
||||
auto path = QString("/Mixers/%1/%2").arg(currentMixer).arg(currentControl);
|
||||
return fromDBusVariant(sendDBusRequest("org.kde.kmix", path, "org.freedesktop.DBus.Properties", "Get",
|
||||
QVariantList({"org.kde.KMix.Control", "volume"})))
|
||||
.toFloat();
|
||||
.toDouble();
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
explicit SystemInfoSource(QObject *_parent, const QStringList &_args);
|
||||
~SystemInfoSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
@ -39,8 +39,8 @@ private:
|
||||
// configuration and values
|
||||
QVariantHash m_values;
|
||||
static QVariant fromDBusVariant(const QVariant &value);
|
||||
static float getCurrentBrightness();
|
||||
static float getCurrentVolume();
|
||||
static double getCurrentBrightness();
|
||||
static double getCurrentVolume();
|
||||
static QVariant sendDBusRequest(const QString &destination, const QString &path, const QString &interface,
|
||||
const QString &method, const QVariantList &args = QVariantList());
|
||||
};
|
||||
|
@ -15,41 +15,48 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef HDDTEMPSOURCE_H
|
||||
#define HDDTEMPSOURCE_H
|
||||
#include "timesource.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
class QProcess;
|
||||
|
||||
class HDDTemperatureSource : public AbstractExtSysMonSource
|
||||
TimeSource::TimeSource(QObject *_parent, const QStringList &_args)
|
||||
: AbstractExtSysMonSource(_parent, _args)
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit HDDTemperatureSource(QObject *_parent, const QStringList &_args);
|
||||
~HDDTemperatureSource() override;
|
||||
static QStringList allHdd();
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
private slots:
|
||||
void updateValue(const QString &_device);
|
||||
|
||||
private:
|
||||
// properties
|
||||
QHash<QString, QProcess *> m_processes;
|
||||
// configuration and values
|
||||
QStringList m_cmd;
|
||||
QStringList m_devices;
|
||||
bool m_smartctl;
|
||||
QHash<QString, QVariant> m_values;
|
||||
};
|
||||
Q_ASSERT(_args.count() == 0);
|
||||
qCDebug(LOG_ESS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
#endif /* HDDTEMPSOURCE_H */
|
||||
QVariant TimeSource::data(const QString &_source)
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
if (_source == "now") {
|
||||
return QDateTime::currentSecsSinceEpoch();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
KSysGuard::SensorInfo *TimeSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
data->name = "Current time";
|
||||
data->variantType = QVariant::LongLong;
|
||||
data->unit = KSysGuard::UnitSecond;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
QStringList TimeSource::sources() const
|
||||
{
|
||||
return QStringList({"now"});
|
||||
}
|
@ -15,37 +15,22 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GPUTEMPSOURCE_H
|
||||
#define GPUTEMPSOURCE_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "abstractextsysmonsource.h"
|
||||
#include "extitemaggregator.h"
|
||||
|
||||
|
||||
class QProcess;
|
||||
|
||||
class GPUTemperatureSource : public AbstractExtSysMonSource
|
||||
class TimeSource : public AbstractExtSysMonSource
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GPUTemperatureSource(QObject *_parent, const QStringList &_args);
|
||||
~GPUTemperatureSource() override;
|
||||
explicit TimeSource(QObject *_parent, const QStringList &_args);
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
void run() override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
// configuration and values
|
||||
QString m_device;
|
||||
QProcess *m_process = nullptr;
|
||||
QVariantHash m_values;
|
||||
};
|
||||
|
||||
|
||||
#endif /* GPUTEMPSOURCE_H */
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "upgradesource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extupgrade.h"
|
||||
|
||||
@ -49,16 +52,14 @@ QVariant UpgradeSource::data(const QString &_source)
|
||||
}
|
||||
|
||||
|
||||
QVariantMap UpgradeSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *UpgradeSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
QVariantMap data;
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Package manager '%1' metadata").arg(m_extUpgrade->itemByTagNumber(index(_source))->uniq());
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
data->name = QString("Package manager '%1' metadata").arg(m_extUpgrade->itemByTagNumber(index(_source))->uniq());
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -74,7 +75,7 @@ QStringList UpgradeSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &item : m_extUpgrade->activeItems())
|
||||
sources.append(QString("upgrade/%1").arg(item->tag("pkgcount")));
|
||||
sources.append(item->tag("pkgcount"));
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
explicit UpgradeSource(QObject *_parent, const QStringList &_args);
|
||||
~UpgradeSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
#include "weathersource.h"
|
||||
|
||||
#include <ksysguard/formatter/Unit.h>
|
||||
#include <ksysguard/systemstats/SensorInfo.h>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "extweather.h"
|
||||
|
||||
@ -45,60 +48,52 @@ QVariant WeatherSource::data(const QString &_source)
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
auto service = _source;
|
||||
service.remove("weather/");
|
||||
if (!m_values.contains(service)) {
|
||||
QVariantHash data = m_extWeather->itemByTagNumber(ind)->run();
|
||||
for (auto &key : data.keys())
|
||||
m_values[key] = data[key];
|
||||
if (!m_values.contains(_source)) {
|
||||
auto data = m_extWeather->itemByTagNumber(ind)->run();
|
||||
m_values.insert(data);
|
||||
}
|
||||
QVariant value = m_values.take(service);
|
||||
return value;
|
||||
return m_values.take(_source);
|
||||
}
|
||||
|
||||
|
||||
QVariantMap WeatherSource::initialData(const QString &_source) const
|
||||
KSysGuard::SensorInfo *WeatherSource::initialData(const QString &_source) const
|
||||
{
|
||||
qCDebug(LOG_ESS) << "Source" << _source;
|
||||
|
||||
int ind = index(_source);
|
||||
QVariantMap data;
|
||||
if (_source.startsWith("weather/weatherId")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 1000;
|
||||
data["name"] = QString("Numeric weather ID for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "integer";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("weather/weather")) {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("ID string map for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
} else if (_source.startsWith("weather/humidity")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 100;
|
||||
data["name"] = QString("Humidity for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "integer";
|
||||
data["units"] = "%";
|
||||
} else if (_source.startsWith("weather/pressure")) {
|
||||
data["min"] = 0;
|
||||
data["max"] = 0;
|
||||
data["name"] = QString("Atmospheric pressure for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "integer";
|
||||
data["units"] = "mb";
|
||||
} else if (_source.startsWith("weather/temperature")) {
|
||||
data["min"] = 0.0;
|
||||
data["max"] = 0.0;
|
||||
data["name"] = QString("Temperature for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "float";
|
||||
data["units"] = "°C";
|
||||
} else if (_source.startsWith("weather/timestamp")) {
|
||||
data["min"] = "";
|
||||
data["max"] = "";
|
||||
data["name"] = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data["type"] = "QString";
|
||||
data["units"] = "";
|
||||
auto data = new KSysGuard::SensorInfo();
|
||||
if (_source.startsWith("weatherId")) {
|
||||
data->min = 0;
|
||||
data->max = 1000;
|
||||
data->name = QString("Numeric weather ID for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("weather")) {
|
||||
data->name = QString("ID string map for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::String;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("humidity")) {
|
||||
data->min = 0;
|
||||
data->max = 100;
|
||||
data->name = QString("Humidity for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitPercent;
|
||||
} else if (_source.startsWith("pressure")) {
|
||||
data->min = 0;
|
||||
data->max = 0;
|
||||
data->name = QString("Atmospheric pressure for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Int;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
} else if (_source.startsWith("temperature")) {
|
||||
data->min = 0.0;
|
||||
data->max = 0.0;
|
||||
data->name = QString("Temperature for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::Double;
|
||||
data->unit = KSysGuard::UnitCelsius;
|
||||
} else if (_source.startsWith("timestamp")) {
|
||||
data->name = QString("Timestamp for '%1'").arg(m_extWeather->itemByTagNumber(ind)->uniq());
|
||||
data->variantType = QVariant::DateTime;
|
||||
data->unit = KSysGuard::UnitNone;
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -115,12 +110,12 @@ QStringList WeatherSource::getSources()
|
||||
{
|
||||
QStringList sources;
|
||||
for (auto &item : m_extWeather->activeItems()) {
|
||||
sources.append(QString("weather/%1").arg(item->tag("weatherId")));
|
||||
sources.append(QString("weather/%1").arg(item->tag("weather")));
|
||||
sources.append(QString("weather/%1").arg(item->tag("humidity")));
|
||||
sources.append(QString("weather/%1").arg(item->tag("pressure")));
|
||||
sources.append(QString("weather/%1").arg(item->tag("temperature")));
|
||||
sources.append(QString("weather/%1").arg(item->tag("timestamp")));
|
||||
sources.append(item->tag("weatherId"));
|
||||
sources.append(item->tag("weather"));
|
||||
sources.append(item->tag("humidity"));
|
||||
sources.append(item->tag("pressure"));
|
||||
sources.append(item->tag("temperature"));
|
||||
sources.append(item->tag("timestamp"));
|
||||
}
|
||||
|
||||
return sources;
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
explicit WeatherSource(QObject *_parent, const QStringList &_args);
|
||||
~WeatherSource() override;
|
||||
QVariant data(const QString &_source) override;
|
||||
[[nodiscard]] QVariantMap initialData(const QString &_source) const override;
|
||||
[[nodiscard]] KSysGuard::SensorInfo *initialData(const QString &_source) const override;
|
||||
void run() override{};
|
||||
[[nodiscard]] QStringList sources() const override;
|
||||
|
||||
|
Reference in New Issue
Block a user