diff --git a/Modules/about-distro/src/CMakeLists.txt b/Modules/about-distro/src/CMakeLists.txt --- a/Modules/about-distro/src/CMakeLists.txt +++ b/Modules/about-distro/src/CMakeLists.txt @@ -11,6 +11,8 @@ BitEntry.cpp MemoryEntry.cpp CPUEntry.cpp + GPUEntry.cpp + FancyString.cpp ) ki18n_wrap_ui(kcm_SRCS Module.ui) diff --git a/Modules/about-distro/src/CPUEntry.cpp b/Modules/about-distro/src/CPUEntry.cpp --- a/Modules/about-distro/src/CPUEntry.cpp +++ b/Modules/about-distro/src/CPUEntry.cpp @@ -10,6 +10,8 @@ #include #include +#include "FancyString.h" + CPUEntry::CPUEntry() : Entry(KLocalizedString(), QString()) { @@ -34,10 +36,7 @@ names.reserve(processorMap.count()); for (auto it = processorMap.constBegin(); it != processorMap.constEnd(); ++it) { const int count = it.value(); - QString name = it.key(); - name.replace(QStringLiteral("(TM)"), QChar(8482)); - name.replace(QStringLiteral("(R)"), QChar(174)); - name = name.simplified(); + QString name = FancyString::fromUgly(it.key()); names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); } diff --git a/Modules/about-distro/src/FancyString.h b/Modules/about-distro/src/FancyString.h new file mode 100644 --- /dev/null +++ b/Modules/about-distro/src/FancyString.h @@ -0,0 +1,17 @@ +/* + SPDX-FileCopyrightText: 2012-2020 Harald Sitter + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +#ifndef FANCYSTRING_H +#define FANCYSTRING_H + +#include + +namespace FancyString +{ + // Turns ugly '(R)' '(TM)' ascii into unicode. + QString fromUgly(const QString &string); +} + +#endif // FANCYSTRING_H diff --git a/Modules/about-distro/src/FancyString.cpp b/Modules/about-distro/src/FancyString.cpp new file mode 100644 --- /dev/null +++ b/Modules/about-distro/src/FancyString.cpp @@ -0,0 +1,19 @@ +/* + SPDX-FileCopyrightText: 2012-2020 Harald Sitter + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +#include "FancyString.h" + +namespace FancyString +{ + +QString fromUgly(const QString &string) +{ + QString ugly(string); + ugly.replace(QStringLiteral("(TM)"), QChar(8482)); + ugly.replace(QStringLiteral("(R)"), QChar(174)); + return ugly.simplified(); +} + +} // namespace FancyString diff --git a/Modules/about-distro/src/GPUEntry.h b/Modules/about-distro/src/GPUEntry.h new file mode 100644 --- /dev/null +++ b/Modules/about-distro/src/GPUEntry.h @@ -0,0 +1,18 @@ +/* + SPDX-FileCopyrightText: 2016 Rohan Garg + SPDX-FileCopyrightText: 2020 Harald Sitter + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +#ifndef GPUENTRY_H +#define GPUENTRY_H + +#include "Entry.h" + +class GPUEntry : public Entry +{ +public: + GPUEntry(); +}; + +#endif // GPUENTRY_H diff --git a/Modules/about-distro/src/GPUEntry.cpp b/Modules/about-distro/src/GPUEntry.cpp new file mode 100644 --- /dev/null +++ b/Modules/about-distro/src/GPUEntry.cpp @@ -0,0 +1,42 @@ +/* + SPDX-FileCopyrightText: 2016 Rohan Garg + + SPDX-FileCopyrightText: 2020 Harald Sitter + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +#include "GPUEntry.h" + +#include +#include +#include +#include + +#include + +#include "FancyString.h" + +GPUEntry::GPUEntry() + : Entry(ki18n("Graphics Processor:"), QString()) +{ + QOpenGLContext context; + QOffscreenSurface surface; + surface.create(); + if (!context.create()) { + qWarning() << "Failed create QOpenGLContext"; + return; + } + + if (context.makeCurrent(&surface)) { + value = QString::fromLatin1(reinterpret_cast( + context.functions()->glGetString(GL_RENDERER))); + value = FancyString::fromUgly(value); + // It seems the renderer value may have excess information in parentheses -> + // strip that. Elide would probably be nicer, a bit meh with QWidgets though. + value = value.mid(0, value.indexOf('(')); + context.doneCurrent(); + } else { + qWarning() << "Failed to make QOpenGLContext current"; + return; + } +} diff --git a/Modules/about-distro/src/Module.cpp b/Modules/about-distro/src/Module.cpp --- a/Modules/about-distro/src/Module.cpp +++ b/Modules/about-distro/src/Module.cpp @@ -20,6 +20,7 @@ #include "CPUEntry.h" #include "BitEntry.h" +#include "GPUEntry.h" #include "KernelEntry.h" #include "MemoryEntry.h" #include "PlasmaEntry.h" @@ -189,7 +190,8 @@ addSectionHeader(i18nc("@title:group", "Hardware")); addEntriesToGrid({ new CPUEntry(), - new MemoryEntry() + new MemoryEntry(), + new GPUEntry() }); }