Libksysguard
SensorFaceController.cpp
45 const auto list = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KSysguard/SensorFace"));
76 KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), [](const KPluginMetaData &plugin) {
77 return plugin.value(QStringLiteral("X-Plasma-RootPath")) == QStringLiteral("org.kde.plasma.systemmonitor");
82 // We iterate backwards because packages under ~/.local are listed first, while we want them last
86 KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), plugin.pluginId());
103 KConfigGroup configGroup(KSharedConfig::openConfig(p.filePath("config", QStringLiteral("faceproperties")), KConfig::SimpleConfig),
108 // all strings for now, type conversion happens in QML side when we have the config property map
139 std::transform(expected.begin(), expected.end(), std::back_inserter(queries), [this](const QJsonValue &entry) {
141 query->connect(query, &KSysGuard::SensorQuery::finished, controller, [this](SensorQuery *query) {
164QList<QPair<QRegularExpression, QString>> KSysGuard::SensorFaceControllerPrivate::sensorIdReplacements;
165QRegularExpression SensorFaceControllerPrivate::oldDiskSensor = QRegularExpression(QStringLiteral("^disk\\/(.+)_\\(\\d+:\\d+\\)"));
166QRegularExpression SensorFaceControllerPrivate::oldPartitionSensor = QRegularExpression(QStringLiteral("^partitions(\\/.+)\\/"));
177 {QRegularExpression(QStringLiteral("network/all/receivedDataRate$")), QStringLiteral("network/all/download")},
178 {QRegularExpression(QStringLiteral("network/all/sentDataRate$")), QStringLiteral("network/all/upload")},
179 {QRegularExpression(QStringLiteral("network/all/totalReceivedData$")), QStringLiteral("network/all/totalDownload")},
180 {QRegularExpression(QStringLiteral("network/all/totalSentData$")), QStringLiteral("network/all/totalUpload")},
183 {QRegularExpression(QStringLiteral("(.*)/receiver/dataTotal$")), QStringLiteral("\\1/totalDownload")},
184 {QRegularExpression(QStringLiteral("(.*)/transmitter/dataTotal$")), QStringLiteral("\\1/totalUpload")},
193 {QRegularExpression(QStringLiteral("cpu/cpu(\\d+)/clock$")), QStringLiteral("cpu/cpu\\1/frequency")},
195 {QRegularExpression(QStringLiteral("mem/physical/allocated")), QStringLiteral("memory/physical/used")},
196 {QRegularExpression(QStringLiteral("mem/physical/available")), QStringLiteral("memory/physical/free")},
197 {QRegularExpression(QStringLiteral("mem/physical/buf")), QStringLiteral("memory/physical/buffer")},
198 {QRegularExpression(QStringLiteral("mem/physical/cached")), QStringLiteral("memory/physical/cache")},
200 {QRegularExpression(QStringLiteral("nvidia/(.*)/temperature$")), QStringLiteral("gpu/\\1/temperature")},
201 {QRegularExpression(QStringLiteral("nvidia/(.*)/memoryClock$")), QStringLiteral("gpu/\\1/memoryFrequency")},
202 {QRegularExpression(QStringLiteral("nvidia/(.*)/processorClock$")), QStringLiteral("gpu/\\1/coreFrequency")},
203 {QRegularExpression(QStringLiteral("nvidia/(.*)/(memory|sharedMemory)$")), QStringLiteral("gpu/\\1/usedVram")},
204 {QRegularExpression(QStringLiteral("nvidia/(.*)/(encoderUsage|decoderUsage)$")), QStringLiteral("gpu/\\1/usage")},
205 {QRegularExpression(QStringLiteral("^(uptime|system/uptime/uptime)$")), QStringLiteral("os/system/uptime")},
218 predicate &= Solid::Predicate(Solid::DeviceInterface::Block, QStringLiteral("device"), QStringLiteral("/dev/%1").arg(device));
241 const QString filePath = match.captured(1) == QLatin1String("/__root__") ? QStringLiteral("/") : match.captured(1);
242 const Solid::Predicate predicate(Solid::DeviceInterface::StorageAccess, QStringLiteral("filePath"), filePath);
252QJsonArray SensorFaceControllerPrivate::readSensors(const KConfigGroup &read, const QString &entryName)
272QJsonArray SensorFaceControllerPrivate::readAndUpdateSensors(KConfigGroup &config, const QString &entryName)
274 auto original = QJsonDocument::fromJson(config.readEntry(entryName, QString()).toUtf8()).array();
286void SensorFaceControllerPrivate::resolveSensors(const QJsonArray &partialEntries, std::function<void(SensorResolver *)> callback)
307 // TODO: eventually support async components? (only useful for qml files from http, we probably don't want that)
338QQuickItem *SensorFaceControllerPrivate::createConfigUi(const QString &file, const QVariantMap &initialProperties)
341 // TODO: eventually support async components? (only useful for qml files from http, we probably don't want that)
388 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("totalSensors")), [this](SensorResolver *resolver) {
392 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("lowPrioritySensorIds")), [this](SensorResolver *resolver) {
396 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("highPrioritySensorIds")), [this](SensorResolver *resolver) {
483 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("totalSensors").toUtf8()).array();
487 d->sensorsGroup.writeEntry("totalSensors", QJsonDocument(totalSensors).toJson(QJsonDocument::Compact));
511 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("highPrioritySensorIds").toUtf8()).array();
515 d->sensorsGroup.writeEntry("highPrioritySensorIds", QJsonDocument(highPrioritySensorIds).toJson(QJsonDocument::Compact));
604 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("lowPrioritySensorIds").toUtf8()).array();
608 d->sensorsGroup.writeEntry("lowPrioritySensorIds", QJsonDocument(lowPrioritySensorIds).toJson(QJsonDocument::Compact));
707 d->facePackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KSysguard/SensorFace"), face);
725 d->faceProperties = KConfigGroup(KSharedConfig::openConfig(d->facePackage.filePath("FaceProperties"), KConfig::SimpleConfig), QStringLiteral("Config"));
758 d->compactRepresentation = d->createGui(d->facePackage.filePath("ui", QStringLiteral("CompactRepresentation.qml")));
770 d->fullRepresentation = d->createGui(d->facePackage.filePath("ui", QStringLiteral("FullRepresentation.qml")));
789 {{QStringLiteral("controller"), QVariant::fromValue(this)}, {QStringLiteral("source"), QUrl::fromLocalFile(filePath)}});
804 d->appearanceConfigUi = d->createConfigUi(QStringLiteral(":/ConfigAppearance.qml"), {{QStringLiteral("controller"), QVariant::fromValue(this)}});
816 d->sensorsConfigUi = d->createConfigUi(QStringLiteral(":/ConfigSensors.qml"), {{QStringLiteral("controller"), QVariant::fromValue(this)}});
853 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("totalSensors")), [this](SensorResolver *resolver) {
857 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("lowPrioritySensorIds")), [this](SensorResolver *resolver) {
861 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("highPrioritySensorIds")), [this](SensorResolver *resolver) {
881 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
889 if (presetPackage.metadata().value(QStringLiteral("X-Plasma-RootPath")) != QStringLiteral("org.kde.plasma.systemmonitor")) {
893 auto c = KSharedConfig::openConfig(presetPackage.filePath("config", QStringLiteral("faceproperties")), KConfig::SimpleConfig);
901 if (d->availablePresetsModel && d->availablePresetsModel->data(d->availablePresetsModel->index(0, 0), PresetsModel::PluginIdRole).toString().isEmpty()) {
909 setFaceId(presetGroup.readEntry(QStringLiteral("chartFace"), QStringLiteral("org.kde.ksysguard.piechart")));
915 KConfigGroup presetGroup(KSharedConfig::openConfig(presetPackage.filePath("FaceProperties"), KConfig::SimpleConfig), QStringLiteral("FaceConfig"));
934 QString pluginName = QStringLiteral("org.kde.plasma.systemmonitor.") + title().simplified().replace(QLatin1Char(' '), QStringLiteral("")).toLower();
937 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
974 if (QFile file{dir.path() % QStringLiteral("/metadata.json")}; file.open(QIODevice::WriteOnly)) {
987 configGroup.writeEntry(QStringLiteral("totalSensors"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
989 configGroup.writeEntry(QStringLiteral("highPrioritySensorIds"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
991 configGroup.writeEntry(QStringLiteral("lowPrioritySensorIds"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
1015 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), pluginId);
1017 if (presetPackage.metadata().value(QStringLiteral("X-Plasma-RootPath")) != QStringLiteral("org.kde.plasma.systemmonitor")) {
1023 auto *job = KPackage::PackageJob::uninstall(QStringLiteral("Plasma/Applet"), pluginId, root.path());
1061 connect(d->faceConfiguration, &KConfigPropertyMap::valueChanged, this, [this](const QString &key) {
1075 auto array = QJsonDocument::fromJson(d->sensorsGroup.readEntry(configEntry, QString()).toUtf8()).array();
1085 d->sensorsGroup.writeEntry("highPrioritySensorIds", replaceSensors(QStringLiteral("highPrioritySensorIds")));
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
bool sync() override
QStringList keyList() const
void copyTo(KConfigBase *other, WriteConfigFlags pFlags=Normal) const
virtual void setProperty(const QVariant &p)=0
virtual QVariant property() const=0
SimpleConfig
void finished(KJob *job)
static PackageJob * uninstall(const QString &packageFormat, const QString &pluginId, const QString &packageRoot=QString())
static PackageJob * install(const QString &packageFormat, const QString &sourcePackage, const QString &packageRoot=QString())
QList< KPluginMetaData > findPackages(const QString &packageFormat, const QString &packageRoot=QString(), std::function< bool(const KPluginMetaData &)> filter=std::function< bool(const KPluginMetaData &)>())
Package loadPackage(const QString &packageFormat, const QString &packagePath=QString())
static PackageLoader * self()
QList< KPluginMetaData > listPackages(const QString &packageFormat, const QString &packageRoot=QString())
void setPath(const QString &path)
QString filePath(const QByteArray &key, const QString &filename=QString()) const
KPluginMetaData metadata() const
QString pluginId() const
bool value(const QString &key, bool defaultValue) const
QString fileName() const
The SensorFaceController links sensor faces and applications in which these faces are shown.
Definition SensorFaceController.h:42
int updateRateLimit
The minimum time that needs to elapse, in milliseconds, between updates of the face.
Definition SensorFaceController.h:158
KConfigPropertyMap * faceConfiguration
A map of config options and values that are specific to the current face as defined by the main....
Definition SensorFaceController.h:113
QAbstractItemModel * availablePresetsModel
A list of available face presets.
Definition SensorFaceController.h:154
QVariantMap sensorLabels
Maps sensorIds to user configurable labels than should be displayed instead of the name of the sensor...
Definition SensorFaceController.h:76
QJsonArray totalSensors
Sensors that are typically used to display a total in some way or form.
Definition SensorFaceController.h:61
Q_INVOKABLE void replaceSensors(const QString &from, const QString &to)
Replace one sensor with another.
Definition SensorFaceController.cpp:1072
bool shouldSync() const
Whether the controller should sync configuration changes.
Definition SensorFaceController.cpp:1030
SensorFaceController(KConfigGroup &config, QQmlEngine *engine)
Creates a new SensorFaceController.
Definition SensorFaceController.cpp:364
QJsonArray missingSensors
Contains the paths of missing sensors, if there are any.
Definition SensorFaceController.h:162
QJsonArray highPrioritySensorIds
Sensors that should always be shown in the face.
Definition SensorFaceController.h:66
QQuickItem * sensorsConfigUi
A user interface for configuring which sensors are displayed in a face Emits configurationChanged if ...
Definition SensorFaceController.h:144
Q_INVOKABLE void loadPreset(const QString &preset)
Loads a specific preset.
Definition SensorFaceController.cpp:875
void setShouldSync(bool sync)
Specifies if the controller should automatically sync configuration changes.
Definition SensorFaceController.cpp:1035
QQuickItem * faceConfigUi
A user interface that is suited for configuring the face specific options.
Definition SensorFaceController.h:131
Q_INVOKABLE void savePreset()
Save the current configuration as a preset.
Definition SensorFaceController.cpp:932
KConfigGroup configGroup() const
Retrieve the KConfigGroup this controller is using to store configuration.
Definition SensorFaceController.cpp:428
QQuickItem * appearanceConfigUi
A user interface for configuring the general appearance of a face like the title and the used face.
Definition SensorFaceController.h:138
QQuickItem * compactRepresentation
The compact representation of the current face.
Definition SensorFaceController.h:124
int maxTotalSensors
The amount of total sensors the current face supports.
Definition SensorFaceController.h:107
bool showTitle
Whether the title should be displayed or if it should be hidden instead.
Definition SensorFaceController.h:52
bool supportsLowPrioritySensors
Whether the current face can display low priority sensors.
Definition SensorFaceController.h:103
bool supportsTotalSensors
Whether the current face can display total sensors.
Definition SensorFaceController.h:99
Q_INVOKABLE void uninstallPreset(const QString &pluginId)
Uninstall a specific preset.
Definition SensorFaceController.cpp:1013
QAbstractItemModel * availableFacesModel
A list of all available faces.
Definition SensorFaceController.h:149
QQuickItem * fullRepresentation
The full representation of the current face.
Definition SensorFaceController.h:119
bool supportsSensorsColors
Whether the current face supports sensor colors.
Definition SensorFaceController.h:95
Q_INVOKABLE void reloadFaceConfiguration()
Reload only the face configuration.
Definition SensorFaceController.cpp:1043
QVariantMap sensorColors
Maps sensorIds to colors that can be used when a color for something relating to a specific sensor is...
Definition SensorFaceController.h:71
An object to query the daemon for a list of sensors and their metadata.
Definition SensorQuery.h:26
static QList< Device > listFromQuery(const Predicate &predicate, const QString &parentUdi=QString())
QString i18n(const char *text, const TYPE &arg...)
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
qreal volume()
QVariant read(const QByteArray &data, int versionOverride=0)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & reload()
QString label(StandardShortcut id)
QString name(StandardShortcut id)
virtual QHash< int, QByteArray > roleNames() const const
bool isValid() const const
bool cdUp()
bool mkpath(const QString &dirPath) const const
QString path() const const
bool isWritable() const const
WriteOnly
void append(const QJsonValue &value)
iterator begin()
iterator end()
Compact
QJsonArray array() const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
void setObject(const QJsonObject &object)
QByteArray toJson(JsonFormat format) const const
reverse_iterator rbegin()
reverse_iterator rend()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
void setParent(QObject *parent)
Ready
virtual QObject * beginCreate(QQmlContext *context)
virtual void completeCreate()
QObject * createWithInitialProperties(const QVariantMap &initialProperties, QQmlContext *context)
status
void setContextObject(QObject *object)
void valueChanged(const QString &key, const QVariant &value)
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
bool contains(const QSet< T > &other) const const
virtual void setData(const QVariant &value, int role)
void appendRow(QStandardItem *item)
void clear()
virtual QVariant data(const QModelIndex &index, int role) const const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QStandardItem * item(int row, int column) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString simplified() const const
QString toLower() const const
void timeout()
QUrl fromLocalFile(const QString &localFile)
StringList
Type type() const const
QVariant fromValue(T &&value)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.