diff --git a/Common/SettingsData.qml b/Common/SettingsData.qml index 7bafefdc..bd6c2cb9 100644 --- a/Common/SettingsData.qml +++ b/Common/SettingsData.qml @@ -185,6 +185,7 @@ Singleton { property int notificationTimeoutCritical: 0 property int notificationPopupPosition: SettingsData.Position.Top property bool osdAlwaysShowValue: false + property bool powerActionConfirm: true property bool updaterUseCustomCommand: false property string updaterCustomCommand: "" property string updaterTerminalAdditionalParams: "" @@ -428,6 +429,7 @@ Singleton { notificationTimeoutCritical = settings.notificationTimeoutCritical !== undefined ? settings.notificationTimeoutCritical : 0 notificationPopupPosition = settings.notificationPopupPosition !== undefined ? settings.notificationPopupPosition : SettingsData.Position.Top osdAlwaysShowValue = settings.osdAlwaysShowValue !== undefined ? settings.osdAlwaysShowValue : false + powerActionConfirm = settings.powerActionConfirm !== undefined ? settings.powerActionConfirm : true updaterUseCustomCommand = settings.updaterUseCustomCommand !== undefined ? settings.updaterUseCustomCommand : false; updaterCustomCommand = settings.updaterCustomCommand !== undefined ? settings.updaterCustomCommand : ""; updaterTerminalAdditionalParams = settings.updaterTerminalAdditionalParams !== undefined ? settings.updaterTerminalAdditionalParams : ""; @@ -594,9 +596,10 @@ Singleton { "notificationTimeoutCritical": notificationTimeoutCritical, "notificationPopupPosition": notificationPopupPosition, "osdAlwaysShowValue": osdAlwaysShowValue, - "updaterUseCustomCommand": updaterUseCustomCommand, - "updaterCustomCommand": updaterCustomCommand, - "updaterTerminalAdditionalParams": updaterTerminalAdditionalParams, + "powerActionConfirm": powerActionConfirm, + "updaterUseCustomCommand": updaterUseCustomCommand, + "updaterCustomCommand": updaterCustomCommand, + "updaterTerminalAdditionalParams": updaterTerminalAdditionalParams, "screenPreferences": screenPreferences, "animationSpeed": animationSpeed }, null, 2)) @@ -653,6 +656,11 @@ Singleton { saveSettings(); } + function setPowerActionConfirm(confirm) { + powerActionConfirm = confirm; + saveSettings(); + } + function setWorkspaceNameIcon(workspaceName, iconData) { var iconMap = JSON.parse(JSON.stringify(workspaceNameIcons)) iconMap[workspaceName] = iconData diff --git a/DMSShell.qml b/DMSShell.qml index e2b52d09..8c7a2d9e 100644 --- a/DMSShell.qml +++ b/DMSShell.qml @@ -243,39 +243,45 @@ Item { } LazyLoader { - id: powerMenuLoader + id: powerMenuLoader - active: false + active: false - PowerMenu { - id: powerMenu + PowerMenu { + id: powerMenu - onPowerActionRequested: (action, title, message) => { - powerConfirmModalLoader.active = true - if (powerConfirmModalLoader.item) { - powerConfirmModalLoader.item.confirmButtonColor = action === "poweroff" ? Theme.error : action === "reboot" ? Theme.warning : Theme.primary - powerConfirmModalLoader.item.show(title, message, function () { - switch (action) { - case "logout": - SessionService.logout() - break - case "suspend": - SessionService.suspend() - break - case "hibernate": - SessionService.hibernate() - break - case "reboot": - SessionService.reboot() - break - case "poweroff": - SessionService.poweroff() - break - } - }, function () {}) - } - } - } + onPowerActionRequested: (action, title, message) => { + if (SettingsData.powerActionConfirm) { + powerConfirmModalLoader.active = true + if (powerConfirmModalLoader.item) { + powerConfirmModalLoader.item.confirmButtonColor = action === "poweroff" ? Theme.error : action === "reboot" ? Theme.warning : Theme.primary + powerConfirmModalLoader.item.show(title, message, actionApply(action), function () {}) + } + } else { + actionApply(action) + } + } + + function actionApply(action) { + switch (action) { + case "logout": + SessionService.logout() + break + case "suspend": + SessionService.suspend() + break + case "hibernate": + SessionService.hibernate() + break + case "reboot": + SessionService.reboot() + break + case "poweroff": + SessionService.poweroff() + break + } + } + } } LazyLoader { @@ -416,43 +422,50 @@ Item { } LazyLoader { - id: powerMenuModalLoader + id: powerMenuModalLoader - active: false + active: false - PowerMenuModal { - id: powerMenuModal + PowerMenuModal { + id: powerMenuModal - onPowerActionRequested: (action, title, message) => { - powerConfirmModalLoader.active = true - if (powerConfirmModalLoader.item) { - powerConfirmModalLoader.item.confirmButtonColor = action === "poweroff" ? Theme.error : action === "reboot" ? Theme.warning : Theme.primary - powerConfirmModalLoader.item.show(title, message, function () { - switch (action) { - case "logout": - SessionService.logout() - break - case "suspend": - SessionService.suspend() - break - case "hibernate": - SessionService.hibernate() - break - case "reboot": - SessionService.reboot() - break - case "poweroff": - SessionService.poweroff() - break - } - }, function () {}) - } - } + onPowerActionRequested: (action, title, message) => { + console.log("CONFIRM: ", SettingsData.powerActionConfirm) + if (SettingsData.powerActionConfirm) { + powerConfirmModalLoader.active = true + if (powerConfirmModalLoader.item) { + powerConfirmModalLoader.item.confirmButtonColor = action === "poweroff" ? Theme.error : action === "reboot" ? Theme.warning : Theme.primary + powerConfirmModalLoader.item.show(title, message, actionApply(action), function () {}) + } + } else { + actionApply(action) + } + } - Component.onCompleted: { - PopoutService.powerMenuModal = powerMenuModal - } - } + function actionApply(action) { + switch (action) { + case "logout": + SessionService.logout() + break + case "suspend": + SessionService.suspend() + break + case "hibernate": + SessionService.hibernate() + break + case "reboot": + SessionService.reboot() + break + case "poweroff": + SessionService.poweroff() + break + } + } + + Component.onCompleted: { + PopoutService.powerMenuModal = powerMenuModal + } + } } DMSShellIPC { diff --git a/Modals/Settings/PowerSettings.qml b/Modals/Settings/PowerSettings.qml index 02f2299c..262d72a7 100644 --- a/Modals/Settings/PowerSettings.qml +++ b/Modals/Settings/PowerSettings.qml @@ -79,7 +79,7 @@ Item { DankToggle { width: parent.width text: I18n.tr("Enable loginctl lock integration") - description: "Bind lock screen to dbus signals from loginctl. Disable if using an external lock screen." + description: "Bind lock screen to dbus signals from loginctl. Disable if using an external lock screen" checked: SessionService.loginctlAvailable && SessionData.loginctlLockIntegration enabled: SessionService.loginctlAvailable onToggled: checked => { @@ -313,6 +313,49 @@ Item { } } + StyledRect { + width: parent.width + height: powerCommandConfirmSection.implicitHeight + Theme.spacingL * 2 + radius: Theme.cornerRadius + color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3) + border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2) + border.width: 0 + + Column { + id: powerCommandConfirmSection + anchors.fill: parent + anchors.margins: Theme.spacingL + spacing: Theme.spacingM + + Row { + width: parent.width + spacing: Theme.spacingM + + DankIcon { + name: "check_circle" + size: Theme.iconSize + color: Theme.primary + anchors.verticalCenter: parent.verticalCenter + } + + StyledText { + text: I18n.tr("Power Action Confirmation") + font.pixelSize: Theme.fontSizeLarge + font.weight: Font.Medium + color: Theme.surfaceText + anchors.verticalCenter: parent.verticalCenter + } + } + + DankToggle { + width: parent.width + text: I18n.tr("Show Confirmation on Power Actions") + description: "Request confirmation on power off, restart, suspend, hibernate and logout actions" + checked: SettingsData.powerActionConfirm + onToggled: checked => SettingsData.setPowerActionConfirm(checked) + } + } + } } } -} \ No newline at end of file +} diff --git a/Modals/Settings/SettingsSidebar.qml b/Modals/Settings/SettingsSidebar.qml index c8d5c655..87f500da 100644 --- a/Modals/Settings/SettingsSidebar.qml +++ b/Modals/Settings/SettingsSidebar.qml @@ -33,8 +33,8 @@ Rectangle { "text": I18n.tr("Theme & Colors"), "icon": "palette" }, { - "text": I18n.tr("Idle & Lock Screen"), - "icon": "lock" + "text": I18n.tr("Power & Battery"), + "icon": "power" }, { "text": I18n.tr("Plugins"), "icon": "extension"