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