File indexing completed on 2024-04-28 16:49:54
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QObject> 0009 #include <QVariant> 0010 0011 #include "processes.h" 0012 #include "unit.h" 0013 0014 namespace KSysGuard 0015 { 0016 class Process; 0017 class CGroup; 0018 0019 class Q_DECL_EXPORT ProcessAttribute : public QObject 0020 { 0021 Q_OBJECT 0022 public: 0023 ProcessAttribute(const QString &id, QObject *parent); 0024 ProcessAttribute(const QString &id, const QString &name, QObject *parent); 0025 0026 ~ProcessAttribute() override; 0027 0028 /** 0029 * A unique non-translatable ID for this attribute. For saving in config files 0030 */ 0031 QString id() const; 0032 0033 /** 0034 * States whether we should update process attributes 0035 */ 0036 bool enabled() const; 0037 0038 /** 0039 * A translated user facing name for the attribute. 0040 * e.g "Download Speed" 0041 */ 0042 QString name() const; 0043 void setName(const QString &name); 0044 0045 /** 0046 * A translated shorter version of the name 0047 * for use in table column headers for example 0048 * e.g "D/L" 0049 * If unset, name is returned 0050 */ 0051 QString shortName() const; 0052 void setShortName(const QString &name); 0053 0054 /** 0055 * A translated human readable description of this attribute 0056 */ 0057 QString description() const; 0058 void setDescription(const QString &description); 0059 0060 /** 0061 * The minimum value possible for this sensor 0062 * (i.e to show a CPU is between 0 and 100) 0063 * Set min and max to 0 if not relevant 0064 */ 0065 qreal min() const; 0066 void setMin(const qreal min); 0067 /** 0068 * The maximum value possible for this attribute 0069 */ 0070 qreal max() const; 0071 void setMax(const qreal max); 0072 0073 KSysGuard::Unit unit() const; 0074 void setUnit(KSysGuard::Unit unit); 0075 0076 /** 0077 * A hint to UIs that this sensor would like to be visible by default. 0078 * 0079 * Defaults to false. 0080 */ 0081 bool isVisibleByDefault() const; 0082 void setVisibleByDefault(bool visible); 0083 0084 /** 0085 * Which update steps are required for this attribute to correctly report its data. 0086 * 0087 * This can be used to determine which flags should be used when calling 0088 * Processes::updateAllProcesses() . By default this will be 0089 * Processess::StandardInformation. 0090 */ 0091 Processes::UpdateFlags requiredUpdateFlags() const; 0092 void setRequiredUpdateFlags(Processes::UpdateFlags flags); 0093 0094 /** 0095 * The last stored value for a given process 0096 */ 0097 virtual QVariant data(KSysGuard::Process *process) const; 0098 0099 /** 0100 * Updates the stored value for a given process 0101 * Note stray processes will be automatically expunged 0102 */ 0103 void setData(KSysGuard::Process *process, const QVariant &value); 0104 /** 0105 * Remove an attribute from our local cache 0106 */ 0107 void clearData(KSysGuard::Process *process); 0108 0109 virtual QVariant cgroupData(KSysGuard::CGroup *cgroup, const QVector<KSysGuard::Process *> &groupProcesses = {}) const; 0110 0111 Q_SIGNALS: 0112 void dataChanged(KSysGuard::Process *process); 0113 void enabledChanged(bool enabled); 0114 0115 protected: 0116 void connectNotify(const QMetaMethod &signal) override; 0117 void disconnectNotify(const QMetaMethod &signal) override; 0118 0119 private: 0120 class Private; 0121 QScopedPointer<Private> d; 0122 }; 0123 0124 }