Skip to content

Commit

Permalink
Update to Plasma 6 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonMagon committed Jun 19, 2024
1 parent 8970627 commit b6c2e10
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 62 deletions.
7 changes: 3 additions & 4 deletions package/contents/config/config.qml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-FileCopyrightText: 2023, 2024 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0

import org.kde.plasma.configuration 2.0
import QtQuick
import org.kde.plasma.configuration

ConfigModel {
ConfigCategory {
Expand Down
28 changes: 15 additions & 13 deletions package/contents/ui/BrightnessItem.qml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
SPDX-FileCopyrightText: 2012-2013 Daniel Nicoletti <[email protected]>
SPDX-FileCopyrightText: 2013, 2015 Kai Uwe Broulik <[email protected]>
SPDX-FileCopyrightText: 2024 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-2.0-or-later
*/

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick
import QtQuick.Layouts

import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components as PlasmaComponents
import org.kde.plasma.core as PlasmaCore
import org.kde.kirigami as Kirigami

PlasmaComponents3.ItemDelegate {
PlasmaComponents.ItemDelegate {
id: root

property alias slider: control
Expand All @@ -33,13 +35,13 @@ PlasmaComponents3.ItemDelegate {
Keys.forwardTo: [slider]

contentItem: RowLayout {
spacing: PlasmaCore.Units.gridUnit
spacing: Kirigami.Units.gridUnit

PlasmaCore.IconItem {
Kirigami.Icon {
id: image
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
source: root.icon.name
}

Expand All @@ -50,22 +52,22 @@ PlasmaComponents3.ItemDelegate {

RowLayout {
Layout.fillWidth: true
spacing: PlasmaCore.Units.smallSpacing
spacing: Kirigami.Units.smallSpacing

PlasmaComponents3.Label {
PlasmaComponents.Label {
id: title
Layout.fillWidth: true
text: root.text
}

PlasmaComponents3.Label {
PlasmaComponents.Label {
id: percent
Layout.alignment: Qt.AlignRight
text: i18nc("Placeholder is brightness percentage", "%1%", root.percentage)
}
}

PlasmaComponents3.Slider {
PlasmaComponents.Slider {
id: control
Layout.fillWidth: true

Expand Down
18 changes: 7 additions & 11 deletions package/contents/ui/ConfigGeneral.qml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-FileCopyrightText: 2023, 2024 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.4 as Kirigami

Item {
id: page
width: childrenRect.width
height: childrenRect.height
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kcmutils as KCM

KCM.SimpleKCM {
signal configurationChanged

function saveConfig() {
Expand All @@ -32,4 +29,3 @@ Item {
}
}
}

55 changes: 27 additions & 28 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
SPDX-FileCopyrightText: 2023 Dmitry Ilyich Sidorov <[email protected]>
SPDX-FileCopyrightText: 2023, 2024 Dmitry Ilyich Sidorov <[email protected]>
SPDX-License-Identifier: LGPL-3.0-or-later
*/

import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick
import QtQuick.Layouts
import QtQuick.Dialogs
import org.kde.plasma.core as PlasmaCore
import org.kde.kirigami as Kirigami
import org.kde.plasma.extras as PlasmaExtras
import org.kde.plasma.plasmoid
import org.kde.plasma.plasma5support as Plasma5Support

import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.plasmoid 2.0
import QtQuick.Dialogs 1.2

Item {
PlasmoidItem {
id: main

property string displayName: i18n("plasma_applet_org.kde.plasma.battery", "Brightness")
property string displayName: i18n("plasma_applet_org.kde.plasma.brightness", "Brightness")

property int minimumScreenBrightness: plasmoid.configuration.minimumBrightness
property int maximumScreenBrightness: 100
Expand All @@ -27,25 +27,24 @@ Item {
id: errorDialog
title: "An error occuried"
text: "Failed to get the current brightness and output values with xrandr."
icon: StandardIcon.Critical
}

Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
preferredRepresentation: compactRepresentation

Plasmoid.fullRepresentation: PlasmaExtras.Representation {
fullRepresentation: PlasmaExtras.Representation {
id: dialogItem

Layout.minimumWidth: PlasmaCore.Units.gridUnit * 10
Layout.maximumWidth: PlasmaCore.Units.gridUnit * 80
Layout.preferredWidth: PlasmaCore.Units.gridUnit * 20
Layout.minimumWidth: Kirigami.Units.gridUnit * 10
Layout.maximumWidth: Kirigami.Units.gridUnit * 80
Layout.preferredWidth: Kirigami.Units.gridUnit * 20

Layout.preferredHeight: implicitHeight

contentItem: BrightnessItem {
id: brightnessSlider

icon.name: "video-display-brightness"
text: i18nd("plasma_applet_org.kde.plasma.battery", "Display Brightness")
text: i18nd("plasma_applet_org.kde.plasma.brightness", "Display Brightness")
value: screenBrightness
maximumValue: maximumScreenBrightness

Expand All @@ -61,20 +60,20 @@ Item {
}

executable.exec(`xrandr --output ${screenOutput} --brightness ${screenBrightness / 100}`)
console.log(`xrandr --output ${screenOutput} --brightness ${screenBrightness / 100}`)
}

}
}

Plasmoid.compactRepresentation: PlasmaCore.IconItem {
compactRepresentation: Kirigami.Icon {
source: Plasmoid.icon
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton
onClicked: {
onClicked: function (mouse) {
if (mouse.button === Qt.LeftButton) {
if (plasmoid.expanded) {
plasmoid.expanded = false
if (main.expanded) {
main.expanded = false
} else {
executable.exec("xrandr --verbose | grep -m 2 -i \" connected\\|brightness\"")
}
Expand All @@ -85,7 +84,7 @@ Item {

Connections {
target: executable
onExited: {
onExited: function(exitCode, exitStatus, stdout, stderr) {
if (exitCode == 0 && exitStatus == 0) {
if (stdout != null && stdout.length > 5) {
var lines = stdout.trim().split('\n')
Expand All @@ -99,8 +98,8 @@ Item {
}
}

if (!plasmoid.expanded) {
plasmoid.expanded = true
if (!main.expanded) {
main.expanded = true
}
}
}
Expand All @@ -110,11 +109,11 @@ Item {
}
}

PlasmaCore.DataSource {
Plasma5Support.DataSource {
id: executable
engine: "executable"
connectedSources: []
onNewData: {
onNewData: function(sourceName, data) {
var exitCode = data["exit code"]
var exitStatus = data["exit status"]
var stdout = data["stdout"]
Expand Down
9 changes: 3 additions & 6 deletions package/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
"Name": "Display Brightness",
"Name[de]": "Monitor-Helligkeit",
"Name[ru]": "Яркость экрана",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "0.9",
"Version": "1.0",
"Website": "https://github.com/JonMagon/plasma-screendimmer"
},
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml",
"X-Plasma-API-Minimum-Version": "6.0",
"KPackageStructure": "Plasma/Applet",
"X-Plasma-NotificationArea": true,
"X-Plasma-NotificationAreaCategory": "Hardware"
}

0 comments on commit b6c2e10

Please sign in to comment.