diff --git a/Modules/about-distro/CMakeLists.txt b/Modules/about-distro/CMakeLists.txt index 9d41c50..0a77d44 100644 --- a/Modules/about-distro/CMakeLists.txt +++ b/Modules/about-distro/CMakeLists.txt @@ -1,11 +1,7 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcm-about-distro\") add_subdirectory(src) -if(BUILD_TESTING) - add_subdirectory(autotests) -endif() - feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/Modules/about-distro/autotests/CMakeLists.txt b/Modules/about-distro/autotests/CMakeLists.txt deleted file mode 100644 index 47f3bbc..0000000 --- a/Modules/about-distro/autotests/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -remove_definitions(-DQT_NO_CAST_FROM_ASCII) - -include(ECMAddTests) - -find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG REQUIRED) - -# Include src to get access to the OSRelease.h -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src) - -add_library(about-distro-test STATIC ../src/OSRelease.cpp) -target_link_libraries(about-distro-test - PUBLIC - KF5::CoreAddons -) - -ecm_add_tests( - OSReleaseTest.cpp - LINK_LIBRARIES - Qt5::Test - about-distro-test -) - -ecm_mark_nongui_executable(OSReleaseTest) diff --git a/Modules/about-distro/autotests/OSReleaseTest.cpp b/Modules/about-distro/autotests/OSReleaseTest.cpp deleted file mode 100644 index 66fdbe1..0000000 --- a/Modules/about-distro/autotests/OSReleaseTest.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (C) 2019 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 - -#include "OSRelease.h" - -class OSReleaseTest : public QObject -{ - Q_OBJECT -private Q_SLOTS: - void initTestCase() {} - - void testParse() - { - auto r = OSRelease(QFINDTESTDATA("data/os-release")); - QCOMPARE(r.name(), "Name"); - QCOMPARE(r.version(), "100.5"); - QCOMPARE(r.id(), "theid"); - QCOMPARE(r.idLike(), QStringList({"otherid", "otherotherid"})); - QCOMPARE(r.versionCodename(), "versioncodename"); - QCOMPARE(r.versionId(), "500.1"); - QCOMPARE(r.prettyName(), "Pretty Name"); - QCOMPARE(r.ansiColor(), "1;34"); - QCOMPARE(r.cpeName(), "cpe:/o:foo:bar:100"); - QCOMPARE(r.homeUrl(), "https://url.home"); - QCOMPARE(r.documentationUrl(), "https://url.docs"); - QCOMPARE(r.supportUrl(), "https://url.support"); - QCOMPARE(r.bugReportUrl(), "https://url.bugs"); - QCOMPARE(r.privacyPolicyUrl(), "https://url.privacy"); - QCOMPARE(r.buildId(), "105.5"); - QCOMPARE(r.variant(), "Test Edition"); - QCOMPARE(r.variantId(), "test"); - QCOMPARE(r.logo(), "start-here-test"); - QCOMPARE(r.extraKeys(), QStringList({"DEBIAN_BTS"})); - QCOMPARE(r.extraValue("DEBIAN_BTS"), "debbugs://bugs.debian.org/"); - } -}; - -QTEST_MAIN(OSReleaseTest) - -#include "OSReleaseTest.moc" diff --git a/Modules/about-distro/autotests/data/os-release b/Modules/about-distro/autotests/data/os-release deleted file mode 100644 index fabd553..0000000 --- a/Modules/about-distro/autotests/data/os-release +++ /dev/null @@ -1,21 +0,0 @@ -NAME="Name" -VERSION="100.5" -ID=theid -ID_LIKE="otherid otherotherid" -VERSION_CODENAME=versioncodename -VERSION_ID="500.1" -PRETTY_NAME="Pretty Name" -ANSI_COLOR="1;34" -CPE_NAME="cpe:/o:foo:bar:100" -HOME_URL="https://url.home" -DOCUMENTATION_URL="https://url.docs" -SUPPORT_URL="https://url.support" -BUG_REPORT_URL="https://url.bugs" -PRIVACY_POLICY_URL="https://url.privacy" -BUILD_ID="105.5" -# comment -VARIANT="Test Edition" -VARIANT_ID=test - # indented comment -LOGO=start-here-test -DEBIAN_BTS="debbugs://bugs.debian.org/" diff --git a/Modules/about-distro/src/CMakeLists.txt b/Modules/about-distro/src/CMakeLists.txt index 709fd5f..ffb9721 100644 --- a/Modules/about-distro/src/CMakeLists.txt +++ b/Modules/about-distro/src/CMakeLists.txt @@ -1,21 +1,20 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/Version.h) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(kcm_SRCS main.cpp Module.cpp - OSRelease.cpp ) ki18n_wrap_ui(kcm_SRCS Module.ui) add_library(kcm_about_distro MODULE ${kcm_SRCS}) target_link_libraries(kcm_about_distro KF5::ConfigWidgets KF5::CoreAddons KF5::I18n KF5::Solid) install(TARGETS kcm_about_distro DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES about-distro.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/Modules/about-distro/src/Module.cpp b/Modules/about-distro/src/Module.cpp index b4bc67e..efa41ab 100644 --- a/Modules/about-distro/src/Module.cpp +++ b/Modules/about-distro/src/Module.cpp @@ -1,315 +1,315 @@ /* Copyright (C) 2012-2014 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 "Module.h" #include "ui_Module.h" #include #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #ifdef Q_OS_LINUX #include #elif defined(Q_OS_FREEBSD) #include #include #endif #include -#include "OSRelease.h" #include "Version.h" static qlonglong calculateTotalRam() { qlonglong ret = -1; #ifdef Q_OS_LINUX struct sysinfo info; if (sysinfo(&info) == 0) // manpage "sizes are given as multiples of mem_unit bytes" ret = qlonglong(info.totalram) * info.mem_unit; #elif defined(Q_OS_FREEBSD) /* Stuff for sysctl */ size_t len; unsigned long memory; len = sizeof(memory); sysctlbyname("hw.physmem", &memory, &len, NULL, 0); ret = memory; #endif return ret; } Module::Module(QWidget *parent, const QVariantList &args) : KCModule(parent, args), ui(new Ui::Module) { KAboutData *aboutData = new KAboutData(QStringLiteral("kcm-about-distro"), i18nc("@title", "About Distribution"), QString::fromLatin1(global_s_versionStringFull), QString(), KAboutLicense::LicenseKey::GPL_V3, i18nc("@info:credit", "Copyright 2012-2014 Harald Sitter")); aboutData->addAuthor(i18nc("@info:credit", "Harald Sitter"), i18nc("@info:credit", "Author"), QStringLiteral("apachelogger@kubuntu.org")); setAboutData(aboutData); ui->setupUi(this); QFont font = ui->nameVersionLabel->font(); font.setPixelSize(24); font.setBold(true); ui->nameVersionLabel->setFont(font); QFont fontVariant = ui->variantLabel->font(); fontVariant.setPixelSize(18); fontVariant.setBold(true); ui->variantLabel->setFont(fontVariant); ui->urlLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); // We have no help so remove the button from the buttons. setButtons(buttons() ^ KCModule::Help ^ KCModule::Default ^ KCModule::Apply); // Setup Copy to Clipboard button connect(ui->pushButtonCopyInfo, &QPushButton::clicked, this, &Module::copyToClipboard); connect(ui->pushButtonCopyInfoInEnglish, &QPushButton::clicked, this, &Module::copyToClipboardInEnglish); if (QLocale::system().language() == QLocale::English) { ui->pushButtonCopyInfoInEnglish->hide(); } ui->pushButtonCopyInfo->setShortcut(QKeySequence::Copy); // https://bugs.kde.org/show_bug.cgi?id=366158 // When a KCM loads fast enough do a blocking load via the constructor. // Otherwise there is a notciable rendering gap where dummy/no data is // shown. Makes it look bad. load(); } Module::~Module() { delete ui; } void Module::load() { labelsForClipboard.clear(); englishTextForClipboard = QStringLiteral(""); loadSoftware(); loadHardware(); } void Module::save() { } void Module::defaults() { } void Module::loadSoftware() { // NOTE: do not include globals, otherwise kdeglobals could provide values // even though we only explicitly want them from our own config. KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kcm-about-distrorc"), KConfig::NoGlobals); KConfigGroup cg = KConfigGroup(config, "General"); - OSRelease os; + KOSRelease os; QString logoPath = cg.readEntry("LogoPath", os.logo()); if (logoPath.isEmpty()) { logoPath = QStringLiteral("start-here-kde"); } const QPixmap logo = QIcon::fromTheme(logoPath).pixmap(128, 128); ui->logoLabel->setPixmap(logo); // We allow overriding of the OS name for branding purposes. // For example OS Ubuntu may be rebranded as Kubuntu. Also Kubuntu Active // as a product brand is different from Kubuntu. const QString distroName = cg.readEntry("Name", os.name()); const QString osrVersion = cg.readEntry("UseOSReleaseVersion", false) ? os.version() : os.versionId(); const QString versionId = cg.readEntry("Version", osrVersion); const QString distroNameVersion = QStringLiteral("%1 %2").arg(distroName, versionId); ui->nameVersionLabel->setText(distroNameVersion); const auto dummyDistroDescriptionLabel = new QLabel(i18nc("@title:row", "Operating System:"), this); dummyDistroDescriptionLabel->hide(); labelsForClipboard << qMakePair(dummyDistroDescriptionLabel, ui->nameVersionLabel); englishTextForClipboard += QStringLiteral("Operating System: %1\n").arg(distroNameVersion); const QString variant = cg.readEntry("Variant", os.variant()); if (variant.isEmpty()) { ui->variantLabel->hide(); } else { ui->variantLabel->setText(variant); } const QString url = cg.readEntry("Website", os.homeUrl()); if (url.isEmpty()) { ui->urlLabel->hide(); } else { ui->urlLabel->setText(QStringLiteral("%1").arg(url)); } // Since Plasma version detection isn't based on a library query it can fail // in weird cases; instead of admitting defeat we simply hide everything :P const QString plasma = plasmaVersion(); if (plasma.isEmpty()) { ui->plasma->hide(); ui->plasmaLabel->hide(); } else { ui->plasmaLabel->setText(plasma); labelsForClipboard << qMakePair(ui->plasma, ui->plasmaLabel); englishTextForClipboard += QStringLiteral("KDE Plasma Version: %1\n").arg(plasma); } const QString frameworksVersion = KCoreAddons::versionString(); ui->frameworksLabel->setText(frameworksVersion); labelsForClipboard << qMakePair(ui->frameworksLabelKey, ui->frameworksLabel); englishTextForClipboard += QStringLiteral("KDE Frameworks Version: %1\n").arg(frameworksVersion); const QString qversion = QString::fromLatin1(qVersion()); ui->qtLabel->setText(qversion); labelsForClipboard << qMakePair(ui->qt, ui->qtLabel); englishTextForClipboard += QStringLiteral("Qt Version: %1\n").arg(qversion); } void Module::loadHardware() { struct utsname utsName; if(uname(&utsName) != 0) { ui->kernel->hide(); ui->kernelLabel->hide(); } else { QString kernelVersion = QString::fromLatin1(utsName.release); ui->kernelLabel->setText(kernelVersion); labelsForClipboard << qMakePair(ui->kernel, ui->kernelLabel); englishTextForClipboard += QStringLiteral("Kernel Version: %1\n").arg(kernelVersion); } const int bits = QT_POINTER_SIZE == 8 ? 64 : 32; const QString bitsStr = QString::number(bits); ui->bitsLabel->setText(i18nc("@label %1 is the CPU bit width (e.g. 32 or 64)", "%1-bit", bitsStr)); labelsForClipboard << qMakePair(ui->bitsKey, ui->bitsLabel); englishTextForClipboard += QStringLiteral("OS Type: %1-bit\n").arg(bitsStr); const QList list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); ui->processor->setText(i18np("Processor:", "Processors:", list.count())); // Format processor string // Group by processor name QMap processorMap; Q_FOREACH(const Solid::Device &device, list) { const QString name = device.product(); auto it = processorMap.find(name); if (it == processorMap.end()) { processorMap.insert(name, 1); } else { ++it.value(); } } // Create a formatted list of grouped processors QStringList names; 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(); names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); } const QString processorLabel = names.join(QStringLiteral(", ")); ui->processorLabel->setText(processorLabel); if (ui->processorLabel->text().isEmpty()) { ui->processor->setHidden(true); ui->processorLabel->setHidden(true); } else { labelsForClipboard << qMakePair(ui->processor, ui->processorLabel); englishTextForClipboard += QStringLiteral("Processors: %1\n").arg(processorLabel); } const qlonglong totalRam = calculateTotalRam(); const QString memoryLabel = totalRam > 0 ? i18nc("@label %1 is the formatted amount of system memory (e.g. 7,7 GiB)", "%1 of RAM", KFormat().formatByteSize(totalRam)) : i18nc("Unknown amount of RAM", "Unknown"); ui->memoryLabel->setText(memoryLabel); labelsForClipboard << qMakePair(ui->memory, ui->memoryLabel); englishTextForClipboard += QStringLiteral("Memory: %1\n").arg(KFormat().formatByteSize(totalRam)); } void Module::copyToClipboard() { QString text; // note that this loop does not necessarily represent the same order as in the GUI for (auto labelPair : qAsConst(labelsForClipboard)) { const auto valueLabel = labelPair.second; if (!valueLabel->isHidden()) { const auto descriptionLabelText = labelPair.first->text(); const auto valueLabelText = valueLabel->text(); text += i18nc("%1 is a label already including a colon, %2 is the corresponding value", "%1 %2", descriptionLabelText, valueLabelText) + QStringLiteral("\n"); } } QGuiApplication::clipboard()->setText(text); } void Module::copyToClipboardInEnglish() { QGuiApplication::clipboard()->setText(englishTextForClipboard); } QString Module::plasmaVersion() const { const QStringList &filePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("xsessions/plasma.desktop")); if (filePaths.length() < 1) { return QString(); } // Despite the fact that there can be multiple desktop files we simply take // the first one as users usually don't have xsessions/ in their $HOME // data location, so the first match should (usually) be the only one and // reflect the plasma session run. KDesktopFile desktopFile(filePaths.first()); return desktopFile.desktopGroup().readEntry("X-KDE-PluginInfo-Version", QString()); } diff --git a/Modules/about-distro/src/OSRelease.cpp b/Modules/about-distro/src/OSRelease.cpp deleted file mode 100644 index 3d8aecc..0000000 --- a/Modules/about-distro/src/OSRelease.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/* - Copyright (C) 2014-2019 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 "OSRelease.h" - -#include -#include - -#include - -// Sets a QString var -static void setVar(QString *var, const QString &value) -{ - // Values may contain quotation marks, strip them as we have no use for them. - KShell::Errors error; - QStringList args = KShell::splitArgs(value, KShell::NoOptions, &error); - if (error != KShell::NoError) { // Failed to parse. - return; - } - *var = args.join(QLatin1Char(' ')); -} - -// Sets a QStringList var (i.e. splits a string value) -static void setVar(QStringList *var, const QString &value) -{ - // Instead of passing the verbatim value we manually strip any initial quotes - // and then run it through KShell. At this point KShell will actually split - // by spaces giving us the final QStringList. - // NOTE: Splitting like this does not actually allow escaped substrings to - // be handled correctly, so "kitteh \"french fries\"" would result in - // three list entries. I'd argue that if someone makes an id like that - // they are at fault for the bogus parsing here though as id explicitly - // is required to not contain spaces even if more advanced shell escaping - // is also allowed... - QString value_ = value; - if (value_.at(0) == QLatin1Char('"') && value_.at(value_.size()-1) == QLatin1Char('"')) { - value_.remove(0, 1); - value_.remove(-1, 1); - } - KShell::Errors error; - QStringList args = KShell::splitArgs(value_, KShell::NoOptions, &error); - if (error != KShell::NoError) { // Failed to parse. - return; - } - *var = args; -} - -class Q_DECL_HIDDEN OSRelease::Private -{ -public: - Private(const QString &filePath) - : name(QStringLiteral("Linux")) - , id(QStringLiteral("linux")) - , prettyName(QStringLiteral("Linux")) - { - // Default values for non-optional fields set above ^. - - if (filePath.isEmpty()) { - return; - } - - QHash stringHash = { - { QStringLiteral("NAME"), &name }, - { QStringLiteral("VERSION"), &version }, - { QStringLiteral("ID"), &id }, - // idLike is not a QString, special handling below! - { QStringLiteral("VERSION_CODENAME"), &versionCodename }, - { QStringLiteral("VERSION_ID"), &versionId }, - { QStringLiteral("PRETTY_NAME"), &prettyName }, - { QStringLiteral("ANSI_COLOR"), &ansiColor }, - { QStringLiteral("CPE_NAME"), &cpeName }, - { QStringLiteral("HOME_URL"), &homeUrl }, - { QStringLiteral("DOCUMENTATION_URL"), &documentationUrl }, - { QStringLiteral("SUPPORT_URL"), &supportUrl }, - { QStringLiteral("BUG_REPORT_URL"), &bugReportUrl }, - { QStringLiteral("PRIVACY_POLICY_URL"), &privacyPolicyUrl }, - { QStringLiteral("BUILD_ID"), &buildId }, - { QStringLiteral("VARIANT"), &variant }, - { QStringLiteral("VARIANT_ID"), &variantId }, - { QStringLiteral("LOGO"), &logo } - }; - - QFile file(filePath); - // NOTE: The os-release specification defines default values for specific - // fields which means that even if we can not read the os-release file - // we have sort of expected default values to use. - // TODO: it might still be handy to indicate to the outside whether - // fallback values are being used or not. - file.open(QIODevice::ReadOnly | QIODevice::Text); - QString line; - QStringList parts; - while (!file.atEnd()) { - // Trimmed to handle indented comment lines properly - line = QString::fromLatin1(file.readLine()).trimmed(); - - if (line.startsWith(QLatin1Char('#'))) { - // Comment line - continue; - } - - parts = line.split(QLatin1Char('=')); - - if (parts.size() != 2 || line.contains(QChar('#'))) { - // Invalid line... - // For the purposes of simple parsing we'll not support >2 = - // or >1 # characters. - // The former makes splitting and the latter makes comment - // stripping difficult. - continue; - } - - QString key = parts.at(0); - QString value = parts.at(1).trimmed(); - - if (QString *var = stringHash.value(key, nullptr)) { - setVar(var, value); - continue; - } - - // ID_LIKE is a list and parsed as such (rather than a QString). - if (key == QLatin1String("ID_LIKE")) { - setVar(&idLike, value); - continue; - } - - // os-release explicitly allows for vendor specific additions, we'll - // collect them as strings and exposes them as "extras". - QString parsedValue; - setVar(&parsedValue, value); - extras.insert(key, parsedValue); - } - } - - QString name; - QString version; - QString id; - QStringList idLike; - QString versionCodename; - QString versionId; - QString prettyName; - QString ansiColor; - QString cpeName; - QString homeUrl; - QString documentationUrl; - QString supportUrl; - QString bugReportUrl; - QString privacyPolicyUrl; - QString buildId; - QString variant; - QString variantId; - QString logo; - - QHash extras; -}; - -OSRelease::OSRelease(const QString &filePath) - : d(new Private(filePath)) -{ -} - -OSRelease::~OSRelease() -{ - delete d; -} - -QString OSRelease::name() const -{ - return d->name; -} - -QString OSRelease::version() const -{ - return d->version; -} - -QString OSRelease::id() const -{ - return d->id; -} - -QStringList OSRelease::idLike() const -{ - return d->idLike; -} - -QString OSRelease::versionCodename() const -{ - return d->versionCodename; -} - -QString OSRelease::versionId() const -{ - return d->versionId; -} - -QString OSRelease::prettyName() const -{ - return d->prettyName; -} - -QString OSRelease::ansiColor() const -{ - return d->ansiColor; -} - -QString OSRelease::cpeName() const -{ - return d->cpeName; -} - -QString OSRelease::homeUrl() const -{ - return d->homeUrl; -} - -QString OSRelease::documentationUrl() const -{ - return d->documentationUrl; -} - -QString OSRelease::supportUrl() const -{ - return d->supportUrl; -} - -QString OSRelease::bugReportUrl() const -{ - return d->bugReportUrl; -} - -QString OSRelease::privacyPolicyUrl() const -{ - return d->privacyPolicyUrl; -} - -QString OSRelease::buildId() const -{ - return d->buildId; -} - -QString OSRelease::variant() const -{ - return d->variant; -} - -QString OSRelease::variantId() const -{ - return d->variantId; -} - -QString OSRelease::logo() const -{ - return d->logo; -} - -QStringList OSRelease::extraKeys() const -{ - return d->extras.keys(); -} - -QString OSRelease::extraValue(const QString &key) const -{ - return d->extras.value(key); -} - -QString OSRelease::defaultFilePath() -{ - if (QFile::exists(QStringLiteral("/etc/os-release"))) { - return QStringLiteral("/etc/os-release"); - } else if (QFile::exists(QStringLiteral("/usr/lib/os-release"))) { - return QStringLiteral("/usr/lib/os-release"); - } else { - return QString(); - } -} diff --git a/Modules/about-distro/src/OSRelease.h b/Modules/about-distro/src/OSRelease.h deleted file mode 100644 index d033c6c..0000000 --- a/Modules/about-distro/src/OSRelease.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright (C) 2014-2019 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 OSRELEASE_H -#define OSRELEASE_H - -#include -#include - -/** - * @brief The OSRelease class parses /etc/os-release files - * - * https://www.freedesktop.org/software/systemd/man/os-release.html - * - * os-release is a free software standard for describing an operating system. - * This class parses and models os-release files. - */ -class OSRelease -{ -public: - /** - * Constructs a new OSRelease instance. Parsing happens in the constructor - * and the data is not cached across instances. - * - * @note For parsing simplicity neither trailing comments nor multiple '=' - * characters are allowed. - * - * @param filePath The path to the os-release file. By default the first - * available file of the paths specified in the os-release manpage is - * parsed. - */ - explicit OSRelease(const QString &filePath = defaultFilePath()); - ~OSRelease(); - - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#NAME= */ - QString name() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#VERSION= */ - QString version() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#ID= */ - QString id() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#ID_LIKE= */ - QStringList idLike() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#VERSION_CODENAME= */ - QString versionCodename() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#VERSION_ID= */ - QString versionId() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#PRETTY_NAME= */ - QString prettyName() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#ANSI_COLOR= */ - QString ansiColor() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#CPE_NAME= */ - QString cpeName() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#HOME_URL= */ - QString homeUrl() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#HOME_URL= */ - QString documentationUrl() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#HOME_URL= */ - QString supportUrl() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#HOME_URL= */ - QString bugReportUrl() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#HOME_URL= */ - QString privacyPolicyUrl() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#BUILD_ID= */ - QString buildId() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#VARIANT= */ - QString variant() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#VARIANT_ID= */ - QString variantId() const; - /** @see https://www.freedesktop.org/software/systemd/man/os-release.html#LOGO= */ - QString logo() const; - - /** - * Extra keys are keys that are unknown or specified by a vendor. - */ - QStringList extraKeys() const; - - /** Extra values are values assoicated with keys that are unknown. */ - QString extraValue(const QString &key) const; - -private: - static QString defaultFilePath(); - - class Private; - Private *const d = nullptr; -}; - -#endif // OSRELEASE_H