From 005c45f5c0365de2e016d6e023523d32d2a81652 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 8 Jan 2021 06:55:41 +0200 Subject: [PATCH] about-distro: various improvements Signed-off-by: Ivailo Monev --- about-distro/src/Module.cpp | 37 +++++++------------ about-distro/src/OSRelease.cpp | 80 ++++++++++++++++++------------------------ about-distro/src/OSRelease.h | 11 +----- 3 files changed, 48 insertions(+), 80 deletions(-) diff --git a/about-distro/src/Module.cpp b/about-distro/src/Module.cpp index 98aba169..c9667dfa 100644 --- a/about-distro/src/Module.cpp +++ b/about-distro/src/Module.cpp @@ -24,8 +24,6 @@ #include #include -#include -#include #include #include #include @@ -52,6 +50,8 @@ static qlonglong calculateTotalRam() if (sysinfo(&info) == 0) // manpage "sizes are given as multiples of mem_unit bytes" ret = info.totalram * info.mem_unit; +#else +# warning calculateTotalRam() not implemented for this OS #endif return ret; } @@ -62,14 +62,15 @@ Module::Module(QWidget *parent, const QVariantList &args) : { KAboutData *about = new KAboutData("kcm-about-distro", 0, ki18n("About Distribution"), - "1.1.0", + "1.2.0", KLocalizedString(), KAboutData::License_GPL_V3, - ki18n("Copyright 2012-2014 Harald Sitter"), + ki18n("Copyright 2012-2014 Harald Sitter\nCopyright 2021 Ivailo Monev"), KLocalizedString(), QByteArray(), - "apachelogger@ubuntu.com"); + "xakepa10@gmail.com"); about->addAuthor(ki18n("Harald Sitter"), ki18n("Author"), "apachelogger@ubuntu.com"); + about->addAuthor(ki18n("Ivailo Monev"), ki18n("Current maintainer"), "xakepa10@gmail.com"); setAboutData(about); ui->setupUi(this); @@ -83,9 +84,6 @@ Module::Module(QWidget *parent, const QVariantList &args) : // We have no help so remove the button from the buttons. setButtons(buttons() ^ KCModule::Help ^ KCModule::Default ^ KCModule::Apply); - - QShortcut *shortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_G), this); - connect(shortcut, SIGNAL(activated()), this, SLOT(onStyle())); } Module::~Module() @@ -95,25 +93,14 @@ Module::~Module() void Module::load() { - KSharedConfig::Ptr config = KSharedConfig::openConfig("kcm-about-distrorc"); - KConfigGroup cg = KConfigGroup(config, "General"); + OSRelease os; - QString logoPath = cg.readEntry("LogoPath", QString()); - QPixmap logo; - if (logoPath.isEmpty()) - logo = KIcon("start-here-kde").pixmap(128, 128); - else - logo = QPixmap(logoPath); + QPixmap logo = KIcon(os.logo).pixmap(128, 128); ui->logoLabel->setPixmap(logo); - OSRelease os; - // 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. - QString distroName = cg.readEntry("Name", os.prettyName); - ui->nameVersionLabel->setText(QString("%1 %2").arg(distroName, os.versionId)); + ui->nameVersionLabel->setText(QString("%1 %2").arg(os.prettyName, os.versionId)); - QString url = cg.readEntry("Website", os.homeUrl); + QString url = os.homeUrl; if (url.isEmpty()) ui->urlLabel->hide(); else @@ -123,13 +110,13 @@ void Module::load() ui->qtLabel->setText(qVersion()); struct utsname utsName; - if(uname(&utsName) != 0) { + if(::uname(&utsName) != 0) { ui->kernel->hide(); ui->kernelLabel->hide(); } else ui->kernelLabel->setText(utsName.release); - const int bits = QT_POINTER_SIZE == 8 ? 64 : 32; + const int bits = (QT_POINTER_SIZE == 8 ? 64 : 32); ui->bitsLabel->setText(i18nc("@label %1 is the CPU bit width (e.g. 32 or 64)", "%1-bit", bits)); diff --git a/about-distro/src/OSRelease.cpp b/about-distro/src/OSRelease.cpp index 22b231c3..d41c5686 100644 --- a/about-distro/src/OSRelease.cpp +++ b/about-distro/src/OSRelease.cpp @@ -35,7 +35,7 @@ static void setVar(QString *var, const QString &value) if (error != KShell::NoError) { // Failed to parse. return; } - *var = args.join(QChar(' ')); + *var = args.join(QLatin1String(" ")); } static void setVar(QStringList *var, const QString &value) @@ -50,7 +50,7 @@ static void setVar(QStringList *var, const QString &value) // is required to not contain spaces even if more advanced shell escaping // is also allowed... QString value_ = value; - if (value_.at(0) == QChar('"') && value_.at(value_.size()-1) == QChar('"')) { + if (value_.at(0) == QLatin1Char('"') && value_.at(value_.size()-1) == QLatin1Char('"')) { value_.remove(0, 1); value_.remove(-1, 1); } @@ -62,65 +62,55 @@ static void setVar(QStringList *var, const QString &value) *var = args; } +// https://www.freedesktop.org/software/systemd/man/os-release.html OSRelease::OSRelease() { - QFile file("/etc/os-release"); // 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); // Set default values for non-optional fields. - name = QLatin1String("Linux"); - id = QLatin1String("linux"); + logo = QLatin1String("start-here-kde"); prettyName = QLatin1String("Linux"); - QString line; - QStringList comps; - while (!file.atEnd()) { - line = file.readLine(); + static const QStringList OSReleaseFiles = QStringList() + << QLatin1String("/etc/os-release") + << QLatin1String("/usr/lib/os-release"); - if (line.startsWith(QChar('#'))) { - // Comment line + foreach (const QString &releaseFile, OSReleaseFiles) { + QFile file(releaseFile); + if (!file.exists()) { continue; } + file.open(QIODevice::ReadOnly | QIODevice::Text); - comps = line.split(QChar('=')); + while (!file.atEnd()) { + QString line = file.readLine(); + if (line.startsWith(QLatin1Char('#'))) { + // Comment line + continue; + } - if (comps.size() != 2) { - // Invalid line. - continue; - } + QStringList comps = line.split(QLatin1Char('=')); + if (comps.size() != 2) { + // Invalid line. + continue; + } - QString key = comps.at(0); - QString value = comps.at(1).trimmed(); - if (key == QLatin1String("NAME")) - setVar(&name, value); - else if (key == QLatin1String("VERSION")) - setVar(&version, value); - else if (key == QLatin1String("ID")) - setVar(&id, value); - else if (key == QLatin1String("ID_LIKE")) - setVar(&idLike, value); - else if (key == QLatin1String("VERSION_ID")) - setVar(&versionId, value); - else if (key == QLatin1String("PRETTY_NAME")) - setVar(&prettyName, value); - else if (key == QLatin1String("ANSI_COLOR")) - setVar(&ansiColor, value); - else if (key == QLatin1String("CPE_NAME")) - setVar(&cpeName, value); - else if (key == QLatin1String("HOME_URL")) - setVar(&homeUrl, value); - else if (key == QLatin1String("SUPPORT_URL")) - setVar(&supportUrl, value); - else if (key == QLatin1String("BUG_REPORT_URL")) - setVar(&bugReportUrl, value); - else if (key == QLatin1String("BUILD_ID")) - setVar(&buildId, value); - // os-release explicitly allows for vendor specific aditions. We have no - // interest in those right now. + QString key = comps.at(0); + QString value = comps.at(1).trimmed(); + if (key == QLatin1String("LOGO")) { + setVar(&logo, value); + } else if (key == QLatin1String("VERSION_ID")) { + setVar(&versionId, value); + } else if (key == QLatin1String("PRETTY_NAME")) { + setVar(&prettyName, value); + } else if (key == QLatin1String("HOME_URL")) { + setVar(&homeUrl, value); + } + // only these above are used right now + } } } diff --git a/about-distro/src/OSRelease.h b/about-distro/src/OSRelease.h index 797b908d..97aabcfa 100644 --- a/about-distro/src/OSRelease.h +++ b/about-distro/src/OSRelease.h @@ -29,19 +29,10 @@ class OSRelease public: OSRelease(); - QString name; - QString version; - QString id; - QStringList idLike; + QString logo; QString versionId; QString prettyName; - QString ansiColor; - QString cpeName; - // TODO: url struct or map? QString homeUrl; - QString supportUrl; - QString bugReportUrl; - QString buildId; }; #endif // OSRELEASE_H -- 2.11.0