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: false
34 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
35 property string lastUpdatedTimeStamp
36 //property string selectedSymbol:"YHOO"
37 property string selectedSymbol:sharedContext.getStockSymbol()
39 function reloadData(){
40 CoreLib.reloadQuotes();
44 function initialize(){
45 var componentToDisplay = sharedContext.getComponentToDisplay();
46 if (componentToDisplay === "StockQuoteDetails"){
47 uiLoader.sourceComponent = stockDetailsComponent;
48 titleBar.buttonType = "Close";
49 titleBar.displayMenu = false;
50 toolBar.displayIcons = false;
53 DBUtility.initialize();
54 uiLoader.sourceComponent = stockQuotesUIComponent;
59 Component.onCompleted: {
65 interval: autoUpdateInterval
66 //running: (autoUpdateInterval == 0? false:true)
69 if (!updateWeekDaysOnly){
70 logUtility.logMessage("Allowed to update all days of the week");
71 mainPage.reloadData();
72 //checkNetworkStatus();
74 else if (Common.isTodayAWeekDay()){
75 logUtility.logMessage("Today is a weekday");
76 mainPage.reloadData();
77 //checkNetworkStatus();
80 logUtility.logMessage("Update not triggered: Today is not a weekday");
86 id: stockQuoteDataModel
100 id: stockQuotesDelegate
103 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
105 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
109 mainPage.selectedSymbol = symbol;
110 uiLoader.sourceComponent = stockDetailsComponent;
111 titleBar.buttonType = "Back";
112 titleBar.displayMenu = false;
113 toolBar.displayIcons = false;
122 anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter}
124 source: "Library/images/information.png"
126 anchors.fill: parent;
128 //console.log("Image clicked");
129 mainPage.selectedSymbol = symbol;
130 uiLoader.sourceComponent = stockDetailsComponent;
131 titleBar.buttonType = "Back";
132 titleBar.displayMenu = false;
133 toolBar.displayIcons = false;
141 informationIcon.visible = true;
142 //console.log("Rectangle clicked");
150 width: mainPage.componentWidth - 60;
153 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
154 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
155 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
156 color: if(change >= 0){"green";} else {"red";}
157 style: Text.Raised; styleColor: "black" }
158 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
159 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
169 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
172 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
174 anchors.verticalCenter: parent.verticalCenter
175 anchors.left: parent.left
176 anchors.leftMargin: 10
177 anchors.right: parent.right
178 text: title; font.pixelSize: 18
180 verticalAlignment: Text.AlignVCenter
181 horizontalAlignment: Text.AlignLeft
182 elide: Text.ElideRight;
189 onDoubleClicked: Qt.openUrlExternally(link);
197 width: parent.width; height: mainPage.titleBarHeight;
198 anchors.top: parent.top
199 title: "Markets Today";
201 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
203 onCloseClicked: Qt.quit()
206 uiLoader.sourceComponent = configTickersComponent;
207 titleBar.buttonType = "Back";
208 titleBar.displayMenu = false;
209 toolBar.displayIcons = false;
213 uiLoader.sourceComponent = configParamsComponent;
214 titleBar.buttonType = "Back";
215 titleBar.displayMenu = false;
216 toolBar.displayIcons = false;
220 uiLoader.sourceComponent = stockQuotesUIComponent;
221 titleBar.buttonType = "Close";
222 titleBar.displayMenu = false;
223 toolBar.displayIcons = true;
224 mainPage.initialize();
231 anchors.top: titleBar.bottom
232 anchors.bottom: toolBar.top
237 width: parent.width; height: mainPage.toolBarHeight
238 anchors.bottom: parent.bottom
240 displayNavigation: false
241 onReloadButtonClicked: mainPage.reloadData();
243 onNewsButtonClicked: {
244 uiLoader.sourceComponent = newsComponent;
245 toolBar.displayIcons = true;
246 toolBar.targetContentType = "Stocks";
249 onStocksButtonClicked: {
250 uiLoader.sourceComponent = stockQuotesUIComponent;
251 toolBar.displayIcons = true;
252 toolBar.targetContentType = "News";
258 onQuoteRefreshStarted:{
259 if (!toolBar.updatePending) toolBar.updatePending = true;
261 onQuoteRefreshCompleted:{
262 toolBar.updatePending = false;
270 id: stockQuotesUIComponent
275 anchors.top: parent.top
276 anchors.bottom: footerTextArea.top
282 flickDeceleration: 500
283 model: stockQuoteDataModel
284 delegate: stockQuotesDelegate
286 snapMode: ListView.SnapToItem
291 id: stockStatusMsgArea
294 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
295 verticalCenter: parent.verticalCenter}
301 text: "Loading quotes.."
302 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
303 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
305 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
306 style: Text.Raised; styleColor: "black"
310 onQuoteRefreshCompleted: {
312 stockStatusMsgArea.visible = false;
313 listViewWrapper.visible = true;
316 stockStatusText.text = strMessage;
317 listViewWrapper.visible = false;
318 stockStatusMsgArea.visible = true;
330 anchors.bottom: parent.bottom
334 text: mainPage.lastUpdatedTimeStamp
335 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
336 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
338 style: Text.Raised; styleColor: "black"
342 id: footerMessageTimer
346 footerMessage.text = mainPage.lastUpdatedTimeStamp;
352 onQuoteRefreshCompleted:{
354 footerMessage.text = "Double-tap on a row to display more details.";
355 footerMessageTimer.start();
358 footerMessage.text = mainPage.lastUpdatedTimeStamp;
367 id: stockDetailsComponent
368 StockDetailsComponent {
369 symbol: selectedSymbol
370 onLogRequest: logUtility.logMessage(strMessage)
380 anchors.top: parent.top
381 anchors.bottom: parent.bottom
387 flickDeceleration: 500
389 delegate: newsDelegate
391 snapMode: ListView.SnapToItem
396 id: newsStatusMsgArea
399 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
400 verticalCenter: parent.verticalCenter}
406 text: "Loading news.."
407 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
408 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
410 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
411 style: Text.Raised; styleColor: "black"
415 onNewsReloadCompleted: {
417 newsStatusMsgArea.visible = false;
418 newsViewArea.visible = true;
421 newsStatusText.text = strMessage;
422 newsViewArea.visible = false;
423 newsStatusMsgArea.visible = true;
433 id: configTickersComponent
435 ConfigTickersComponent{
436 itemHeight: mainPage.itemHeight
437 componentWidth: mainPage.componentWidth
438 onLogRequest: logUtility.logMessage(strMessage)
443 id: configParamsComponent
444 ConfigParametersComponent{
445 onLogRequest: logUtility.logMessage(strMessage)