shift-shell/kcms/time/ui/main.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

251 lines
8.3 KiB
QML
Raw Normal View History

// -*- coding: iso-8859-1 -*-
/*
* SPDX-FileCopyrightText: 2011 Sebastian Kügler <sebas@kde.org>
* SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
*
* 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-09-21 18:05:48 +00:00
import org.kde.kirigami as Kirigami
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
SimpleKCM {
id: timeModule
leftPadding: 0
rightPadding: 0
2023-09-21 18:05:48 +00:00
topPadding: 0
bottomPadding: 0
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-09-21 18:05:48 +00:00
FormCard.FormDelegateSeparator { above: hourFormatSwitch; below: timeZoneSelect }
FormCard.FormButtonDelegate {
id: timeZoneSelect
text: i18n("Timezone")
description: kcm.timeZone
onClicked: timeZonePickerDialog.open()
2023-09-21 18:05:48 +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) {
kcm.ntpServer = "";
kcm.saveTime();
}
}
2023-09-21 18:05:48 +00:00
}
FormCard.FormDelegateSeparator { above: ntpCheckBox; below: timeSelect }
FormCard.FormButtonDelegate {
id: timeSelect
enabled: !ntpCheckBox.checked
icon.name: "clock"
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
text: i18n("System Date")
2023-09-21 18:05:48 +00:00
description: Qt.formatDate(kcm.currentDate, Locale.LongFormat)
icon.name: "view-calendar"
enabled: !ntpCheckBox.checked
onClicked: datePickerDialog.open()
}
}
}
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
property string selectedTimeZoneId
2023-09-21 18:05:48 +00:00
onOpened: {
selectedTimeZoneId = kcm.timeZone;
}
onAccepted: {
kcm.saveTimeZone(selectedTimeZoneId)
}
2023-09-21 18:05:48 +00:00
ListView {
id: listView
currentIndex: -1 // otherwise the vkbd will constantly open and close while typing
headerPositioning: ListView.OverlayHeader
implicitWidth: 18 * Kirigami.Units.gridUnit
implicitHeight: 18 * Kirigami.Units.gridUnit
2023-09-21 18:05:48 +00:00
header: Controls.Control {
z: 1
2023-09-21 18:05:48 +00:00
topPadding: Kirigami.Units.smallSpacing
bottomPadding: 0
leftPadding: Kirigami.Units.smallSpacing
rightPadding: Kirigami.Units.smallSpacing
2024-07-27 03:47:44 +00:00
background: Rectangle {
color: Kirigami.Theme.backgroundColor
}
2023-09-21 18:05:48 +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
}
}
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
}
}
},
Kirigami.PromptDialog {
id: datePickerDialog
title: i18n("Pick System Date")
topPadding: Kirigami.Units.largeSpacing
bottomPadding: Kirigami.Units.largeSpacing
preferredWidth: Kirigami.Units.gridUnit * 15
preferredHeight: Kirigami.Units.gridUnit * 13
standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel
onAccepted: {
kcm.currentDate = datePicker.isoDate;
kcm.saveTime();
}
onOpened: {
let date = new Date(kcm.currentDate)
datePicker.day = date.getDate();
datePicker.month = date.getMonth() + 1;
datePicker.year = date.getFullYear();
}
DatePicker {
id: datePicker
implicitHeight: Kirigami.Units.gridUnit * 6
Connections {
target: kcm
function onCurrentDateChanged() {
if (datePickerDialog.visible) {
return;
}
let date = new Date(kcm.currentDate);
datePicker.day = date.getDate();
datePicker.month = date.getMonth() + 1;
datePicker.year = date.getFullYear();
}
}
}
},
Kirigami.PromptDialog {
id: timePickerDialog
title: i18n("Pick System Time")
preferredWidth: Kirigami.Units.gridUnit * 15
topPadding: Kirigami.Units.largeSpacing
bottomPadding: Kirigami.Units.largeSpacing
standardButtons: Kirigami.Dialog.Save | Kirigami.Dialog.Cancel
onAccepted: {
kcm.currentTime = String(timePicker.hours).padStart(2, '0')
+ ':'
+ String(timePicker.minutes).padStart(2, '0')
+ ':00';
kcm.saveTime();
}
onOpened: {
var date = new Date(kcm.currentTime);
timePicker.hours = date.getHours();
timePicker.minutes = date.getMinutes();
console.log(date + ' ' + date.getHours() + date.getMinutes())
}
TimePicker {
id: timePicker
Connections {
target: kcm
function onCurrentTimeChanged() {
if (timePicker.userConfiguring) {
return;
}
var date = new Date(kcm.currentTime);
timePicker.hours = date.getHours();
timePicker.minutes = date.getMinutes();
}
}
}
}
]
}