Changeset View
Changeset View
Standalone View
Standalone View
applets/systemmonitor/systemmonitor/systemmonitor.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Marco Martin <mart@kde.org> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #include "systemmonitor.h" | ||||
21 | | ||||
22 | #include <QtQml> | ||||
23 | #include <QDebug> | ||||
24 | #include <QQuickItem> | ||||
25 | #include <QQuickWindow> | ||||
26 | #include <QStandardPaths> | ||||
27 | #include <QWindow> | ||||
28 | | ||||
29 | #include <sensors/SensorQuery.h> | ||||
30 | #include <faces/SensorFaceController.h> | ||||
31 | | ||||
32 | #include <KConfigLoader> | ||||
33 | #include <KLocalizedString> | ||||
34 | #include <KDeclarative/QmlObjectSharedEngine> | ||||
35 | | ||||
36 | SystemMonitor::SystemMonitor(QObject *parent, const QVariantList &args) | ||||
37 | : Plasma::Applet(parent, args) | ||||
38 | { | ||||
39 | setHasConfigurationInterface(true); | ||||
40 | | ||||
41 | //Don't set the preset right now as we can't write on the config here because we don't have a Corona yet | ||||
42 | if (args.count() > 2 && args.mid(3).length() > 0) { | ||||
43 | const QString preset = args.mid(3).first().toString(); | ||||
44 | if (preset.length() > 0) { | ||||
45 | m_pendingStartupPreset = preset; | ||||
46 | } | ||||
47 | } | ||||
48 | } | ||||
49 | | ||||
50 | SystemMonitor::~SystemMonitor() | ||||
51 | = default; | ||||
52 | | ||||
53 | void SystemMonitor::init() | ||||
54 | { | ||||
55 | configChanged(); | ||||
56 | | ||||
57 | // NOTE: taking the pluginId this way, we take it from the child applet (cpu monitor, memory, whatever) rather than the parent fallback applet (systemmonitor) | ||||
58 | const QString pluginId = KPluginMetaData(kPackage().path() + QStringLiteral("metadata.desktop")).pluginId(); | ||||
59 | | ||||
60 | //FIXME HACK: better way to get the engine At least AppletQuickItem should have an engine() getter | ||||
61 | KDeclarative::QmlObjectSharedEngine *qmlObject = new KDeclarative::QmlObjectSharedEngine(); | ||||
62 | KConfigGroup cg = config(); | ||||
63 | m_sensorFaceController = new KSysGuard::SensorFaceController(cg, qmlObject->engine()); | ||||
64 | qmlObject->deleteLater(); | ||||
65 | | ||||
66 | if (!m_pendingStartupPreset.isNull()) { | ||||
67 | m_sensorFaceController->loadPreset(m_pendingStartupPreset); | ||||
68 | } else { | ||||
69 | //Take it from the config, which is *not* accessible from plasmoid.config as is not in config.xml | ||||
70 | const QString preset = config().readEntry("CurrentPreset", pluginId); | ||||
71 | m_sensorFaceController->loadPreset(preset); | ||||
72 | } | ||||
73 | } | ||||
74 | | ||||
75 | KSysGuard::SensorFaceController *SystemMonitor::faceController() const | ||||
76 | { | ||||
77 | return m_sensorFaceController; | ||||
78 | } | ||||
79 | | ||||
80 | void SystemMonitor::configChanged() | ||||
81 | { | ||||
82 | if (m_sensorFaceController) { | ||||
83 | m_sensorFaceController->reloadConfig(); | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
87 | K_EXPORT_PLASMA_APPLET_WITH_JSON(systemmonitor, SystemMonitor, "metadata.json") | ||||
88 | | ||||
89 | #include "systemmonitor.moc" |