From 6c746e62d54fe998679c5879ea664a87ba6ea3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Tue, 14 Jan 2025 16:46:12 +0100 Subject: [PATCH] [info kcm]: add vendorinfo card MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- kcms/info/info.cpp | 31 ++++++++++++++++++++++++++++++- kcms/info/info.h | 9 +++++++++ kcms/info/ui/main.qml | 25 +++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/kcms/info/info.cpp b/kcms/info/info.cpp index 0b43587d..5bc9d069 100644 --- a/kcms/info/info.cpp +++ b/kcms/info/info.cpp @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include K_PLUGIN_CLASS_WITH_JSON(Info, "kcm_mobile_info.json") @@ -21,12 +23,18 @@ Info::Info(QObject *parent, const KPluginMetaData &metaData) { 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 { - const QString clipboardText = QStringLiteral( + QString clipboardText = QStringLiteral( "Operating System: %1\n" "KDE Plasma Version: %2\n" "KDE Frameworks Version: %3\n" @@ -44,6 +52,17 @@ void Info::copyInfoToClipboard() const 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); } @@ -62,4 +81,14 @@ 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" diff --git a/kcms/info/info.h b/kcms/info/info.h index 1dda1b26..45c3721c 100644 --- a/kcms/info/info.h +++ b/kcms/info/info.h @@ -9,6 +9,8 @@ #include "softwareinfo.h" #include +#include + #ifndef INFO_H #define INFO_H @@ -19,10 +21,16 @@ class Info : public KQuickConfigModule Q_PROPERTY(DistroInfo *distroInfo READ distroInfo NOTIFY distroInfoChanged) Q_PROPERTY(SoftwareInfo *softwareInfo READ softwareInfo NOTIFY softwareInfoChanged) Q_PROPERTY(HardwareInfo *hardwareInfo READ hardwareInfo NOTIFY hardwareInfoChanged) + Q_PROPERTY(QVariantList vendorInfo READ vendorInfo CONSTANT) + Q_PROPERTY(QString vendorInfoTitle READ vendorInfoTitle CONSTANT) + DistroInfo *distroInfo() const; SoftwareInfo *softwareInfo() const; HardwareInfo *hardwareInfo() const; + QVariantList vendorInfo() const; + QString vendorInfoTitle() const; + public: Info(QObject *parent, const KPluginMetaData &metaData); @@ -37,6 +45,7 @@ private: DistroInfo *m_distroInfo; SoftwareInfo *m_softwareInfo; HardwareInfo *m_hardwareInfo; + QJsonDocument m_vendorInfo; }; #endif // INFO_H diff --git a/kcms/info/ui/main.qml b/kcms/info/ui/main.qml index 82b7ae3a..03ce5ef7 100644 --- a/kcms/info/ui/main.qml +++ b/kcms/info/ui/main.qml @@ -122,5 +122,30 @@ KCM.SimpleKCM { } } } + + FormCard.FormHeader { + visible: kcm.vendorInfoTitle !== "" + title: kcm.vendorInfoTitle + } + + FormCard.FormCard { + visible: kcm.vendorInfoTitle !== "" + Repeater { + model: kcm.vendorInfo + ColumnLayout { + id: delegate + + required property var modelData + + spacing: 0 + + FormCard.FormTextDelegate { + text: delegate.modelData.Key + description: delegate.modelData.Value + } + FormCard.FormDelegateSeparator {} + } + } + } } }