1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
|
/*
* SPDX-FileCopyrightText: 2022, 2023 Jakob Petsovits <jpetso@petsovits.com>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kcmutils as KCM
import org.kde.kirigami as Kirigami
import org.kde.powerdevil as PD
Kirigami.FormLayout {
id: root
required property string profileId
required property string profileLabel
readonly property var profileSettings: kcm.settings["profile" + profileId]
function formatPercentageText(value) {
return i18nc(
"Percentage value example, used for formatting brightness levels in the power management settings",
"10%"
).replace("10", value);
}
Connections {
target: profileSettings
onAutoSuspendIdleTimeoutSecChanged: suspendComplianceWarning.showIfNeeded();
onAutoSuspendActionChanged: suspendComplianceWarning.showIfNeeded();
}
//
// Suspend Session
Item {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18nc("@title:group", "Suspend Session")
visible: (
autoSuspendActionRow.visible
|| powerButtonActionCombo.visible
|| lidActionCombo.visible
|| triggersLidActionWhenExternalMonitorPresentCheck.visible
|| sleepModeCombo.visible
)
}
Kirigami.InlineMessage {
Kirigami.FormData.isSection: true
visible: autoSuspendActionCombo.visible && !autoSuspendActionCombo.isConfiguredValueSupported
Layout.fillWidth: true
type: Kirigami.MessageType.Warning
text: i18nc("@info:status", "The action you had previously configured to happen when inactive is now unsupported on your system. Please select a different one.")
}
RowLayout {
id: autoSuspendActionRow
Kirigami.FormData.label: i18nc(
"@label:combobox Suspend action such as sleep/hibernate to perform when the system is idle",
"When &inactive:"
)
Kirigami.FormData.buddyFor: autoSuspendActionCombo
visible: kcm.supportedActions["SuspendSession"] === true
Layout.fillWidth: true
spacing: Kirigami.Units.smallSpacing
ComboBoxWithIcon {
id: autoSuspendActionCombo
Accessible.name: i18nc("@accessible:name:combobox", "Action to perform when the system is idle")
Layout.fillWidth: true
implicitContentWidthPolicy: QQC2.ComboBox.WidestTextWhenCompleted
model: kcm.autoSuspendActionModel
textRole: "name"
valueRole: "value"
readonly property bool isConfiguredValueSupported: currentValue === profileSettings.autoSuspendAction
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "AutoSuspendAction"
}
Component.onCompleted: {
// indexOfValue() is invalid before onCompleted, so wait until here to bind currentIndex.
currentIndex = Qt.binding(() => indexOfValue(profileSettings.autoSuspendAction));
}
onActivated: {
profileSettings.autoSuspendAction = currentValue;
}
}
TimeDurationComboBox {
id: autoSuspendIdleTimeoutCombo
durationPromptLabel: autoSuspendActionRow.Kirigami.FormData.label
durationPromptAcceptsUnits: [DurationPromptDialog.Unit.Seconds, DurationPromptDialog.Unit.Minutes]
function translateSeconds(n, formatUnit = DurationPromptDialog.Unit.Seconds) {
return formatUnit == DurationPromptDialog.Unit.Minutes
? translateMinutes(n / 60) : i18ncp("@option:combobox", "After %1 second", "After %1 seconds", n);
}
function translateMinutes(n) { return i18ncp("@option:combobox", "After %1 minute", "After %1 minutes", n); }
valueRole: "seconds"
textRole: "text"
unitOfValueRole: DurationPromptDialog.Unit.Seconds
durationPromptFromValue: 60
presetOptions: [
{ seconds: 1 * 60, text: translateMinutes(1), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 2 * 60, text: translateMinutes(2), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 5 * 60, text: translateMinutes(5), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 10 * 60, text: translateMinutes(10), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 15 * 60, text: translateMinutes(15), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 30 * 60, text: translateMinutes(30), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: -1, text: i18nc("@option:combobox Choose a custom value outside the list of preset values", "Custom…") },
]
customRequesterValue: -1
configuredValue: profileSettings.autoSuspendIdleTimeoutSec
configuredDisplayUnit: model[indexOfValue(configuredValue)]?.unit ?? DurationPromptDialog.Unit.Minutes
onRegularValueActivated: {
profileSettings.autoSuspendIdleTimeoutSec = currentValue;
}
onCustomDurationAccepted: {
profileSettings.autoSuspendIdleTimeoutSec = valueToUnit(
customDuration.value, customDuration.unit, DurationPromptDialog.Unit.Seconds);
}
onConfiguredValueOptionMissing: {
const unit = configuredValue % 60 === 0
? customDuration?.unit ?? DurationPromptDialog.Unit.Minutes
: DurationPromptDialog.Unit.Seconds;
customOptions = [{
seconds: configuredValue,
text: translateSeconds(configuredValue, unit),
unit: unit,
}];
customDuration = null;
}
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "AutoSuspendIdleTimeoutSec"
extraEnabledConditions: autoSuspendActionCombo.currentValue !== PD.PowerDevil.PowerButtonAction.NoAction
}
}
}
// EU Regulation 2023/826 requires automatic suspend after max. 20 minutes and a warning
// if the user disables auto suspend.
Kirigami.InlineMessage {
id: suspendComplianceWarning
Layout.fillWidth: true
Kirigami.FormData.isSection: true
type: Kirigami.MessageType.Warning
visible: text !== ""
function showIfNeeded() {
if (profileSettings.autoSuspendAction === PD.PowerDevil.PowerButtonAction.NoAction) {
text = i18nc("@info:status", "Disabling automatic suspend will result in higher energy consumption.");
} else if (profileSettings.autoSuspendIdleTimeoutSec > 20 * 60) {
text = i18nc("@info:status A long duration until suspend/shutdown", "A long duration will result in higher energy consumption.");
} else {
text = "";
}
}
}
Kirigami.InlineMessage {
Kirigami.FormData.isSection: true
visible: powerButtonActionCombo.visible && !powerButtonActionCombo.isConfiguredValueSupported
Layout.fillWidth: true
type: Kirigami.MessageType.Warning
text: i18nc("@info:status", "The action you had previously configured for when the power button is pressed is now unsupported on your system. Please select a different one.")
}
ComboBoxWithIcon {
id: powerButtonActionCombo
Kirigami.FormData.label: i18nc(
"@label:combobox Suspend action such as sleep/hibernate to perform when the power button is pressed",
"When &power button pressed:"
)
Accessible.name: i18nc("@accessible:name:combobox", "Action to perform when the power button is pressed")
visible: kcm.supportedActions["HandleButtonEvents"] === true && kcm.isPowerButtonPresent
Layout.fillWidth: true
implicitContentWidthPolicy: QQC2.ComboBox.WidestTextWhenCompleted
model: kcm.powerButtonActionModel
textRole: "name"
valueRole: "value"
readonly property bool isConfiguredValueSupported: currentValue === profileSettings.powerButtonAction
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "PowerButtonAction"
}
Component.onCompleted: {
// indexOfValue() is invalid before onCompleted, so wait until here to bind currentIndex.
currentIndex = Qt.binding(() => indexOfValue(profileSettings.powerButtonAction));
}
onActivated: {
profileSettings.powerButtonAction = currentValue;
}
}
Kirigami.InlineMessage {
Kirigami.FormData.isSection: true
visible: lidActionCombo.visible && !lidActionCombo.isConfiguredValueSupported
Layout.fillWidth: true
type: Kirigami.MessageType.Warning
text: i18nc("@info:status", "The action you had previously configured for when the lid is closed is now unsupported on your system. Please select a different one.")
}
ComboBoxWithIcon {
id: lidActionCombo
Kirigami.FormData.label: i18nc(
"@label:combobox Suspend action such as sleep/hibernate to perform when the power button is pressed",
"When laptop &lid closed:"
)
Accessible.name: i18nc("@accessible:name:combobox", "Action to perform when the laptop lid is closed")
visible: kcm.supportedActions["HandleButtonEvents"] === true && kcm.isLidPresent
Layout.fillWidth: true
implicitContentWidthPolicy: QQC2.ComboBox.WidestTextWhenCompleted
model: kcm.lidActionModel
textRole: "name"
valueRole: "value"
readonly property bool isConfiguredValueSupported: currentValue === profileSettings.lidAction
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "LidAction"
}
Component.onCompleted: {
// indexOfValue() is invalid before onCompleted, so wait until here to bind currentIndex.
currentIndex = Qt.binding(() => indexOfValue(profileSettings.lidAction));
}
onActivated: {
profileSettings.lidAction = currentValue;
}
}
QQC2.CheckBox {
id: triggersLidActionWhenExternalMonitorPresentCheck
text: i18nc(
"@text:checkbox Trigger laptop lid action even when an external monitor is connected",
"Even when an external monitor is connected"
)
Accessible.name: i18n("Perform laptop lid action even when an external monitor is connected")
visible: lidActionCombo.visible
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "InhibitLidActionWhenExternalMonitorPresent"
extraEnabledConditions: lidActionCombo.currentValue !== PD.PowerDevil.PowerButtonAction.NoAction
}
checked: !profileSettings.inhibitLidActionWhenExternalMonitorPresent
onToggled: { profileSettings.inhibitLidActionWhenExternalMonitorPresent = !checked; }
}
Kirigami.InlineMessage {
Kirigami.FormData.isSection: true
visible: sleepModeCombo.visible && sleepModeCombo.enabled && !sleepModeCombo.isConfiguredValueSupported
Layout.fillWidth: true
type: Kirigami.MessageType.Warning
text: i18nc("@info:status", "The sleep mode you had previously configured is now unsupported on your system. Please select a different one.")
}
QQC2.ComboBox {
id: sleepModeCombo
Kirigami.FormData.label: i18nc(
"@label:combobox Sleep mode selection - suspend to memory, disk or both",
"When sleeping, enter:"
)
Accessible.name: i18nc("@accessible:name:combobox", "When sleeping, enter this power-save mode")
visible: count > 1 && (kcm.supportedActions["SuspendSession"] === true || kcm.supportedActions["HandleButtonEvents"] === true)
Layout.fillWidth: true
implicitContentWidthPolicy: QQC2.ComboBox.WidestTextWhenCompleted
model: kcm.sleepModeModel
textRole: "name"
valueRole: "value"
delegate: Kirigami.SubtitleDelegate {
required property string index
// model roles from roleNames(), expose these in your QAbstractItemModel if you haven't already
required property string name
required property string subtext
text: name
subtitle: subtext
icon.width: 0
width: sleepModeCombo.popup.width
highlighted: index === sleepModeCombo.currentIndex
}
readonly property bool isConfiguredValueSupported: currentValue === profileSettings.sleepMode
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "SleepMode"
extraEnabledConditions: (
autoSuspendActionCombo.currentValue === PD.PowerDevil.PowerButtonAction.Sleep
|| powerButtonActionCombo.currentValue === PD.PowerDevil.PowerButtonAction.Sleep
|| lidActionCombo.currentValue === PD.PowerDevil.PowerButtonAction.Sleep
)
}
Component.onCompleted: {
// indexOfValue() is invalid before onCompleted, so wait until here to bind currentIndex.
currentIndex = Qt.binding(() => indexOfValue(profileSettings.sleepMode));
}
onActivated: {
profileSettings.sleepMode = currentValue;
}
}
//
// Display and Brightness
Item {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18nc("@title:group", "Display and Brightness")
visible: (
kcm.supportedActions["DimDisplay"] === true
|| kcm.supportedActions["DPMSControl"] === true
|| kcm.supportedActions["KeyboardBrightnessControl"] === true
|| kcm.supportedActions["ScreenBrightnessControl"] === true
)
}
RowLayout {
Kirigami.FormData.label: i18nc("@label:slider Brightness level", "Change scr&een brightness:")
Kirigami.FormData.buddyFor: displayBrightnessCheck
visible: kcm.supportedActions["ScreenBrightnessControl"] === true
Layout.fillWidth: true
spacing: Kirigami.Units.smallSpacing
QQC2.CheckBox {
id: displayBrightnessCheck
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "UseProfileSpecificDisplayBrightness"
}
checked: profileSettings.useProfileSpecificDisplayBrightness
onToggled: { profileSettings.useProfileSpecificDisplayBrightness = checked; }
}
QQC2.Slider {
id: displayBrightnessSlider
Layout.fillWidth: true
from: 1
to: 100
stepSize: 1
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "DisplayBrightness"
extraEnabledConditions: displayBrightnessCheck.checked
}
value: profileSettings.displayBrightness
onMoved: { profileSettings.displayBrightness = value; }
}
QQC2.Label {
enabled: displayBrightnessCheck.checked
text: formatPercentageText(displayBrightnessSlider.value)
Layout.preferredWidth: displayBrightnessPercentageMetrics.width
}
TextMetrics {
id: displayBrightnessPercentageMetrics
text: formatPercentageText(100)
}
}
TimeDurationComboBox {
id: dimDisplayIdleTimeoutCombo
visible: kcm.supportedActions["DimDisplay"] === true
Layout.fillWidth: true
Kirigami.FormData.label: i18nc("@label:combobox Dim screen after X minutes", "Di&m automatically:")
durationPromptLabel: i18nc("@label:spinbox Dim screen after X minutes", "Di&m automatically after:")
durationPromptAcceptsUnits: [DurationPromptDialog.Unit.Seconds, DurationPromptDialog.Unit.Minutes]
function translateSeconds(n, formatUnit = DurationPromptDialog.Unit.Seconds) {
return formatUnit == DurationPromptDialog.Unit.Minutes
? translateMinutes(n / 60) : i18ncp("@option:combobox", "%1 second", "%1 seconds", n);
}
function translateMinutes(n) { return i18ncp("@option:combobox", "%1 minute", "%1 minutes", n); }
valueRole: "seconds"
textRole: "text"
unitOfValueRole: DurationPromptDialog.Unit.Seconds
durationPromptFromValue: 10
presetOptions: [
{ seconds: -1, text: i18nc("@option:combobox Dim screen automatically", "Never") },
{ seconds: 30, text: translateSeconds(30), unit: DurationPromptDialog.Unit.Seconds },
{ seconds: 1 * 60, text: translateMinutes(1), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 2 * 60, text: translateMinutes(2), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 5 * 60, text: translateMinutes(5), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 10 * 60, text: translateMinutes(10), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 15 * 60, text: translateMinutes(15), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: -2, text: i18nc("@option:combobox Choose a custom value outside the list of preset values", "Custom…") },
]
customRequesterValue: -2
configuredValue: profileSettings.dimDisplayWhenIdle ? profileSettings.dimDisplayIdleTimeoutSec : -1
configuredDisplayUnit: model[indexOfValue(configuredValue)]?.unit ?? DurationPromptDialog.Unit.Minutes
onRegularValueActivated: {
profileSettings.dimDisplayIdleTimeoutSec = currentValue;
profileSettings.dimDisplayWhenIdle = currentValue > 0;
}
onCustomDurationAccepted: {
profileSettings.dimDisplayIdleTimeoutSec = valueToUnit(
customDuration.value, customDuration.unit, DurationPromptDialog.Unit.Seconds);
profileSettings.dimDisplayWhenIdle = customDuration.value > 0;
}
onConfiguredValueOptionMissing: {
const unit = configuredValue % 60 === 0
? customDuration?.unit ?? DurationPromptDialog.Unit.Minutes
: DurationPromptDialog.Unit.Seconds;
customOptions = [{
seconds: configuredValue,
text: translateSeconds(configuredValue, unit),
unit: unit,
}];
customDuration = null;
}
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "DimDisplayIdleTimeoutSec"
}
}
Kirigami.InlineMessage {
Kirigami.FormData.isSection: true
visible: (
dimDisplayIdleTimeoutCombo.visible
&& profileSettings.dimDisplayWhenIdle && profileSettings.turnOffDisplayWhenIdle
&& profileSettings.dimDisplayIdleTimeoutSec >= profileSettings.turnOffDisplayIdleTimeoutSec
&& profileSettings.dimDisplayIdleTimeoutSec >= profileSettings.turnOffDisplayIdleTimeoutWhenLockedSec
)
Layout.fillWidth: true
type: Kirigami.MessageType.Warning
text: i18nc("@info:status", "The screen will not be dimmed because it is configured to turn off sooner.")
}
RowLayout {
id: turnOffDisplayRow
Kirigami.FormData.label: i18nc("@label:combobox After X minutes", "&Turn off screen:")
Kirigami.FormData.buddyFor: turnOffDisplayIdleTimeoutCombo
visible: kcm.supportedActions["DPMSControl"] === true
Layout.fillWidth: true
spacing: Kirigami.Units.smallSpacing
TimeDurationComboBox {
id: turnOffDisplayIdleTimeoutCombo
Layout.fillWidth: true
durationPromptAcceptsUnits: [DurationPromptDialog.Unit.Seconds, DurationPromptDialog.Unit.Minutes]
durationPromptLabel: i18nc("@label:spinbox After X minutes", "Turn off screen after:")
function translateSeconds(n, formatUnit = DurationPromptDialog.Unit.Seconds) {
return formatUnit == DurationPromptDialog.Unit.Minutes
? translateMinutes(n / 60) : i18ncp("@option:combobox Turn off screen (caution: watch for string length)", "%1 second", "%1 seconds", n);
}
function translateMinutes(n) { return i18ncp("@option:combobox Turn off screen (caution: watch for string length)", "%1 minute", "%1 minutes", n); }
valueRole: "seconds"
textRole: "text"
unitOfValueRole: DurationPromptDialog.Unit.Seconds
durationPromptFromValue: 30
presetOptions: [
{ seconds: -1, text: i18nc("@option:combobox Turn off screen (caution: watch for string length)", "Never") },
{ seconds: 1 * 60, text: translateMinutes(1), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 2 * 60, text: translateMinutes(2), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 5 * 60, text: translateMinutes(5), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 10 * 60, text: translateMinutes(10), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 15 * 60, text: translateMinutes(15), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 30 * 60, text: translateMinutes(30), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: -2, text: i18nc("@option:combobox Choose a custom value outside the list of preset values (caution: watch for string length)", "Custom…") },
]
customRequesterValue: -2
configuredValue: profileSettings.turnOffDisplayWhenIdle ? profileSettings.turnOffDisplayIdleTimeoutSec : -1
configuredDisplayUnit: model[indexOfValue(configuredValue)]?.unit ?? DurationPromptDialog.Unit.Minutes
onRegularValueActivated: {
profileSettings.turnOffDisplayIdleTimeoutSec = currentValue;
profileSettings.turnOffDisplayWhenIdle = currentValue > 0;
}
onCustomDurationAccepted: {
profileSettings.turnOffDisplayIdleTimeoutSec = valueToUnit(
customDuration.value, customDuration.unit, DurationPromptDialog.Unit.Seconds);
profileSettings.turnOffDisplayWhenIdle = customDuration.value > 0;
}
onConfiguredValueOptionMissing: {
const unit = configuredValue % 60 === 0
? customDuration?.unit ?? DurationPromptDialog.Unit.Minutes
: DurationPromptDialog.Unit.Seconds;
customOptions = [{
seconds: configuredValue,
text: translateSeconds(configuredValue, unit),
unit: unit,
}];
customDuration = null;
}
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "TurnOffDisplayIdleTimeoutSec"
}
}
TimeDurationComboBox {
id: turnOffDisplayIdleTimeoutWhenLockedCombo
durationPromptAcceptsUnits: [DurationPromptDialog.Unit.Seconds, DurationPromptDialog.Unit.Minutes]
durationPromptLabel: i18nc("@label:spinbox After X minutes", "When locked, turn off screen after:")
function translateSeconds(n, formatUnit = DurationPromptDialog.Unit.Seconds) {
return formatUnit == DurationPromptDialog.Unit.Minutes
? translateMinutes(n / 60) : i18ncp("@option:combobox Turn off screen (caution: watch for string length)", "When locked: %1 second", "When locked: %1 seconds", n);
}
function translateMinutes(n) { return i18ncp("@option:combobox Turn off screen (caution: watch for string length)", "When locked: %1 minute", "When locked: %1 minutes", n); }
valueRole: "seconds"
textRole: "text"
unitOfValueRole: DurationPromptDialog.Unit.Seconds
durationPromptFromValue: 10
presetOptions: [
{ seconds: -2, text: i18nc("@option:combobox Turn off screen after X minutes regardless of lock screen (caution: watch for string length)", "When locked and unlocked") },
// -1 would be "Never", same as for the unlocked timeout, if we want that option
{ seconds: 0, text: i18nc("@option:combobox Turn off screen (caution: watch for string length)", "When locked: Immediately") },
{ seconds: 20, text: translateSeconds(20), unit: DurationPromptDialog.Unit.Seconds },
{ seconds: 1 * 60, text: translateMinutes(1), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 2 * 60, text: translateMinutes(2), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 5 * 60, text: translateMinutes(5), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: -3, text: i18nc("@option:combobox Choose a custom value outside the list of preset values", "Custom…") },
]
customRequesterValue: -3
configuredValue: profileSettings.turnOffDisplayIdleTimeoutWhenLockedSec
configuredDisplayUnit: model[indexOfValue(configuredValue)]?.unit ?? DurationPromptDialog.Unit.Seconds
onRegularValueActivated: { profileSettings.turnOffDisplayIdleTimeoutWhenLockedSec = currentValue; }
onCustomDurationAccepted: {
profileSettings.turnOffDisplayIdleTimeoutWhenLockedSec = valueToUnit(
customDuration.value, customDuration.unit, DurationPromptDialog.Unit.Seconds);
}
onConfiguredValueOptionMissing: {
const unit = configuredValue % 60 === 0
? customDuration?.unit ?? DurationPromptDialog.Unit.Minutes
: DurationPromptDialog.Unit.Seconds;
customOptions = [{
seconds: configuredValue,
text: translateSeconds(configuredValue, unit),
unit: unit,
}];
customDuration = null;
}
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "TurnOffDisplayIdleTimeoutWhenLockedSec"
extraEnabledConditions: profileSettings.turnOffDisplayWhenIdle
}
}
}
RowLayout {
Kirigami.FormData.label: i18nc("@label:slider Brightness level", "Change key&board brightness:")
Kirigami.FormData.buddyFor: keyboardBrightnessCheck
visible: kcm.supportedActions["KeyboardBrightnessControl"] === true
Layout.fillWidth: true
spacing: Kirigami.Units.smallSpacing
QQC2.CheckBox {
id: keyboardBrightnessCheck
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "UseProfileSpecificKeyboardBrightness"
}
checked: profileSettings.useProfileSpecificKeyboardBrightness
onToggled: { profileSettings.useProfileSpecificKeyboardBrightness = checked; }
}
QQC2.Slider {
id: keyboardBrightnessSlider
Layout.fillWidth: true
from: 0
to: 100
stepSize: 1
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "KeyboardBrightness"
extraEnabledConditions: keyboardBrightnessCheck.checked
}
value: profileSettings.keyboardBrightness
onMoved: { profileSettings.keyboardBrightness = value; }
}
QQC2.Label {
enabled: keyboardBrightnessCheck.checked
text: formatPercentageText(keyboardBrightnessSlider.value)
Layout.preferredWidth: keyboardBrightnessPercentageMetrics.width
}
TextMetrics {
id: keyboardBrightnessPercentageMetrics
text: formatPercentageText(100)
}
}
//
// Advanced customization options
Item {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18nc("@title:group", "Other Settings")
visible: kcm.supportedActions["RunScript"] === true || powerProfileCombo.visible
}
ComboBoxWithIcon {
id: powerProfileCombo
Kirigami.FormData.label: i18nc(
"@label:combobox Power Save, Balanced or Performance profile - same options as in the Battery applet",
"Switch to po&wer profile:"
)
Accessible.name: i18nc(
"@accessible:name:combobox Power Save, Balanced or Performance profile - same options as in the Battery applet",
"Switch to power profile"
)
visible: kcm.supportedActions["PowerProfile"] === true && count > 1
Layout.fillWidth: true
implicitContentWidthPolicy: QQC2.ComboBox.WidestTextWhenCompleted
model: kcm.powerProfileModel
textRole: "name"
valueRole: "value"
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "PowerProfile"
}
Component.onCompleted: {
// indexOfValue() is invalid before onCompleted, so wait until here to bind currentIndex.
// Also observe count - PowerProfileModel has delayed initialization due to a D-Bus call.
currentIndex = Qt.binding(() => count ? indexOfValue(profileSettings.powerProfile) : -1);
}
onActivated: {
profileSettings.powerProfile = currentValue;
}
}
QQC2.Button {
id: addScriptCommandButton
Kirigami.FormData.label: i18nc("@label:button", "Run command or script:")
visible: (kcm.supportedActions["RunScript"] === true
// If power states aren't switchable, only show the idleTimeoutCommand field
// because profile load and unload fields are not useful, just confusing.
&& kcm.supportsBatteryProfiles
)
icon.name: "settings-configure"
text: i18nc(
"@text:button Determine what will trigger a command or script to run in this power state",
"Choose run conditions"
)
Accessible.name: i18nc("@accessible:name:button", "Choose run conditions for command or script")
Accessible.role: Accessible.ButtonMenu
onClicked: {
if (addScriptCommandMenu.opened) {
addScriptCommandMenu.close(); // closePolicy: Popup.CloseOnPressOutside does not seem to work?
} else {
addScriptCommandMenu.open();
}
}
QQC2.Menu {
id: addScriptCommandMenu
title: addScriptCommandButton.text
y: addScriptCommandButton.height
Kirigami.Action {
id: profileLoadCommandEditAction
text: i18nc(
"@text:action:menu Command or script to run for power state (On AC Power, On Battery, ...)",
"When entering \"%1\" state", root.profileLabel
)
checkable: true
Component.onCompleted: {
profileLoadCommandEditAction.checked = profileSettings.profileLoadCommand !== "";
}
onToggled: {
if (checked) {
profileLoadCommandEdit.forceActiveFocus();
} else {
profileSettings.profileLoadCommand = "";
}
}
}
Kirigami.Action {
id: profileUnloadCommandEditAction
text: i18nc(
"@text:action:menu Command or script to run for power state (On AC Power, On Battery, ...)",
"When exiting \"%1\" state", root.profileLabel
)
checkable: true
Component.onCompleted: {
profileUnloadCommandEditAction.checked = profileSettings.profileUnloadCommand !== "";
}
onToggled: {
if (checked) {
profileUnloadCommandEdit.forceActiveFocus();
} else {
profileSettings.profileUnloadCommand = "";
}
}
}
Kirigami.Action {
id: idleTimeoutCommandEditAction
text: i18nc(
"@text:action:menu Command or script to run",
"When inactive"
)
checkable: true
Component.onCompleted: {
idleTimeoutCommandEditAction.checked = (profileSettings.idleTimeoutCommand !== ""
// Always show field, regardless of addScriptCommandButton.visible.
|| (kcm.supportedActions["RunScript"] === true && !kcm.supportsBatteryProfiles));
}
onToggled: {
if (checked) {
idleTimeoutCommandEdit.forceActiveFocus();
} else {
profileSettings.idleTimeoutCommand = "";
}
}
}
}
}
RunScriptEdit {
id: profileLoadCommandEdit
Kirigami.FormData.label: i18nc(
"@label:textfield Command or script to run for power state (On AC Power, On Battery, ...)",
"When e&ntering \"%1\" state:", root.profileLabel
)
Accessible.name: i18nc(
"@label:textfield for power state (On AC Power, On Battery, ...)",
"Command or script when entering \"%1\" state", root.profileLabel
)
visible: profileLoadCommandEditAction.checked
Layout.fillWidth: true
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "ProfileLoadCommand"
}
command: profileSettings.profileLoadCommand
onCommandChanged: {
profileSettings.profileLoadCommand = command;
}
function resetToProfileSettings() {
command = profileSettings.profileLoadCommand;
profileLoadCommandEditAction.checked |= profileSettings.profileLoadCommand !== "";
}
Connections {
target: root
function onProfileSettingsChanged() { profileLoadCommandEdit.resetToProfileSettings(); }
}
Connections {
target: profileSettings
function onProfileLoadCommandChanged() { profileLoadCommandEdit.resetToProfileSettings(); }
}
}
RunScriptEdit {
id: profileUnloadCommandEdit
Kirigami.FormData.label: i18nc(
"@label:textfield Command or script to run for power state (On AC Power, On Battery, ...)",
"When e&xiting \"%1\" state:", root.profileLabel
)
Accessible.name: i18nc(
"@label:textfield for power state (On AC Power, On Battery, ...)",
"Command or script when exiting \"%1\" state", root.profileLabel
)
visible: profileUnloadCommandEditAction.checked
Layout.fillWidth: true
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "ProfileUnloadCommand"
}
command: profileSettings.profileUnloadCommand
onCommandChanged: {
profileSettings.profileUnloadCommand = command;
}
function resetToProfileSettings() {
command = profileSettings.profileUnloadCommand;
profileUnloadCommandEditAction.checked |= profileSettings.profileUnloadCommand !== "";
}
Connections {
target: root
function onProfileSettingsChanged() { profileUnloadCommandEdit.resetToProfileSettings(); }
}
Connections {
target: profileSettings
function onProfileUnloadCommandChanged() { profileUnloadCommandEdit.resetToProfileSettings(); }
}
}
TimeDurationComboBox {
id: idleTimeoutCommandTimeDelayCombo
Accessible.name: i18nc("@accessible:name:spinbox", "Duration of inactivity before the command or script runs")
Layout.fillWidth: true
visible: idleTimeoutCommandEdit.visible
Kirigami.FormData.label: i18nc(
"@label:textfield Command or script to run",
"When i&nactive:"
)
durationPromptLabel: i18nc("@label:spinbox After X minutes", "Run command or script after:")
durationPromptAcceptsUnits: [DurationPromptDialog.Unit.Seconds, DurationPromptDialog.Unit.Minutes]
function translateSeconds(n, formatUnit = DurationPromptDialog.Unit.Seconds) {
return formatUnit == DurationPromptDialog.Unit.Minutes
? translateMinutes(n / 60) : i18ncp("@option:combobox", "Run after %1 second", "Run after %1 seconds", n);
}
function translateMinutes(n) { return i18ncp("@option:combobox", "Run after %1 minute", "Run after %1 minutes", n); }
valueRole: "seconds"
textRole: "text"
unitOfValueRole: DurationPromptDialog.Unit.Seconds
durationPromptFromValue: 10
presetOptions: [
{ seconds: 1 * 60, text: translateMinutes(1), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 2 * 60, text: translateMinutes(2), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 5 * 60, text: translateMinutes(5), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 10 * 60, text: translateMinutes(10), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 15 * 60, text: translateMinutes(15), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: 30 * 60, text: translateMinutes(30), unit: DurationPromptDialog.Unit.Minutes },
{ seconds: -1, text: i18nc("@option:combobox Choose a custom value outside the list of preset values", "Custom…") },
]
customRequesterValue: -1
configuredValue: profileSettings.runScriptIdleTimeoutSec
configuredDisplayUnit: model[indexOfValue(configuredValue)]?.unit ?? DurationPromptDialog.Unit.Minutes
onRegularValueActivated: { profileSettings.runScriptIdleTimeoutSec = currentValue; }
onCustomDurationAccepted: {
profileSettings.runScriptIdleTimeoutSec = valueToUnit(
customDuration.value, customDuration.unit, DurationPromptDialog.Unit.Seconds);
}
onConfiguredValueOptionMissing: {
const unit = configuredValue % 60 === 0
? customDuration?.unit ?? DurationPromptDialog.Unit.Minutes
: DurationPromptDialog.Unit.Seconds;
customOptions = [{
seconds: configuredValue,
text: translateSeconds(configuredValue, unit),
unit: unit,
}];
customDuration = null;
}
}
RunScriptEdit {
id: idleTimeoutCommandEdit
Accessible.name: i18nc("@accessible:name:textfield", "Command or script when inactive")
visible: idleTimeoutCommandEditAction.checked
Layout.fillWidth: true
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "IdleTimeoutCommand"
}
command: profileSettings.idleTimeoutCommand
onCommandChanged: {
profileSettings.idleTimeoutCommand = command;
}
function resetToProfileSettings() {
command = profileSettings.idleTimeoutCommand;
idleTimeoutCommandEditAction.checked |= profileSettings.idleTimeoutCommand !== "";
}
Connections {
target: root
function onProfileSettingsChanged() { idleTimeoutCommandEdit.resetToProfileSettings(); }
}
Connections {
target: profileSettings
function onIdleTimeoutCommandChanged() { idleTimeoutCommandEdit.resetToProfileSettings(); }
}
KCM.SettingStateBinding {
configObject: profileSettings
settingName: "RunScriptIdleTimeoutSec"
}
}
}
|