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