Departure object changes, tests, small fix
[pywienerlinien] / qml / Settings.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "UIConstants.js" as UIConstants
4 import "ExtrasConstants.js" as ExtrasConstants
5
6 Page {
7     tools: settingsTools
8
9     ToolBarLayout {
10         id: settingsTools
11         x: 0
12         y: 0
13         ToolIcon { iconId: "toolbar-back"; onClicked: { menu.close(); pageStack.pop(null,false); } }
14     }
15
16     Flickable {
17         id: settingsContent
18         anchors.fill: parent
19         anchors.margins: UIConstants.DEFAULT_MARGIN
20
21         contentHeight: content_column.height + 2 * UIConstants.DEFAULT_MARGIN
22         flickableDirection: Flickable.VerticalFlick
23
24         Component.onCompleted: {
25             var updateAvailable = config.checkStationsUpdate();
26             if (updateAvailable) {
27                 btnUpdate.color = "green"
28             }
29         }
30
31         Column {
32             id: content_column
33             spacing: UIConstants.DEFAULT_MARGIN
34             width: parent.width
35
36             Text {
37                 text: qsTr("Settings")
38                 font.pixelSize: UIConstants.FONT_XLARGE
39                 color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
40                 anchors.left: parent.left
41             }
42
43             Row {
44                 anchors.left: parent.left
45                 anchors.right: parent.right
46                 Text {
47                     text: "Enable GPS"
48                     anchors.left: parent.left
49                     font.pixelSize: UIConstants.FONT_LARGE
50                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
51                     anchors.verticalCenter: parent.verticalCenter
52                 }
53                 CheckBox {
54                     id: gpsEnable
55                     anchors.right: parent.right
56                     checked: config.getGpsEnabled()
57
58                     onCheckedChanged: {
59                         var gps = config.setGpsEnabled(checked);
60                         if (gps !== '') {
61                             // Unable to set config
62                             console.log(gps);
63                             checked=!checked;
64                         } else {
65                             positionSource.active = checked;
66                         }
67                         if (checked) {
68                             positionSource.start();
69                         } else {
70                             positionSource.stop();
71                         }
72                     }
73                 }
74             }
75
76             UpdateDialog {
77                 id:updateDialog
78             }
79
80             Row {
81                 anchors.left: parent.left
82                 anchors.right: parent.right
83                 Text {
84                     text: "Update stations"
85                     anchors.left: parent.left
86                     font.pixelSize: UIConstants.FONT_LARGE
87                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
88                     anchors.verticalCenter: parent.verticalCenter
89                 }
90
91                 Button {
92                     id: btnUpdate
93                     anchors.right: parent.right
94                     text: "Update"
95                     width: 100
96
97                     Component.onCompleted: {
98                         if (config.checkStationsUpdate()) {
99                             btnUpdate.color = "green"
100                         }
101                     }
102
103                     onClicked: {
104                         var updateAvailable = config.checkStationsUpdate();
105                         if (updateAvailable) {
106                             var updated = config.updateStations();
107                             if (updated !== '') {
108                                 updateDialog.text = "Stations updated\nPlease restart app"
109                                 txtLastUpdate.text = updated
110                             } else {
111                                 updateDialog.text = "[UpdateError]:\nTry again later or send me an email:\n<gotovienna@logic.at>"
112                             }
113                         } else {
114                             updateDialog.text = "No updates available";
115                         }
116                         updateDialog.open();
117                     }
118                 }
119             }
120
121             Row {
122                 anchors.left: parent.left
123                 anchors.right: parent.right
124                 Text {
125                     anchors.left: parent.left
126                     text: "Last updated:"
127                     font.pixelSize: UIConstants.FONT_LSMALL
128                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
129                     anchors.verticalCenter: parent.verticalCenter
130                 }
131                 Text {
132                     id: txtLastUpdate
133                     anchors.right: parent.right
134                     text: config.getLastUpdate()
135                     font.pixelSize: UIConstants.FONT_LSMALL
136                     color: !theme.inverted ? UIConstants.COLOR_FOREGROUND : UIConstants.COLOR_INVERTED_FOREGROUND
137                     anchors.verticalCenter: parent.verticalCenter
138                 }
139             }
140         }
141     }
142 }