Commit cc789f3a authored by Marco Martin's avatar Marco Martin

Add KSysGuard::Sensors library

Summary:
This adds a new library for communicating with a new KSysGuard
DBus-based daemon that provides sensors. The daemon will be
posted by d_ed later on.

This new library pretty much maps the different objects from
the daemon to C++ objects.

Depends on D28333

Test Plan: None yet, needs the new daemon.

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: ngraham, mart, zzag, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28141
parent b1e9126e
......@@ -43,7 +43,9 @@ set_package_properties(Qt5WebChannel PROPERTIES
PURPOSE "Used by the HTML-based GUI ksysguard library"
)
find_package(KF5 REQUIRED COMPONENTS CoreAddons Config I18n JobWidgets WindowSystem Completion Auth WidgetsAddons IconThemes ConfigWidgets Service GlobalAccel KIO)
find_package(KF5 REQUIRED COMPONENTS CoreAddons Config I18n JobWidgets WindowSystem Completion Auth WidgetsAddons IconThemes ConfigWidgets Service GlobalAccel KIO Package Declarative)
find_package(KF5 OPTIONAL_COMPONENTS Plasma)
set_package_properties(KF5Plasma PROPERTIES
URL "https://cgit.kde.org/plasma-framework.git/"
......@@ -110,6 +112,8 @@ add_subdirectory( lsofui )
add_subdirectory( processcore )
add_subdirectory( processui )
add_subdirectory( sensors )
add_subdirectory( faces )
if (KF5Plasma_FOUND)
add_subdirectory( signalplotter )
endif()
......
set(KSYSGUARD_SENSORS_SOVERSION 1)
add_subdirectory(import)
add_subdirectory(facepackages)
add_subdirectory(packagestructure)
add_definitions(-DTRANSLATION_DOMAIN=\"ksysguard_faces\")
set(faces_LIB_SRCS
SensorFaceController.cpp
SensorFace.cpp
)
set(faces_LIB_HEADERS
SensorFace_p.h
SensorFaceController.h
)
ecm_qt_declare_logging_category(faces_LIB_SRCS
HEADER faces_logging.h
IDENTIFIER LIBKSYSGUARD_SENSORS
CATEGORY_NAME org.kde.libksysguard.faces
)
set_source_files_properties(org.kde.KSysGuardDaemon.xml PROPERTIES INCLUDE SensorInfo_p.h)
qt5_add_resources(RESOURCES resources.qrc)
add_library(SensorFaces ${faces_LIB_SRCS} ${RESOURCES})
add_library(KSysGuard::SensorFaces ALIAS SensorFaces)
target_include_directories(SensorFaces
PUBLIC
"$<BUILD_INTERFACE:${libksysguard_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/ksysguard/>"
)
generate_export_header(SensorFaces)
target_link_libraries(SensorFaces
PUBLIC
Qt5::Qml
Qt5::Quick
KF5::ConfigCore
KF5::ConfigGui
KSysGuard::Formatter
KSysGuard::Sensors
PRIVATE
Qt5::Core
Qt5::DBus
KF5::I18n
KF5::Package
KF5::Declarative
)
set_target_properties(SensorFaces PROPERTIES
LIBRARY_OUTPUT_NAME KSysGuardSensorFaces
VERSION ${KSYSGUARD_VERSION_STRING}
SOVERSION ${KSYSGUARD_SENSORS_SOVERSION}
)
install(TARGETS SensorFaces EXPORT libksysguardLibraryTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES
${faces_LIB_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/sensorfaces_export.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/ksysguard/faces
COMPONENT Devel
)
/*
* Copyright 2019 Marco Martin <mart@kde.org>
* Copyright 2019 David Edmundson <davidedmundson@kde.org>
* Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.9
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.2 as QQC2
import org.kde.kirigami 2.5 as Kirigami
import org.kde.kquickcontrols 2.0
import org.kde.kconfig 1.0 // for KAuthorized
import org.kde.newstuff 1.62 as NewStuff
import org.kde.quickcharts 1.0 as Charts
import org.kde.ksysguard.sensors 1.0 as Sensors
import org.kde.ksysguard.faces 1.0 as Faces
Kirigami.FormLayout {
id: root
signal configurationChanged
function saveConfig() {
controller.title = cfg_title;
controller.faceId = cfg_chartFace;
var preset = pendingPreset;
pendingPreset = "";
if (preset != "") {
controller.loadPreset(preset);
root.controller.highPrioritySensorColors = automaticColorSource.colors
}
}
property Faces.SensorFaceController controller
property alias cfg_title: titleField.text
property string cfg_chartFace
onCfg_titleChanged: configurationChanged();
onCfg_chartFaceChanged: configurationChanged();
// config keys of the selected preset to be applied on save
property string pendingPreset
Component.onCompleted: {
cfg_title = controller.title;
cfg_chartFace = controller.faceId;
}
Charts.ColorGradientSource {
id: automaticColorSource
baseColor: Kirigami.Theme.highlightColor
itemCount: root.controller.highPrioritySensorIds.length
}
Kirigami.OverlaySheet {
id: presetSheet
parent: root
ListView {
implicitWidth: Kirigami.Units.gridUnit * 15
model: controller.availablePresetsModel
delegate: Kirigami.SwipeListItem {
contentItem: QQC2.Label {
Layout.fillWidth: true
text: model.display
}
actions: Kirigami.Action {
icon.name: "delete"
visible: model.writable
onTriggered: controller.uninstallPreset(model.pluginId);
}
onClicked: {
cfg_title = model.display;
pendingPreset = model.pluginId;
if (model.config.chartFace) {
cfg_chartFace = model.config.chartFace;
}
root.configurationChanged();
presetSheet.close();
}
}
}
}
RowLayout {
Kirigami.FormData.label: i18n("Presets:")
QQC2.Button {
icon.name: "document-open"
text: i18n("Load Preset...")
onClicked: presetSheet.open()
}
NewStuff.Button {
Accessible.name: i18n("Get new presets...")
configFile: "systemmonitor-presets.knsrc"
text: ""
onChangedEntriesChanged: controller.availablePresetsModel.reload();
QQC2.ToolTip {
text: parent.Accessible.name
}
}
QQC2.Button {
id: saveButton
icon.name: "document-save"
text: i18n("Save Settings As Preset")
enabled: controller.currentPreset.length == 0
onClicked: controller.savePreset();
}
}
Kirigami.Separator {
Kirigami.FormData.isSection: true
}
QQC2.TextField {
id: titleField
Kirigami.FormData.label: i18n("Title:")
}
RowLayout {
Kirigami.FormData.label: i18n("Display Style:")
QQC2.ComboBox {
id: faceCombo
model: controller.availableFacesModel
textRole: "display"
currentIndex: {
// TODO just make an indexOf invokable on the model?
for (var i = 0; i < count; ++i) {
if (model.pluginId(i) === cfg_chartFace) {
return i;
}
}
return -1;
}
onActivated: {
cfg_chartFace = model.pluginId(index);
}
}
NewStuff.Button {
text: i18n("Get New Display Styles...")
configFile: "systemmonitor-faces.knsrc"
onChangedEntriesChanged: controller.availableFacesModel.reload();
}
}
}
This diff is collapsed.
/*
* Copyright 2019 Marco Martin <mart@kde.org>
* Copyright 2019 David Edmundson <davidedmundson@kde.org>
* Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.9
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.5 as Kirigami
import org.kde.kquickcontrols 2.0
import org.kde.ksysguard.sensors 1.0 as Sensors
import org.kde.ksysguard.faces 1.0 as Faces
Loader {
id: root
property Faces.SensorFaceController controller
signal configurationChanged
function saveConfig() {
if (item.saveConfig) {
item.saveConfig()
}
for (var key in root.controller.faceConfiguration) {
if (item.hasOwnProperty("cfg_" + key)) {
root.controller.faceConfiguration[key] = item["cfg_" + key]
}
}
}
onItemChanged: {
if (!item || !root.controller.faceConfiguration) {
return;
}
for (var key in root.controller.faceConfiguration) {
if (!item.hasOwnProperty("cfg_" + key)) {
continue;
}
item["cfg_" + key] = root.controller.faceConfiguration[key];
var changedSignal = item["cfg_" + key + "Changed"];
if (changedSignal) {
changedSignal.connect(root.configurationChanged);
}
}
}
}
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "SensorFace_p.h"
#include "SensorFaceController.h"
#include <QDebug>
using namespace KSysGuard;
class SensorFace::Private {
public:
QPointer<QQuickItem> contentItem;
SensorFaceController *controller = nullptr;
FormFactor formFactor = Planar;
};
SensorFace::SensorFace(QQuickItem *parent)
: QQuickItem(parent),
d(std::make_unique<Private>())
{
}
SensorFace::~SensorFace()
{
}
SensorFaceController *SensorFace::controller() const
{
return d->controller;
}
// Not writable from QML
void SensorFace::setController(SensorFaceController *controller)
{
d->controller = controller;
}
SensorFace::FormFactor SensorFace::formFactor() const
{
return d->formFactor;
}
void SensorFace::setFormFactor(SensorFace::FormFactor formFactor)
{
if (d->formFactor == formFactor) {
return;
}
d->formFactor = formFactor;
emit formFactorChanged();
}
QQuickItem * SensorFace::contentItem() const
{
return d->contentItem;
}
void SensorFace::setContentItem(QQuickItem *item)
{
if (d->contentItem == item) {
return;
}
d->contentItem = item;
if (d->contentItem) {
d->contentItem->setParentItem(this);
d->contentItem->setX(0);
d->contentItem->setY(0);
d->contentItem->setSize(size());
}
emit contentItemChanged();
}
void SensorFace::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
if (d->contentItem) {
d->contentItem->setX(0);
d->contentItem->setY(0);
d->contentItem->setSize(newGeometry.size());
}
QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
#include "moc_SensorFace_p.cpp"
This diff is collapsed.
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include <QObject>
#include <QPointer>
#include <QQuickItem>
#include <QAbstractItemModel>
#include <KConfigGroup>
#include "sensorfaces_export.h"
namespace KDeclarative {
class ConfigPropertyMap;
}
class QQmlEngine;
class KDesktopFile;
class KConfigLoader;
namespace KSysGuard {
class SensorFace;
class SENSORFACES_EXPORT SensorFaceController : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString faceId READ faceId WRITE setFaceId NOTIFY faceIdChanged)
Q_PROPERTY(QJsonArray totalSensors READ totalSensors WRITE setTotalSensors NOTIFY totalSensorsChanged)
Q_PROPERTY(QJsonArray highPrioritySensorIds READ highPrioritySensorIds WRITE setHighPrioritySensorIds NOTIFY highPrioritySensorIdsChanged)
Q_PROPERTY(QVariantMap sensorColors READ sensorColors WRITE setSensorColors NOTIFY sensorColorsChanged)
Q_PROPERTY(QJsonArray lowPrioritySensorIds READ lowPrioritySensorIds WRITE setLowPrioritySensorIds NOTIFY lowPrioritySensorIdsChanged)
Q_PROPERTY(QString name READ name NOTIFY faceIdChanged)
Q_PROPERTY(QString icon READ icon NOTIFY faceIdChanged)
Q_PROPERTY(bool supportsSensorsColors READ supportsSensorsColors NOTIFY faceIdChanged)
Q_PROPERTY(bool supportsTotalSensors READ supportsTotalSensors NOTIFY faceIdChanged)
Q_PROPERTY(bool supportsLowPrioritySensors READ supportsLowPrioritySensors NOTIFY faceIdChanged)
Q_PROPERTY(KDeclarative::ConfigPropertyMap *faceConfiguration READ faceConfiguration NOTIFY faceIdChanged)
Q_PROPERTY(QQuickItem *fullRepresentation READ fullRepresentation NOTIFY faceIdChanged)
Q_PROPERTY(QQuickItem *compactRepresentation READ compactRepresentation NOTIFY faceIdChanged)
Q_PROPERTY(QQuickItem *faceConfigUi READ faceConfigUi NOTIFY faceIdChanged)
Q_PROPERTY(QQuickItem *appearanceConfigUi READ appearanceConfigUi NOTIFY faceIdChanged)
Q_PROPERTY(QQuickItem *sensorsConfigUi READ sensorsConfigUi NOTIFY faceIdChanged)
Q_PROPERTY(QAbstractItemModel *availableFacesModel READ availableFacesModel CONSTANT)
Q_PROPERTY(QAbstractItemModel *availablePresetsModel READ availablePresetsModel CONSTANT)
public:
SensorFaceController(KConfigGroup &config, QQmlEngine *engine);
~SensorFaceController();
void setFaceId(const QString &face);
QString faceId() const;
QQuickItem *fullRepresentation();
QQuickItem *compactRepresentation();
QQuickItem *faceConfigUi();
QQuickItem *appearanceConfigUi();
QQuickItem *sensorsConfigUi();
KDeclarative::ConfigPropertyMap *faceConfiguration() const;
QString title() const;
void setTitle(const QString &title);
QJsonArray totalSensors() const;
void setTotalSensors(const QJsonArray &sensor);
QJsonArray highPrioritySensorIds() const;
void setHighPrioritySensorIds(const QJsonArray &ids);
QJsonArray sensors() const;
QJsonArray lowPrioritySensorIds() const;
void setLowPrioritySensorIds(const QJsonArray &ids);
QVariantMap sensorColors() const;
void setSensorColors(const QVariantMap &colors);
// from face config, immutable by the user
QString name() const;
const QString icon() const;
bool supportsSensorsColors() const;
bool supportsTotalSensors() const;
bool supportsLowPrioritySensors() const;
QAbstractItemModel *availableFacesModel();
QAbstractItemModel *availablePresetsModel();
Q_INVOKABLE void reloadConfig();
Q_INVOKABLE void loadPreset(const QString &preset);
Q_INVOKABLE void savePreset();
Q_INVOKABLE void uninstallPreset(const QString &pluginId);
Q_SIGNALS:
void faceIdChanged();
void titleChanged();
void totalSensorsChanged();
void highPrioritySensorIdsChanged();
void lowPrioritySensorIdsChanged();
void sensorsChanged();
void sensorColorsChanged();
private:
class Private;
const std::unique_ptr<Private> d;
};
}
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
#include <QQuickItem>
#include <QStandardItemModel>
class QQmlEngine;
namespace KSysGuard {
class SensorFaceController;
class FacesModel : public QStandardItemModel
{
Q_OBJECT
public:
enum AdditionalRoles {
PluginIdRole = Qt::UserRole + 1,
};
Q_ENUM(AdditionalRoles)
FacesModel(QObject *parent = nullptr);
~FacesModel() = default;
Q_INVOKABLE void reload();
Q_INVOKABLE QString pluginId(int row);
QHash<int, QByteArray> roleNames() const override;
};
class PresetsModel : public QStandardItemModel
{
Q_OBJECT
public:
enum AdditionalRoles {
PluginIdRole = Qt::UserRole + 1,
ConfigRole,
WritableRole
};
Q_ENUM(AdditionalRoles)
PresetsModel(QObject *parent = nullptr);
~PresetsModel() = default;
Q_INVOKABLE void reload();
QHash<int, QByteArray> roleNames() const override;
};
}
/*
Copyright (C) 2020 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public