3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
9 import "Library" as Library
10 import "Library/js/ISODate.js" as DateLib
11 import "Library/js/DBUtility.js" as DBUtility
12 import "Library/js/Common.js" as Common
15 id: screen; width: 400; height: 325
17 signal showConfigInNewWindow
18 signal quoteRefreshStarted
19 signal quoteRefreshCompleted
21 property int autoUpdateInterval: 300000
22 property bool updateWeekDaysOnly: false
26 var symbolsArray = DBUtility.getAllSymbols();
27 if (symbolsArray && symbolsArray.length > 0){
29 for (i = 0; i< symbolsArray.length; i++) {
30 logUtility.logMessage("Appending "+symbolsArray[i]+ " to Query");
33 query = '"'+symbolsArray[i]+'"';
36 query = query + ',"' + symbolsArray[i]+'"';
45 function reloadQuotes(){
46 var query = getQuery();
48 screen.quoteRefreshStarted();
49 logUtility.logMessage("Reloading Data..");
51 //var queryURL = 'http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol in ("INDU","^IXIC","^GSPC","CLJ11.NYM","YHOO","AAPL","GOOG","MSFT")&env=store://datatables.org/alltableswithkeys';
52 var queryURL = 'http://query.yahooapis.com/v1/public/yql?q=select Symbol,Name,LastTradePriceOnly,Change,ChangeinPercent from yahoo.finance.quotes where symbol in ('+query+')&env=store://datatables.org/alltableswithkeys';
53 logUtility.logMessage(queryURL);
55 var response = new XMLHttpRequest();
56 response.onreadystatechange = function() {
57 if (response.readyState == XMLHttpRequest.DONE) {
58 stockQuoteDataModel.xml = response.responseText;
59 lastUpdatedDateModel.xml = response.responseText;
60 logUtility.logMessage("Data Reload Completed..");
61 screen.quoteRefreshCompleted();
65 response.open("GET", queryURL);
69 logUtility.logMessage("No stock symbols found in configuration.");
73 function loadSettings(){
75 value = DBUtility.getSetting("UpdateFreqency");
76 if (!value || value == "0.0" || value == ""){
77 autoUpdateInterval = 0;
80 autoUpdateInterval = parseInt(value)*60*1000; //Convert minutes to milliseconds
82 value = DBUtility.getSetting("UpdateWeekdaysOnly");
83 if (!value || value == "0.0" || value == ""){
84 updateWeekDaysOnly = false;
87 updateWeekDaysOnly = true;
91 function initialize(){
92 if (autoUpdateTimer.running) autoUpdateTimer.stop();
95 if (autoUpdateInterval != 0) {
96 logUtility.logMessage("Starting Timer..");
97 autoUpdateTimer.start();
101 Component.onCompleted: {
107 interval: autoUpdateInterval
108 //running: (autoUpdateInterval == 0? false:true)
111 if (!updateWeekDaysOnly){
112 logUtility.logMessage("Update triggered: Allowed to update all days of the week");
115 else if (Common.isTodayAWeekDay()){
116 logUtility.logMessage("Update triggered: Today is a weekday");
120 logUtility.logMessage("Update not triggered: Today is not a weekday");
126 id: stockQuoteDataModel
127 query: "/query/results/quote"
129 XmlRole { name: "symbol"; query: "Symbol/string()" }
130 XmlRole { name: "stockName"; query: "Name/string()" }
131 XmlRole { name: "lastTradedPrice"; query: "LastTradePriceOnly/string()" }
132 XmlRole { name: "change"; query: "Change/string()" }
133 XmlRole { name: "changePercentage"; query: "ChangeinPercent/string()" }
136 if (status == XmlListModel.Ready){
137 logUtility.logMessage("No. of tickers: "+stockQuoteDataModel.count);
143 id: lastUpdatedDateModel
145 namespaceDeclarations: "declare namespace yahoo='http://www.yahooapis.com/v1/base.rng';"
146 XmlRole { name: "timestamp"; query: '@yahoo:created/string()'}
149 if (status == XmlListModel.Ready && lastUpdatedDateModel.get(0)){
150 logUtility.logMessage("Updated: "+DateLib.ISODate.format(lastUpdatedDateModel.get(0).timestamp));
157 anchors.fill: parent;
160 property int itemHeight: 50
164 width: parent.width; height: 60;
165 anchors.top: parent.top
166 title: "Markets Today";
167 buttonType: "Config";
169 screen.showConfigInNewWindow();
178 id: marketsTodayLoader
179 anchors.top: titleBar.bottom
180 anchors.bottom: parent.bottom
182 sourceComponent: stockQuotesParentComponent
186 id: stockQuotesParentComponent
187 StockQuotesComponent{
188 id:stockQuotesComponent
189 componentWidth: background.width
190 stockQuotesListModel: stockQuoteDataModel
191 lastUpdatedModel: lastUpdatedDateModel
196 onQuoteRefreshStarted: {
197 stockQuotesComponent.updateStarted();
200 onQuoteRefreshCompleted: {
201 stockQuotesComponent.updateCompleted();
205 Component.onCompleted: {
206 titleBar.title = "Markets Today";
207 titleBar.buttonType = "Config";