shift-shell/kcms/info/info.cpp
Sebastian Kügler 6c746e62d5 [info kcm]: add vendorinfo card
This change adds a card to the Information KCM which can be used to
display vendor-specific information (think of product info, serial or
model number, support info, etc.).

The information is read from a json file in /etc/vendorinfo.json, format
as follows:

'''
{
    "Title" : "Vendor Information",
    "Content" : [
        {
            "Key": "Model Number",
            "Value": "24ABC-13N4"
        },
        {
            "Key": "Serial Number",
            "Value": "778899223344"
        },
        {
            "Key": "Support Phone",
            "Value": "+31 6 48370928"
        }
    ]
}
'''

Title is the card header, each Key/Value block adds a TextDelegate. This
block is only displayed if the file actually exists and has a Title set.

Signed-off-by: Sebastian Kügler <sebas@kde.org>
2025-01-17 09:51:12 +00:00

94 lines
2.8 KiB
C++

/*
SPDX-FileCopyrightText: 2019 Jonah Brüchert <jbb@kaidan.im>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "info.h"
#include <KLocalizedString>
#include <KPluginFactory>
#include <QClipboard>
#include <QFile>
#include <QGuiApplication>
#include <QJsonArray>
K_PLUGIN_CLASS_WITH_JSON(Info, "kcm_mobile_info.json")
Info::Info(QObject *parent, const KPluginMetaData &metaData)
: KQuickConfigModule(parent, metaData)
, m_distroInfo(new DistroInfo(this))
, m_softwareInfo(new SoftwareInfo(this))
, m_hardwareInfo(new HardwareInfo(this))
{
setButtons({});
QFile vendorInfoFile;
vendorInfoFile.setFileName("/etc/vendorinfo.json");
vendorInfoFile.open(QIODevice::ReadOnly);
m_vendorInfo = QJsonDocument::fromJson(vendorInfoFile.readAll());
qDebug() << "Info module loaded.";
}
void Info::copyInfoToClipboard() const
{
QString clipboardText = QStringLiteral(
"Operating System: %1\n"
"KDE Plasma Version: %2\n"
"KDE Frameworks Version: %3\n"
"Qt Version: %4\n"
"Kernel Version: %5\n"
"OS-Type: %6\n"
"Processor: %7\n"
"Memory: %8\n")
.arg(distroInfo()->name(),
softwareInfo()->plasmaVersion(),
softwareInfo()->frameworksVersion(),
softwareInfo()->qtVersion(),
softwareInfo()->kernelRelease(),
softwareInfo()->osType(),
hardwareInfo()->processors(),
hardwareInfo()->memory());
// add vendor information if available
if (!vendorInfoTitle().isEmpty()) {
for (const auto &li : vendorInfo()) {
const auto &m = li.toMap();
clipboardText.append(QString("%1: %2\n").arg(
m[QStringLiteral("Key")].toString(),
m[QStringLiteral("Value")].toString()
));
}
}
QGuiApplication::clipboard()->setText(clipboardText);
}
DistroInfo *Info::distroInfo() const
{
return m_distroInfo;
}
SoftwareInfo *Info::softwareInfo() const
{
return m_softwareInfo;
}
HardwareInfo *Info::hardwareInfo() const
{
return m_hardwareInfo;
}
QString Info::vendorInfoTitle() const
{
return m_vendorInfo[QStringLiteral("Title")].toString();
}
QVariantList Info::vendorInfo() const
{
return m_vendorInfo[QStringLiteral("Content")].toArray().toVariantList();
}
#include "info.moc"