Changeset View
Changeset View
Standalone View
Standalone View
Modules/about-distro/src/CPUEntry.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2012-2020 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public License as | ||||
6 | published by the Free Software Foundation; either version 2 of | ||||
7 | the License or (at your option) version 3 or any later version | ||||
8 | accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | defined in Section 14 of version 3 of the license. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "CPUEntry.h" | ||||
22 | | ||||
23 | #include <QMap> | ||||
24 | | ||||
25 | #include <solid/device.h> | ||||
26 | #include <solid/processor.h> | ||||
27 | | ||||
28 | CPUEntry::CPUEntry() | ||||
29 | : Entry(KLocalizedString(), QString()) | ||||
30 | { | ||||
31 | const QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); | ||||
32 | | ||||
33 | label = ki18np("Processor:", "Processors:").subs(list.count()); | ||||
34 | | ||||
35 | // Format processor string | ||||
36 | // Group by processor name | ||||
37 | QMap<QString, int> processorMap; | ||||
38 | for (const Solid::Device &device : list) { | ||||
39 | const QString name = device.product(); | ||||
40 | auto it = processorMap.find(name); | ||||
41 | if (it == processorMap.end()) { | ||||
42 | processorMap.insert(name, 1); | ||||
43 | } else { | ||||
44 | ++it.value(); | ||||
45 | } | ||||
46 | } | ||||
47 | // Create a formatted list of grouped processors | ||||
48 | QStringList names; | ||||
49 | names.reserve(processorMap.count()); | ||||
50 | for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) { | ||||
51 | const int count = it.value(); | ||||
52 | QString name = it.key(); | ||||
53 | name.replace(QStringLiteral("(TM)"), QChar(8482)); | ||||
54 | name.replace(QStringLiteral("(R)"), QChar(174)); | ||||
55 | name = name.simplified(); | ||||
56 | names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); | ||||
57 | } | ||||
58 | | ||||
59 | value = names.join(QLatin1String(", ")); | ||||
60 | } |