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/CSVUtility.js" as CSVUtility
13 import "Library/js/Common.js" as Common
14 import "Library/js/CoreLogic.js" as CoreLib
19 signal showConfigInNewWindow
20 signal showStockDetails(string strSymbol)
21 signal quoteRefreshStarted
22 signal quoteRefreshCompleted(bool success, string strMessage)
23 signal newsReloadCompleted(bool success, string strMessage)
24 signal checkNetworkStatus
26 property int itemHeight: 50
27 property int titleBarHeight: 60
28 property int toolBarHeight: 40
29 property int componentWidth: mainPage.width
30 property int autoUpdateInterval: 300000
31 property bool updateWeekDaysOnly: false
32 property bool updateOnSavedNetworksOnly: false
33 property bool isDesktopWidget: true
34 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
35 property string lastUpdatedTimeStamp
36 property string selectedSymbol:""
38 function reloadData(){
39 CoreLib.reloadQuotes();
43 function initialize(){
44 DBUtility.initialize();
48 Component.onCompleted: {
54 interval: autoUpdateInterval
55 //running: (autoUpdateInterval == 0? false:true)
58 if (!updateWeekDaysOnly){
59 logUtility.logMessage("Allowed to update all days of the week");
60 mainPage.reloadData();
61 //checkNetworkStatus();
63 else if (Common.isTodayAWeekDay()){
64 logUtility.logMessage("Today is a weekday");
65 mainPage.reloadData();
66 //checkNetworkStatus();
69 logUtility.logMessage("Update not triggered: Today is not a weekday");
75 id: stockQuoteDataModel
88 Component.onCompleted: {
89 console.log("Rectangle Height = "+background.height);
93 id: stockQuotesDelegate
96 id: wrapper; width: parent.width; height: itemHeight
99 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
105 anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter}
107 source: "Library/images/information.png"
109 anchors.fill: parent;
111 logUtility.logMessage("Image clicked");
112 showStockDetails(symbol);
120 informationIcon.visible = true;
121 //console.log("Rectangle clicked");
127 anchors {left: parent.left;leftMargin: 10;right: parent.right;rightMargin: 10}
128 //width: componentWidth;
129 height: parent.height
132 Text { text: symbol; width: parent.width * 25/100; font.pixelSize: 18; font.bold: true; verticalAlignment:Text.AlignVCenter; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
133 Text { text: lastTradedPrice; width: parent.width * 25/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
136 width: parent.width * 20/100; height: parent.height
138 Text { text: change; font.pixelSize: 16; elide: Text.ElideRight
139 color: if(change >= 0){"green";} else {"red";}
140 style: Text.Raised; styleColor: "black" }
141 Text { text: changePercentage; font.pixelSize: 16; elide: Text.ElideRight;
142 color: if(change >= 0){"green";} else {"red";}
143 style: Text.Raised; styleColor: "black" }
145 Text { text: volume; width: parent.width * 30/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
155 id: newsWrapper; width: componentWidth; height: itemHeight
158 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
160 anchors.verticalCenter: parent.verticalCenter
161 anchors.left: parent.left
162 anchors.leftMargin: 10
163 anchors.right: parent.right
164 text: title; font.pixelSize: 14
166 verticalAlignment: Text.AlignVCenter
167 horizontalAlignment: Text.AlignLeft
168 elide: Text.ElideRight;
175 onClicked: Qt.openUrlExternally(link);
183 width: parent.width; height: mainPage.titleBarHeight
184 anchors.top: parent.top
185 title: "Markets Today"
187 displayMenuIcon: false
190 uiLoader.sourceComponent = stockQuotesUIComponent;
191 titleBar.buttonType = "";
192 titleBar.displayMenu = false;
193 toolBar.displayIcons = true;
200 anchors.top: titleBar.bottom
201 anchors.bottom: toolBar.top
202 sourceComponent: stockQuotesUIComponent
207 width: parent.width; height: mainPage.toolBarHeight
208 anchors.bottom: parent.bottom
210 displayNavigation: true
211 onReloadButtonClicked: mainPage.reloadData();
212 onNewsButtonClicked: {
213 uiLoader.sourceComponent = newsComponent;
214 toolBar.displayIcons = true;
215 toolBar.targetContentType = "Stocks";
218 onStocksButtonClicked: {
219 uiLoader.sourceComponent = stockQuotesUIComponent;
220 toolBar.displayIcons = true;
221 toolBar.targetContentType = "News";
227 onQuoteRefreshStarted:{
228 if (!toolBar.updatePending) toolBar.updatePending = true;
230 onQuoteRefreshCompleted:{
231 toolBar.updatePending = false;
237 id: stockQuotesUIComponent
242 anchors.top: parent.top
243 anchors.bottom: footerText.top
249 flickDeceleration: 500
250 //preferredHighlightBegin: 1/stockQuotesView.count
251 //preferredHighlightEnd: 1/stockQuotesView.count
252 //pathItemCount: count
255 model: stockQuoteDataModel
256 delegate: stockQuotesDelegate
262 y: stockQuotesView.count * itemHeight + itemHeight/2
265 Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
266 Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
270 onQuoteRefreshCompleted:{
271 stockQuotesView.currentIndex = 0;
277 onDownButtonClicked: {
278 if (!stockQuotesView.moving && stockQuotesView.interactive)
279 stockQuotesView.currentIndex = stockQuotesView.currentIndex + 1
282 if (!stockQuotesView.moving && stockQuotesView.interactive)
283 stockQuotesView.currentIndex = stockQuotesView.currentIndex - 1
290 id: stockStatusMsgArea
293 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
294 verticalCenter: parent.verticalCenter}
300 text: "Loading quotes.."
301 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
302 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
304 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
305 style: Text.Raised; styleColor: "black"
309 onQuoteRefreshCompleted: {
311 stockStatusMsgArea.visible = false;
312 pathViewWrapper.visible = true;
315 stockStatusText.text = strMessage;
316 pathViewWrapper.visible = false;
317 stockStatusMsgArea.visible = true;
329 anchors.bottom: parent.bottom
333 text: mainPage.lastUpdatedTimeStamp
334 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
335 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
337 style: Text.Raised; styleColor: "black"
341 onQuoteRefreshCompleted:{
342 timeStamp.text = mainPage.lastUpdatedTimeStamp;
356 anchors.top: parent.top
357 anchors.bottom: parent.bottom
363 flickDeceleration: 500
367 delegate: newsDelegate
373 y: newsView.count * itemHeight + itemHeight/2
376 Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
377 Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
381 onQuoteRefreshCompleted:{
382 newsView.currentIndex = 0;
388 onDownButtonClicked: {
389 if (!newsView.moving && newsView.interactive)
390 newsView.currentIndex = newsView.currentIndex + 1
393 if (!newsView.moving && newsView.interactive)
394 newsView.currentIndex = newsView.currentIndex - 1
401 id: newsStatusMsgArea
404 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
405 verticalCenter: parent.verticalCenter}
411 text: "Loading news.."
412 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
413 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
415 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
416 style: Text.Raised; styleColor: "black"
420 onNewsReloadCompleted: {
422 newsStatusMsgArea.visible = false;
423 newsViewArea.visible = true;
426 newsStatusText.text = strMessage;
427 newsViewArea.visible = false;
428 newsStatusMsgArea.visible = true;