Warning, /plasma/plasma-mobile/kcms/time/ui/main.qml is written in an unsupported language. File is not indexed.
0001 // -*- coding: iso-8859-1 -*- 0002 /* 0003 * SPDX-FileCopyrightText: 2011 Sebastian Kügler <sebas@kde.org> 0004 * SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Layouts 0011 import QtQuick.Controls as Controls 0012 0013 import org.kde.kirigami as Kirigami 0014 import org.kde.kcmutils 0015 import org.kde.timesettings 0016 import org.kde.kirigamiaddons.formcard 1 as FormCard 0017 import org.kde.kirigamiaddons.delegates 1 as Delegates 0018 0019 SimpleKCM { 0020 id: timeModule 0021 0022 leftPadding: 0 0023 rightPadding: 0 0024 topPadding: 0 0025 bottomPadding: 0 0026 0027 ColumnLayout { 0028 spacing: 0 0029 0030 FormCard.FormHeader { 0031 title: i18n("Display") 0032 } 0033 0034 FormCard.FormCard { 0035 FormCard.FormSwitchDelegate { 0036 id: hourFormatSwitch 0037 text: i18n("24-Hour Format") 0038 description: i18n("Whether to use a 24-hour format for clocks.") 0039 checked: kcm.twentyFour 0040 onCheckedChanged: { 0041 kcm.twentyFour = checked 0042 } 0043 } 0044 0045 FormCard.FormDelegateSeparator { above: hourFormatSwitch; below: timeZoneSelect } 0046 0047 FormCard.FormButtonDelegate { 0048 id: timeZoneSelect 0049 text: i18n("Timezone") 0050 description: kcm.timeZone 0051 onClicked: timeZonePickerDialog.open() 0052 } 0053 } 0054 0055 FormCard.FormHeader { 0056 title: i18n("Time and Date") 0057 } 0058 0059 FormCard.FormCard { 0060 FormCard.FormSwitchDelegate { 0061 id: ntpCheckBox 0062 text: i18n("Automatic Time Synchronization") 0063 description: i18n("Whether to set the time automatically.") 0064 checked: kcm.useNtp 0065 onCheckedChanged: { 0066 kcm.useNtp = checked 0067 if (!checked) { 0068 kcm.ntpServer = ""; 0069 kcm.saveTime(); 0070 } 0071 } 0072 } 0073 0074 FormCard.FormDelegateSeparator { above: ntpCheckBox; below: timeSelect } 0075 0076 FormCard.FormButtonDelegate { 0077 id: timeSelect 0078 enabled: !ntpCheckBox.checked 0079 icon.name: "clock" 0080 text: i18n("System Time") 0081 description: Qt.formatTime(kcm.currentTime, kcm.twentyFour ? 'hh:mm' : 'hh:mm ap') 0082 onClicked: timePickerDialog.open() 0083 } 0084 0085 FormCard.FormDelegateSeparator { above: timeSelect; below: dateSelect } 0086 0087 FormCard.FormButtonDelegate { 0088 id: dateSelect 0089 text: i18n("System Date") 0090 description: Qt.formatDate(kcm.currentDate, Locale.LongFormat) 0091 icon.name: "view-calendar" 0092 enabled: !ntpCheckBox.checked 0093 onClicked: datePickerDialog.open() 0094 } 0095 } 0096 } 0097 0098 data: [ 0099 Kirigami.Dialog { 0100 id: timeZonePickerDialog 0101 title: i18nc("@title:window", "Pick Timezone") 0102 standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel 0103 0104 property string selectedTimeZoneId 0105 0106 onOpened: { 0107 selectedTimeZoneId = kcm.timeZone; 0108 } 0109 0110 onAccepted: { 0111 kcm.saveTimeZone(selectedTimeZoneId) 0112 } 0113 0114 ListView { 0115 id: listView 0116 headerPositioning: ListView.OverlayHeader 0117 implicitWidth: 18 * Kirigami.Units.gridUnit 0118 implicitHeight: 18 * Kirigami.Units.gridUnit 0119 0120 header: Controls.Control { 0121 z: 1 0122 0123 topPadding: Kirigami.Units.smallSpacing 0124 bottomPadding: 0 0125 leftPadding: Kirigami.Units.smallSpacing 0126 rightPadding: Kirigami.Units.smallSpacing 0127 0128 background: Rectangle { 0129 color: Kirigami.Theme.backgroundColor 0130 } 0131 0132 contentItem: ColumnLayout { 0133 spacing: Kirigami.Units.smallSpacing 0134 Kirigami.SearchField { 0135 Layout.fillWidth: true 0136 onTextChanged: kcm.timeZonesModel.filterString = text 0137 } 0138 Kirigami.Separator { Layout.fillWidth: true } 0139 } 0140 } 0141 0142 model: kcm.timeZonesModel 0143 delegate: Controls.RadioDelegate { 0144 z: -1 0145 width: ListView.view.width 0146 checked: timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId 0147 0148 text: { 0149 if (model.region) { 0150 return "%1 / %2".arg(model.region).arg(model.city); 0151 } else { 0152 return model.city; 0153 } 0154 } 0155 0156 onClicked: { 0157 timeZonePickerDialog.selectedTimeZoneId = model.timeZoneId; 0158 checked = Qt.binding(() => timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId); 0159 console.log(timeZonePickerDialog.selectedTimeZoneId + ' ' + model.timeZoneId + ' ' + (timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId)); 0160 } 0161 } 0162 } 0163 }, 0164 0165 Kirigami.PromptDialog { 0166 id: datePickerDialog 0167 title: i18n("Pick System Date") 0168 topPadding: Kirigami.Units.largeSpacing 0169 bottomPadding: Kirigami.Units.largeSpacing 0170 preferredWidth: Kirigami.Units.gridUnit * 15 0171 preferredHeight: Kirigami.Units.gridUnit * 13 0172 0173 standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel 0174 0175 onAccepted: { 0176 kcm.currentDate = datePicker.isoDate; 0177 kcm.saveTime(); 0178 } 0179 0180 onOpened: { 0181 let date = new Date(kcm.currentDate) 0182 datePicker.day = date.getDate(); 0183 datePicker.month = date.getMonth() + 1; 0184 datePicker.year = date.getFullYear(); 0185 } 0186 0187 DatePicker { 0188 id: datePicker 0189 implicitHeight: Kirigami.Units.gridUnit * 6 0190 0191 Connections { 0192 target: kcm 0193 function onCurrentDateChanged() { 0194 if (datePickerDialog.visible) { 0195 return; 0196 } 0197 0198 let date = new Date(kcm.currentDate); 0199 datePicker.day = date.getDate(); 0200 datePicker.month = date.getMonth() + 1; 0201 datePicker.year = date.getFullYear(); 0202 } 0203 } 0204 } 0205 }, 0206 0207 Kirigami.PromptDialog { 0208 id: timePickerDialog 0209 title: i18n("Pick System Time") 0210 preferredWidth: Kirigami.Units.gridUnit * 15 0211 topPadding: Kirigami.Units.largeSpacing 0212 bottomPadding: Kirigami.Units.largeSpacing 0213 0214 standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel 0215 0216 onAccepted: { 0217 kcm.currentTime = String(timePicker.hours).padStart(2, '0') 0218 + ':' 0219 + String(timePicker.minutes).padStart(2, '0') 0220 + ':00'; 0221 kcm.saveTime(); 0222 } 0223 0224 onOpened: { 0225 var date = new Date(kcm.currentTime); 0226 timePicker.hours = date.getHours(); 0227 timePicker.minutes = date.getMinutes(); 0228 console.log(date + ' ' + date.getHours() + date.getMinutes()) 0229 } 0230 0231 TimePicker { 0232 id: timePicker 0233 0234 Connections { 0235 target: kcm 0236 function onCurrentTimeChanged() { 0237 if (timePicker.userConfiguring) { 0238 return; 0239 } 0240 0241 var date = new Date(kcm.currentTime); 0242 timePicker.hours = date.getHours(); 0243 timePicker.minutes = date.getMinutes(); 0244 } 0245 } 0246 } 0247 } 0248 ] 0249 }