Changeset View
Changeset View
Standalone View
Standalone View
Modules/about-distro/src/CPUEntry.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | SPDX-FileCopyrightText: 2012-2020 Harald Sitter <sitter@kde.org> | 2 | SPDX-FileCopyrightText: 2012-2020 Harald Sitter <sitter@kde.org> | ||
3 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | 3 | SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL | ||
4 | */ | 4 | */ | ||
5 | 5 | | |||
6 | #include "CPUEntry.h" | 6 | #include "CPUEntry.h" | ||
7 | 7 | | |||
8 | #include <QMap> | 8 | #include <QMap> | ||
9 | 9 | | |||
10 | #include <solid/device.h> | 10 | #include <solid/device.h> | ||
11 | #include <solid/processor.h> | 11 | #include <solid/processor.h> | ||
12 | 12 | | |||
13 | #include "FancyString.h" | ||||
14 | | ||||
13 | CPUEntry::CPUEntry() | 15 | CPUEntry::CPUEntry() | ||
14 | : Entry(KLocalizedString(), QString()) | 16 | : Entry(KLocalizedString(), QString()) | ||
15 | { | 17 | { | ||
16 | const QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); | 18 | const QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); | ||
17 | 19 | | |||
18 | label = ki18np("Processor:", "Processors:").subs(list.count()); | 20 | label = ki18np("Processor:", "Processors:").subs(list.count()); | ||
19 | 21 | | |||
20 | // Format processor string | 22 | // Format processor string | ||
21 | // Group by processor name | 23 | // Group by processor name | ||
22 | QMap<QString, int> processorMap; | 24 | QMap<QString, int> processorMap; | ||
23 | for (const Solid::Device &device : list) { | 25 | for (const Solid::Device &device : list) { | ||
24 | const QString name = device.product(); | 26 | const QString name = device.product(); | ||
25 | auto it = processorMap.find(name); | 27 | auto it = processorMap.find(name); | ||
26 | if (it == processorMap.end()) { | 28 | if (it == processorMap.end()) { | ||
27 | processorMap.insert(name, 1); | 29 | processorMap.insert(name, 1); | ||
28 | } else { | 30 | } else { | ||
29 | ++it.value(); | 31 | ++it.value(); | ||
30 | } | 32 | } | ||
31 | } | 33 | } | ||
32 | // Create a formatted list of grouped processors | 34 | // Create a formatted list of grouped processors | ||
33 | QStringList names; | 35 | QStringList names; | ||
34 | names.reserve(processorMap.count()); | 36 | names.reserve(processorMap.count()); | ||
35 | for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) { | 37 | for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) { | ||
36 | const int count = it.value(); | 38 | const int count = it.value(); | ||
37 | QString name = it.key(); | 39 | QString name = FancyString::fromUgly(it.key()); | ||
38 | name.replace(QStringLiteral("(TM)"), QChar(8482)); | | |||
39 | name.replace(QStringLiteral("(R)"), QChar(174)); | | |||
40 | name = name.simplified(); | | |||
41 | names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); | 40 | names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); | ||
42 | } | 41 | } | ||
43 | 42 | | |||
44 | value = names.join(QLatin1String(", ")); | 43 | value = names.join(QLatin1String(", ")); | ||
45 | } | 44 | } |