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: 50
47 property int titleBarHeight: 60
48 property int toolBarHeight: 40
49 property int componentWidth: mainPage.width
51 function reloadData(){
52 CoreLib.reloadQuotes();
56 function initializePage(){
57 var componentToDisplay = sharedContext.getComponentToDisplay();
58 if (componentToDisplay === "StockQuoteDetails"){
59 uiLoader.sourceComponent = stockDetailsComponent;
60 titleBar.buttonType = "Close";
61 titleBar.displayMenu = false;
62 toolBar.displayIcons = false;
65 DBUtility.initialize();
66 uiLoader.sourceComponent = stockQuotesUIComponent;
71 Component.onCompleted: {
77 interval: autoUpdateInterval
78 //running: (autoUpdateInterval == 0? false:true)
81 if (!updateWeekDaysOnly){
82 logUtility.logMessage("Allowed to update all days of the week");
83 mainPage.reloadData();
84 //checkNetworkStatus();
86 else if (Common.isTodayAWeekDay()){
87 logUtility.logMessage("Today is a weekday");
88 mainPage.reloadData();
89 //checkNetworkStatus();
92 logUtility.logMessage("Update not triggered: Today is not a weekday");
98 id: stockQuoteDataModel
107 anchors.fill: parent;
112 id: stockQuotesDelegateLandscape
115 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
117 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
121 appWindow.selectedSymbol = symbol;
122 uiLoader.sourceComponent = stockDetailsComponent;
123 titleBar.buttonType = "Back";
124 titleBar.displayMenu = false;
125 toolBar.displayIcons = false;
132 width: mainPage.componentWidth - 60;
135 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
136 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
137 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
138 color: if(change >= 0){"green";} else {"red";}
139 style: Text.Raised; styleColor: "black" }
140 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
141 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
148 id: stockQuotesDelegatePortrait
151 id: wrapperItem; width: mainPage.componentWidth; height: mainPage.itemHeight
153 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapperItem.height - 2; width: wrapperItem.width; y: 1
157 appWindow.selectedSymbol = symbol;
158 uiLoader.sourceComponent = stockDetailsComponent;
159 titleBar.buttonType = "Back";
160 titleBar.displayMenu = false;
161 toolBar.displayIcons = false;
168 width: mainPage.componentWidth - 5;
171 Text { text: stockName; width: parent.width * 42/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
172 Text { text: lastTradedPrice; width: parent.width * 20/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
175 width: parent.width * 18/100; height: parent.height
177 Text { text: change; font.pixelSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
178 color: if(change >= 0){"green";} else {"red";}
179 style: Text.Raised; styleColor: "black" }
180 Text { text: changePercentage; font.pixelSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight;
181 color: if(change >= 0){"green";} else {"red";}
182 style: Text.Raised; styleColor: "black" }
184 Text { text: volume; width: parent.width * 20/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
194 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
197 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
199 anchors.verticalCenter: parent.verticalCenter
200 anchors.left: parent.left
201 anchors.leftMargin: 10
202 anchors.right: parent.right
203 text: title; font.pixelSize: 18
205 verticalAlignment: Text.AlignVCenter
206 horizontalAlignment: Text.AlignLeft
207 elide: Text.ElideRight;
214 onDoubleClicked: Qt.openUrlExternally(link);
222 width: parent.width; height: mainPage.titleBarHeight;
223 anchors.top: parent.top
224 title: "Markets Today";
226 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
228 onCloseClicked: Qt.quit()
231 uiLoader.sourceComponent = configTickersComponent;
232 titleBar.buttonType = "Back";
233 titleBar.displayMenu = false;
234 toolBar.displayIcons = false;
238 uiLoader.sourceComponent = configParamsComponent;
239 titleBar.buttonType = "Back";
240 titleBar.displayMenu = false;
241 toolBar.displayIcons = false;
245 uiLoader.sourceComponent = stockQuotesUIComponent;
246 titleBar.buttonType = "Close";
247 titleBar.displayMenu = false;
248 toolBar.displayIcons = true;
249 mainPage.initializePage();
256 anchors.top: titleBar.bottom
257 anchors.bottom: toolBar.top
262 width: parent.width; height: mainPage.toolBarHeight
263 anchors.bottom: parent.bottom
265 displayNavigation: false
266 onReloadButtonClicked: mainPage.reloadData();
268 onNewsButtonClicked: {
269 uiLoader.sourceComponent = newsComponent;
270 toolBar.displayIcons = true;
271 toolBar.targetContentType = "Stocks";
274 onStocksButtonClicked: {
275 uiLoader.sourceComponent = stockQuotesUIComponent;
276 toolBar.displayIcons = true;
277 toolBar.targetContentType = "News";
283 onQuoteRefreshStarted:{
284 if (!toolBar.updatePending) toolBar.updatePending = true;
286 onQuoteRefreshCompleted:{
287 toolBar.updatePending = false;
295 id: stockQuotesUIComponent
300 anchors.top: parent.top
301 anchors.bottom: footerTextArea.top
307 flickDeceleration: 500
308 model: stockQuoteDataModel
309 delegate: listViewWrapper.height > listViewWrapper.width ? stockQuotesDelegatePortrait : stockQuotesDelegateLandscape
311 snapMode: ListView.SnapToItem
316 id: stockStatusMsgArea
319 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
320 verticalCenter: parent.verticalCenter}
326 text: "Loading quotes.."
327 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
328 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
330 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
331 style: Text.Raised; styleColor: "black"
335 onQuoteRefreshCompleted: {
337 stockStatusMsgArea.visible = false;
338 listViewWrapper.visible = true;
341 stockStatusText.text = strMessage;
342 stockStatusMsgArea.visible = true;
343 listViewWrapper.visible = true;
355 anchors.bottom: parent.bottom
359 text: lastUpdatedTimeStamp
360 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
361 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
363 style: Text.Raised; styleColor: "black"
367 id: footerMessageTimer
371 footerMessage.text = appWindow.lastUpdatedTimeStamp;
377 onQuoteRefreshCompleted:{
379 footerMessage.text = "Double-tap on a row to display more details.";
380 footerMessageTimer.start();
383 footerMessage.text = appWindow.lastUpdatedTimeStamp;
392 id: stockDetailsComponent
393 StockDetailsComponent {
395 symbol: selectedSymbol
396 onLogRequest: logUtility.logMessage(strMessage)
397 orientation: (appWindow.inPortrait)? "Portrait":"Landscape"; //Initial Orientation
401 when: !appWindow.inPortrait
403 target: detailsComponent
404 orientation: "Landscape"
409 when: appWindow.inPortrait
411 target: detailsComponent
412 orientation: "Portrait"
417 Component.onCompleted: {
418 if (appWindow.inPortrait){
419 logUtility.logMessage("Initial orientation is Portrait");
423 logUtility.logMessage("Initial orientation is Landscape");
435 anchors.top: parent.top
436 anchors.bottom: parent.bottom
442 flickDeceleration: 500
444 delegate: newsDelegate
446 snapMode: ListView.SnapToItem
451 id: newsStatusMsgArea
454 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
455 verticalCenter: parent.verticalCenter}
461 text: "Loading news.."
462 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
463 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
465 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
466 style: Text.Raised; styleColor: "black"
470 onNewsReloadCompleted: {
472 newsStatusMsgArea.visible = false;
473 newsViewArea.visible = true;
476 newsStatusText.text = strMessage;
477 newsViewArea.visible = false;
478 newsStatusMsgArea.visible = true;
489 id: configTickersComponent
491 ConfigTickersComponent{
492 itemHeight: mainPage.itemHeight
493 componentWidth: mainPage.componentWidth
494 onLogRequest: logUtility.logMessage(strMessage)
499 id: configParamsComponent
500 ConfigParametersComponent{
501 onLogRequest: logUtility.logMessage(strMessage)