File indexing completed on 2024-12-15 03:45:04

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "platforminfosource.h"
0008 
0009 #include <QSysInfo>
0010 #include <QVariant>
0011 
0012 using namespace KUserFeedback;
0013 
0014 PlatformInfoSource::PlatformInfoSource() :
0015     AbstractDataSource(QStringLiteral("platform"), Provider::BasicSystemInformation)
0016 {
0017 }
0018 
0019 QString PlatformInfoSource::description() const
0020 {
0021     return tr("Type and version of the operating system.");
0022 }
0023 
0024 QVariant PlatformInfoSource::data()
0025 {
0026     QVariantMap m;
0027 #if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID))
0028     // on Linux productType() is the distro name
0029     m.insert(QStringLiteral("os"), QStringLiteral("linux"));
0030 
0031     // openSUSE Tumbleweed has the current date as version number, that is a bit too precise for us
0032     if (QSysInfo::productType() == QLatin1String("opensuse") && QSysInfo::productVersion().startsWith(QLatin1String("201"))) {
0033         // old form in use until early 2018
0034         m.insert(QStringLiteral("version"), QString(QSysInfo::productType() + QLatin1String("-tumbleweed")));
0035     } else if (QSysInfo::productType() == QLatin1String("opensuse-tumbleweed")) {
0036         // new form in use since early 2018
0037         m.insert(QStringLiteral("version"), QSysInfo::productType());
0038     }
0039     // Arch and other rolling-release distros set productVersion to "unknown"
0040     else if (QSysInfo::productVersion() == QLatin1String("unknown")) {
0041         m.insert(QStringLiteral("version"), QSysInfo::productType());
0042     } else {
0043         m.insert(QStringLiteral("version"), QString(QSysInfo::productType() + QLatin1Char('-') + QSysInfo::productVersion()));
0044     }
0045 #elif defined(Q_OS_MAC)
0046     // QSysInfo::productType() on macOS alternates between "osx" and "macos"...
0047     m.insert(QStringLiteral("os"), QStringLiteral("macos"));
0048     m.insert(QStringLiteral("version"), QSysInfo::productVersion());
0049 #else
0050     m.insert(QStringLiteral("os"), QSysInfo::productType());
0051     m.insert(QStringLiteral("version"), QSysInfo::productVersion());
0052 #endif
0053     return m;
0054 }
0055 
0056 QString PlatformInfoSource::name() const
0057 {
0058     return tr("Platform information");
0059 }