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;
121 width: mainPage.componentWidth - 60;
124 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
125 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
126 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
127 color: change >= 0 ? "#00ff00":"#ff0000";
128 style: Text.Raised; styleColor: "black" }
129 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
130 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
140 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
143 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
145 anchors.verticalCenter: parent.verticalCenter
146 anchors.left: parent.left
147 anchors.leftMargin: 10
148 anchors.right: parent.right
149 text: title; font.pixelSize: 18
151 verticalAlignment: Text.AlignVCenter
152 horizontalAlignment: Text.AlignLeft
153 elide: Text.ElideRight;
160 onDoubleClicked: Qt.openUrlExternally(link);
168 width: parent.width; height: mainPage.titleBarHeight;
169 anchors.top: parent.top
170 title: "Markets Today";
172 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
174 onCloseClicked: Qt.quit()
177 uiLoader.sourceComponent = configTickersComponent;
178 titleBar.buttonType = "Back";
179 titleBar.displayMenu = false;
180 toolBar.displayIcons = false;
184 uiLoader.sourceComponent = configParamsComponent;
185 titleBar.buttonType = "Back";
186 titleBar.displayMenu = false;
187 toolBar.displayIcons = false;
191 uiLoader.sourceComponent = stockQuotesUIComponent;
192 titleBar.buttonType = "Close";
193 titleBar.displayMenu = false;
194 toolBar.displayIcons = true;
195 mainPage.initialize();
202 anchors.top: titleBar.bottom
203 anchors.bottom: toolBar.top
208 width: parent.width; height: mainPage.toolBarHeight
209 anchors.bottom: parent.bottom
211 displayNavigation: false
212 onReloadButtonClicked: mainPage.reloadData();
214 onNewsButtonClicked: {
215 uiLoader.sourceComponent = newsComponent;
216 toolBar.displayIcons = true;
217 toolBar.targetContentType = "Stocks";
220 onStocksButtonClicked: {
221 uiLoader.sourceComponent = stockQuotesUIComponent;
222 toolBar.displayIcons = true;
223 toolBar.targetContentType = "News";
229 onQuoteRefreshStarted:{
230 if (!toolBar.updatePending) toolBar.updatePending = true;
232 onQuoteRefreshCompleted:{
233 toolBar.updatePending = false;
241 id: stockQuotesUIComponent
246 anchors.top: parent.top
247 anchors.bottom: footerTextArea.top
253 flickDeceleration: 500
254 model: stockQuoteDataModel
255 delegate: stockQuotesDelegate
257 snapMode: ListView.SnapToItem
262 id: stockStatusMsgArea
265 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
266 verticalCenter: parent.verticalCenter}
272 text: "Loading quotes.."
273 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
274 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
276 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
277 style: Text.Raised; styleColor: "black"
281 onQuoteRefreshCompleted: {
283 stockStatusMsgArea.visible = false;
284 listViewWrapper.visible = true;
287 stockStatusText.text = strMessage;
288 listViewWrapper.visible = false;
289 stockStatusMsgArea.visible = true;
301 anchors.bottom: parent.bottom
305 text: mainPage.lastUpdatedTimeStamp
306 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
307 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
309 style: Text.Raised; styleColor: "black"
313 id: footerMessageTimer
317 footerMessage.text = mainPage.lastUpdatedTimeStamp;
323 onQuoteRefreshCompleted:{
325 footerMessage.text = "Double-tap on a row to display more details.";
326 footerMessageTimer.start();
329 footerMessage.text = mainPage.lastUpdatedTimeStamp;
338 id: stockDetailsComponent
339 StockDetailsComponent {
340 symbol: selectedSymbol
341 onLogRequest: logUtility.logMessage(strMessage)
351 anchors.top: parent.top
352 anchors.bottom: parent.bottom
358 flickDeceleration: 500
360 delegate: newsDelegate
362 snapMode: ListView.SnapToItem
367 id: newsStatusMsgArea
370 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
371 verticalCenter: parent.verticalCenter}
377 text: "Loading news.."
378 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
379 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
381 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
382 style: Text.Raised; styleColor: "black"
386 onNewsReloadCompleted: {
388 newsStatusMsgArea.visible = false;
389 newsViewArea.visible = true;
392 newsStatusText.text = strMessage;
393 newsViewArea.visible = false;
394 newsStatusMsgArea.visible = true;
404 id: configTickersComponent
406 ConfigTickersComponent{
407 itemHeight: mainPage.itemHeight
408 componentWidth: mainPage.componentWidth
409 onLogRequest: logUtility.logMessage(strMessage)
414 id: configParamsComponent
415 ConfigParametersComponent{
416 onLogRequest: logUtility.logMessage(strMessage)