From 8c3f894d0675ae9e33c40ce0a0def60b9d6fcf8b Mon Sep 17 00:00:00 2001 From: reionwong Date: Sun, 25 Jul 2021 21:41:40 +0800 Subject: [PATCH] Add power module --- CMakeLists.txt | 1 + src/application.cpp | 2 + src/images/performance.svg | 111 ++++--------------------------------- src/images/powersave.svg | 101 +++------------------------------ src/powermanager.cpp | 46 +++++++++++++++ src/powermanager.h | 45 +++++++++++++++ src/qml/Power/Main.qml | 21 ++++--- src/qml/SideBar.qml | 14 +++-- 8 files changed, 137 insertions(+), 204 deletions(-) create mode 100644 src/powermanager.cpp create mode 100644 src/powermanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a53b0b..c88b7e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ set(SRCS src/cicontheme.cpp src/fonts/kxftconfig.cpp src/fonts/fonts.cpp + src/powermanager.cpp ) set(RESOURCES diff --git a/src/application.cpp b/src/application.cpp index 1f58521..5aad03a 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -15,6 +15,7 @@ #include "background.h" #include "language.h" #include "password.h" +#include "powermanager.h" static QObject *passwordSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) { @@ -62,6 +63,7 @@ Application::Application(int &argc, char **argv) qmlRegisterType(uri, 1, 0, "Background"); qmlRegisterType(uri, 1, 0, "Language"); qmlRegisterType(uri, 1, 0, "Fonts"); + qmlRegisterType(uri, 1, 0, "PowerManager"); qmlRegisterSingletonType(uri, 1, 0, "Password", passwordSingleton); qmlRegisterType(); diff --git a/src/images/performance.svg b/src/images/performance.svg index 0402096..395e817 100644 --- a/src/images/performance.svg +++ b/src/images/performance.svg @@ -1,101 +1,14 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/images/powersave.svg b/src/images/powersave.svg index c4bd63e..dc3f4da 100644 --- a/src/images/powersave.svg +++ b/src/images/powersave.svg @@ -1,93 +1,10 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - + + + + + + + + + diff --git a/src/powermanager.cpp b/src/powermanager.cpp new file mode 100644 index 0000000..68b1d12 --- /dev/null +++ b/src/powermanager.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "powermanager.h" + +PowerManager::PowerManager(QObject *parent) + : QObject(parent) + , m_iface("org.cutefish.PowerManager", + "/CPUManagement", "org.cutefish.CPUManagement", + QDBusConnection::sessionBus()) + , m_mode(-1) +{ + if (m_iface.isValid()) { + m_mode = m_iface.property("mode").toInt(); + } +} + +int PowerManager::mode() const +{ + return m_mode; +} + +void PowerManager::setMode(int mode) +{ + if (m_mode != mode) { + m_iface.call("setMode", mode); + m_mode = mode; + emit modeChanged(); + } +} diff --git a/src/powermanager.h b/src/powermanager.h new file mode 100644 index 0000000..3d5c200 --- /dev/null +++ b/src/powermanager.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef POWERMANAGER_H +#define POWERMANAGER_H + +#include +#include + +class PowerManager : public QObject +{ + Q_OBJECT + Q_PROPERTY(int mode READ mode WRITE setMode NOTIFY modeChanged) + +public: + explicit PowerManager(QObject *parent = nullptr); + + int mode() const; + void setMode(int mode); + +signals: + void modeChanged(); + +private: + QDBusInterface m_iface; + int m_mode; +}; + +#endif // POWERMANAGER_H diff --git a/src/qml/Power/Main.qml b/src/qml/Power/Main.qml index bf4ac1c..65a5bf0 100644 --- a/src/qml/Power/Main.qml +++ b/src/qml/Power/Main.qml @@ -22,6 +22,7 @@ import QtQuick.Controls 2.4 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 +import Cutefish.Settings 1.0 import FishUI 1.0 as FishUI import "../" @@ -29,6 +30,10 @@ ItemPage { id: control headerTitle: qsTr("Power") + PowerManager { + id: power + } + Scrollable { anchors.fill: parent contentHeight: layout.implicitHeight @@ -51,19 +56,21 @@ ItemPage { IconCheckBox { source: "qrc:/images/powersave.svg" text: qsTr("Power Save") - checked: false + checked: power.mode === 0 + onClicked: power.mode = 0 } - IconCheckBox { - source: "qrc:/images/balance.svg" - text: qsTr("Balance") - checked: false - } +// IconCheckBox { +// source: "qrc:/images/balance.svg" +// text: qsTr("Balance") +// checked: false +// } IconCheckBox { source: "qrc:/images/performance.svg" text: qsTr("Performance") - checked: true + checked: power.mode === 1 + onClicked: power.mode = 1 } } } diff --git a/src/qml/SideBar.qml b/src/qml/SideBar.qml index 8df0751..9946e71 100644 --- a/src/qml/SideBar.qml +++ b/src/qml/SideBar.qml @@ -164,12 +164,14 @@ Item { category: qsTr("System") } -// ListElement { -// title: qsTr("Power") -// name: "power" -// page: "qrc:/qml/Power/Main.qml" -// iconSource: "power.svg" -// } + ListElement { + title: qsTr("Power") + name: "power" + page: "qrc:/qml/Power/Main.qml" + iconColor: "#FE8433" + iconSource: "power.svg" + category: qsTr("System") + } ListElement { title: qsTr("About")