Libksysguard
SensorFaceController.cpp
47 const auto list = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KSysguard/SensorFace"));
78 KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), [](const KPluginMetaData &plugin) {
79 return plugin.value(QStringLiteral("X-Plasma-RootPath")) == QStringLiteral("org.kde.plasma.systemmonitor");
84 // We iterate backwards because packages under ~/.local are listed first, while we want them last
88 KPackage::Package p = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), plugin.pluginId());
105 KConfigGroup configGroup(KSharedConfig::openConfig(p.filePath("config", QStringLiteral("faceproperties")), KConfig::SimpleConfig),
110 // all strings for now, type conversion happens in QML side when we have the config property map
141 std::transform(expected.begin(), expected.end(), std::back_inserter(queries), [this](const QJsonValue &entry) -> SensorQuery * {
147 query->connect(query, &KSysGuard::SensorQuery::finished, controller, [this](SensorQuery *query) {
172QList<QPair<QRegularExpression, QString>> KSysGuard::SensorFaceControllerPrivate::sensorIdReplacements;
173QRegularExpression SensorFaceControllerPrivate::oldDiskSensor = QRegularExpression(QStringLiteral("^disk\\/(.+)_\\(\\d+:\\d+\\)"));
174QRegularExpression SensorFaceControllerPrivate::oldPartitionSensor = QRegularExpression(QStringLiteral("^partitions(\\/.+)\\/"));
185 {QRegularExpression(QStringLiteral("network/all/receivedDataRate$")), QStringLiteral("network/all/download")},
186 {QRegularExpression(QStringLiteral("network/all/sentDataRate$")), QStringLiteral("network/all/upload")},
187 {QRegularExpression(QStringLiteral("network/all/totalReceivedData$")), QStringLiteral("network/all/totalDownload")},
188 {QRegularExpression(QStringLiteral("network/all/totalSentData$")), QStringLiteral("network/all/totalUpload")},
191 {QRegularExpression(QStringLiteral("(.*)/receiver/dataTotal$")), QStringLiteral("\\1/totalDownload")},
192 {QRegularExpression(QStringLiteral("(.*)/transmitter/dataTotal$")), QStringLiteral("\\1/totalUpload")},
201 {QRegularExpression(QStringLiteral("cpu/cpu(\\d+)/clock$")), QStringLiteral("cpu/cpu\\1/frequency")},
203 {QRegularExpression(QStringLiteral("mem/physical/allocated")), QStringLiteral("memory/physical/used")},
204 {QRegularExpression(QStringLiteral("mem/physical/available")), QStringLiteral("memory/physical/free")},
205 {QRegularExpression(QStringLiteral("mem/physical/buf")), QStringLiteral("memory/physical/buffer")},
206 {QRegularExpression(QStringLiteral("mem/physical/cached")), QStringLiteral("memory/physical/cache")},
208 {QRegularExpression(QStringLiteral("nvidia/(.*)/temperature$")), QStringLiteral("gpu/\\1/temperature")},
209 {QRegularExpression(QStringLiteral("nvidia/(.*)/memoryClock$")), QStringLiteral("gpu/\\1/memoryFrequency")},
210 {QRegularExpression(QStringLiteral("nvidia/(.*)/processorClock$")), QStringLiteral("gpu/\\1/coreFrequency")},
211 {QRegularExpression(QStringLiteral("nvidia/(.*)/(memory|sharedMemory)$")), QStringLiteral("gpu/\\1/usedVram")},
212 {QRegularExpression(QStringLiteral("nvidia/(.*)/(encoderUsage|decoderUsage)$")), QStringLiteral("gpu/\\1/usage")},
213 {QRegularExpression(QStringLiteral("^(uptime|system/uptime/uptime)$")), QStringLiteral("os/system/uptime")},
226 predicate &= Solid::Predicate(Solid::DeviceInterface::Block, QStringLiteral("device"), QStringLiteral("/dev/%1").arg(device));
249 const QString filePath = match.captured(1) == QLatin1String("/__root__") ? QStringLiteral("/") : match.captured(1);
250 const Solid::Predicate predicate(Solid::DeviceInterface::StorageAccess, QStringLiteral("filePath"), filePath);
260QJsonArray SensorFaceControllerPrivate::readSensors(const KConfigGroup &read, const QString &entryName)
280QJsonArray SensorFaceControllerPrivate::readAndUpdateSensors(KConfigGroup &config, const QString &entryName)
282 auto original = QJsonDocument::fromJson(config.readEntry(entryName, QString()).toUtf8()).array();
294void SensorFaceControllerPrivate::resolveSensors(const QJsonArray &partialEntries, std::function<void(SensorResolver *)> callback)
315 // TODO: eventually support async components? (only useful for qml files from http, we probably don't want that)
346QQuickItem *SensorFaceControllerPrivate::createConfigUi(const QString &file, const QVariantMap &initialProperties)
349 // TODO: eventually support async components? (only useful for qml files from http, we probably don't want that)
372SensorFaceController::SensorFaceController(KConfigGroup &config, QQmlEngine *engine, QQmlEngine *configEngine)
398 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("totalSensors")), [this](SensorResolver *resolver) {
402 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("lowPrioritySensorIds")), [this](SensorResolver *resolver) {
406 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("highPrioritySensorIds")), [this](SensorResolver *resolver) {
493 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("totalSensors").toUtf8()).array();
497 d->sensorsGroup.writeEntry("totalSensors", QJsonDocument(totalSensors).toJson(QJsonDocument::Compact));
521 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("highPrioritySensorIds").toUtf8()).array();
525 d->sensorsGroup.writeEntry("highPrioritySensorIds", QJsonDocument(highPrioritySensorIds).toJson(QJsonDocument::Compact));
614 const auto currentEntry = QJsonDocument::fromJson(d->sensorsGroup.readEntry("lowPrioritySensorIds").toUtf8()).array();
618 d->sensorsGroup.writeEntry("lowPrioritySensorIds", QJsonDocument(lowPrioritySensorIds).toJson(QJsonDocument::Compact));
717 d->facePackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KSysguard/SensorFace"), face);
735 d->faceProperties = KConfigGroup(KSharedConfig::openConfig(d->facePackage.filePath("FaceProperties"), KConfig::SimpleConfig), QStringLiteral("Config"));
768 d->compactRepresentation = d->createGui(d->facePackage.filePath("ui", QStringLiteral("CompactRepresentation.qml")));
780 d->fullRepresentation = d->createGui(d->facePackage.filePath("ui", QStringLiteral("FullRepresentation.qml")));
799 {{QStringLiteral("controller"), QVariant::fromValue(this)}, {QStringLiteral("source"), QUrl::fromLocalFile(filePath)}});
814 d->appearanceConfigUi = d->createConfigUi(QStringLiteral(":/ConfigAppearance.qml"), {{QStringLiteral("controller"), QVariant::fromValue(this)}});
826 d->sensorsConfigUi = d->createConfigUi(QStringLiteral(":/ConfigSensors.qml"), {{QStringLiteral("controller"), QVariant::fromValue(this)}});
863 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("totalSensors")), [this](SensorResolver *resolver) {
867 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("lowPrioritySensorIds")), [this](SensorResolver *resolver) {
871 d->resolveSensors(d->readAndUpdateSensors(d->sensorsGroup, QStringLiteral("highPrioritySensorIds")), [this](SensorResolver *resolver) {
891 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
899 if (presetPackage.metadata().value(QStringLiteral("X-Plasma-RootPath")) != QStringLiteral("org.kde.plasma.systemmonitor")) {
903 auto c = KSharedConfig::openConfig(presetPackage.filePath("config", QStringLiteral("faceproperties")), KConfig::SimpleConfig);
911 if (d->availablePresetsModel && d->availablePresetsModel->data(d->availablePresetsModel->index(0, 0), PresetsModel::PluginIdRole).toString().isEmpty()) {
919 setFaceId(presetGroup.readEntry(QStringLiteral("chartFace"), QStringLiteral("org.kde.ksysguard.piechart")));
925 KConfigGroup presetGroup(KSharedConfig::openConfig(presetPackage.filePath("FaceProperties"), KConfig::SimpleConfig), QStringLiteral("FaceConfig"));
961 qCWarning(LIBKSYSGUARD_FACES) << "Failed to install package:" << qPrintable(job->errorString());
968 QString pluginName = QStringLiteral("org.kde.plasma.systemmonitor.") + title().simplified().replace(QLatin1Char(' '), QStringLiteral("")).toLower();
971 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
1011 KConfig faceConfig(QString::fromStdString((path / "contents" / "config" / "faceproperties").string()));
1016 configGroup.writeEntry(QStringLiteral("totalSensors"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
1018 configGroup.writeEntry(QStringLiteral("highPrioritySensorIds"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
1020 configGroup.writeEntry(QStringLiteral("lowPrioritySensorIds"), QJsonDocument(sensors).toJson(QJsonDocument::Compact));
1039 auto presetPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"), pluginId);
1041 if (presetPackage.metadata().value(QStringLiteral("X-Plasma-RootPath")) != QStringLiteral("org.kde.plasma.systemmonitor")) {
1047 auto *job = KPackage::PackageJob::uninstall(QStringLiteral("Plasma/Applet"), pluginId, root.path());
1085 connect(d->faceConfiguration, &KConfigPropertyMap::valueChanged, this, [this](const QString &key) {
1099 auto array = QJsonDocument::fromJson(d->sensorsGroup.readEntry(configEntry, QString()).toUtf8()).array();
1109 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
QStringList keyList() const
void copyTo(KConfigBase *other, WriteConfigFlags pFlags=Normal) const
virtual void setProperty(const QVariant &p)=0
virtual QVariant property() const=0
SimpleConfig
virtual QString errorString() const
int error() const
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(QStringView key, bool defaultValue) const
QString fileName() const
The SensorFaceController links sensor faces and applications in which these faces are shown.
Definition SensorFaceController.h:44
int updateRateLimit
The minimum time that needs to elapse, in milliseconds, between updates of the face.
Definition SensorFaceController.h:162
KConfigPropertyMap * faceConfiguration
A map of config options and values that are specific to the current face as defined by the main....
Definition SensorFaceController.h:117
QAbstractItemModel * availablePresetsModel
A list of available face presets.
Definition SensorFaceController.h:158
QVariantMap sensorLabels
Maps sensorIds to user configurable labels than should be displayed instead of the name of the sensor...
Definition SensorFaceController.h:80
QJsonArray totalSensors
Sensors that are typically used to display a total in some way or form.
Definition SensorFaceController.h:65
Q_INVOKABLE void replaceSensors(const QString &from, const QString &to)
Replace one sensor with another.
Definition SensorFaceController.cpp:1096
bool shouldSync() const
Whether the controller should sync configuration changes.
Definition SensorFaceController.cpp:1054
QJsonArray missingSensors
Contains the paths of missing sensors, if there are any.
Definition SensorFaceController.h:166
QJsonArray highPrioritySensorIds
Sensors that should always be shown in the face.
Definition SensorFaceController.h:70
QQuickItem * sensorsConfigUi
A user interface for configuring which sensors are displayed in a face Emits configurationChanged if ...
Definition SensorFaceController.h:148
Q_INVOKABLE void loadPreset(const QString &preset)
Loads a specific preset.
Definition SensorFaceController.cpp:885
void setShouldSync(bool sync)
Specifies if the controller should automatically sync configuration changes.
Definition SensorFaceController.cpp:1059
QQuickItem * faceConfigUi
A user interface that is suited for configuring the face specific options.
Definition SensorFaceController.h:135
Q_INVOKABLE void savePreset()
Save the current configuration as a preset.
Definition SensorFaceController.cpp:942
KConfigGroup configGroup() const
Retrieve the KConfigGroup this controller is using to store configuration.
Definition SensorFaceController.cpp:438
QQuickItem * appearanceConfigUi
A user interface for configuring the general appearance of a face like the title and the used face.
Definition SensorFaceController.h:142
SensorFaceController(KConfigGroup &config, QQmlEngine *engine, QQmlEngine *configEngine)
Creates a new SensorFaceController.
Definition SensorFaceController.cpp:372
QQuickItem * compactRepresentation
The compact representation of the current face.
Definition SensorFaceController.h:128
int maxTotalSensors
The amount of total sensors the current face supports.
Definition SensorFaceController.h:111
bool showTitle
Whether the title should be displayed or if it should be hidden instead.
Definition SensorFaceController.h:56
bool supportsLowPrioritySensors
Whether the current face can display low priority sensors.
Definition SensorFaceController.h:107
bool supportsTotalSensors
Whether the current face can display total sensors.
Definition SensorFaceController.h:103
Q_INVOKABLE void uninstallPreset(const QString &pluginId)
Uninstall a specific preset.
Definition SensorFaceController.cpp:1037
QAbstractItemModel * availableFacesModel
A list of all available faces.
Definition SensorFaceController.h:153
QQuickItem * fullRepresentation
The full representation of the current face.
Definition SensorFaceController.h:123
bool supportsSensorsColors
Whether the current face supports sensor colors.
Definition SensorFaceController.h:99
Q_INVOKABLE void reloadFaceConfiguration()
Reload only the face configuration.
Definition SensorFaceController.cpp:1067
QVariantMap sensorColors
Maps sensorIds to colors that can be used when a color for something relating to a specific sensor is...
Definition SensorFaceController.h:75
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)
QString path(const QString &relativePath)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
const QList< QKeySequence > & reload()
QString label(StandardShortcut id)
virtual QHash< int, QByteArray > roleNames() const const
bool isValid() const const
bool cdUp()
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()
qsizetype removeAll(const AT &t)
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)
QList< QQmlError > errors() const const
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
QString fromStdString(const std::string &str)
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
std::string toStdString() 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 Mon Nov 18 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.