Harmattan Ready, Fremantle Testing Pending
[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/topfinstories"
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: newsSectionLabel
84             anchors.top: parent.top
85             anchors.left: parent.left
86             anchors.leftMargin: 35
87             height: 50
88             horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
89             font.pixelSize: 22; font.bold: true; elide: Text.ElideRight; color: "#B8B8B8"; style: Text.Raised; styleColor: "black"
90             text: "News Feed"
91         }
92
93         Rectangle {
94             id: newsSection
95             border.width: 1
96             border.color: "#BFBFBF"
97             color:"#2E2E2E"
98             anchors.top: newsSectionLabel.bottom
99             anchors.topMargin: 10
100             anchors.left: parent.left
101             anchors.leftMargin: 30
102             anchors.right: parent.right
103             anchors.rightMargin: 30
104             height: 60
105             radius: 15
106
107             Row {
108                 id: rowRSSURL
109                 //anchors.top: parent.top
110                 //anchors.topMargin: 5
111                 anchors.verticalCenter: parent.verticalCenter
112                 anchors.left: parent.left
113                 anchors.leftMargin: 5
114                 anchors.right: parent.right
115                 height: 50
116                 spacing: 5
117
118                 Text{
119                     height:parent.height
120                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
121                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
122                     text: "RSS URL: "
123                     color: "#ffffff";
124                 }
125
126                 Item {
127                     height: 40
128                     //updateConfig.width > updateConfig.height?
129                     width:  parent.width*3/4
130                     BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
131                     TextInput{
132                         id: txtRSSURL
133                         height: parent.height
134                         anchors.left: parent.left
135                         anchors.leftMargin: 10
136                         anchors.right: parent.right
137                         anchors.verticalCenter: parent.verticalCenter
138                         focus: true
139                         text: configParametersComponent.rssURL
140                         horizontalAlignment: Text.AlignLeft
141                         font.pixelSize: 18
142                         inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhPreferLowercase
143                         onTextChanged: {
144                             configParametersComponent.rssURL = txtRSSURL.text;
145                         }
146                     }
147                 }
148             }
149         }
150
151         Text {
152             id: autoUpdateSectionLabel
153             anchors.top: newsSection.bottom
154             //anchors.topMargin: 10
155             anchors.left: parent.left
156             anchors.leftMargin: 35
157             height: 50
158             horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
159             font.pixelSize: 22; font.bold: true; elide: Text.ElideRight; color: "#B8B8B8"; style: Text.Raised; styleColor: "black"
160             text: "Auto-Update"
161         }
162
163         Rectangle {
164             id: autoUpdateSection
165             border.width: 1
166             border.color: "#BFBFBF"
167             color:"#2E2E2E"
168             anchors.top: autoUpdateSectionLabel.bottom
169             anchors.topMargin: 10
170             anchors.left: parent.left
171             anchors.leftMargin: 30
172             anchors.right: parent.right
173             anchors.rightMargin: 30
174             height: 120
175             radius: 15
176
177             Row {
178                 id: rowUpdateFreq
179                 anchors.top: parent.top
180                 anchors.topMargin: 5
181                 anchors.left: parent.left
182                 anchors.leftMargin: 5
183                 anchors.right: parent.right
184                 height: 50
185                 spacing: 5
186
187                 Image {
188                     id: checkboxUpdateFreqImg
189                     source: configParametersComponent.updateFreqEnabled? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
190                     width: 32; height: 32
191                     MouseArea {
192                         anchors.fill: parent;
193                         onClicked: {
194                             configParametersComponent.updateFreqEnabled = !configParametersComponent.updateFreqEnabled;
195                             if (!configParametersComponent.updateFreqEnabled){
196                                 txtUpdateFreqMin.text = "";
197                                 configParametersComponent.updateWeekdaysOnly = false;
198                             }
199                         }
200                     }
201                 }
202
203                 Text{
204                     height:parent.height
205                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
206                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
207                     text: "Every "
208                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
209                 }
210                 Item {
211                     height: 40
212                     width: 80
213                     BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
214                     TextInput{                        
215                         id: txtUpdateFreqMin
216                         anchors.fill: parent
217                         focus: true
218                         text: configParametersComponent.updateFreqMin
219                         horizontalAlignment: Text.AlignHCenter
220                         font.pixelSize: 18
221                         inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
222                         onTextChanged: {
223                             configParametersComponent.updateFreqMin = txtUpdateFreqMin.text;
224                         }
225                     }
226                 }
227                 Text{
228                     height:parent.height
229                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
230                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
231                     text: " minutes"
232                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
233                 }
234             }
235             Row {
236                 id: rowUpdateDays
237                 anchors.top: rowUpdateFreq.bottom
238                 anchors.topMargin: 5
239                 anchors.left: parent.left
240                 anchors.leftMargin: 5
241                 anchors.right: parent.right
242                 height: 50
243                 spacing: 5
244
245                 Image {
246                     id: checkboxUpdateWeekdays
247                     source: configParametersComponent.updateWeekdaysOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
248                     width: 32; height: 32
249                     MouseArea {
250                         anchors.fill: parent;
251                         onClicked: {
252                             configParametersComponent.updateWeekdaysOnly = !configParametersComponent.updateWeekdaysOnly;
253                         }
254                     }
255                 }
256
257                 Text{
258                     height:parent.height
259                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
260                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
261                     text: "Only on weekdays"
262                     color: configParametersComponent.updateWeekdaysOnly? "#ffffff" :"#B8B8B8";
263                 }
264             }
265 /*
266             Row {
267                 id: rowUpdateConnections
268                 anchors.top: rowUpdateDays.bottom
269                 anchors.topMargin: 5
270                 anchors.left: parent.left
271                 anchors.leftMargin: 5
272                 anchors.right: parent.right
273                 height: 50
274                 spacing: 5
275
276                 Image {
277                     id: checkboxUpdateKnownConnections
278                     source: configParametersComponent.updateOnSavedNetworksOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
279                     width: 32; height: 32
280                     MouseArea {
281                         anchors.fill: parent;
282                         onClicked: {
283                             configParametersComponent.updateOnSavedNetworksOnly = !configParametersComponent.updateOnSavedNetworksOnly;
284                         }
285                     }
286                 }
287
288                 Text{
289                     height:parent.height
290                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
291                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
292                     text: "Only on saved Wifi connections"
293                     color: configParametersComponent.updateOnSavedNetworksOnly? "#ffffff" :"#B8B8B8";
294                 }
295             }
296 */
297         }
298     //Here
299     }
300 }