mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
[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>
This commit is contained in:
parent
49e009c26c
commit
6c746e62d5
3 changed files with 64 additions and 1 deletions
|
|
@ -9,7 +9,9 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QFile>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
K_PLUGIN_CLASS_WITH_JSON(Info, "kcm_mobile_info.json")
|
K_PLUGIN_CLASS_WITH_JSON(Info, "kcm_mobile_info.json")
|
||||||
|
|
||||||
|
|
@ -21,12 +23,18 @@ Info::Info(QObject *parent, const KPluginMetaData &metaData)
|
||||||
{
|
{
|
||||||
setButtons({});
|
setButtons({});
|
||||||
|
|
||||||
|
QFile vendorInfoFile;
|
||||||
|
|
||||||
|
vendorInfoFile.setFileName("/etc/vendorinfo.json");
|
||||||
|
vendorInfoFile.open(QIODevice::ReadOnly);
|
||||||
|
m_vendorInfo = QJsonDocument::fromJson(vendorInfoFile.readAll());
|
||||||
|
|
||||||
qDebug() << "Info module loaded.";
|
qDebug() << "Info module loaded.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Info::copyInfoToClipboard() const
|
void Info::copyInfoToClipboard() const
|
||||||
{
|
{
|
||||||
const QString clipboardText = QStringLiteral(
|
QString clipboardText = QStringLiteral(
|
||||||
"Operating System: %1\n"
|
"Operating System: %1\n"
|
||||||
"KDE Plasma Version: %2\n"
|
"KDE Plasma Version: %2\n"
|
||||||
"KDE Frameworks Version: %3\n"
|
"KDE Frameworks Version: %3\n"
|
||||||
|
|
@ -44,6 +52,17 @@ void Info::copyInfoToClipboard() const
|
||||||
hardwareInfo()->processors(),
|
hardwareInfo()->processors(),
|
||||||
hardwareInfo()->memory());
|
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);
|
QGuiApplication::clipboard()->setText(clipboardText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,4 +81,14 @@ HardwareInfo *Info::hardwareInfo() const
|
||||||
return m_hardwareInfo;
|
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"
|
#include "info.moc"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
#include "softwareinfo.h"
|
#include "softwareinfo.h"
|
||||||
#include <KQuickConfigModule>
|
#include <KQuickConfigModule>
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
#ifndef INFO_H
|
#ifndef INFO_H
|
||||||
#define INFO_H
|
#define INFO_H
|
||||||
|
|
||||||
|
|
@ -19,10 +21,16 @@ class Info : public KQuickConfigModule
|
||||||
Q_PROPERTY(DistroInfo *distroInfo READ distroInfo NOTIFY distroInfoChanged)
|
Q_PROPERTY(DistroInfo *distroInfo READ distroInfo NOTIFY distroInfoChanged)
|
||||||
Q_PROPERTY(SoftwareInfo *softwareInfo READ softwareInfo NOTIFY softwareInfoChanged)
|
Q_PROPERTY(SoftwareInfo *softwareInfo READ softwareInfo NOTIFY softwareInfoChanged)
|
||||||
Q_PROPERTY(HardwareInfo *hardwareInfo READ hardwareInfo NOTIFY hardwareInfoChanged)
|
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;
|
DistroInfo *distroInfo() const;
|
||||||
SoftwareInfo *softwareInfo() const;
|
SoftwareInfo *softwareInfo() const;
|
||||||
HardwareInfo *hardwareInfo() const;
|
HardwareInfo *hardwareInfo() const;
|
||||||
|
|
||||||
|
QVariantList vendorInfo() const;
|
||||||
|
QString vendorInfoTitle() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Info(QObject *parent, const KPluginMetaData &metaData);
|
Info(QObject *parent, const KPluginMetaData &metaData);
|
||||||
|
|
||||||
|
|
@ -37,6 +45,7 @@ private:
|
||||||
DistroInfo *m_distroInfo;
|
DistroInfo *m_distroInfo;
|
||||||
SoftwareInfo *m_softwareInfo;
|
SoftwareInfo *m_softwareInfo;
|
||||||
HardwareInfo *m_hardwareInfo;
|
HardwareInfo *m_hardwareInfo;
|
||||||
|
QJsonDocument m_vendorInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INFO_H
|
#endif // INFO_H
|
||||||
|
|
|
||||||
|
|
@ -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 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue