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
13 import "Library/js/CoreLogic.js" as CoreLib
18 signal showConfigInNewWindow
19 signal showStockDetails(string strSymbol)
20 signal quoteRefreshStarted
21 signal quoteRefreshCompleted(bool success, string strMessage)
22 signal newsReloadCompleted(bool success, string strMessage)
23 signal checkNetworkStatus
25 property int itemHeight: 50
26 property int titleBarHeight: 60
27 property int toolBarHeight: 40
28 property int componentWidth: mainPage.width
29 property int autoUpdateInterval: 300000
30 property bool updateWeekDaysOnly: false
31 property bool updateOnSavedNetworksOnly: false
32 property bool isDesktopWidget: true
33 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
34 property string lastUpdatedTimeStamp
35 property string selectedSymbol:""
37 function reloadData(){
38 CoreLib.reloadQuotes();
42 function initialize(){
43 DBUtility.initialize();
47 Component.onCompleted: {
53 interval: autoUpdateInterval
54 //running: (autoUpdateInterval == 0? false:true)
57 if (!updateWeekDaysOnly){
58 logUtility.logMessage("Allowed to update all days of the week");
59 mainPage.reloadData();
60 //checkNetworkStatus();
62 else if (Common.isTodayAWeekDay()){
63 logUtility.logMessage("Today is a weekday");
64 mainPage.reloadData();
65 //checkNetworkStatus();
68 logUtility.logMessage("Update not triggered: Today is not a weekday");
74 id: stockQuoteDataModel
87 Component.onCompleted: {
88 console.log("Rectangle Height = "+background.height);
92 id: stockQuotesDelegate
95 id: wrapper; width: parent.width; height: itemHeight
98 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
104 anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter}
106 source: "Library/images/information.png"
108 anchors.fill: parent;
110 logUtility.logMessage("Image clicked");
111 showStockDetails(symbol);
119 informationIcon.visible = true;
120 //console.log("Rectangle clicked");
126 anchors {left: parent.left;leftMargin: 10;right: parent.right;rightMargin: 10}
127 //width: componentWidth;
128 height: parent.height
131 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" }
132 Text { text: lastTradedPrice; width: parent.width * 25/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
135 width: parent.width * 20/100; height: parent.height
137 Text { text: change; font.pixelSize: 16; elide: Text.ElideRight
138 color: if(change >= 0){"green";} else {"red";}
139 style: Text.Raised; styleColor: "black" }
140 Text { text: changePercentage; font.pixelSize: 16; elide: Text.ElideRight;
141 color: if(change >= 0){"green";} else {"red";}
142 style: Text.Raised; styleColor: "black" }
144 Text { text: volume; width: parent.width * 30/100; font.pixelSize: 18; verticalAlignment:Text.AlignVCenter; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
154 id: newsWrapper; width: componentWidth; height: itemHeight
157 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
159 anchors.verticalCenter: parent.verticalCenter
160 anchors.left: parent.left
161 anchors.leftMargin: 10
162 anchors.right: parent.right
163 text: title; font.pixelSize: 14
165 verticalAlignment: Text.AlignVCenter
166 horizontalAlignment: Text.AlignLeft
167 elide: Text.ElideRight;
174 onClicked: Qt.openUrlExternally(link);
182 width: parent.width; height: mainPage.titleBarHeight
183 anchors.top: parent.top
184 title: "Markets Today"
186 displayMenuIcon: false
189 uiLoader.sourceComponent = stockQuotesUIComponent;
190 titleBar.buttonType = "";
191 titleBar.displayMenu = false;
192 toolBar.displayIcons = true;
199 anchors.top: titleBar.bottom
200 anchors.bottom: toolBar.top
201 sourceComponent: stockQuotesUIComponent
206 width: parent.width; height: mainPage.toolBarHeight
207 anchors.bottom: parent.bottom
209 displayNavigation: true
210 onReloadButtonClicked: mainPage.reloadData();
211 onNewsButtonClicked: {
212 uiLoader.sourceComponent = newsComponent;
213 toolBar.displayIcons = true;
214 toolBar.targetContentType = "Stocks";
217 onStocksButtonClicked: {
218 uiLoader.sourceComponent = stockQuotesUIComponent;
219 toolBar.displayIcons = true;
220 toolBar.targetContentType = "News";
226 onQuoteRefreshStarted:{
227 if (!toolBar.updatePending) toolBar.updatePending = true;
229 onQuoteRefreshCompleted:{
230 toolBar.updatePending = false;
236 id: stockQuotesUIComponent
241 anchors.top: parent.top
242 anchors.bottom: footerText.top
248 flickDeceleration: 500
249 //preferredHighlightBegin: 1/stockQuotesView.count
250 //preferredHighlightEnd: 1/stockQuotesView.count
251 //pathItemCount: count
254 model: stockQuoteDataModel
255 delegate: stockQuotesDelegate
261 y: stockQuotesView.count * itemHeight + itemHeight/2
264 Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
265 Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
269 onQuoteRefreshCompleted:{
270 stockQuotesView.currentIndex = 0;
276 onDownButtonClicked: {
277 if (!stockQuotesView.moving && stockQuotesView.interactive)
278 stockQuotesView.currentIndex = stockQuotesView.currentIndex + 1
281 if (!stockQuotesView.moving && stockQuotesView.interactive)
282 stockQuotesView.currentIndex = stockQuotesView.currentIndex - 1
289 id: stockStatusMsgArea
292 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
293 verticalCenter: parent.verticalCenter}
299 text: "Loading quotes.."
300 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
301 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
303 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
304 style: Text.Raised; styleColor: "black"
308 onQuoteRefreshCompleted: {
310 stockStatusMsgArea.visible = false;
311 pathViewWrapper.visible = true;
314 stockStatusText.text = strMessage;
315 pathViewWrapper.visible = false;
316 stockStatusMsgArea.visible = true;
328 anchors.bottom: parent.bottom
332 text: mainPage.lastUpdatedTimeStamp
333 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
334 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
336 style: Text.Raised; styleColor: "black"
340 onQuoteRefreshCompleted:{
341 timeStamp.text = mainPage.lastUpdatedTimeStamp;
355 anchors.top: parent.top
356 anchors.bottom: parent.bottom
362 flickDeceleration: 500
366 delegate: newsDelegate
372 y: newsView.count * itemHeight + itemHeight/2
375 Keys.onDownPressed: if (!moving && interactive) incrementCurrentIndex()
376 Keys.onUpPressed: if (!moving && interactive) decrementCurrentIndex()
380 onQuoteRefreshCompleted:{
381 newsView.currentIndex = 0;
387 onDownButtonClicked: {
388 if (!newsView.moving && newsView.interactive)
389 newsView.currentIndex = newsView.currentIndex + 1
392 if (!newsView.moving && newsView.interactive)
393 newsView.currentIndex = newsView.currentIndex - 1
400 id: newsStatusMsgArea
403 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
404 verticalCenter: parent.verticalCenter}
410 text: "Loading news.."
411 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
412 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
414 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
415 style: Text.Raised; styleColor: "black"
419 onNewsReloadCompleted: {
421 newsStatusMsgArea.visible = false;
422 newsViewArea.visible = true;
425 newsStatusText.text = strMessage;
426 newsViewArea.visible = false;
427 newsStatusMsgArea.visible = true;