Version 0.2
[marketstoday] / src / qml / ConfigParametersComponent.qml
1 /*
2 @version: 0.1
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     signal logRequest(string strMessage)
17
18     Rectangle {
19         id: updateConfig
20         anchors.fill: parent
21         color:"#343434"
22
23         Component.onCompleted: {
24                 DBUtility.initialize();
25                 loadSettings();
26         }
27
28         Component.onDestruction:{
29             logRequest("Saving settings");
30             saveSettings();
31         }
32
33         function loadSettings(){
34             var value;
35             value  = DBUtility.getSetting("UpdateFreqency");
36             if (!value || value == "0.0" || value == ""){
37                 configParametersComponent.updateFreqEnabled = false;
38             }
39             else{
40                 configParametersComponent.updateFreqEnabled = true;
41                 configParametersComponent.updateFreqMin = parseInt(value);
42             }
43             value  = DBUtility.getSetting("UpdateWeekdaysOnly");
44             if (!value || value == "0.0" || value == ""){
45                 configParametersComponent.updateWeekdaysOnly = false;
46             }
47             else{
48                 configParametersComponent.updateWeekdaysOnly = true;
49             }
50
51             value  = DBUtility.getSetting("UpdateOnSavedNetworksOnly");
52             if (!value || value == "0.0" || value == ""){
53                 configParametersComponent.updateOnSavedNetworksOnly = false;
54             }
55             else{
56                 configParametersComponent.updateOnSavedNetworksOnly = true;
57             }
58         }
59
60         function saveSettings(){
61             DBUtility.setSetting("UpdateFreqency",configParametersComponent.updateFreqMin);
62             DBUtility.setSetting("UpdateWeekdaysOnly",(configParametersComponent.updateWeekdaysOnly?1:0));
63             DBUtility.setSetting("UpdateOnSavedNetworksOnly",(configParametersComponent.updateOnSavedNetworksOnly?1:0));
64         }
65
66         Text {
67             id: autoUpdateSectionLabel
68             anchors.top: parent.top
69             //anchors.topMargin: 10
70             anchors.left: parent.left
71             anchors.leftMargin: 45
72             height: 50
73             horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
74             font.pixelSize: 22; font.bold: true; elide: Text.ElideRight; color: "#B8B8B8"; style: Text.Raised; styleColor: "black"
75             text: "Auto-Update"
76         }
77
78         Rectangle {
79             id: autoUpdateSection
80             border.width: 1
81             border.color: "#BFBFBF"
82             color:"#2E2E2E"
83             anchors.top: autoUpdateSectionLabel.bottom
84             anchors.topMargin: 10
85             anchors.left: parent.left
86             anchors.leftMargin: 40
87             anchors.right: parent.right
88             anchors.rightMargin: 40
89             height: 160
90             radius: 15
91
92             Row {
93                 id: rowUpdateFreq
94                 anchors.top: parent.top
95                 anchors.topMargin: 5
96                 anchors.left: parent.left
97                 anchors.leftMargin: 5
98                 anchors.right: parent.right
99                 height: 50
100                 spacing: 5
101
102                 Image {
103                     id: checkboxUpdateFreqImg
104                     source: configParametersComponent.updateFreqEnabled? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
105                     width: 32; height: 32
106                     MouseArea {
107                         anchors.fill: parent;
108                         onClicked: {
109                             configParametersComponent.updateFreqEnabled = !configParametersComponent.updateFreqEnabled;
110                             if (!configParametersComponent.updateFreqEnabled){
111                                 txtUpdateFreqMin.text = "";
112                                 configParametersComponent.updateWeekdaysOnly = false;
113                             }
114                         }
115                     }
116                 }
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: "Every "
123                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
124                 }
125                 Item {
126                     height: 40
127                     width: 80
128                     BorderImage { source: "Library/images/lineedit.sci"; anchors.fill: parent }
129                     TextInput{                        
130                         id: txtUpdateFreqMin
131                         anchors.fill: parent
132                         focus: true
133                         text: configParametersComponent.updateFreqMin
134                         horizontalAlignment: Text.AlignHCenter
135                         inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
136                         onTextChanged: {
137                             configParametersComponent.updateFreqMin = txtUpdateFreqMin.text;
138                         }
139                     }
140                 }
141                 Text{
142                     height:parent.height
143                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
144                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
145                     text: " minutes"
146                     color: configParametersComponent.updateFreqEnabled? "#ffffff" :"#B8B8B8";
147                 }
148             }
149             Row {
150                 id: rowUpdateDays
151                 anchors.top: rowUpdateFreq.bottom
152                 anchors.topMargin: 5
153                 anchors.left: parent.left
154                 anchors.leftMargin: 5
155                 anchors.right: parent.right
156                 height: 50
157                 spacing: 5
158
159                 Image {
160                     id: checkboxUpdateWeekdays
161                     source: configParametersComponent.updateWeekdaysOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
162                     width: 32; height: 32
163                     MouseArea {
164                         anchors.fill: parent;
165                         onClicked: {
166                             configParametersComponent.updateWeekdaysOnly = !configParametersComponent.updateWeekdaysOnly;
167                         }
168                     }
169                 }
170
171                 Text{
172                     height:parent.height
173                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
174                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
175                     text: "Only on weekdays"
176                     color: configParametersComponent.updateWeekdaysOnly? "#ffffff" :"#B8B8B8";
177                 }
178             }            
179             Row {
180                 id: rowUpdateConnections
181                 anchors.top: rowUpdateDays.bottom
182                 anchors.topMargin: 5
183                 anchors.left: parent.left
184                 anchors.leftMargin: 5
185                 anchors.right: parent.right
186                 height: 50
187                 spacing: 5
188
189                 Image {
190                     id: checkboxUpdateKnownConnections
191                     source: configParametersComponent.updateOnSavedNetworksOnly? "Library/images/checkbox_checked.png":"Library/images/checkbox_unchecked.png"
192                     width: 32; height: 32
193                     MouseArea {
194                         anchors.fill: parent;
195                         onClicked: {
196                             configParametersComponent.updateOnSavedNetworksOnly = !configParametersComponent.updateOnSavedNetworksOnly;
197                         }
198                     }
199                 }
200
201                 Text{
202                     height:parent.height
203                     horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
204                     font.pixelSize: 20; font.bold: false; elide: Text.ElideRight; style: Text.Raised; styleColor: "black"
205                     text: "Only on saved Wifi connections"
206                     color: configParametersComponent.updateOnSavedNetworksOnly? "#ffffff" :"#B8B8B8";
207                 }
208             }
209         }
210     }
211 }