Commit 4cfd889c authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

unbreak about CPU value when solid is missing a product string

instead of `Processors: 4 x` one now gets `Processors: 4`, or
`Processors: 4 x Unknown Type, 12 x AMD Ryzen 5 3600X 6-Core Processor`
when some of the cores have a product and the others do not.

The latter is an incredible edge case but I suppose we best handle it
properly. It did require reshuffling of the entry though. We now list
the cores in the ctor to generate the label but only generate the values
at call time so as to localize this potential placeholder accordingly.

Meanwhile the former case ultimately lumps all processors together even
when they are actually different from a physical POV (such as the
heterogenous CPU set up of "ARM big.LITTLE"), but given the high level
overview this KCM provides there is no point in expansively trying to
figure out what the actual topology is (we do indeed not concern
ourselves with topology at all in this entry).

BUG: 439464
FIXED-IN: 5.22.4


(cherry picked from commit 0e5e4567)
parent 1fe0af32
/*
SPDX-FileCopyrightText: 2012-2020 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2012-2021 Harald Sitter <sitter@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
......@@ -7,7 +7,6 @@
#include <QMap>
#include <solid/device.h>
#include <solid/processor.h>
#include "FancyString.h"
......@@ -15,14 +14,18 @@
CPUEntry::CPUEntry()
: Entry(KLocalizedString(), QString())
{
const QList<Solid::Device> list = Solid::Device::listFromType(Solid::DeviceInterface::Processor);
m_label = ki18np("Processor:", "Processors:").subs(m_cpus.count());
}
m_label = ki18np("Processor:", "Processors:").subs(list.count());
QString CPUEntry::localizedValue(Language language) const
{
const KLocalizedString l10nUnknown = ki18nc("unknown CPU type/product name; presented as `Processors: 4 × Unknown Type'", "Unknown Type");
const QString unknownName = localize(l10nUnknown, language);
// Format processor string
// Group by processor name
QMap<QString, int> processorMap;
for (const Solid::Device &device : list) {
for (const Solid::Device &device : m_cpus) {
const QString name = device.product();
auto it = processorMap.find(name);
if (it == processorMap.end()) {
......@@ -34,11 +37,20 @@ CPUEntry::CPUEntry()
// Create a formatted list of grouped processors
QStringList names;
names.reserve(processorMap.count());
const bool multipleProducts = processorMap.count() > 1;
for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) {
const int count = it.value();
QString name = FancyString::fromUgly(it.key());
names.append(QStringLiteral("%1 × %2").arg(count).arg(name));
// In case solid doesn't have a product name available we'll either show no name or a placeholder.
if (name.isEmpty() && !multipleProducts) {
names.append(QString::number(count));
} else {
if (name.isEmpty()) {
name = unknownName;
}
names.append(QStringLiteral("%1 × %2").arg(count).arg(name));
}
}
m_value = names.join(QLatin1String(", "));
return names.join(QLatin1String(", "));
}
/*
SPDX-FileCopyrightText: 2012-2020 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2012-2021 Harald Sitter <sitter@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#ifndef CPUENTRY_H
#define CPUENTRY_H
#include <solid/device.h>
#include "Entry.h"
class CPUEntry : public Entry
{
public:
CPUEntry();
QString localizedValue(Language language = Language::System) const override;
private:
const QList<Solid::Device> m_cpus = Solid::Device::listFromType(Solid::DeviceInterface::Processor);
};
#endif // CPUENTRY_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment