mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Move QuickSettingsModel to C++
This commit is contained in:
parent
0d7f10abbc
commit
9ac1cc139e
9 changed files with 334 additions and 161 deletions
|
|
@ -5,7 +5,8 @@ set(mobilehomescreencomponentsplugin_SRCS
|
|||
applicationlistmodel.cpp
|
||||
favoritesmodel.cpp
|
||||
homescreenutils.cpp
|
||||
)
|
||||
quicksettingsmodel.cpp
|
||||
)
|
||||
|
||||
add_library(mobilehomescreencomponentsplugin ${mobilehomescreencomponentsplugin_SRCS})
|
||||
|
||||
|
|
|
|||
|
|
@ -22,14 +22,18 @@
|
|||
#include <QQmlContext>
|
||||
#include <QQuickItem>
|
||||
|
||||
#include "favoritesmodel.h"
|
||||
#include "applicationlistmodel.h"
|
||||
#include "favoritesmodel.h"
|
||||
#include "homescreenutils.h"
|
||||
#include "quicksettingsmodel.h"
|
||||
|
||||
void MobileHomeScreenComponentsPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.private.mobilehomescreencomponents"));
|
||||
|
||||
qmlRegisterType<QuickSetting>(uri, 0, 1, "QuickSetting");
|
||||
qmlRegisterType<QuickSettingsModel>(uri, 0, 1, "QuickSettingsModel");
|
||||
|
||||
qmlRegisterSingletonType<HomeScreenUtils>(uri, 0, 1, "HomeScreenUtils",
|
||||
[](QQmlEngine *, QJSEngine *) {
|
||||
return new HomeScreenUtils{};
|
||||
|
|
|
|||
94
components/mobilehomescreencomponents/quicksettingsmodel.cpp
Normal file
94
components/mobilehomescreencomponents/quicksettingsmodel.cpp
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "quicksettingsmodel.h"
|
||||
|
||||
QuickSettingsModel::QuickSettingsModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> QuickSettingsModel::roleNames() const
|
||||
{
|
||||
return {{Qt::UserRole, "modelData"}};
|
||||
}
|
||||
|
||||
QQmlListProperty<QuickSetting> QuickSettingsModel::children()
|
||||
{
|
||||
return QQmlListProperty<QuickSetting>(this, &m_children);
|
||||
}
|
||||
|
||||
int QuickSettingsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_children.count();
|
||||
}
|
||||
|
||||
QVariant QuickSettingsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_children.count() || role != Qt::UserRole) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return QVariant::fromValue<QObject *>(m_children[index.row()]);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
|
||||
QuickSetting::QuickSetting(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void QuickSetting::setEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled == enabled)
|
||||
return;
|
||||
|
||||
m_enabled = enabled;
|
||||
Q_EMIT enabledChanged(enabled);
|
||||
}
|
||||
|
||||
void QuickSetting::setSettingsCommand(const QString &settingsCommand)
|
||||
{
|
||||
if (m_settingsCommand == settingsCommand)
|
||||
return;
|
||||
|
||||
m_settingsCommand = settingsCommand;
|
||||
Q_EMIT settingsCommandChanged(settingsCommand);
|
||||
}
|
||||
|
||||
void QuickSetting::setIconName(const QString &iconName)
|
||||
{
|
||||
if (m_iconName == iconName)
|
||||
return;
|
||||
|
||||
m_iconName = iconName;
|
||||
Q_EMIT iconNameChanged(iconName);
|
||||
}
|
||||
|
||||
void QuickSetting::setText(const QString &text)
|
||||
{
|
||||
if (m_text == text)
|
||||
return;
|
||||
|
||||
m_text = text;
|
||||
Q_EMIT textChanged(text);
|
||||
}
|
||||
|
||||
QQmlListProperty<QObject> QuickSetting::children()
|
||||
{
|
||||
return QQmlListProperty<QObject>(this, &m_children);
|
||||
}
|
||||
|
||||
void QuickSettingsModel::include(QuickSetting *item)
|
||||
{
|
||||
beginInsertRows({}, m_children.count(), m_children.count());
|
||||
m_children.append(item);
|
||||
endInsertRows();
|
||||
}
|
||||
89
components/mobilehomescreencomponents/quicksettingsmodel.h
Normal file
89
components/mobilehomescreencomponents/quicksettingsmodel.h
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef QUICKSETTINGSMODEL_H
|
||||
#define QUICKSETTINGSMODEL_H
|
||||
|
||||
#include "qqml.h"
|
||||
#include <QAbstractListModel>
|
||||
#include <QQmlListProperty>
|
||||
|
||||
class QuickSetting : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText REQUIRED NOTIFY textChanged)
|
||||
Q_PROPERTY(QString icon READ iconName WRITE setIconName REQUIRED NOTIFY iconNameChanged)
|
||||
Q_PROPERTY(QString settingsCommand READ settingsCommand WRITE setSettingsCommand NOTIFY settingsCommandChanged)
|
||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
|
||||
Q_PROPERTY(QQmlListProperty<QObject> children READ children CONSTANT)
|
||||
Q_CLASSINFO("DefaultProperty", "children")
|
||||
QML_NAMED_ELEMENT("QuickSetting")
|
||||
public:
|
||||
QuickSetting(QObject *parent = nullptr);
|
||||
|
||||
QString text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
QString iconName() const
|
||||
{
|
||||
return m_iconName;
|
||||
}
|
||||
QString settingsCommand() const
|
||||
{
|
||||
return m_settingsCommand;
|
||||
}
|
||||
bool isEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void setText(const QString &text);
|
||||
void setIconName(const QString &iconName);
|
||||
void setSettingsCommand(const QString &settingsCommand);
|
||||
void setEnabled(bool enabled);
|
||||
QQmlListProperty<QObject> children();
|
||||
|
||||
Q_SIGNALS:
|
||||
void enabledChanged(bool enabled);
|
||||
void textChanged(const QString &text);
|
||||
void iconNameChanged(const QString &icon);
|
||||
void settingsCommandChanged(const QString &settingsCommand);
|
||||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
QString m_text;
|
||||
QString m_iconName;
|
||||
QString m_settingsCommand;
|
||||
QList<QObject *> m_children;
|
||||
};
|
||||
|
||||
class QuickSettingsModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QQmlListProperty<QuickSetting> children READ children NOTIFY childrenChanged)
|
||||
Q_CLASSINFO("DefaultProperty", "children")
|
||||
QML_ELEMENT
|
||||
|
||||
public:
|
||||
QuickSettingsModel(QObject *parent = nullptr);
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
QQmlListProperty<QuickSetting> children();
|
||||
|
||||
Q_SCRIPTABLE void include(QuickSetting *item);
|
||||
|
||||
Q_SIGNALS:
|
||||
void childrenChanged();
|
||||
|
||||
private:
|
||||
QList<QuickSetting *> m_children;
|
||||
};
|
||||
|
||||
#endif // QUICKSETTINGSMODEL_H
|
||||
|
|
@ -21,6 +21,7 @@ import org.kde.taskmanager 0.1 as TaskManager
|
|||
|
||||
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
|
||||
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
||||
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
|
||||
|
||||
import "LayoutManager.js" as LayoutManager
|
||||
|
||||
|
|
@ -148,7 +149,7 @@ Item {
|
|||
IndicatorProviders.VolumeProvider {
|
||||
id: volumeProvider
|
||||
|
||||
readonly property var soundQuickSetting: QuickSetting {
|
||||
readonly property var setting: HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Sound")
|
||||
icon: "audio-speakers-symbolic"
|
||||
enabled: false
|
||||
|
|
@ -156,8 +157,8 @@ Item {
|
|||
function toggle() {
|
||||
volumeProvider.showVolumeOverlay()
|
||||
}
|
||||
Component.onCompleted: quickSettings.quickSettingsModel.model.push(volumeProvider.soundQuickSetting)
|
||||
}
|
||||
Component.onCompleted: quickSettings.quickSettingsModel.include(setting)
|
||||
}
|
||||
IndicatorProviders.WifiProvider {
|
||||
id: wifiProvider
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import QtQuick 2.10
|
||||
|
||||
QtObject
|
||||
{
|
||||
required property string text
|
||||
required property string icon
|
||||
property string settingsCommand
|
||||
property bool enabled: true
|
||||
|
||||
default property var children: []
|
||||
}
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
|
||||
* SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
import QtQuick 2.14
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick.Window 2.2
|
||||
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.components 3.0 as PC3
|
||||
|
||||
Item {
|
||||
id: modelItem
|
||||
property bool screenshotRequested: false
|
||||
|
||||
signal panelClosed()
|
||||
|
||||
onPanelClosed: {
|
||||
if (screenshotRequested) {
|
||||
plasmoid.nativeInterface.takeScreenshot();
|
||||
screenshotRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
readonly property list<QuickSetting> model: [
|
||||
QuickSetting {
|
||||
text: i18n("Settings")
|
||||
icon: "configure"
|
||||
enabled: false
|
||||
settingsCommand: "plasma-settings"
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Wifi")
|
||||
icon: "network-wireless-signal"
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_wifi"
|
||||
function toggle() {
|
||||
nmHandler.enableWireless(!enabledConnections.wirelessEnabled)
|
||||
}
|
||||
enabled: enabledConnections.wirelessEnabled
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Bluetooth")
|
||||
icon: "network-bluetooth"
|
||||
settingsCommand: "plasma-settings -m kcm_bluetooth"
|
||||
function toggle() {
|
||||
var enable = !BluezQt.Manager.bluetoothOperational;
|
||||
BluezQt.Manager.bluetoothBlocked = !enable;
|
||||
|
||||
for (var i = 0; i < BluezQt.Manager.adapters.length; ++i) {
|
||||
var adapter = BluezQt.Manager.adapters[i];
|
||||
adapter.powered = enable;
|
||||
}
|
||||
}
|
||||
enabled: BluezQt.Manager.bluetoothOperational
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Mobile Data")
|
||||
icon: "network-modem"
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_broadband"
|
||||
enabled: enabledConnections.wwanEnabled
|
||||
function toggle() {
|
||||
nmHandler.enableWwan(!enabledConnections.wwanEnabled)
|
||||
}
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Battery")
|
||||
icon: "battery-full"
|
||||
enabled: false
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_power"
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Flashlight")
|
||||
icon: "flashlight-on"
|
||||
enabled: plasmoid.nativeInterface.torchEnabled
|
||||
function toggle() {
|
||||
plasmoid.nativeInterface.toggleTorch()
|
||||
}
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Location")
|
||||
icon: "gps"
|
||||
enabled: false
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Screenshot")
|
||||
icon: "spectacle"
|
||||
enabled: false
|
||||
function toggle() {
|
||||
modelItem.screenshotRequested = true;
|
||||
root.closeRequested();
|
||||
}
|
||||
},
|
||||
QuickSetting {
|
||||
text: i18n("Auto-rotate")
|
||||
icon: "rotation-allowed"
|
||||
enabled: plasmoid.nativeInterface.autoRotateEnabled
|
||||
function toggle() {
|
||||
plasmoid.nativeInterface.autoRotateEnabled = !enabled
|
||||
}
|
||||
},
|
||||
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;
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
PlasmaNM.Handler {
|
||||
id: nmHandler
|
||||
}
|
||||
|
||||
PlasmaNM.EnabledConnections {
|
||||
id: enabledConnections
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ Item {
|
|||
|
||||
onClosed: quickSettingsModel.panelClosed()
|
||||
|
||||
property QuickSettingsModel quickSettingsModel: QuickSettingsModel {}
|
||||
readonly property SettingsModel quickSettingsModel: SettingsModel {}
|
||||
|
||||
PlasmaCore.FrameSvgItem {
|
||||
id: background
|
||||
|
|
@ -132,7 +132,7 @@ Item {
|
|||
spacing: 0
|
||||
|
||||
Repeater {
|
||||
model: quickSettingsModel.model
|
||||
model: quickSettingsModel
|
||||
delegate: Delegate {
|
||||
id: delegateItem
|
||||
required property var modelData
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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 QtQuick 2.14
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick.Window 2.2
|
||||
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
|
||||
|
||||
import org.kde.plasma.components 3.0 as PC3
|
||||
|
||||
HomeScreenComponents.QuickSettingsModel
|
||||
{
|
||||
id: modelItem
|
||||
property bool screenshotRequested: false
|
||||
|
||||
signal panelClosed()
|
||||
|
||||
onPanelClosed: {
|
||||
if (screenshotRequested) {
|
||||
plasmoid.nativeInterface.takeScreenshot();
|
||||
screenshotRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Settings")
|
||||
icon: "configure"
|
||||
enabled: false
|
||||
settingsCommand: "plasma-settings"
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
PlasmaNM.Handler {
|
||||
id: nmHandler
|
||||
}
|
||||
|
||||
PlasmaNM.EnabledConnections {
|
||||
id: enabledConnections
|
||||
}
|
||||
|
||||
text: i18n("Wifi")
|
||||
icon: "network-wireless-signal"
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_wifi"
|
||||
function toggle() {
|
||||
nmHandler.enableWireless(!enabledConnections.wirelessEnabled)
|
||||
}
|
||||
enabled: enabledConnections.wirelessEnabled
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Bluetooth")
|
||||
icon: "network-bluetooth"
|
||||
settingsCommand: "plasma-settings -m kcm_bluetooth"
|
||||
function toggle() {
|
||||
var enable = !BluezQt.Manager.bluetoothOperational;
|
||||
BluezQt.Manager.bluetoothBlocked = !enable;
|
||||
|
||||
for (var i = 0; i < BluezQt.Manager.adapters.length; ++i) {
|
||||
var adapter = BluezQt.Manager.adapters[i];
|
||||
adapter.powered = enable;
|
||||
}
|
||||
}
|
||||
enabled: BluezQt.Manager.bluetoothOperational
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Mobile Data")
|
||||
icon: "network-modem"
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_broadband"
|
||||
enabled: enabledConnections.wwanEnabled
|
||||
function toggle() {
|
||||
nmHandler.enableWwan(!enabledConnections.wwanEnabled)
|
||||
}
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Battery")
|
||||
icon: "battery-full"
|
||||
enabled: false
|
||||
settingsCommand: "plasma-settings -m kcm_mobile_power"
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Flashlight")
|
||||
icon: "flashlight-on"
|
||||
enabled: plasmoid.nativeInterface.torchEnabled
|
||||
function toggle() {
|
||||
plasmoid.nativeInterface.toggleTorch()
|
||||
}
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Location")
|
||||
icon: "gps"
|
||||
enabled: false
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Screenshot")
|
||||
icon: "spectacle"
|
||||
enabled: false
|
||||
function toggle() {
|
||||
modelItem.screenshotRequested = true;
|
||||
root.closeRequested();
|
||||
}
|
||||
}
|
||||
HomeScreenComponents.QuickSetting {
|
||||
text: i18n("Auto-rotate")
|
||||
icon: "rotation-allowed"
|
||||
enabled: plasmoid.nativeInterface.autoRotateEnabled
|
||||
function toggle() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue