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 @@ -25,6 +25,8 @@ #include #include +#include "FancyString.h" + CPUEntry::CPUEntry() : Entry(KLocalizedString(), QString()) { @@ -49,10 +51,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,32 @@ +/* + Copyright (C) 2012-2020 Harald Sitter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#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,34 @@ +/* + Copyright (C) 2012-2020 Harald Sitter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#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,33 @@ +/* + Copyright (C) 2016 Rohan Garg + Copyright (C) 2020 Harald Sitter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#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,56 @@ +/* + Copyright (C) 2016 Rohan Garg + Copyright (C) 2020 Harald Sitter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#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 @@ -35,6 +35,7 @@ #include "CPUEntry.h" #include "BitEntry.h" +#include "GPUEntry.h" #include "KernelEntry.h" #include "MemoryEntry.h" #include "PlasmaEntry.h" @@ -204,7 +205,8 @@ addSectionHeader(i18nc("@title:group", "Hardware")); addEntriesToGrid({ new CPUEntry(), - new MemoryEntry() + new MemoryEntry(), + new GPUEntry() }); }