File: info.cpp

package info (click to toggle)
plasma-mobile 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,412 kB
  • sloc: xml: 38,474; cpp: 18,529; javascript: 139; sh: 82; makefile: 5
file content (94 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
    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"