configTimeZones.qml 8.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Copyright 2013 Kai Uwe Broulik <kde@privat.broulik.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

21
import QtQuick 2.12
22
import QtQuick.Controls 2.8 as QQC2
23
24
25
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.1

26
import org.kde.kquickcontrolsaddons 2.0 // For kcmshell
27
28
import org.kde.plasma.private.digitalclock 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
29
import org.kde.kirigami 2.14 as Kirigami
30

31
ColumnLayout {
32
33
34
    id: timeZonesPage

    property alias cfg_selectedTimeZones: timeZones.selectedTimeZones
35
36
    property alias cfg_wheelChangesTimezone: enableWheelCheckBox.checked

37
38
39

    TimeZoneModel {

40
        id: timeZones
41
        onSelectedTimeZonesChanged: {
Laurent Montel's avatar
Laurent Montel committed
42
            if (selectedTimeZones.length === 0) {
43
                // Don't let the user remove all time zones
44
45
46
47
48
49
                messageWidget.visible = true;
                timeZones.selectLocalTimeZone();
            }
        }
    }

50
    QQC2.ScrollView {
51
        Layout.fillWidth: true
52
        Layout.preferredHeight: Kirigami.Units.gridUnit * 16
53
54
55
56
57
58
59
60
61
62
63
64
        Component.onCompleted: background.visible = true // enable border

        ListView {
            id: configuredTimezoneList
            clip: true // Avoid visual glitches
            focus: true // keyboard navigation
            activeFocusOnTab: true // keyboard navigation

            model: TimeZoneFilterProxy {
                sourceModel: timeZones
                onlyShowChecked: true
            }
65
66
67
            // We have no concept of selection in this list, so don't pre-select
            // the first item
            currentIndex: -1
68

69
            delegate: Kirigami.BasicListItem {
70
71
                id: timeZoneListItem
                property bool isCurrent: plasmoid.configuration.lastSelectedTimezone === model.timeZoneId
72

73
74
                bold: isCurrent

75
76
                // Don't want a highlight effect here because it doesn't look good
                hoverEnabled: false
77
                activeBackgroundColor: "transparent"
78
79
                activeTextColor: Kirigami.Theme.textColor

80
                reserveSpaceForSubtitle: true
81
82
83
84
85
86
87
88
                // FIXME: this should have already evaluated to false because
                // the list item doesn't have an icon
                reserveSpaceForIcon: false

                // TODO: create Kirigami.MutuallyExclusiveListItem to be the
                // RadioButton equivalent of Kirigami.CheckableListItem,
                // and then port to use that in Plasma 5.22
                leading: QQC2.RadioButton {
89
                    id: radioButton
90
                    visible: configuredTimezoneList.count > 1
91
                    checked: timeZoneListItem.isCurrent
92
93
94
95
                    onToggled: clickAction.trigger()
                }

                label: model.city
96
                subtitle: isCurrent && configuredTimezoneList.count > 1 ? i18n("Clock is currently using this time zone") : ""
97
98
99
100
101
102
103

                action: Kirigami.Action {
                    id: clickAction
                    onTriggered: plasmoid.configuration.lastSelectedTimezone = model.timeZoneId
                }

                trailing: RowLayout {
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
                    QQC2.Button {
                        visible: model.isLocalTimeZone && KCMShell.authorize("clock.desktop").length > 0
                        text: i18n("Switch Local Time Zone...")
                        icon.name: "preferences-system-time"
                        onClicked: KCMShell.openSystemSettings("clock")
                    }
                    QQC2.Button {
                        visible: !model.isLocalTimeZone && configuredTimezoneList.count > 1
                        icon.name: "edit-delete"
                        onClicked: model.checked = false;
                        QQC2.ToolTip {
                            text: i18n("Remove this time zone")
                        }
                    }
                }
            }

            section {
                property: "isLocalTimeZone"
                delegate: Kirigami.ListSectionHeader {
                    label: section == "true" ? i18n("System's Local Time Zone") : i18n("Additional Time Zones")
                }
            }

            Kirigami.PlaceholderMessage {
                visible: configuredTimezoneList.count === 1
130
                anchors.centerIn: parent
131
132
133
134
                width: parent.width - (Kirigami.Units.largeSpacing * 12)
                text: i18n("Add more time zones to display all of them in the applet's pop-up, or use one of them for the clock itself")
            }
        }
135
    }
136

137
138
139
140
141
142
143
    QQC2.Button {
        Layout.alignment: Qt.AlignLeft // Explicitly set so it gets reversed for LTR mode
        text: i18n("Add Time Zones...")
        icon.name: "list-add"
        onClicked: timezoneSheet.open()
    }

144
145
    QQC2.CheckBox {
        id: enableWheelCheckBox
146
        visible: configuredTimezoneList.count > 1
147
148
149
150
151
        Layout.fillWidth: true
        Layout.topMargin: Kirigami.Units.largeSpacing * 2
        text: i18n("Switch displayed time zone by scrolling over clock applet")
    }

152
153
    QQC2.Label {
        visible: configuredTimezoneList.count > 1
154
        Layout.fillWidth: true
155
156
157
        Layout.topMargin: Kirigami.Units.largeSpacing * 2
        Layout.leftMargin: Kirigami.Units.largeSpacing * 2
        Layout.rightMargin: Kirigami.Units.largeSpacing * 2
158
159
        text: i18n("Note that using a different time zone for the clock does not change the systemwide local time zone. When you travel, switch the local time zone instead.")
        wrapMode: Text.Wrap
160
    }
161

Yunhe Guo's avatar
Yunhe Guo committed
162
    Item {
163
        // Tighten up the layout
164
        Layout.fillHeight: true
165
    }
166

167
168
    Kirigami.OverlaySheet {
        id: timezoneSheet
169

170
171
172
        onSheetOpenChanged: {
            filter.text = "";
            messageWidget.visible = false;
173
174
175
            if (sheetOpen) {
                filter.forceActiveFocus()
            }
176
        }
177

178
179
        // Need to manually set the parent when using this in a Plasma config dialog
        parent: timeZonesPage.parent
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
        // It interferes with the search field in the header
        showCloseButton: false

        header: ColumnLayout {
            Layout.preferredWidth: Kirigami.Units.gridUnit * 25

            Kirigami.Heading {
                Layout.fillWidth: true
                text: i18n("Add More Timezones")
                wrapMode: Text.Wrap
            }
            Kirigami.SearchField {
                id: filter
                Layout.fillWidth: true
            }
            Kirigami.InlineMessage {
                id: messageWidget
                Layout.fillWidth: true
                type: Kirigami.MessageType.Warning
                text: i18n("At least one time zone needs to be enabled. Your local timezone was enabled automatically.")
                showCloseButton: true
Yunhe Guo's avatar
Yunhe Guo committed
202
            }
203
        }
204

205
206
207
        footer: QQC2.DialogButtonBox {
            standardButtons: QQC2.DialogButtonBox.Ok
            onAccepted: timezoneSheet.close()
208
        }
Yunhe Guo's avatar
Yunhe Guo committed
209

210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
        ListView {
            id: listView
            focus: true // keyboard navigation
            activeFocusOnTab: true // keyboard navigation
            implicitWidth: Kirigami.Units.gridUnit * 25

            model: TimeZoneFilterProxy {
                sourceModel: timeZones
                filterString: filter.text
            }

            delegate: QQC2.CheckDelegate {
                id: checkbox
                width: listView.width
                focus: true // keyboard navigation
                text: !city || city.indexOf("UTC") === 0 ? comment : comment ? i18n("%1, %2 (%3)", city, region, comment) : i18n("%1, %2", city, region)
                checked: model.checked
                onToggled: {
                    model.checked = checkbox.checked
                    listView.currentIndex = index // highlight
                    listView.forceActiveFocus() // keyboard navigation
                }
                highlighted: ListView.isCurrentItem
            }
        }
    }
236
}