2023-03-14 01:45:47 +00:00
|
|
|
// -*- coding: iso-8859-1 -*-
|
|
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2011 Sebastian Kügler <sebas@kde.org>
|
2023-12-17 04:54:06 +00:00
|
|
|
* SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
|
2023-03-14 01:45:47 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
2023-09-21 18:05:48 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
import QtQuick.Controls as Controls
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-09-21 18:05:48 +00:00
|
|
|
import org.kde.kirigami as Kirigami
|
2023-06-06 19:31:58 +00:00
|
|
|
import org.kde.kcmutils
|
2023-09-21 18:05:48 +00:00
|
|
|
import org.kde.timesettings
|
|
|
|
|
import org.kde.kirigamiaddons.formcard 1 as FormCard
|
|
|
|
|
import org.kde.kirigamiaddons.delegates 1 as Delegates
|
2024-11-02 04:09:48 +00:00
|
|
|
import org.kde.kirigamiaddons.dateandtime as DateAndTime
|
2023-03-14 01:45:47 +00:00
|
|
|
|
|
|
|
|
SimpleKCM {
|
|
|
|
|
id: timeModule
|
|
|
|
|
|
|
|
|
|
leftPadding: 0
|
|
|
|
|
rightPadding: 0
|
2023-09-21 18:05:48 +00:00
|
|
|
topPadding: 0
|
|
|
|
|
bottomPadding: 0
|
2023-03-14 01:45:47 +00:00
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
spacing: 0
|
|
|
|
|
|
2023-09-21 18:05:48 +00:00
|
|
|
FormCard.FormHeader {
|
|
|
|
|
title: i18n("Display")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormCard.FormCard {
|
|
|
|
|
FormCard.FormSwitchDelegate {
|
|
|
|
|
id: hourFormatSwitch
|
|
|
|
|
text: i18n("24-Hour Format")
|
|
|
|
|
description: i18n("Whether to use a 24-hour format for clocks.")
|
|
|
|
|
checked: kcm.twentyFour
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
|
kcm.twentyFour = checked
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 18:05:48 +00:00
|
|
|
|
|
|
|
|
FormCard.FormDelegateSeparator { above: hourFormatSwitch; below: timeZoneSelect }
|
|
|
|
|
|
|
|
|
|
FormCard.FormButtonDelegate {
|
|
|
|
|
id: timeZoneSelect
|
|
|
|
|
text: i18n("Timezone")
|
|
|
|
|
description: kcm.timeZone
|
2023-12-17 04:54:06 +00:00
|
|
|
onClicked: timeZonePickerDialog.open()
|
2023-09-21 18:05:48 +00:00
|
|
|
}
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-21 18:05:48 +00:00
|
|
|
FormCard.FormHeader {
|
|
|
|
|
title: i18n("Time and Date")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormCard.FormCard {
|
|
|
|
|
FormCard.FormSwitchDelegate {
|
|
|
|
|
id: ntpCheckBox
|
|
|
|
|
text: i18n("Automatic Time Synchronization")
|
|
|
|
|
description: i18n("Whether to set the time automatically.")
|
|
|
|
|
checked: kcm.useNtp
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
|
kcm.useNtp = checked
|
|
|
|
|
if (!checked) {
|
2023-12-17 04:54:06 +00:00
|
|
|
kcm.ntpServer = "";
|
|
|
|
|
kcm.saveTime();
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-21 18:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormCard.FormDelegateSeparator { above: ntpCheckBox; below: timeSelect }
|
|
|
|
|
|
|
|
|
|
FormCard.FormButtonDelegate {
|
|
|
|
|
id: timeSelect
|
|
|
|
|
enabled: !ntpCheckBox.checked
|
|
|
|
|
icon.name: "clock"
|
2023-12-17 04:54:06 +00:00
|
|
|
text: i18n("System Time")
|
|
|
|
|
description: Qt.formatTime(kcm.currentTime, kcm.twentyFour ? 'hh:mm' : 'hh:mm ap')
|
|
|
|
|
onClicked: timePickerDialog.open()
|
2023-09-21 18:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormCard.FormDelegateSeparator { above: timeSelect; below: dateSelect }
|
|
|
|
|
|
|
|
|
|
FormCard.FormButtonDelegate {
|
|
|
|
|
id: dateSelect
|
2023-12-17 04:54:06 +00:00
|
|
|
text: i18n("System Date")
|
2023-09-21 18:05:48 +00:00
|
|
|
description: Qt.formatDate(kcm.currentDate, Locale.LongFormat)
|
2023-12-17 04:54:06 +00:00
|
|
|
icon.name: "view-calendar"
|
|
|
|
|
enabled: !ntpCheckBox.checked
|
|
|
|
|
onClicked: datePickerDialog.open()
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
data: [
|
|
|
|
|
Kirigami.Dialog {
|
|
|
|
|
id: timeZonePickerDialog
|
|
|
|
|
title: i18nc("@title:window", "Pick Timezone")
|
|
|
|
|
standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
property string selectedTimeZoneId
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
onOpened: {
|
|
|
|
|
selectedTimeZoneId = kcm.timeZone;
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
onAccepted: {
|
|
|
|
|
kcm.saveTimeZone(selectedTimeZoneId)
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
ListView {
|
|
|
|
|
id: listView
|
2024-03-18 03:26:34 +00:00
|
|
|
currentIndex: -1 // otherwise the vkbd will constantly open and close while typing
|
2023-12-17 04:54:06 +00:00
|
|
|
headerPositioning: ListView.OverlayHeader
|
|
|
|
|
implicitWidth: 18 * Kirigami.Units.gridUnit
|
|
|
|
|
implicitHeight: 18 * Kirigami.Units.gridUnit
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
header: Controls.Control {
|
|
|
|
|
z: 1
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
topPadding: Kirigami.Units.smallSpacing
|
|
|
|
|
bottomPadding: 0
|
|
|
|
|
leftPadding: Kirigami.Units.smallSpacing
|
|
|
|
|
rightPadding: Kirigami.Units.smallSpacing
|
2024-07-27 03:47:44 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
background: Rectangle {
|
|
|
|
|
color: Kirigami.Theme.backgroundColor
|
|
|
|
|
}
|
2023-09-21 18:05:48 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
|
spacing: Kirigami.Units.smallSpacing
|
|
|
|
|
Kirigami.SearchField {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
onTextChanged: kcm.timeZonesModel.filterString = text
|
|
|
|
|
}
|
|
|
|
|
Kirigami.Separator { Layout.fillWidth: true }
|
2023-09-21 18:05:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
model: kcm.timeZonesModel
|
|
|
|
|
delegate: Controls.RadioDelegate {
|
|
|
|
|
z: -1
|
|
|
|
|
width: ListView.view.width
|
|
|
|
|
checked: timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId
|
|
|
|
|
|
|
|
|
|
text: {
|
|
|
|
|
if (model.region) {
|
|
|
|
|
return "%1 / %2".arg(model.region).arg(model.city);
|
|
|
|
|
} else {
|
|
|
|
|
return model.city;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
timeZonePickerDialog.selectedTimeZoneId = model.timeZoneId;
|
|
|
|
|
checked = Qt.binding(() => timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId);
|
|
|
|
|
console.log(timeZonePickerDialog.selectedTimeZoneId + ' ' + model.timeZoneId + ' ' + (timeZonePickerDialog.selectedTimeZoneId == model.timeZoneId));
|
|
|
|
|
}
|
2023-09-21 18:05:48 +00:00
|
|
|
}
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
2023-12-17 04:54:06 +00:00
|
|
|
},
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2024-11-02 04:09:48 +00:00
|
|
|
DateAndTime.DatePopup {
|
2023-12-17 04:54:06 +00:00
|
|
|
id: datePickerDialog
|
2024-11-02 04:09:48 +00:00
|
|
|
modal: true
|
|
|
|
|
parent: timeModule
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
onOpened: {
|
2024-11-02 04:09:48 +00:00
|
|
|
value = kcm.currentDate;
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-02 04:09:48 +00:00
|
|
|
onAccepted: {
|
|
|
|
|
kcm.currentDate = value;
|
|
|
|
|
kcm.saveTime();
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
2023-12-17 04:54:06 +00:00
|
|
|
},
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
Kirigami.PromptDialog {
|
|
|
|
|
id: timePickerDialog
|
|
|
|
|
title: i18n("Pick System Time")
|
|
|
|
|
preferredWidth: Kirigami.Units.gridUnit * 15
|
|
|
|
|
standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
onAccepted: {
|
|
|
|
|
kcm.currentTime = String(timePicker.hours).padStart(2, '0')
|
|
|
|
|
+ ':'
|
|
|
|
|
+ String(timePicker.minutes).padStart(2, '0')
|
|
|
|
|
+ ':00';
|
|
|
|
|
kcm.saveTime();
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
onOpened: {
|
|
|
|
|
var date = new Date(kcm.currentTime);
|
|
|
|
|
timePicker.hours = date.getHours();
|
|
|
|
|
timePicker.minutes = date.getMinutes();
|
|
|
|
|
console.log(date + ' ' + date.getHours() + date.getMinutes())
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
TimePicker {
|
|
|
|
|
id: timePicker
|
2024-11-02 04:09:48 +00:00
|
|
|
width: timePickerDialog.width - timePickerDialog.leftPadding - timePickerDialog.rightPadding
|
2023-12-17 04:54:06 +00:00
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: kcm
|
|
|
|
|
function onCurrentTimeChanged() {
|
|
|
|
|
if (timePicker.userConfiguring) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-14 01:45:47 +00:00
|
|
|
|
2023-12-17 04:54:06 +00:00
|
|
|
var date = new Date(kcm.currentTime);
|
|
|
|
|
timePicker.hours = date.getHours();
|
|
|
|
|
timePicker.minutes = date.getMinutes();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-17 04:54:06 +00:00
|
|
|
]
|
2023-03-14 01:45:47 +00:00
|
|
|
}
|