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/Common.js" as Common
14 import "Library/js/CoreLogic.js" as CoreLib
22 property int autoUpdateInterval: 300000
23 property bool updateWeekDaysOnly: false
24 property bool updateOnSavedNetworksOnly: false
25 property bool isDesktopWidget: false
26 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
27 property string lastUpdatedTimeStamp
28 //property string selectedSymbol:"YHOO"
29 property string selectedSymbol:sharedContext.getStockSymbol()
31 signal showConfigInNewWindow
32 signal showStockDetails(string strSymbol)
33 signal quoteRefreshStarted
34 signal quoteRefreshCompleted(bool success, string strMessage)
35 signal newsReloadCompleted(bool success, string strMessage)
36 signal checkNetworkStatus
38 function initialize(){
39 mainPage.initializePage();
45 property int itemHeight: 50
46 property int titleBarHeight: 60
47 property int toolBarHeight: 40
48 property int componentWidth: mainPage.width
50 function reloadData(){
51 CoreLib.reloadQuotes();
55 function initializePage(){
56 var componentToDisplay = sharedContext.getComponentToDisplay();
57 if (componentToDisplay === "StockQuoteDetails"){
58 uiLoader.sourceComponent = stockDetailsComponent;
59 titleBar.buttonType = "Close";
60 titleBar.displayMenu = false;
61 toolBar.displayIcons = false;
64 DBUtility.initialize();
65 uiLoader.sourceComponent = stockQuotesUIComponent;
70 Component.onCompleted: {
76 interval: autoUpdateInterval
77 //running: (autoUpdateInterval == 0? false:true)
80 if (!updateWeekDaysOnly){
81 logUtility.logMessage("Allowed to update all days of the week");
82 mainPage.reloadData();
83 //checkNetworkStatus();
85 else if (Common.isTodayAWeekDay()){
86 logUtility.logMessage("Today is a weekday");
87 mainPage.reloadData();
88 //checkNetworkStatus();
91 logUtility.logMessage("Update not triggered: Today is not a weekday");
97 id: stockQuoteDataModel
106 anchors.fill: parent;
111 id: stockQuotesDelegateLandscape
114 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
116 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
120 appWindow.selectedSymbol = symbol;
121 uiLoader.sourceComponent = stockDetailsComponent;
122 titleBar.buttonType = "Back";
123 titleBar.displayMenu = false;
124 toolBar.displayIcons = false;
131 width: mainPage.componentWidth - 60;
134 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
135 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
136 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
137 color: if(change >= 0){"green";} else {"red";}
138 style: Text.Raised; styleColor: "black" }
139 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
140 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
147 id: stockQuotesDelegatePortrait
150 id: wrapperItem; width: mainPage.componentWidth; height: mainPage.itemHeight
152 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapperItem.height - 2; width: wrapperItem.width; y: 1
156 appWindow.selectedSymbol = symbol;
157 uiLoader.sourceComponent = stockDetailsComponent;
158 titleBar.buttonType = "Back";
159 titleBar.displayMenu = false;
160 toolBar.displayIcons = false;
167 width: mainPage.componentWidth - 5;
170 Text { text: stockName; width: parent.width * 42/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
171 Text { text: lastTradedPrice; width: parent.width * 20/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
174 width: parent.width * 18/100; height: parent.height
176 Text { text: change; font.pixelSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
177 color: if(change >= 0){"green";} else {"red";}
178 style: Text.Raised; styleColor: "black" }
179 Text { text: changePercentage; font.pixelSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight;
180 color: if(change >= 0){"green";} else {"red";}
181 style: Text.Raised; styleColor: "black" }
183 Text { text: volume; width: parent.width * 20/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
193 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
196 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
198 anchors.verticalCenter: parent.verticalCenter
199 anchors.left: parent.left
200 anchors.leftMargin: 10
201 anchors.right: parent.right
202 text: title; font.pixelSize: 18
204 verticalAlignment: Text.AlignVCenter
205 horizontalAlignment: Text.AlignLeft
206 elide: Text.ElideRight;
213 onDoubleClicked: Qt.openUrlExternally(link);
221 width: parent.width; height: mainPage.titleBarHeight;
222 anchors.top: parent.top
223 title: "Markets Today";
225 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
227 onCloseClicked: Qt.quit()
230 uiLoader.sourceComponent = configTickersComponent;
231 titleBar.buttonType = "Back";
232 titleBar.displayMenu = false;
233 toolBar.displayIcons = false;
237 uiLoader.sourceComponent = configParamsComponent;
238 titleBar.buttonType = "Back";
239 titleBar.displayMenu = false;
240 toolBar.displayIcons = false;
244 uiLoader.sourceComponent = stockQuotesUIComponent;
245 titleBar.buttonType = "Close";
246 titleBar.displayMenu = false;
247 toolBar.displayIcons = true;
248 mainPage.initializePage();
255 anchors.top: titleBar.bottom
256 anchors.bottom: toolBar.top
261 width: parent.width; height: mainPage.toolBarHeight
262 anchors.bottom: parent.bottom
264 displayNavigation: false
265 onReloadButtonClicked: mainPage.reloadData();
267 onNewsButtonClicked: {
268 uiLoader.sourceComponent = newsComponent;
269 toolBar.displayIcons = true;
270 toolBar.targetContentType = "Stocks";
273 onStocksButtonClicked: {
274 uiLoader.sourceComponent = stockQuotesUIComponent;
275 toolBar.displayIcons = true;
276 toolBar.targetContentType = "News";
282 onQuoteRefreshStarted:{
283 if (!toolBar.updatePending) toolBar.updatePending = true;
285 onQuoteRefreshCompleted:{
286 toolBar.updatePending = false;
294 id: stockQuotesUIComponent
299 anchors.top: parent.top
300 anchors.bottom: footerTextArea.top
306 flickDeceleration: 500
307 model: stockQuoteDataModel
308 delegate: listViewWrapper.height > listViewWrapper.width ? stockQuotesDelegatePortrait : stockQuotesDelegateLandscape
310 snapMode: ListView.SnapToItem
315 id: stockStatusMsgArea
318 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
319 verticalCenter: parent.verticalCenter}
325 text: "Loading quotes.."
326 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
327 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
329 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
330 style: Text.Raised; styleColor: "black"
334 onQuoteRefreshCompleted: {
336 stockStatusMsgArea.visible = false;
337 listViewWrapper.visible = true;
340 stockStatusText.text = strMessage;
341 stockStatusMsgArea.visible = true;
342 listViewWrapper.visible = true;
354 anchors.bottom: parent.bottom
358 text: lastUpdatedTimeStamp
359 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
360 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
362 style: Text.Raised; styleColor: "black"
366 id: footerMessageTimer
370 footerMessage.text = appWindow.lastUpdatedTimeStamp;
376 onQuoteRefreshCompleted:{
378 footerMessage.text = "Double-tap on a row to display more details.";
379 footerMessageTimer.start();
382 footerMessage.text = appWindow.lastUpdatedTimeStamp;
391 id: stockDetailsComponent
392 StockDetailsComponent {
394 symbol: selectedSymbol
395 onLogRequest: logUtility.logMessage(strMessage)
396 orientation: (appWindow.inPortrait)? "Portrait":"Landscape"; //Initial Orientation
400 when: !appWindow.inPortrait
402 target: detailsComponent
403 orientation: "Landscape"
408 when: appWindow.inPortrait
410 target: detailsComponent
411 orientation: "Portrait"
416 Component.onCompleted: {
417 if (appWindow.inPortrait){
418 logUtility.logMessage("Initial orientation is Portrait");
422 logUtility.logMessage("Initial orientation is Landscape");
434 anchors.top: parent.top
435 anchors.bottom: parent.bottom
441 flickDeceleration: 500
443 delegate: newsDelegate
445 snapMode: ListView.SnapToItem
450 id: newsStatusMsgArea
453 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
454 verticalCenter: parent.verticalCenter}
460 text: "Loading news.."
461 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
462 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
464 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
465 style: Text.Raised; styleColor: "black"
469 onNewsReloadCompleted: {
471 newsStatusMsgArea.visible = false;
472 newsViewArea.visible = true;
475 newsStatusText.text = strMessage;
476 newsViewArea.visible = false;
477 newsStatusMsgArea.visible = true;
488 id: configTickersComponent
490 ConfigTickersComponent{
491 itemHeight: mainPage.itemHeight
492 componentWidth: mainPage.componentWidth
493 onLogRequest: logUtility.logMessage(strMessage)
498 id: configParamsComponent
499 ConfigParametersComponent{
500 onLogRequest: logUtility.logMessage(strMessage)