cpu.cpp 4.72 KB
Newer Older
David Redondo's avatar
David Redondo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
    Copyright (c) 2020 David Redondo <kde@david-redondo.de>

    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 "cpu.h"

David Redondo's avatar
David Redondo committed
22
23
#include <KLocalizedString>

David Redondo's avatar
David Redondo committed
24
BaseCpuObject::BaseCpuObject(const QString &id, const QString &name, SensorContainer *parent)
David Redondo's avatar
David Redondo committed
25
26
    : SensorObject(id, name, parent)
{
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
}

void BaseCpuObject::makeSensors()
{
    m_usage = new SensorProperty(QStringLiteral("usage"), this);
    m_system = new SensorProperty(QStringLiteral("system"), this);
    m_user = new SensorProperty(QStringLiteral("user"), this);
    m_wait = new SensorProperty(QStringLiteral("wait"), this);
    auto n = new SensorProperty(QStringLiteral("name"), i18nc("@title", "Name"), name(), this);
    n->setVariantType(QVariant::String);
}


void BaseCpuObject::initialize()
{
42
    makeSensors();
43
44
45

    m_usage->setPrefix(name());
    m_usage->setName(i18nc("@title", "Total Usage"));
David Redondo's avatar
David Redondo committed
46
    m_usage->setShortName(i18nc("@title, Short for 'Total Usage'", "Usage"));
David Redondo's avatar
David Redondo committed
47
48
49
50
    m_usage->setUnit(KSysGuard::UnitPercent);
    m_usage->setVariantType(QVariant::Double);
    m_usage->setMax(100);

51
52
    m_system->setPrefix(name());
    m_system->setName(i18nc("@title", "System Usage"));
David Redondo's avatar
David Redondo committed
53
    m_system->setShortName(i18nc("@title, Short for 'System Usage'", "System"));
David Redondo's avatar
David Redondo committed
54
55
56
57
    m_system->setUnit(KSysGuard::UnitPercent);
    m_system->setVariantType(QVariant::Double);
    m_system->setMax(100);

58
59
    m_user->setPrefix(name());
    m_user->setName(i18nc("@title", "User Usage"));
David Redondo's avatar
David Redondo committed
60
    m_user->setShortName(i18nc("@title, Short for 'User Usage'", "User"));
David Redondo's avatar
David Redondo committed
61
62
63
64
    m_user->setUnit(KSysGuard::UnitPercent);
    m_user->setVariantType(QVariant::Double);
    m_user->setMax(100);

65
66
    m_wait->setPrefix(name());
    m_wait->setName(i18nc("@title", "Wait Usage"));
67
    m_wait->setShortName(i18nc("@title, Short for 'Wait Load'", "Wait"));
David Redondo's avatar
David Redondo committed
68
69
70
    m_wait->setUnit(KSysGuard::UnitPercent);
    m_wait->setVariantType(QVariant::Double);
    m_wait->setMax(100);
David Redondo's avatar
David Redondo committed
71
72
}

73

David Redondo's avatar
David Redondo committed
74
75
76
CpuObject::CpuObject(const QString &id, const QString &name, SensorContainer *parent)
    : BaseCpuObject(id, name, parent)
{
77
78
79
80
81
82
83
84
85
}

void CpuObject::makeSensors()
{
    BaseCpuObject::makeSensors();

    m_frequency = new SensorProperty(QStringLiteral("frequency"), this);
    m_temperature = new SensorProperty(QStringLiteral("temperature"), this);
}
David Redondo's avatar
David Redondo committed
86

87
88
89
90
91
92
void CpuObject::initialize()
{
    BaseCpuObject::initialize();

    m_frequency->setPrefix(name());
    m_frequency->setName(i18nc("@title", "Current Frequency"));
David Redondo's avatar
David Redondo committed
93
94
95
96
97
    m_frequency->setShortName(i18nc("@title, Short for 'Current Frequency'", "Frequency"));
    m_frequency->setDescription(i18nc("@info", "Current frequency of the CPU"));
    m_frequency->setVariantType(QVariant::Double);
    m_frequency->setUnit(KSysGuard::Unit::UnitMegaHertz);

98
99
    m_temperature->setPrefix(name());
    m_temperature->setPrefix(i18nc("@title", "Current Temperature"));
David Redondo's avatar
David Redondo committed
100
101
102
103
104
    m_temperature->setShortName(i18nc("@title, Short for Current Temperatur", "Temperature"));
    m_temperature->setVariantType(QVariant::Double);
    m_temperature->setUnit(KSysGuard::Unit::UnitCelsius);
}

105

106
AllCpusObject::AllCpusObject(SensorContainer *parent)
David Redondo's avatar
David Redondo committed
107
108
    : BaseCpuObject(QStringLiteral("all"), i18nc("@title", "All"), parent)
{
109
110
111
112
}

void AllCpusObject::makeSensors()
{
113
114
    BaseCpuObject::makeSensors();

115
116
117
118
119
120
    m_cpuCount = new SensorProperty(QStringLiteral("cpuCount"), this);
    m_coreCount = new SensorProperty(QStringLiteral("coreCount"), this);
}

void AllCpusObject::initialize()
{
121
122
    BaseCpuObject::initialize();

123
124
125
    m_cpuCount->setName(i18nc("@title", "Number of CPUs"));
    m_cpuCount->setShortName(i18nc("@title, Short fort 'Number of CPUs'", "CPUs"));
    m_cpuCount->setDescription(i18nc("@info", "Number of physical CPUs installed in the system"));
126

127
128
129
    m_coreCount->setName(i18nc("@title", "Number of Cores"));
    m_coreCount->setShortName(i18nc("@title, Short fort 'Number of Cores'", "Cores"));
    m_coreCount->setDescription(i18nc("@info", "Number of CPU cores across all physical CPUS"));
David Redondo's avatar
David Redondo committed
130
}
131
132
133
134

void AllCpusObject::setCounts(unsigned int cpuCount, unsigned int coreCount)
{
    m_cpuCount->setValue(cpuCount);
David Redondo's avatar
David Redondo committed
135
    m_coreCount->setValue(coreCount);
136
}