2c9625234f4d911b1e79b69692ae0bf0bf6c6307
[marketstoday] / src / qml / ConfigParametersComponent.qml
1 /*
2 @version: 0.2
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 import Qt 4.7
8 import "Library/js/DBUtility.js" as DBUtility
9
10 Item {
11     id: configParametersComponent
12     property bool updateFreqEnabled
13     property string  updateFreqMin
14     property bool updateWeekdaysOnly
15     //property bool updateOnSavedNetworksOnly
16     property string  rssURL: "http://finance.yahoo.com/rss/topstories"
17     signal logRequest(string strMessage)
18
19     Rectangle {
20         id: updateConfig
21         anchors.fill: parent
22         color:"#343434"
23
24         Component.onCompleted: {
25                 DBUtility.initialize();
26                 loadSettings();
27         }
28
29         Component.onDestruction:{
30             logRequest("Saving settings");
31             saveSettings();
32         }
33
34         function loadSettings(){
35             var value;
36             value  = DBUtility.getSetting("UpdateFreqency");
37             if (!value || value == "0.0" || value === "" || isNaN(value)){
38                 configParametersComponent.updateFreqEnabled = false;
39             }
40             else{
41                 configParametersComponent.updateFreqEnabled = true;
42                 configParametersComponent.updateFreqMin = parseInt(value);
43             }
44             value  = DBUtility.getSetting("UpdateWeekdaysOnly");
45             if (!value || value == "0.0" || value === ""){
46                 configParametersComponent.updateWeekdaysOnly = false;
47             }
48             else{
49                 configParametersComponent.updateWeekdaysOnly = true;
50             }
51
52 /*
53             value  = DBUtility.getSetting("UpdateOnSavedNetworksOnly");
54             if (!value || value == "0.0" || value === ""){
55                 configParametersComponent.updateOnSavedNetworksOnly = false;
56             }
57             else{
58                 configParametersComponent.updateOnSavedNetworksOnly = true;
59             }
60 */
61
62             value  = DBUtility.getSetting("RSSURL");
63             if (!value || value == "Unknown" || value === ""){
64                 //configParametersComponent.rssURL = configParametersComponent.defaultRSSFeed;
65             }
66             else{
67                 configParametersComponent.rssURL = value;
68             }
69         }
70
71         function saveSettings(){
72             if (isNaN(configParametersComponent.updateFreqMin))
73                 DBUtility.setSetting("UpdateFreqency","");
74             else
75                 DBUtility.setSetting("UpdateFreqency",configParametersComponent.updateFreqMin);
76
77             DBUtility.setSetting("UpdateWeekdaysOnly",(configParametersComponent.updateWeekdaysOnly?1:0));
78             //DBUtility.setSetting("UpdateOnSavedNetworksOnly",(configParametersComponent.updateOnSavedNetworksOnly?1:0));
79             DBUtility.setSetting("RSSURL",configParametersComponent.rssURL);
80         }
81
82         Text {
83             id: autoUpdateSectionLabel
84             anchors.top: parent.top
85             //anchors.topMargin: 10
86             anchors.left: parent.left
87             anchors.leftMargin: 45
88             height: 50
89             horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
90             font.pixelSize: 22; font.bold: true; elide: Text.ElideRight; color: "#B8B8B8"; style: Text.Raised; styleColor: "black"
91             text: "Auto-Update"
92         }
93
94         Rectangle {
95             id: autoUpdateSection
96             border.width: 1
97             border.color: "#BFBFBF"
98             color:"#2E2E2E"
99             anchors.top: autoUpdateSectionLabel.bottom
100             anchors.topMargin: 10
101             anchors.left: parent.left
102             anchors.leftMargin: 40
103             anchors.right: parent.right
104             anchors.rightMargin: 40
105             height: 120
106             radius: 15
107
108             Row {
109                 id: rowUpdateFreq
110                 anchors.top: parent.top
111                 anchors.topMargin: 5
112                 anchors.left: parent.left
113                 anchors.leftMargin: 5
114                 anchors.right: parent.right
115                 height: 50
116                 spacing: 5
117
118                 Image {
119                     id: checkboxUpdateFreqImg
120                     source: configParametersComponent.updateFreqEnabled? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
121                     width: 32; height: 32
122                     MouseArea {
123                         anchors.fill: parent;
124                         onClicked: {
125                             configParametersComponent.updateFreqEnabled = !configParametersComponent.updateFreqEnabled;
126                             if (!configParametersComponent.updateFreqEnabled){
127                                 txtUpdateFreqMin.text = "";
128                                 configParametersComponent.updateWeekdaysOnly = false;
129                             }
130                         }
131                     }
132                 }
133
134                 Text{
135                     height:parent.height
136                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
137                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
138                     text: "Every "
139                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
140                 }
141                 Item {
142                     height: 40
143                     width: 80
144                     BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
145                     TextInput{                        
146                         id: txtUpdateFreqMin
147                         anchors.fill: parent
148                         focus: true
149                         text: configParametersComponent.updateFreqMin
150                         horizontalAlignment: Text.AlignHCenter
151                         font.pixelSize: 18
152                         inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
153                         onTextChanged: {
154                             configParametersComponent.updateFreqMin = txtUpdateFreqMin.text;
155                         }
156                     }
157                 }
158                 Text{
159                     height:parent.height
160                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
161                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
162                     text: " minutes"
163                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
164                 }
165             }
166             Row {
167                 id: rowUpdateDays
168                 anchors.top: rowUpdateFreq.bottom
169                 anchors.topMargin: 5
170                 anchors.left: parent.left
171                 anchors.leftMargin: 5
172                 anchors.right: parent.right
173                 height: 50
174                 spacing: 5
175
176                 Image {
177                     id: checkboxUpdateWeekdays
178                     source: configParametersComponent.updateWeekdaysOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
179                     width: 32; height: 32
180                     MouseArea {
181                         anchors.fill: parent;
182                         onClicked: {
183                             configParametersComponent.updateWeekdaysOnly = !configParametersComponent.updateWeekdaysOnly;
184                         }
185                     }
186                 }
187
188                 Text{
189                     height:parent.height
190                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
191                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
192                     text: "Only on weekdays"
193                     color: configParametersComponent.updateWeekdaysOnly? "#ffffff" :"#B8B8B8";
194                 }
195             }
196 /*
197             Row {
198                 id: rowUpdateConnections
199                 anchors.top: rowUpdateDays.bottom
200                 anchors.topMargin: 5
201                 anchors.left: parent.left
202                 anchors.leftMargin: 5
203                 anchors.right: parent.right
204                 height: 50
205                 spacing: 5
206
207                 Image {
208                     id: checkboxUpdateKnownConnections
209                     source: configParametersComponent.updateOnSavedNetworksOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
210                     width: 32; height: 32
211                     MouseArea {
212                         anchors.fill: parent;
213                         onClicked: {
214                             configParametersComponent.updateOnSavedNetworksOnly = !configParametersComponent.updateOnSavedNetworksOnly;
215                         }
216                     }
217                 }
218
219                 Text{
220                     height:parent.height
221                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
222                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
223                     text: "Only on saved Wifi connections"
224                     color: configParametersComponent.updateOnSavedNetworksOnly? "#ffffff" :"#B8B8B8";
225                 }
226             }
227 */
228         }
229
230         Text {
231             id: newsSectionLabel
232             anchors.top: autoUpdateSection.bottom
233             //anchors.topMargin: 10
234             anchors.left: parent.left
235             anchors.leftMargin: 45
236             height: 50
237             horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
238             font.pixelSize: 22; font.bold: true; elide: Text.ElideRight; color: "#B8B8B8"; style: Text.Raised; styleColor: "black"
239             text: "RSS - News Feed"
240         }
241
242         Rectangle {
243             id: newsSection
244             border.width: 1
245             border.color: "#BFBFBF"
246             color:"#2E2E2E"
247             anchors.top: newsSectionLabel.bottom
248             anchors.topMargin: 10
249             anchors.left: parent.left
250             anchors.leftMargin: 40
251             anchors.right: parent.right
252             anchors.rightMargin: 40
253             height: 60
254             radius: 15
255
256             Row {
257                 id: rowRSSURL
258                 anchors.top: parent.top
259                 anchors.topMargin: 5
260                 anchors.left: parent.left
261                 anchors.leftMargin: 5
262                 anchors.right: parent.right
263                 height: 50
264                 spacing: 5
265
266                 Text{
267                     height:parent.height
268                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
269                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
270                     text: "RSS URL: "
271                     color: "#ffffff";
272                 }
273
274                 Item {
275                     height: 40
276                     width: parent.width*4/5
277                     BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
278                     TextInput{
279                         id: txtRSSURL
280                         height: parent.height
281                         anchors.left: parent.left
282                         anchors.leftMargin: 10
283                         anchors.right: parent.right
284                         focus: true
285                         text: configParametersComponent.rssURL                        
286                         horizontalAlignment: Text.AlignLeft
287                         font.pixelSize: 18
288                         inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase
289                         onTextChanged: {
290                             configParametersComponent.rssURL = txtRSSURL.text;
291                         }
292                     }
293                 }
294             }
295         }
296     }
297 }