mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Make it possible for QuickSettings to be created in a KPackage
Move the NightColor one into a KPackage to prove it
This commit is contained in:
parent
9ac1cc139e
commit
dd888a707f
6 changed files with 85 additions and 22 deletions
|
|
@ -49,6 +49,7 @@ include(CheckIncludeFiles)
|
|||
|
||||
plasma_install_package(look-and-feel org.kde.plasma.phone look-and-feel)
|
||||
plasma_install_package(shell org.kde.plasma.phoneshell shells)
|
||||
plasma_install_package(quicksettings/nightcolor org.kde.plasma.nightcolor quicksettings)
|
||||
|
||||
install(FILES plasma_phone_components.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@
|
|||
|
||||
#include "quicksettingsmodel.h"
|
||||
|
||||
#include <KPackage/PackageLoader>
|
||||
#include <QFileInfo>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlEngine>
|
||||
|
||||
QuickSettingsModel::QuickSettingsModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
|
|
@ -38,6 +43,36 @@ QVariant QuickSettingsModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant::fromValue<QObject *>(m_children[index.row()]);
|
||||
}
|
||||
|
||||
void QuickSettingsModel::classBegin()
|
||||
{
|
||||
QQmlEngine *engine = qmlEngine(this);
|
||||
|
||||
const auto packages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/GenericQML"), "plasma/quicksettings");
|
||||
auto c = new QQmlComponent(engine, this);
|
||||
for (const auto &metaData : packages) {
|
||||
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", QFileInfo(metaData.fileName()).path());
|
||||
if (!package.isValid()) {
|
||||
qWarning() << "Could not load" << metaData.fileName();
|
||||
continue;
|
||||
}
|
||||
|
||||
c->loadUrl(package.fileUrl("mainscript"), QQmlComponent::PreferSynchronous);
|
||||
auto created = c->create(engine->rootContext());
|
||||
auto createdSetting = qobject_cast<QuickSetting *>(created);
|
||||
if (!createdSetting) {
|
||||
qWarning() << "Could not load" << metaData.fileName() << created;
|
||||
delete created;
|
||||
continue;
|
||||
}
|
||||
include(createdSetting);
|
||||
}
|
||||
delete c;
|
||||
}
|
||||
|
||||
void QuickSettingsModel::componentComplete()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
|
||||
QuickSetting::QuickSetting(QObject *parent)
|
||||
|
|
|
|||
|
|
@ -61,9 +61,10 @@ private:
|
|||
QList<QObject *> m_children;
|
||||
};
|
||||
|
||||
class QuickSettingsModel : public QAbstractListModel
|
||||
class QuickSettingsModel : public QAbstractListModel, public QQmlParserStatus
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QQmlParserStatus)
|
||||
Q_PROPERTY(QQmlListProperty<QuickSetting> children READ children NOTIFY childrenChanged)
|
||||
Q_CLASSINFO("DefaultProperty", "children")
|
||||
QML_ELEMENT
|
||||
|
|
@ -77,6 +78,8 @@ public:
|
|||
|
||||
QQmlListProperty<QuickSetting> children();
|
||||
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
Q_SCRIPTABLE void include(QuickSetting *item);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import org.kde.plasma.core 2.0 as PlasmaCore
|
|||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
|
||||
import org.kde.bluezqt 1.0 as BluezQt
|
||||
import org.kde.colorcorrect 0.1 as CC
|
||||
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
|
||||
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
|
||||
|
||||
|
|
@ -116,24 +115,4 @@ HomeScreenComponents.QuickSettingsModel
|
|||
plasmoid.nativeInterface.autoRotateEnabled = !enabled
|
||||
}
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Night Color")
|
||||
icon: "redshift-status-on"
|
||||
enabled: compositorAdaptor.active
|
||||
settingsCommand: "plasma-settings -m kcm_nightcolor"
|
||||
|
||||
CC.CompositorAdaptor {
|
||||
id: compositorAdaptor
|
||||
}
|
||||
function toggle() {
|
||||
if (compositorAdaptor.active) {
|
||||
compositorAdaptor.activeStaged = false;
|
||||
} else {
|
||||
compositorAdaptor.activeStaged = true;
|
||||
compositorAdaptor.modeStaged = 3; // always on
|
||||
}
|
||||
compositorAdaptor.sendConfigurationAll();
|
||||
enabled = compositorAdaptor.active;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
quicksettings/nightcolor/contents/ui/main.qml
Normal file
31
quicksettings/nightcolor/contents/ui/main.qml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import org.kde.colorcorrect 0.1 as CC
|
||||
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
|
||||
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Night Color")
|
||||
icon: "redshift-status-on"
|
||||
enabled: compositorAdaptor.active
|
||||
settingsCommand: "plasma-settings -m kcm_nightcolor"
|
||||
|
||||
CC.CompositorAdaptor {
|
||||
id: compositorAdaptor
|
||||
}
|
||||
function toggle() {
|
||||
if (compositorAdaptor.active) {
|
||||
compositorAdaptor.activeStaged = false;
|
||||
} else {
|
||||
compositorAdaptor.activeStaged = true;
|
||||
compositorAdaptor.modeStaged = 3; // always on
|
||||
}
|
||||
compositorAdaptor.sendConfigurationAll();
|
||||
enabled = compositorAdaptor.active;
|
||||
}
|
||||
}
|
||||
14
quicksettings/nightcolor/metadata.desktop
Normal file
14
quicksettings/nightcolor/metadata.desktop
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Desktop Entry]
|
||||
Name=Night Color
|
||||
Icon=redshift-status-on
|
||||
|
||||
Type=Service
|
||||
X-KDE-ServiceTypes=KPackage/GenericQML
|
||||
|
||||
X-KDE-PluginInfo-Author=Aleix Pol
|
||||
X-KDE-PluginInfo-Email=aleixpol@kde.org
|
||||
X-KDE-PluginInfo-Name=org.kde.plasma.nightcolor
|
||||
X-KDE-PluginInfo-Version=0.1
|
||||
X-KDE-PluginInfo-Website=https://kde.org
|
||||
X-KDE-PluginInfo-License=GPL
|
||||
|
||||
Loading…
Reference in a new issue