initial plasma6 support

This commit is contained in:
2024-03-07 12:09:46 +02:00
parent eecb128865
commit 4d01b87088
176 changed files with 2569 additions and 3795 deletions

View File

@ -1,4 +1,4 @@
set(SUBPROJECT plasma_dataengine_extsysmon)
set(SUBPROJECT ksystemstats_plugin_extsysmon)
message(STATUS "Subproject ${SUBPROJECT}")
add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.plasma.awesomewidget\")
@ -9,27 +9,19 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE}
${Kf6_INCLUDE}
)
file(GLOB SUBPROJECT_DESKTOP_IN *.desktop)
file(RELATIVE_PATH SUBPROJECT_DESKTOP ${CMAKE_SOURCE_DIR} ${SUBPROJECT_DESKTOP_IN})
file(GLOB SUBPROJECT_SOURCE *.cpp ${CMAKE_SOURCE_DIR}/*.cpp)
file(GLOB SUBPROJECT_HEADER *.h)
file(GLOB SUBPROJECT_CONF *.conf)
# prepare
configure_file(${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
# make
add_library(${SUBPROJECT} MODULE ${SUBPROJECT_SOURCE} ${SUBPROJECT_HEADER})
target_link_libraries(${SUBPROJECT}
${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES}
${Qt_LIBRARIES} ${Kf5_LIBRARIES})
kcoreaddons_desktop_to_json(${SUBPROJECT} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP}
SERVICE_TYPES plasma-dataengine.desktop)
${Qt_LIBRARIES} ${Kf6_LIBRARIES})
# install
install(TARGETS ${SUBPROJECT} DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES ${SUBPROJECT_CONF} DESTINATION ${CONFIG_INSTALL_DIR})
install(TARGETS ${SUBPROJECT} DESTINATION ${KDE_INSTALL_PLUGINDIR}/ksystemstats)
install(FILES ${SUBPROJECT_CONF} DESTINATION /${KDE_INSTALL_CONFDIR})

View File

@ -17,85 +17,40 @@
#include "extsysmon.h"
#include <KPluginFactory>
#include <QDBusMetaType>
#include <QFile>
#include <QRegularExpression>
#include <QSettings>
#include <QStandardPaths>
#include "awdebug.h"
#include "extsysmonaggregator.h"
#include "gpuloadsource.h"
#include "hddtempsource.h"
ExtendedSysMon::ExtendedSysMon(QObject *_parent, const QVariantList &_args)
: Plasma::DataEngine(_parent, _args)
: KSysGuard::SensorPlugin(_parent, _args)
{
Q_UNUSED(_args)
qSetMessagePattern(AWDebug::LOG_FORMAT);
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
for (auto &metadata : AWDebug::getBuildData())
qCDebug(LOG_ESM) << metadata;
setMinimumPollingInterval(333);
readConfiguration();
// init aggregator
m_aggregator = new ExtSysMonAggregator(this, m_configuration);
for (auto &source : m_aggregator->sources())
setData(source, m_aggregator->initialData(source));
}
ExtendedSysMon::~ExtendedSysMon()
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
}
QStringList ExtendedSysMon::sources() const
{
return m_aggregator->sources();
}
bool ExtendedSysMon::sourceRequestEvent(const QString &_source)
{
qCDebug(LOG_ESM) << "Source" << _source;
return updateSourceEvent(_source);
}
bool ExtendedSysMon::updateSourceEvent(const QString &_source)
{
qCDebug(LOG_ESM) << "Source" << _source;
if (m_aggregator->hasSource(_source)) {
QVariant data = m_aggregator->data(_source);
if (data.isNull())
return false;
setData(_source, "value", data);
} else {
qCWarning(LOG_ESM) << "Unknown source" << _source;
return false;
}
return true;
addContainer(new ExtSysMonAggregator("extsysmon", "Extended system monitor", this, m_configuration));
}
void ExtendedSysMon::readConfiguration()
{
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
auto fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
qCInfo(LOG_ESM) << "Configuration file" << fileName;
QSettings settings(fileName, QSettings::IniFormat);
QHash<QString, QString> rawConfig;
settings.beginGroup("Configuration");
rawConfig["ACPIPATH"] = settings.value("ACPIPATH", "/sys/class/power_supply/").toString();
rawConfig["GPUDEV"] = settings.value("GPUDEV", "auto").toString();
rawConfig["HDDDEV"] = settings.value("HDDDEV", "all").toString();
rawConfig["HDDTEMPCMD"] = settings.value("HDDTEMPCMD", "sudo smartctl -a").toString();
rawConfig["MPDADDRESS"] = settings.value("MPDADDRESS", "localhost").toString();
rawConfig["MPDPORT"] = settings.value("MPDPORT", "6600").toString();
rawConfig["MPRIS"] = settings.value("MPRIS", "auto").toString();
@ -111,31 +66,6 @@ QHash<QString, QString> ExtendedSysMon::updateConfiguration(QHash<QString, QStri
{
qCDebug(LOG_ESM) << "Raw configuration" << _rawConfig;
// gpudev
if (_rawConfig["GPUDEV"] == "disable")
;
else if (_rawConfig["GPUDEV"] == "auto")
_rawConfig["GPUDEV"] = GPULoadSource::autoGpu();
else if ((_rawConfig["GPUDEV"] != "ati") && (_rawConfig["GPUDEV"] != "nvidia"))
_rawConfig["GPUDEV"] = GPULoadSource::autoGpu();
// hdddev
QStringList allHddDevices = HDDTemperatureSource::allHdd();
if (_rawConfig["HDDDEV"] == "all") {
_rawConfig["HDDDEV"] = allHddDevices.join(',');
} else if (_rawConfig["HDDDEV"] == "disable") {
_rawConfig["HDDDEV"] = "";
} else {
QStringList deviceList = _rawConfig["HDDDEV"].split(',', Qt::SkipEmptyParts);
QStringList devices;
QRegExp diskRegexp = QRegExp("^/dev/[hms]d[a-z]$");
for (auto &device : deviceList)
if ((QFile::exists(device)) && (device.contains(diskRegexp)))
devices.append(device);
if (devices.isEmpty())
_rawConfig["HDDDEV"] = allHddDevices.join(',');
else
_rawConfig["HDDDEV"] = devices.join(',');
}
// player
if ((_rawConfig["PLAYER"] != "mpd") && (_rawConfig["PLAYER"] != "mpris") && (_rawConfig["PLAYER"] != "disable"))
_rawConfig["PLAYER"] = "mpris";
@ -149,6 +79,6 @@ QHash<QString, QString> ExtendedSysMon::updateConfiguration(QHash<QString, QStri
}
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(extsysmon, ExtendedSysMon, "plasma-dataengine-extsysmon.json")
K_PLUGIN_CLASS_WITH_JSON(ExtendedSysMon, "metadata.json")
#include "extsysmon.moc"

View File

@ -18,27 +18,19 @@
#ifndef EXTSYSMON_H
#define EXTSYSMON_H
#include <Plasma/DataEngine>
#include <ksysguard/systemstats/SensorPlugin.h>
class ExtSysMonAggregator;
class ExtendedSysMon : public Plasma::DataEngine
class ExtendedSysMon : public KSysGuard::SensorPlugin
{
Q_OBJECT
public:
explicit ExtendedSysMon(QObject *_parent, const QVariantList &_args);
~ExtendedSysMon() override;
protected:
[[nodiscard]] QStringList sources() const override;
bool sourceRequestEvent(const QString &_source) override;
bool updateSourceEvent(const QString &_source) override;
[[nodiscard]] QString providerName() const override { return QStringLiteral("extsysmon"); }
private:
// configuration
ExtSysMonAggregator *m_aggregator = nullptr;
QHash<QString, QString> m_configuration;
// methods
void readConfiguration();

View File

@ -21,9 +21,7 @@
#include "batterysource.h"
#include "customsource.h"
#include "desktopsource.h"
#include "gpuloadsource.h"
#include "gputempsource.h"
#include "hddtempsource.h"
#include "extsysmonsensor.h"
#include "loadsource.h"
#include "networksource.h"
#include "playersource.h"
@ -31,12 +29,14 @@
#include "quotessource.h"
#include "requestsource.h"
#include "systeminfosource.h"
#include "timesource.h"
#include "upgradesource.h"
#include "weathersource.h"
ExtSysMonAggregator::ExtSysMonAggregator(QObject *_parent, const QHash<QString, QString> &_config)
: QObject(_parent)
ExtSysMonAggregator::ExtSysMonAggregator(const QString &_id, const QString &_name, KSysGuard::SensorPlugin *_parent,
const QHash<QString, QString> &_config)
: KSysGuard::SensorContainer(_id, _name, _parent)
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
@ -44,41 +44,11 @@ ExtSysMonAggregator::ExtSysMonAggregator(QObject *_parent, const QHash<QString,
}
ExtSysMonAggregator::~ExtSysMonAggregator()
void ExtSysMonAggregator::createSensor(const QString &_id, const QString &_name, AbstractExtSysMonSource *_source)
{
qCDebug(LOG_ESM) << __PRETTY_FUNCTION__;
qCDebug(LOG_ESM) << "Register sensor" << _name << "with id" << _id;
m_map.clear();
}
QVariant ExtSysMonAggregator::data(const QString &_source) const
{
qCDebug(LOG_ESM) << "Source" << _source;
return m_map[_source]->data(_source);
}
bool ExtSysMonAggregator::hasSource(const QString &_source) const
{
qCDebug(LOG_ESM) << "Source" << _source;
return m_map.contains(_source);
}
QVariantMap ExtSysMonAggregator::initialData(const QString &_source) const
{
qCDebug(LOG_ESM) << "Source" << _source;
return hasSource(_source) ? m_map[_source]->initialData(_source) : QVariantMap();
}
QStringList ExtSysMonAggregator::sources() const
{
return m_map.keys();
addObject(new ExtSysMonSensor(this, _id, _name, _source));
}
@ -87,68 +57,34 @@ void ExtSysMonAggregator::init(const QHash<QString, QString> &_config)
qCDebug(LOG_ESM) << "Configuration" << _config;
// battery
AbstractExtSysMonSource *batteryItem = new BatterySource(this, QStringList() << _config["ACPIPATH"]);
for (auto &source : batteryItem->sources())
m_map[source] = batteryItem;
createSensor("battery", i18n("Battery"), new BatterySource(this, {_config["ACPIPATH"]}));
// custom
AbstractExtSysMonSource *customItem = new CustomSource(this, QStringList());
for (auto &source : customItem->sources())
m_map[source] = customItem;
createSensor("custom", i18n("Scripts"), new CustomSource(this, {}));
// desktop
AbstractExtSysMonSource *desktopItem = new DesktopSource(this, QStringList());
for (auto &source : desktopItem->sources())
m_map[source] = desktopItem;
// gpu load
AbstractExtSysMonSource *gpuLoadItem = new GPULoadSource(this, QStringList({_config["GPUDEV"]}));
for (auto &source : gpuLoadItem->sources())
m_map[source] = gpuLoadItem;
// gpu temperature
AbstractExtSysMonSource *gpuTempItem = new GPUTemperatureSource(this, QStringList({_config["GPUDEV"]}));
for (auto &source : gpuTempItem->sources())
m_map[source] = gpuTempItem;
// hdd temperature
AbstractExtSysMonSource *hddTempItem
= new HDDTemperatureSource(this, QStringList({_config["HDDDEV"], _config["HDDTEMPCMD"]}));
for (auto &source : hddTempItem->sources())
m_map[source] = hddTempItem;
// FIXME causes segfault in kde libs
// createSensor("desktop", i18n("Desktop"), new DesktopSource(this, {}));
// network
AbstractExtSysMonSource *networkItem = new NetworkSource(this, QStringList());
for (auto &source : networkItem->sources())
m_map[source] = networkItem;
createSensor("network", i18n("Network"), new NetworkSource(this, {}));
// player
AbstractExtSysMonSource *playerItem
= new PlayerSource(this, QStringList({_config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"],
_config["MPRIS"], _config["PLAYERSYMBOLS"]}));
for (auto &source : playerItem->sources())
m_map[source] = playerItem;
createSensor("player", i18n("Music player"),
new PlayerSource(this, {_config["PLAYER"], _config["MPDADDRESS"], _config["MPDPORT"], _config["MPRIS"],
_config["PLAYERSYMBOLS"]}));
// processes
AbstractExtSysMonSource *processesItem = new ProcessesSource(this, QStringList());
for (auto &source : processesItem->sources())
m_map[source] = processesItem;
createSensor("ps", i18n("Processes"), new ProcessesSource(this, {}));
// network request
AbstractExtSysMonSource *requestItem = new RequestSource(this, QStringList());
for (auto &source : requestItem->sources())
m_map[source] = requestItem;
createSensor("requests", i18n("Network requests"), new RequestSource(this, {}));
// quotes
AbstractExtSysMonSource *quotesItem = new QuotesSource(this, QStringList());
for (auto &source : quotesItem->sources())
m_map[source] = quotesItem;
createSensor("quotes", i18n("Quotes"), new QuotesSource(this, {}));
// system
AbstractExtSysMonSource *systemItem = new SystemInfoSource(this, QStringList());
for (auto &source : systemItem->sources())
m_map[source] = systemItem;
createSensor("system", i18n("System"), new SystemInfoSource(this, {}));
// current time
createSensor("time", i18n("Time"), new TimeSource(this, {}));
// upgrade
AbstractExtSysMonSource *upgradeItem = new UpgradeSource(this, QStringList());
for (auto &source : upgradeItem->sources())
m_map[source] = upgradeItem;
createSensor("upgrade", i18n("Upgrades"), new UpgradeSource(this, {}));
// weather
AbstractExtSysMonSource *weatherItem = new WeatherSource(this, QStringList());
for (auto &source : weatherItem->sources())
m_map[source] = weatherItem;
createSensor("weather", i18n("Weather"), new WeatherSource(this, {}));
#ifdef BUILD_LOAD
// additional load source
AbstractExtSysMonSource *loadItem = new LoadSource(this, QStringList());
for (auto &source : loadItem->sources())
m_map[source] = loadItem;
createSensor("load", i18n("Load"), new LoadSource(this, {}));
#endif /* BUILD_LOAD */
}

View File

@ -15,30 +15,26 @@
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef EXTSYSMONAGGREGATOR_H
#define EXTSYSMONAGGREGATOR_H
#pragma once
#include <QObject>
#include <ksysguard/systemstats/SensorContainer.h>
#include "abstractextsysmonsource.h"
class ExtSysMonAggregator : public QObject
class AbstractExtSysMonSource;
class ExtSysMonSensor;
class ExtSysMonAggregator : public KSysGuard::SensorContainer
{
Q_OBJECT
public:
explicit ExtSysMonAggregator(QObject *_parent, const QHash<QString, QString> &_config);
~ExtSysMonAggregator() override;
[[nodiscard]] QVariant data(const QString &_source) const;
[[nodiscard]] bool hasSource(const QString &_source) const;
[[nodiscard]] QVariantMap initialData(const QString &_source) const;
[[nodiscard]] QStringList sources() const;
explicit ExtSysMonAggregator(const QString &_id, const QString &_name, KSysGuard::SensorPlugin *_parent,
const QHash<QString, QString> &_config);
private:
void createSensor(const QString &_id, const QString &_name, AbstractExtSysMonSource *_source);
void init(const QHash<QString, QString> &_config);
QHash<QString, AbstractExtSysMonSource *> m_map;
};
#endif /* EXTSYSMONAGGREGATOR_H */

View File

@ -0,0 +1,3 @@
{
"providerName": "extsysmon"
}

View File

@ -1,13 +1,6 @@
[Configuration]
# ACPI devices
ACPIPATH=/sys/class/power_supply/
# May be 'nvidia' (for nvidia), 'ati' (for ATI RADEON), 'disable' or 'auto'
GPUDEV=auto
# HDD temperature
## Set block device for hddtemp comma separated or use 'all' or 'disable'
HDDDEV=all
# cmd
HDDTEMPCMD=sudo smartctl -a
# mpd server settings
MPDADDRESS=localhost
MPDPORT=6600

View File

@ -1,16 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=Extended SystemMonitor
Comment=Adds some additional functions to System DataEngine
ServiceTypes=Plasma/DataEngine
Type=Service
Icon=utilities-system-monitor
X-KDE-Library=plasma_dataengine_extsysmon
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=extsysmon
X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-License=GPL3