Time.qml 7.01 KB
Newer Older
1 2
// -*- coding: iso-8859-1 -*-
/*
Sebastian Kügler's avatar
Sebastian Kügler committed
3
 *   Copyright 2011 Sebastian Kügler <sebas@kde.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

Jonah Brüchert's avatar
Jonah Brüchert committed
21 22
import QtQuick 2.7
import QtQuick.Layouts 1.3
Jonah Brüchert's avatar
Jonah Brüchert committed
23
import QtQuick.Controls 2.3 as Controls
24

25
import org.kde.kirigami 2.10 as Kirigami
Jonah Brüchert's avatar
Jonah Brüchert committed
26
import org.kde.kcm 1.2
27

Jonah Brüchert's avatar
Jonah Brüchert committed
28
SimpleKCM {
29 30
    id: timeModule

31 32 33 34 35 36 37
    Component {
        id: listDelegateComponent

        Kirigami.BasicListItem {
            text: display

            onClicked: {
38
                timeZonePickerSheet.close()
39 40 41 42 43
                kcm.saveTimeZone(display)
            }
        }
    }

Jonah Brüchert's avatar
Jonah Brüchert committed
44 45 46 47
    ColumnLayout {
        width: parent.width
        spacing: 0
        id: formLayout
48

49 50
        Kirigami.ListSectionHeader {
            label: i18n("Time Display")
Jonah Brüchert's avatar
Jonah Brüchert committed
51
        }
52

Jonah Brüchert's avatar
Jonah Brüchert committed
53 54 55
        Kirigami.BasicListItem {
            label: i18n("Use 24-hour clock:")
            icon: "clock"
Jonah Brüchert's avatar
Jonah Brüchert committed
56
            Controls.Switch {
57 58 59 60 61
                id: twentyFourSwitch
                checked: kcm.twentyFour
                onClicked : {
                    kcm.twentyFour = checked
                    print(kcm.timeZone);
62
                }
63
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
64
        }
65

Jonah Brüchert's avatar
Jonah Brüchert committed
66 67 68
        Kirigami.BasicListItem {
            label: "Timezone:"
            Controls.ToolButton {
69 70
                id: timeZoneButton
                text: kcm.timeZone
71
                onClicked: timeZonePickerSheet.open()
72
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
73
        }
74

75 76
        Kirigami.ListSectionHeader {
            label: i18n("Set Time and Date")
Jonah Brüchert's avatar
Jonah Brüchert committed
77
        }
78

Jonah Brüchert's avatar
Jonah Brüchert committed
79 80
        Kirigami.BasicListItem {
            label: i18n("Set time automatically:")
Jonah Brüchert's avatar
Jonah Brüchert committed
81
            Controls.Switch {
82 83 84 85 86 87 88
                id: ntpCheckBox
                checked: kcm.useNtp
                onClicked: {
                    kcm.useNtp = checked;
                    if (!checked) {
                        kcm.ntpServer = ""
                        kcm.saveTime()
Sebastian Kügler's avatar
Sebastian Kügler committed
89
                    }
90 91
                }
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
92 93 94 95 96 97 98 99 100 101
        }

        Kirigami.BasicListItem {
            label: i18n("Time")
            icon: "clock"
            Controls.ToolButton {
                text: {
                    var date = new Date(kcm.currentTime);
                    return date.toTimeString()
                }
102
                onClicked: timePickerSheet.open()
103
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
104
        }
105

Jonah Brüchert's avatar
Jonah Brüchert committed
106 107
        Kirigami.BasicListItem {
            label: i18n("Date")
108
            icon: "view-calendar"
Jonah Brüchert's avatar
Jonah Brüchert committed
109 110 111 112 113
            Controls.ToolButton {
                text: {
                    var date = new Date(kcm.currentDate);
                    return date.toDateString()
                }
114
                onClicked: datePickerSheet.open()
Jonah Brüchert's avatar
Jonah Brüchert committed
115 116 117 118
            }
        }
    }

119 120
    Kirigami.OverlaySheet {
        id: timeZonePickerSheet
121
        header: Kirigami.Heading { text: i18nc("@title:window", "Pick Timezone") }
122 123 124 125 126 127 128

        footer: RowLayout {
            Controls.Button {
                Layout.alignment: Qt.AlignHCenter

                text: i18nc("@action:button", "Close")

Jonah Brüchert's avatar
Jonah Brüchert committed
129
                onClicked: timeZonePickerSheet.close()
130 131
            }
        }
Jonah Brüchert's avatar
Jonah Brüchert committed
132
        ListView {
133 134
            header: Kirigami.SearchField {
                Layout.fillWidth: true
135
                width: parent.width
136 137 138 139 140
                onTextChanged: {
                    kcm.timeZoneFilterChanged(text)
                }
            }

Jonah Brüchert's avatar
Jonah Brüchert committed
141 142
            clip: true
            anchors.fill: parent
143 144 145 146
            implicitWidth: 18 * Kirigami.Units.gridUnit
            model: kcm.timeZonesModel
            delegate: Kirigami.DelegateRecycler {
                width: parent.width
Jonah Brüchert's avatar
Jonah Brüchert committed
147

148
                sourceComponent: listDelegateComponent
Jonah Brüchert's avatar
Jonah Brüchert committed
149 150 151
            }
        }
    }
152

153 154 155 156
    Kirigami.OverlaySheet {
        id: timePickerSheet
        header:  Kirigami.Heading { text: i18n("Pick Time") }
        TimePicker {
Jonah Brüchert's avatar
Jonah Brüchert committed
157 158 159 160
            id: timePicker
            enabled: !ntpCheckBox.checked
            twentyFour: twentyFourSwitch.checked

161 162
            implicitWidth: width > Kirigami.Units.gridUnit * 15 ? width : Kirigami.Units.gridUnit * 15

Jonah Brüchert's avatar
Jonah Brüchert committed
163 164 165 166 167 168 169 170 171 172 173 174
            Component.onCompleted: {
                var date = new Date(kcm.currentTime);
                timePicker.hours = date.getHours();
                timePicker.minutes = date.getMinutes();
                timePicker.seconds = date.getSeconds();
            }
            Connections {
                target: kcm
                onCurrentTimeChanged: {
                    if (timePicker.userConfiguring) {
                        return;
                    }
175

176 177 178 179
                    var date = new Date(kcm.currentTime);
                    timePicker.hours = date.getHours();
                    timePicker.minutes = date.getMinutes();
                    timePicker.seconds = date.getSeconds();
180
                }
181
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
182 183 184
            onUserConfiguringChanged: {
                kcm.currentTime = timeString
                kcm.saveTime()
Sebastian Kügler's avatar
Sebastian Kügler committed
185
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
186
        }
187 188 189 190 191 192 193 194 195
        footer: RowLayout {
            Controls.Button {
                Layout.alignment: Qt.AlignRight

                text: i18nc("@action:button", "Close")

                onClicked: timePickerSheet.close()
            }
        }
Jonah Brüchert's avatar
Jonah Brüchert committed
196
    }
197

198 199 200 201
    Kirigami.OverlaySheet {
        id: datePickerSheet
        header: Kirigami.Heading { text: i18n("Pick Date") }
        DatePicker {
Jonah Brüchert's avatar
Jonah Brüchert committed
202 203 204
            id: datePicker
            enabled: !ntpCheckBox.checked

205 206
            implicitWidth: width > Kirigami.Units.gridUnit * 15 ? width : Kirigami.Units.gridUnit * 15

Jonah Brüchert's avatar
Jonah Brüchert committed
207 208 209 210 211 212 213 214 215 216 217 218
            Component.onCompleted: {
                var date = new Date(kcm.currentDate)
                datePicker.day = date.getDate()
                datePicker.month = date.getMonth()+1
                datePicker.year = date.getFullYear()
            }
            Connections {
                target: kcm
                onCurrentDateChanged: {
                    if (datePicker.userConfiguring) {
                        return
                    }
Sebastian Kügler's avatar
Sebastian Kügler committed
219

220
                    var date = new Date(kcm.currentDate)
Jonah Brüchert's avatar
Jonah Brüchert committed
221

222 223 224 225 226
                    datePicker.day = date.getDate()
                    datePicker.month = date.getMonth()+1
                    datePicker.year = date.getFullYear()
                }
            }
Jonah Brüchert's avatar
Jonah Brüchert committed
227 228 229
            onUserConfiguringChanged: {
                kcm.currentDate = isoDate
                kcm.saveTime()
230
            }
231
        }
232 233 234 235 236 237
        footer: RowLayout {
            Controls.Button {
                Layout.alignment: Qt.AlignRight

                text: i18nc("@action:button", "Close")

Jonah Brüchert's avatar
Jonah Brüchert committed
238
                onClicked: datePickerSheet.close()
239 240
            }
        }
241
    }
242
}