diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt index 47176390..f6d2f0a7 100644 --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -1,3 +1,5 @@ plasma_install_package(activities org.kde.phone.activities) plasma_install_package(clock org.kde.phone.clock) plasma_install_package(notifications org.kde.phone.notifications) + +add_subdirectory(quicksettings) diff --git a/applets/quicksettings/CMakeLists.txt b/applets/quicksettings/CMakeLists.txt new file mode 100644 index 00000000..bcd38f12 --- /dev/null +++ b/applets/quicksettings/CMakeLists.txt @@ -0,0 +1,19 @@ +set(quicksettings_SRCS + quicksettings.cpp +) + +add_library(plasma_applet_quicksettings MODULE ${quicksettings_SRCS}) + +kcoreaddons_desktop_to_json(plasma_applet_quicksettings package/metadata.desktop) + +target_link_libraries(plasma_applet_quicksettings + Qt5::Gui + KF5::Plasma + KF5::I18n) + + +install(TARGETS plasma_applet_quicksettings DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets) +#install(FILES plasma-quicksettings-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) + +plasma_install_package(package org.kde.phone.quicksettings) + diff --git a/applets/quicksettings/Messages.sh b/applets/quicksettings/Messages.sh new file mode 100755 index 00000000..83683e21 --- /dev/null +++ b/applets/quicksettings/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp +$XGETTEXT `find . -name \*.js -o -name \*.qml -o -name \*.cpp` -o $podir/plasma_applet_org.kde.phone.quicksettings.pot +rm -f rc.cpp diff --git a/applets/quicksettings/package/contents/ui/BrightnessDelegate.qml b/applets/quicksettings/package/contents/ui/BrightnessDelegate.qml new file mode 100644 index 00000000..0e592700 --- /dev/null +++ b/applets/quicksettings/package/contents/ui/BrightnessDelegate.qml @@ -0,0 +1,75 @@ +/* + * Copyright 2015 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +Item { + id: delegateRoot + implicitWidth: delegate.implicitWidth + implicitHeight: delegate.implicitHeight + (slider.opacity > 0 ? slider.height : 0) + + property int screenBrightness + readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0 + + PlasmaCore.DataSource { + id: pmSource + engine: "powermanagement" + connectedSources: ["PowerDevil"] + + onDataChanged: { + delegateRoot.screenBrightness = source.data["PowerDevil"]["Screen Brightness"]; + } + } + + Delegate { + id: delegate + toggled: slider.opacity > 0 + function toggle() { + slider.opacity = slider.opacity > 0 ? 0 : 1; + } + } + PlasmaComponents.Slider { + id: slider + anchors.top: delegate.bottom + width: flow.width + opacity: 0 + x: -delegateRoot.parent.x + value: screenBrightness + minimumValue: maximumValue > 100 ? 1 : 0 + maximumValue: delegateRoot.maximumScreenBrightness + Behavior on opacity { + OpacityAnimator { + duration: units.shortDuration + easing.type: Easing.InOutQuad + } + } + } + + onScreenBrightnessChanged: { + var service = pmSource.serviceForSource("PowerDevil"); + var operation = service.operationDescription("setBrightness"); + operation.brightness = slider.value; + operation.silent = true + service.startOperationCall(operation); + } +} + diff --git a/applets/quicksettings/package/contents/ui/Delegate.qml b/applets/quicksettings/package/contents/ui/Delegate.qml new file mode 100644 index 00000000..5752de39 --- /dev/null +++ b/applets/quicksettings/package/contents/ui/Delegate.qml @@ -0,0 +1,85 @@ +/* + * Copyright 2015 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +RowLayout { + id: delegateRoot + property bool toggled: model.enabled + spacing: units.smallSpacing + implicitWidth: flow.width / 2 - units.largeSpacing / 2 + Rectangle { + Layout.minimumWidth: units.iconSizes.large + Layout.minimumHeight: width + color: toggled ? + Qt.rgba(PlasmaCore.ColorScope.highlightColor.r, PlasmaCore.ColorScope.highlightColor.g, PlasmaCore.ColorScope.highlightColor.b, iconMouseArea.pressed ? 0.5 : 0.3) : + Qt.rgba(PlasmaCore.ColorScope.textColor.r, PlasmaCore.ColorScope.textColor.g, PlasmaCore.ColorScope.textColor.b, iconMouseArea.pressed ? 0.5 : 0.2) + + PlasmaCore.IconItem { + colorGroup: PlasmaCore.ColorScope.colorGroup + anchors { + fill: parent + margins: units.smallSpacing + } + source: model.icon + MouseArea { + id: iconMouseArea + anchors.fill: parent + onClicked: { + if (delegateRoot.toggle) { + delegateRoot.toggle(); + } else if (model.toggleFunction) { + root[model.toggleFunction](); + } else if (model.settingsCommand) { + plasmoid.nativeInterface.executeCommand(model.settingsCommand); + } + } + } + } + } + Rectangle { + Layout.fillWidth: true + Layout.fillHeight: true + color: Qt.rgba(PlasmaCore.ColorScope.textColor.r, PlasmaCore.ColorScope.textColor.g, PlasmaCore.ColorScope.textColor.b, labelMouseArea.pressed ? 0.5 : 0.2) + PlasmaComponents.Label { + anchors { + fill: parent + margins: units.smallSpacing + } + text: model.text + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + MouseArea { + id: labelMouseArea + anchors.fill: parent + onClicked: { + if (model.settingsCommand) { + plasmoid.nativeInterface.executeCommand(model.settingsCommand); + } else if (model.toggleFunction) { + root[model.toggleFunction](); + } + } + } + } + } +} + diff --git a/applets/quicksettings/package/contents/ui/main.qml b/applets/quicksettings/package/contents/ui/main.qml new file mode 100644 index 00000000..d7cd163a --- /dev/null +++ b/applets/quicksettings/package/contents/ui/main.qml @@ -0,0 +1,130 @@ +/* + * Copyright 2015 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.plasmoid 2.0 + + +Item { + id: root + + function toggleAirplane() { + print("toggle airplane mode") + } + + Plasmoid.preferredRepresentation: plasmoid.fullRepresentation + + Layout.minimumHeight: flow.implicitHeight + units.largeSpacing*2 + + ListModel { + id: settingsModel + + ListElement { + text: "Settings" + icon: "configure" + enabled: false + settingsCommand: "active-settings" + toggleFunction: "" + delegate: "" + } + ListElement { + text: "Mobile network" + icon: "network-mobile-80" + enabled: true + settingsCommand: "" + } + ListElement { + text: "Airplane mode" + icon: "flightmode-on" + enabled: false + settingsCommand: "" + toggleFunction: "toggleAirplane" + } + ListElement { + text: "Bluetooth" + icon: "preferences-system-bluetooth" + enabled: false + settingsCommand: "" + } + ListElement { + text: "Wireless" + icon: "network-wireless-on" + enabled: true + settingsCommand: "active-settings -m org.kde.plasma.phone.settings.wifi" + } + ListElement { + text: "Alarms" + icon: "korgac" + enabled: false + settingsCommand: "" + } + ListElement { + text: "Notifications" + icon: "preferences-desktop-notification" + enabled: true + settingsCommand: "" + } + ListElement { + text: "Brightness" + icon: "video-display-brightness" + enabled: false + settingsCommand: "active-settings -m org.kde.active.settings.powermanagement" + delegate: "BrightnessDelegate" + } + ListElement { + text: "Flashlight" + icon: "package_games_puzzle" + enabled: false + settingsCommand: "" + } + ListElement { + text: "Location" + icon: "plasmaapplet-location" + enabled: false + settingsCommand: "" + } + } + + Flow { + id: flow + anchors { + fill: parent + margins: units.largeSpacing + } + spacing: units.largeSpacing + Repeater { + model: settingsModel + delegate: Loader { + width: item ? item.implicitWidth : 0 + height: item ? item.implicitHeight : 0 + source: Qt.resolvedUrl((model.delegate ? model.delegate : "Delegate") + ".qml") + } + } + move: Transition { + NumberAnimation { + duration: units.shortDuration + easing.type: Easing.InOutQuad + properties: "x,y" + } + } + } +} diff --git a/applets/quicksettings/package/metadata.desktop b/applets/quicksettings/package/metadata.desktop new file mode 100644 index 00000000..fb11f66a --- /dev/null +++ b/applets/quicksettings/package/metadata.desktop @@ -0,0 +1,22 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Quick Settings + +Comment=A panel to quickly access most important settings + +Icon=systemsettings +Type=Service +X-KDE-ParentApp= +X-KDE-PluginInfo-Author=Marco Martin +X-KDE-PluginInfo-Email=mart@kde.org +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=org.kde.phone.quicksettings +X-KDE-Library=plasma_applet_quicksettings +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=plasma.kde.org +X-KDE-ServiceTypes=Plasma/Applet +X-Plasma-API=declarativeappletscript +X-KDE-PluginInfo-Category=Settings + +X-Plasma-MainScript=ui/main.qml +X-Plasma-RemoteLocation= diff --git a/applets/quicksettings/quicksettings.cpp b/applets/quicksettings/quicksettings.cpp new file mode 100644 index 00000000..f82e0a61 --- /dev/null +++ b/applets/quicksettings/quicksettings.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2015 Marco Martin * + * * + * 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 2 of the License, or * + * (at your option) 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "quicksettings.h" + +#include +#include + +QuickSettings::QuickSettings(QObject *parent, const QVariantList &args) + : Plasma::Applet(parent, args) +{ + setHasConfigurationInterface(true); +} + +QuickSettings::~QuickSettings() +{ +} + +void QuickSettings::executeCommand(const QString &command) +{ + qWarning()<<"Executing"< * + * + * * + * 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 2 of the License, or * + * (at your option) 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, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#ifndef QUICKSETTINGS_H +#define QUICKSETTINGS_H + + +#include + + +class QuickSettings : public Plasma::Applet +{ + Q_OBJECT + +public: + QuickSettings( QObject *parent, const QVariantList &args ); + ~QuickSettings(); + +public Q_SLOTS: + void executeCommand(const QString &command); + +private: + +}; + +#endif