Warning, /multimedia/kasts/src/qml/SleepTimerDialog.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * SPDX-FileCopyrightText: 2022 Bart De Vries <bart@mogwai.be>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as Controls
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.kasts
0013 import org.kde.kasts.settings
0014 
0015 Kirigami.Dialog {
0016     id: sleepTimerDialog
0017     title: i18n("Sleep Timer")
0018     padding: Kirigami.Units.largeSpacing
0019     closePolicy: Kirigami.Dialog.CloseOnEscape | Kirigami.Dialog.CloseOnPressOutside
0020     standardButtons: Kirigami.Dialog.NoButton
0021 
0022     property bool timerActive: AudioManager.remainingSleepTime > 0
0023 
0024     customFooterActions: [
0025         Kirigami.Action {
0026             enabled: !timerActive
0027             text: i18n("Start")
0028             icon.name: "dialog-ok"
0029             onTriggered: {
0030                 sleepTimerDialog.close();
0031                 var sleepTimeSeconds = sleepTimerValueBox.value * sleepTimerUnitsBox.model[sleepTimerUnitsBox.currentIndex]["secs"];
0032                 if (sleepTimeSeconds > 0) {
0033                     SettingsManager.sleepTimerValue = sleepTimerValueBox.value;
0034                     SettingsManager.sleepTimerUnits = sleepTimerUnitsBox.currentValue;
0035                     SettingsManager.save();
0036                     AudioManager.sleepTime = sleepTimeSeconds;
0037                 }
0038             }
0039         },
0040         Kirigami.Action {
0041             enabled: timerActive
0042             text: i18n("Stop")
0043             icon.name: "dialog-cancel"
0044             onTriggered: {
0045                 sleepTimerDialog.close();
0046                 AudioManager.sleepTime = undefined; // make use of RESET
0047             }
0048         }
0049     ]
0050 
0051     ColumnLayout {
0052         id: content
0053         Controls.Label {
0054             text: (timerActive) ? i18n("Status: Active") : i18n("Status: Inactive")
0055         }
0056 
0057         Controls.Label {
0058             opacity: (timerActive) ? 1 : 0.5
0059             Layout.bottomMargin: Kirigami.Units.largeSpacing
0060             text: i18n("Remaining time: %1", AudioManager.formattedRemainingSleepTime)
0061         }
0062 
0063         RowLayout {
0064             Controls.SpinBox {
0065                 id: sleepTimerValueBox
0066                 enabled: !timerActive
0067                 value: SettingsManager.sleepTimerValue
0068                 from: 1
0069                 to: 24 * 60 * 60
0070             }
0071 
0072             Controls.ComboBox {
0073                 id: sleepTimerUnitsBox
0074                 enabled: !timerActive
0075                 textRole: "text"
0076                 valueRole: "value"
0077                 model: [{"text": i18n("Seconds"), "value": 0, "secs": 1, "max": 24 * 60 * 60},
0078                         {"text": i18n("Minutes"), "value": 1, "secs": 60, "max": 24 * 60},
0079                         {"text": i18n("Hours"),   "value": 2, "secs": 60 * 60, "max": 24}]
0080                 Component.onCompleted: {
0081                     currentIndex = indexOfValue(SettingsManager.sleepTimerUnits);
0082                     sleepTimerValueBox.to = sleepTimerUnitsBox.model[currentIndex]["max"];
0083                     if (sleepTimerValueBox.value > sleepTimerUnitsBox.model[currentIndex]["max"]) {
0084                         sleepTimerValueBox.value = sleepTimerUnitsBox.model[currentIndex]["max"];
0085                     }
0086                 }
0087                 onActivated: {
0088                     SettingsManager.sleepTimerUnits = currentValue;
0089                     if (sleepTimerValueBox.value > sleepTimerUnitsBox.model[currentIndex]["max"]) {
0090                         sleepTimerValueBox.value = sleepTimerUnitsBox.model[currentIndex]["max"];
0091                     }
0092                     sleepTimerValueBox.to = sleepTimerUnitsBox.model[currentIndex]["max"];
0093                 }
0094             }
0095         }
0096     }
0097 }