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: change >= 0 ? "#00ff00":"#ff0000"; 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: change >= 0 ? "#00ff00":"#ff0000";
178 style: Text.Raised; styleColor: "black" }
179 Text { text: changePercentage; font.pixelSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight;
180 color: change >= 0 ? "#00ff00":"#ff0000";
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)