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: false
33 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
34 property string lastUpdatedTimeStamp
35 //property string selectedSymbol:"YHOO"
36 property string selectedSymbol:sharedContext.getStockSymbol()
38 function reloadData(){
39 CoreLib.reloadQuotes();
43 function initialize(){
44 var componentToDisplay = sharedContext.getComponentToDisplay();
45 if (componentToDisplay === "StockQuoteDetails"){
46 uiLoader.sourceComponent = stockDetailsComponent;
47 titleBar.buttonType = "Close";
48 titleBar.displayMenu = false;
49 toolBar.displayIcons = false;
52 DBUtility.initialize();
53 uiLoader.sourceComponent = stockQuotesUIComponent;
58 Component.onCompleted: {
64 interval: autoUpdateInterval
65 //running: (autoUpdateInterval == 0? false:true)
68 if (!updateWeekDaysOnly){
69 logUtility.logMessage("Allowed to update all days of the week");
70 mainPage.reloadData();
71 //checkNetworkStatus();
73 else if (Common.isTodayAWeekDay()){
74 logUtility.logMessage("Today is a weekday");
75 mainPage.reloadData();
76 //checkNetworkStatus();
79 logUtility.logMessage("Update not triggered: Today is not a weekday");
85 id: stockQuoteDataModel
99 id: stockQuotesDelegate
102 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
104 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
108 mainPage.selectedSymbol = symbol;
109 uiLoader.sourceComponent = stockDetailsComponent;
110 titleBar.buttonType = "Back";
111 titleBar.displayMenu = false;
112 toolBar.displayIcons = false;
121 anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter}
123 source: "Library/images/information.png"
125 anchors.fill: parent;
127 //console.log("Image clicked");
128 mainPage.selectedSymbol = symbol;
129 uiLoader.sourceComponent = stockDetailsComponent;
130 titleBar.buttonType = "Back";
131 titleBar.displayMenu = false;
132 toolBar.displayIcons = false;
140 informationIcon.visible = true;
141 //console.log("Rectangle clicked");
149 width: mainPage.componentWidth - 60;
152 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
153 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
154 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
155 color: if(change >= 0){"green";} else {"red";}
156 style: Text.Raised; styleColor: "black" }
157 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
158 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
168 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
171 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
173 anchors.verticalCenter: parent.verticalCenter
174 anchors.left: parent.left
175 anchors.leftMargin: 10
176 anchors.right: parent.right
177 text: title; font.pixelSize: 18
179 verticalAlignment: Text.AlignVCenter
180 horizontalAlignment: Text.AlignLeft
181 elide: Text.ElideRight;
188 onDoubleClicked: Qt.openUrlExternally(link);
196 width: parent.width; height: mainPage.titleBarHeight;
197 anchors.top: parent.top
198 title: "Markets Today";
200 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
202 onCloseClicked: Qt.quit()
205 uiLoader.sourceComponent = configTickersComponent;
206 titleBar.buttonType = "Back";
207 titleBar.displayMenu = false;
208 toolBar.displayIcons = false;
212 uiLoader.sourceComponent = configParamsComponent;
213 titleBar.buttonType = "Back";
214 titleBar.displayMenu = false;
215 toolBar.displayIcons = false;
219 uiLoader.sourceComponent = stockQuotesUIComponent;
220 titleBar.buttonType = "Close";
221 titleBar.displayMenu = false;
222 toolBar.displayIcons = true;
223 mainPage.initialize();
230 anchors.top: titleBar.bottom
231 anchors.bottom: toolBar.top
236 width: parent.width; height: mainPage.toolBarHeight
237 anchors.bottom: parent.bottom
239 displayNavigation: false
240 onReloadButtonClicked: mainPage.reloadData();
242 onNewsButtonClicked: {
243 uiLoader.sourceComponent = newsComponent;
244 toolBar.displayIcons = true;
245 toolBar.targetContentType = "Stocks";
248 onStocksButtonClicked: {
249 uiLoader.sourceComponent = stockQuotesUIComponent;
250 toolBar.displayIcons = true;
251 toolBar.targetContentType = "News";
257 onQuoteRefreshStarted:{
258 if (!toolBar.updatePending) toolBar.updatePending = true;
260 onQuoteRefreshCompleted:{
261 toolBar.updatePending = false;
269 id: stockQuotesUIComponent
274 anchors.top: parent.top
275 anchors.bottom: footerTextArea.top
281 flickDeceleration: 500
282 model: stockQuoteDataModel
283 delegate: stockQuotesDelegate
285 snapMode: ListView.SnapToItem
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 listViewWrapper.visible = true;
315 stockStatusText.text = strMessage;
316 listViewWrapper.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 id: footerMessageTimer
345 footerMessage.text = mainPage.lastUpdatedTimeStamp;
351 onQuoteRefreshCompleted:{
353 footerMessage.text = "Double-tap on a row to display more details.";
354 footerMessageTimer.start();
357 footerMessage.text = mainPage.lastUpdatedTimeStamp;
366 id: stockDetailsComponent
367 StockDetailsComponent {
368 symbol: selectedSymbol
369 onLogRequest: logUtility.logMessage(strMessage)
379 anchors.top: parent.top
380 anchors.bottom: parent.bottom
386 flickDeceleration: 500
388 delegate: newsDelegate
390 snapMode: ListView.SnapToItem
395 id: newsStatusMsgArea
398 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
399 verticalCenter: parent.verticalCenter}
405 text: "Loading news.."
406 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
407 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
409 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
410 style: Text.Raised; styleColor: "black"
414 onNewsReloadCompleted: {
416 newsStatusMsgArea.visible = false;
417 newsViewArea.visible = true;
420 newsStatusText.text = strMessage;
421 newsViewArea.visible = false;
422 newsStatusMsgArea.visible = true;
432 id: configTickersComponent
434 ConfigTickersComponent{
435 itemHeight: mainPage.itemHeight
436 componentWidth: mainPage.componentWidth
437 onLogRequest: logUtility.logMessage(strMessage)
442 id: configParamsComponent
443 ConfigParametersComponent{
444 onLogRequest: logUtility.logMessage(strMessage)