diff --git a/lookandfeel/contents/logout/Logout.qml b/lookandfeel/contents/logout/Logout.qml index d25a868c3..7524ed246 100644 --- a/lookandfeel/contents/logout/Logout.qml +++ b/lookandfeel/contents/logout/Logout.qml @@ -1,204 +1,210 @@ /*************************************************************************** * Copyright (C) 2014 by Aleix Pol Gonzalez * * * * 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 . * ***************************************************************************/ import QtQuick 2.2 import QtQuick.Layouts 1.2 import QtQuick.Controls 1.1 as Controls import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kcoreaddons 1.0 as KCoreAddons import "../components" +import "timer.js" as AutoTriggerTimer PlasmaCore.ColorScope { id: root colorGroup: PlasmaCore.Theme.ComplementaryColorGroup height: screenGeometry.height width: screenGeometry.width signal logoutRequested() signal haltRequested() signal suspendRequested(int spdMethod) signal rebootRequested() signal rebootRequested2(int opt) signal cancelRequested() signal lockScreenRequested() property alias backgroundColor: backgroundRect.color function sleepRequested() { root.suspendRequested(2); } property real timeout: 30 property real remainingTime: root.timeout property var currentAction: { switch (sdtype) { case ShutdownType.ShutdownTypeReboot: return root.rebootRequested; case ShutdownType.ShutdownTypeHalt: return root.haltRequested; default: return root.logoutRequested; } } KCoreAddons.KUser { id: kuser } Controls.Action { onTriggered: root.cancelRequested() shortcut: "Escape" } onRemainingTimeChanged: { if (remainingTime <= 0) { root.currentAction(); } } Timer { id: countDownTimer running: true repeat: true interval: 1000 onTriggered: remainingTime-- + Component.onCompleted: { + AutoTriggerTimer.addCancelAutoTriggerCallback(function() { + countDownTimer.running = false; + }); + } } function isLightColor(color) { return Math.max(color.r, color.g, color.b) > 0.5 } Rectangle { id: backgroundRect anchors.fill: parent //use "black" because this is intended to look like a general darkening of the scene. a dark gray as normal background would just look too "washed out" color: root.isLightColor(PlasmaCore.ColorScope.backgroundColor) ? PlasmaCore.ColorScope.backgroundColor : "black" opacity: 0.5 } MouseArea { anchors.fill: parent onClicked: root.cancelRequested() } UserDelegate { width: units.iconSizes.enormous height: width anchors { horizontalCenter: parent.horizontalCenter bottom: parent.verticalCenter } constrainText: false avatarPath: kuser.faceIconUrl iconSource: "user-identity" isCurrent: true name: kuser.fullName } ColumnLayout { anchors { top: parent.verticalCenter topMargin: units.gridUnit * 2 horizontalCenter: parent.horizontalCenter } spacing: units.largeSpacing height: Math.max(implicitHeight, units.gridUnit * 10) width: Math.max(implicitWidth, units.gridUnit * 16) RowLayout { spacing: units.largeSpacing * 2 Layout.alignment: Qt.AlignHCenter LogoutButton { id: suspendButton iconSource: "system-suspend" text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Suspend") action: root.sleepRequested KeyNavigation.left: logoutButton KeyNavigation.right: rebootButton visible: spdMethods.SuspendState } LogoutButton { id: rebootButton iconSource: "system-reboot" text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Reboot") action: root.rebootRequested KeyNavigation.left: suspendButton KeyNavigation.right: shutdownButton focus: sdtype == ShutdownType.ShutdownTypeReboot visible: maysd } LogoutButton { id: shutdownButton iconSource: "system-shutdown" text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Shutdown") action: root.haltRequested KeyNavigation.left: rebootButton KeyNavigation.right: logoutButton focus: sdtype == ShutdownType.ShutdownTypeHalt visible: maysd } LogoutButton { id: logoutButton iconSource: "system-log-out" text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Logout") action: root.logoutRequested KeyNavigation.left: shutdownButton KeyNavigation.right: suspendButton focus: sdtype == ShutdownType.ShutdownTypeNone visible: canLogout } } PlasmaComponents.Label { Layout.alignment: Qt.AlignHCenter //opacity, as visible would re-layout opacity: countDownTimer.running ? 1 : 0 Behavior on opacity { OpacityAnimator { duration: units.longDuration easing.type: Easing.InOutQuad } } text: { switch (sdtype) { case ShutdownType.ShutdownTypeReboot: return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Reboot in 1 second", "Reboot in %1 seconds", root.remainingTime); case ShutdownType.ShutdownTypeHalt: return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Shutting down in 1 second", "Shutting down in %1 seconds", root.remainingTime); default: return i18ndp("plasma_lookandfeel_org.kde.lookandfeel", "Logging out in 1 second", "Logging out in %1 seconds", root.remainingTime); } } } RowLayout { Layout.alignment: Qt.AlignHCenter PlasmaComponents.Button { enabled: root.currentAction != null text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "OK") onClicked: root.currentAction() } PlasmaComponents.Button { text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Cancel") onClicked: root.cancelRequested() } } } } diff --git a/lookandfeel/contents/logout/LogoutButton.qml b/lookandfeel/contents/logout/LogoutButton.qml index 620503cda..c3bae6b8b 100644 --- a/lookandfeel/contents/logout/LogoutButton.qml +++ b/lookandfeel/contents/logout/LogoutButton.qml @@ -1,41 +1,42 @@ /*************************************************************************** * Copyright (C) 2016 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 . * ***************************************************************************/ import QtQuick 2.2 import QtQuick.Layouts 1.2 import org.kde.plasma.core 2.0 as PlasmaCore import "../components" +import "timer.js" as AutoTriggerTimer ActionButton { property var action onClicked: action() Layout.alignment: Qt.AlignTop iconSize: units.iconSizes.huge opacity: activeFocus || containsMouse ? 1 : 0.5 font.underline: false Behavior on opacity { OpacityAnimator { duration: units.longDuration easing.type: Easing.InOutQuad } } - Keys.onPressed: countDownTimer.running = false + Keys.onPressed: AutoTriggerTimer.cancelAutoTrigger(); } diff --git a/lookandfeel/contents/logout/LogoutButton.qml b/lookandfeel/contents/logout/timer.js similarity index 69% copy from lookandfeel/contents/logout/LogoutButton.qml copy to lookandfeel/contents/logout/timer.js index 620503cda..eeb9a4b1e 100644 --- a/lookandfeel/contents/logout/LogoutButton.qml +++ b/lookandfeel/contents/logout/timer.js @@ -1,41 +1,39 @@ /*************************************************************************** - * Copyright (C) 2016 Marco Martin * + * Copyright (C) 2018 David Edmundson * * * * 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 . * ***************************************************************************/ -import QtQuick 2.2 -import QtQuick.Layouts 1.2 +.pragma library -import org.kde.plasma.core 2.0 as PlasmaCore +//written as a library to share knowledge of when a key was pressed +//between the multiple views, so pressing a key on one cancels all timers -import "../components" +var callbacks = []; -ActionButton { - property var action - onClicked: action() - Layout.alignment: Qt.AlignTop - iconSize: units.iconSizes.huge - opacity: activeFocus || containsMouse ? 1 : 0.5 - font.underline: false - Behavior on opacity { - OpacityAnimator { - duration: units.longDuration - easing.type: Easing.InOutQuad +function addCancelAutoTriggerCallback(callback) { + callbacks.push(callback); +} + +function cancelAutoTrigger() { + callbacks.forEach(function(c) { + if (!c) { + return; } - } - Keys.onPressed: countDownTimer.running = false + c(); + }); } +