Changeset View
Changeset View
Standalone View
Standalone View
processcore/process_attribute.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2019 David Edmundson <davidedmundson@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | #pragma once | ||||
20 | | ||||
21 | #include <QObject> | ||||
22 | #include <QVariant> | ||||
23 | | ||||
24 | #include "unit.h" | ||||
25 | | ||||
26 | namespace KSysGuard { | ||||
27 | | ||||
28 | class Process; | ||||
29 | | ||||
30 | class Q_DECL_EXPORT ProcessAttribute : public QObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | public: | ||||
34 | ProcessAttribute(const QString &id, QObject *parent); | ||||
35 | ProcessAttribute(const QString &id, const QString &name, QObject *parent); | ||||
36 | | ||||
37 | ~ProcessAttribute() override; | ||||
38 | | ||||
39 | /** | ||||
40 | * A unique non-translatable ID for this attribute. For saving in config files | ||||
41 | */ | ||||
42 | QString id() const; | ||||
43 | | ||||
44 | /** | ||||
45 | * Controls whether we should fetch process attributes | ||||
46 | */ | ||||
47 | bool enabled() const; | ||||
48 | void setEnabled(const bool enable); | ||||
49 | | ||||
50 | /** | ||||
51 | * A translated user facing name for the attribute. | ||||
52 | * e.g "Download Speed" | ||||
53 | */ | ||||
54 | QString name() const; | ||||
55 | void setName(const QString &name); | ||||
56 | | ||||
57 | /** | ||||
58 | * A translated shorter version of the name | ||||
59 | * for use in table column headers for example | ||||
60 | * e.g "D/L" | ||||
61 | * If unset, name is returned | ||||
62 | */ | ||||
63 | QString shortName() const; | ||||
64 | void setShortName(const QString &name); | ||||
65 | | ||||
66 | /** | ||||
67 | * A translated human readable description of this attribute | ||||
68 | */ | ||||
69 | QString description() const; | ||||
70 | void setDescription(const QString &description); | ||||
71 | | ||||
72 | /** | ||||
73 | * The minimum value possible for this sensor | ||||
74 | * (i.e to show a CPU is between 0 and 100) | ||||
75 | * Set min and max to 0 if not relevant | ||||
76 | */ | ||||
77 | qreal min() const; | ||||
78 | void setMin(const qreal min); | ||||
79 | /** | ||||
80 | * The maximum value possible for this attribute | ||||
81 | */ | ||||
82 | qreal max() const; | ||||
83 | void setMax(const qreal max); | ||||
84 | | ||||
85 | KSysGuard::Unit unit() const; | ||||
86 | void setUnit(KSysGuard::Unit unit); | ||||
87 | | ||||
88 | /** | ||||
89 | * The last stored value for a given process | ||||
90 | */ | ||||
91 | QVariant data(KSysGuard::Process *process); | ||||
92 | | ||||
93 | /** | ||||
94 | * Updates the stored value for a given process | ||||
95 | * Note stray processes will be automatically expunged | ||||
96 | */ | ||||
97 | void setData(KSysGuard::Process *process, const QVariant &value); | ||||
98 | /** | ||||
99 | * Remove an attribute from our local cache | ||||
100 | */ | ||||
101 | void clearData(KSysGuard::Process *process); | ||||
102 | | ||||
103 | Q_SIGNALS: | ||||
104 | void dataChanged(KSysGuard::Process *process); | ||||
105 | void enabledChanged(bool enabled); | ||||
106 | | ||||
107 | private: | ||||
108 | class Private; | ||||
109 | QScopedPointer<Private> d; | ||||
110 | }; | ||||
111 | | ||||
112 | } |