~jonas-drange/ubuntu-system-settings/hotspots-binding

« back to all changes in this revision

Viewing changes to plugins/time-date/PageComponent.qml

sync with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import Ubuntu.SystemSettings.TimeDate 1.0
27
27
 
28
28
ItemPage {
 
29
    id: root
29
30
    title: i18n.tr("Time & Date")
30
31
    objectName: "timeDatePage"
 
32
    flickable: scrollWidget
31
33
 
32
34
    function getUTCOffset() {
33
35
        // We get the difference in minutes between UTC and our TZ (UTC - TZ)
47
49
        }
48
50
    }
49
51
 
50
 
    Column {
 
52
    Flickable {
 
53
        id: scrollWidget
51
54
        anchors.fill: parent
52
 
 
53
 
        SettingsItemTitle { text: i18n.tr ("Time zone:") }
54
 
 
55
 
        ListItem.SingleValue {
56
 
            objectName: "timeZone"
57
 
            id: timeZone
58
 
            //e.g. America/New_York -> America/New York
59
 
            text: timeDatePanel.timeZone.replace("_", " ")
60
 
            value: getUTCOffset()
61
 
            progression: true
62
 
            onClicked: pageStack.push(Qt.resolvedUrl("ChooseTimeZone.qml"))
63
 
        }
64
 
 
65
 
        SettingsItemTitle {
66
 
            text: i18n.tr ("Set the time and date:")
67
 
        }
68
 
 
69
 
        ListItem.ItemSelector {
70
 
            id: setTimeAutomatically
71
 
            objectName: "timeItemSelector"
72
 
            model: [ i18n.tr("Automatically") , i18n.tr("Manually")]
73
 
            expanded: true
74
 
            onSelectedIndexChanged: {
75
 
                var useNTP = (selectedIndex === 0) // 0 = Automatically
76
 
                timeDatePanel.useNTP = useNTP
77
 
            }
78
 
        }
79
 
 
80
 
        Binding {
81
 
            target: setTimeAutomatically
82
 
            property: "selectedIndex"
83
 
            value: timeDatePanel.useNTP ? 0 : 1
84
 
        }
85
 
 
86
 
        Timer {
87
 
            onTriggered: currentTime.text = Qt.formatDateTime(
88
 
                            new Date(),
89
 
                            Qt.DefaultLocaleLongDate)
90
 
            triggeredOnStart: true
91
 
            repeat: true
92
 
            running: true
93
 
        }
94
 
 
95
 
        Component {
96
 
            id: timePicker
97
 
            TimePicker {}
98
 
        }
99
 
 
100
 
        ListItem.Standard {
101
 
            id: currentTime
102
 
            objectName: "currentTime"
103
 
            progression: setTimeAutomatically.selectedIndex === 1 // Manually
104
 
            enabled: progression
105
 
            onClicked: {
106
 
                Qt.inputMethod.hide()
107
 
                var popupObj = PopupUtils.open(timePicker);
108
 
                popupObj.accepted.connect(
109
 
                            function(hour, minute, second,
110
 
                                     day, month, year) {
111
 
                                var newDate =  new Date(year,
112
 
                                                        month,
113
 
                                                        day,
114
 
                                                        hour,
115
 
                                                        minute,
116
 
                                                        second)
117
 
                                // Milliseconds to microseconds
118
 
                                timeDatePanel.setTime(newDate.getTime() * 1000)
119
 
                })
 
55
        contentHeight: contentItem.childrenRect.height
 
56
        boundsBehavior: (contentHeight > root.height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
 
57
        flickableDirection: Flickable.VerticalFlick
 
58
 
 
59
        Column {
 
60
            anchors.left: parent.left
 
61
            anchors.right: parent.right
 
62
 
 
63
            SettingsItemTitle { text: i18n.tr ("Time zone:") }
 
64
 
 
65
            ListItem.SingleValue {
 
66
                objectName: "timeZone"
 
67
                id: timeZone
 
68
                //e.g. America/New_York -> America/New York
 
69
                text: timeDatePanel.timeZone.replace("_", " ")
 
70
                value: getUTCOffset()
 
71
                progression: true
 
72
                onClicked: pageStack.push(Qt.resolvedUrl("ChooseTimeZone.qml"))
 
73
            }
 
74
 
 
75
            SettingsItemTitle {
 
76
                text: i18n.tr ("Set the time and date:")
 
77
            }
 
78
 
 
79
            ListItem.ItemSelector {
 
80
                id: setTimeAutomatically
 
81
                objectName: "timeItemSelector"
 
82
                model: [ i18n.tr("Automatically") , i18n.tr("Manually")]
 
83
                expanded: true
 
84
                onSelectedIndexChanged: {
 
85
                    var useNTP = (selectedIndex === 0) // 0 = Automatically
 
86
                    timeDatePanel.useNTP = useNTP
 
87
                }
 
88
            }
 
89
 
 
90
            Binding {
 
91
                target: setTimeAutomatically
 
92
                property: "selectedIndex"
 
93
                value: timeDatePanel.useNTP ? 0 : 1
 
94
            }
 
95
 
 
96
            Timer {
 
97
                onTriggered: currentTime.text = Qt.formatDateTime(
 
98
                                new Date(),
 
99
                                Qt.DefaultLocaleLongDate)
 
100
                triggeredOnStart: true
 
101
                repeat: true
 
102
                running: true
 
103
            }
 
104
 
 
105
            Component {
 
106
                id: timePicker
 
107
                TimePicker {}
 
108
            }
 
109
 
 
110
            ListItem.Standard {
 
111
                id: currentTime
 
112
                objectName: "currentTime"
 
113
                progression: setTimeAutomatically.selectedIndex === 1 // Manually
 
114
                enabled: progression
 
115
                onClicked: {
 
116
                    Qt.inputMethod.hide()
 
117
                    var popupObj = PopupUtils.open(timePicker);
 
118
                    popupObj.accepted.connect(
 
119
                                function(hour, minute, second,
 
120
                                         day, month, year) {
 
121
                                    var newDate =  new Date(year,
 
122
                                                            month,
 
123
                                                            day,
 
124
                                                            hour,
 
125
                                                            minute,
 
126
                                                            second)
 
127
                                    // Milliseconds to microseconds
 
128
                                    timeDatePanel.setTime(newDate.getTime() * 1000)
 
129
                    })
 
130
                }
120
131
            }
121
132
        }
122
133
    }