3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
8 import com.nokia.meego 1.0
10 import "Library" as Library
11 import "Library/js/ISODate.js" as DateLib
12 import "Library/js/DBUtility.js" as DBUtility
13 import "Library/js/CSVUtility.js" as CSVUtility
14 import "Library/js/Common.js" as Common
15 import "Library/js/CoreLogic.js" as CoreLib
23 property int autoUpdateInterval: 300000
24 property bool updateWeekDaysOnly: false
25 property bool updateOnSavedNetworksOnly: false
26 property bool isDesktopWidget: false
27 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
28 property string lastUpdatedTimeStamp
29 //property string selectedSymbol:"YHOO"
30 property string selectedSymbol:sharedContext.getStockSymbol()
32 signal showConfigInNewWindow
33 signal showStockDetails(string strSymbol)
34 signal quoteRefreshStarted
35 signal quoteRefreshCompleted(bool success, string strMessage)
36 signal newsReloadCompleted(bool success, string strMessage)
37 signal checkNetworkStatus
39 function initialize(){
40 mainPage.initializePage();
46 property int itemHeight: 75
47 property int titleBarHeight: 60
48 property int toolBarHeight: 40
49 property int fontSizeMed: 24
50 property int fontSizeSmall: 20
51 property int colSpacing: 4
52 property int componentWidth: mainPage.width
54 function reloadData(){
55 CoreLib.reloadQuotes();
59 function initializePage(){
60 var componentToDisplay = sharedContext.getComponentToDisplay();
61 if (componentToDisplay === "StockQuoteDetails"){
62 uiLoader.sourceComponent = stockDetailsComponent;
63 titleBar.buttonType = "Close";
64 titleBar.displayMenu = false;
65 toolBar.displayIcons = false;
68 DBUtility.initialize();
69 uiLoader.sourceComponent = stockQuotesUIComponent;
74 Component.onCompleted: {
80 interval: autoUpdateInterval
81 //running: (autoUpdateInterval == 0? false:true)
84 if (!updateWeekDaysOnly){
85 logUtility.logMessage("Allowed to update all days of the week");
86 mainPage.reloadData();
87 //checkNetworkStatus();
89 else if (Common.isTodayAWeekDay()){
90 logUtility.logMessage("Today is a weekday");
91 mainPage.reloadData();
92 //checkNetworkStatus();
95 logUtility.logMessage("Update not triggered: Today is not a weekday");
101 id: stockQuoteDataModel
110 anchors.fill: parent;
115 id: stockQuotesDelegateLandscape
118 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
120 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
124 appWindow.selectedSymbol = symbol;
125 uiLoader.sourceComponent = stockDetailsComponent;
126 titleBar.buttonType = "Back";
127 titleBar.displayMenu = false;
128 toolBar.displayIcons = false;
134 x: 30;y: (wrapper.height - mainPage.fontSizeMed)/2;
135 width: mainPage.componentWidth - 60;
138 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: mainPage.fontSizeMed; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
139 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
140 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
141 color: change >= 0 ? "#00ff00":"#ff0000"; style: Text.Raised; styleColor: "black"}
142 Text { text: volume; width: parent.width * 18/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
143 Text { text: marketCap; width: parent.width * 12/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
150 id: stockQuotesDelegatePortrait
153 id: wrapperItem; width: mainPage.componentWidth; height: mainPage.itemHeight
155 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapperItem.height - 2; width: wrapperItem.width; y: 1
159 appWindow.selectedSymbol = symbol;
160 uiLoader.sourceComponent = stockDetailsComponent;
161 titleBar.buttonType = "Back";
162 titleBar.displayMenu = false;
163 toolBar.displayIcons = false;
169 x: 10;y: (wrapperItem.height - mainPage.fontSizeMed)/2;
170 width: mainPage.componentWidth - 5;
173 Text { text: stockName; width: parent.width * 42/100; font.pixelSize: mainPage.fontSizeMed; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black"}
174 Text { text: lastTradedPrice; width: parent.width * 20/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black"}
176 y: (wrapperItem.height - mainPage.colSpacing - mainPage.fontSizeSmall*2)/2 - (wrapperItem.height - mainPage.fontSizeMed)/2;
177 width: parent.width * 18/100; height: parent.height
178 spacing: mainPage.colSpacing
179 Text { text: change; font.pixelSize: mainPage.fontSizeSmall; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
180 color: change >= 0 ? "#00ff00":"#ff0000";
181 style: Text.Raised; styleColor: "black" }
182 Text { text: changePercentage; font.pixelSize: mainPage.fontSizeSmall; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight;
183 color: change >= 0 ? "#00ff00":"#ff0000";
184 style: Text.Raised; styleColor: "black" }
186 Text { text: volume !== ''? Common.abbreviateNumber(volume,2) :''; width: parent.width * 20/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black"}
196 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
199 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
201 anchors.verticalCenter: parent.verticalCenter
202 anchors.left: parent.left
203 anchors.leftMargin: 10
204 anchors.right: parent.right
205 text: title; font.pixelSize: mainPage.fontSizeSmall
207 verticalAlignment: Text.AlignVCenter
208 horizontalAlignment: Text.AlignLeft
209 elide: Text.ElideRight;
216 onDoubleClicked: Qt.openUrlExternally(link);
224 width: parent.width; height: mainPage.titleBarHeight;
225 anchors.top: parent.top
226 title: "Markets Today";
228 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
230 onCloseClicked: Qt.quit()
233 uiLoader.sourceComponent = configTickersComponent;
234 titleBar.buttonType = "Back";
235 titleBar.displayMenu = false;
236 toolBar.displayIcons = false;
240 uiLoader.sourceComponent = configParamsComponent;
241 titleBar.buttonType = "Back";
242 titleBar.displayMenu = false;
243 toolBar.displayIcons = false;
247 uiLoader.sourceComponent = stockQuotesUIComponent;
248 titleBar.buttonType = "Close";
249 titleBar.displayMenu = false;
250 toolBar.displayIcons = true;
251 mainPage.initializePage();
258 anchors.top: titleBar.bottom
259 anchors.bottom: toolBar.top
264 width: parent.width; height: mainPage.toolBarHeight
265 anchors.bottom: parent.bottom
267 displayNavigation: false
268 onReloadButtonClicked: mainPage.reloadData();
270 onNewsButtonClicked: {
271 uiLoader.sourceComponent = newsComponent;
272 toolBar.displayIcons = true;
273 toolBar.targetContentType = "Stocks";
276 onStocksButtonClicked: {
277 uiLoader.sourceComponent = stockQuotesUIComponent;
278 toolBar.displayIcons = true;
279 toolBar.targetContentType = "News";
285 onQuoteRefreshStarted:{
286 if (!toolBar.updatePending) toolBar.updatePending = true;
288 onQuoteRefreshCompleted:{
289 toolBar.updatePending = false;
297 id: stockQuotesUIComponent
302 anchors.top: parent.top
303 anchors.bottom: footerTextArea.top
309 flickDeceleration: 500
310 model: stockQuoteDataModel
311 delegate: listViewWrapper.height > listViewWrapper.width ? stockQuotesDelegatePortrait : stockQuotesDelegateLandscape
313 snapMode: ListView.SnapToItem
318 id: stockStatusMsgArea
321 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
322 verticalCenter: parent.verticalCenter}
328 text: "Loading quotes.."
329 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
330 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
332 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
333 style: Text.Raised; styleColor: "black"
337 onQuoteRefreshCompleted: {
339 stockStatusMsgArea.visible = false;
340 listViewWrapper.visible = true;
343 stockStatusText.text = strMessage;
344 stockStatusMsgArea.visible = true;
345 listViewWrapper.visible = true;
357 anchors.bottom: parent.bottom
361 text: lastUpdatedTimeStamp
362 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
363 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
365 style: Text.Raised; styleColor: "black"
369 id: footerMessageTimer
373 footerMessage.text = appWindow.lastUpdatedTimeStamp;
379 onQuoteRefreshCompleted:{
381 footerMessage.text = "Double-tap on a row to display more details.";
382 footerMessageTimer.start();
385 footerMessage.text = appWindow.lastUpdatedTimeStamp;
394 id: stockDetailsComponent
395 StockDetailsComponent {
397 symbol: selectedSymbol
398 onLogRequest: logUtility.logMessage(strMessage)
399 orientation: (appWindow.inPortrait)? "Portrait":"Landscape"; //Initial Orientation
403 when: !appWindow.inPortrait
405 target: detailsComponent
406 orientation: "Landscape"
411 when: appWindow.inPortrait
413 target: detailsComponent
414 orientation: "Portrait"
419 Component.onCompleted: {
420 if (appWindow.inPortrait){
421 logUtility.logMessage("Initial orientation is Portrait");
425 logUtility.logMessage("Initial orientation is Landscape");
437 anchors.top: parent.top
438 anchors.bottom: parent.bottom
444 flickDeceleration: 500
446 delegate: newsDelegate
448 snapMode: ListView.SnapToItem
453 id: newsStatusMsgArea
456 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
457 verticalCenter: parent.verticalCenter}
463 text: "Loading news.."
464 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
465 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
467 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
468 style: Text.Raised; styleColor: "black"
472 onNewsReloadCompleted: {
474 newsStatusMsgArea.visible = false;
475 newsViewArea.visible = true;
478 newsStatusText.text = strMessage;
479 newsViewArea.visible = false;
480 newsStatusMsgArea.visible = true;
491 id: configTickersComponent
493 ConfigTickersComponent{
494 itemHeight: mainPage.itemHeight
495 componentWidth: mainPage.componentWidth
496 onLogRequest: logUtility.logMessage(strMessage)
501 id: configParamsComponent
502 ConfigParametersComponent{
503 onLogRequest: logUtility.logMessage(strMessage)