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/CSVUtility.js" as CSVUtility
13 import "Library/js/Common.js" as Common
14 import "Library/js/CoreLogic.js" as CoreLib
19 signal showConfigInNewWindow
20 signal showStockDetails(string strSymbol)
21 signal quoteRefreshStarted
22 signal quoteRefreshCompleted(bool success, string strMessage)
23 signal newsReloadCompleted(bool success, string strMessage)
24 signal checkNetworkStatus
26 property int itemHeight: 75
27 property int titleBarHeight: 60
28 property int toolBarHeight: 40
29 property int fontSizeMed: 24
30 property int fontSizeSmall: 20
31 property int componentWidth: mainPage.width
32 property int autoUpdateInterval: 300000
33 property bool updateWeekDaysOnly: false
34 property bool updateOnSavedNetworksOnly: false
35 property bool isDesktopWidget: false
36 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
37 property string lastUpdatedTimeStamp
38 //property string selectedSymbol:"YHOO"
39 property string selectedSymbol:sharedContext.getStockSymbol()
41 function reloadData(){
42 CoreLib.reloadQuotes();
46 function initialize(){
47 var componentToDisplay = sharedContext.getComponentToDisplay();
48 if (componentToDisplay === "StockQuoteDetails"){
49 uiLoader.sourceComponent = stockDetailsComponent;
50 titleBar.buttonType = "Close";
51 titleBar.displayMenu = false;
52 toolBar.displayIcons = false;
55 DBUtility.initialize();
56 uiLoader.sourceComponent = stockQuotesUIComponent;
61 Component.onCompleted: {
67 interval: autoUpdateInterval
68 //running: (autoUpdateInterval == 0? false:true)
71 if (!updateWeekDaysOnly){
72 logUtility.logMessage("Allowed to update all days of the week");
73 mainPage.reloadData();
74 //checkNetworkStatus();
76 else if (Common.isTodayAWeekDay()){
77 logUtility.logMessage("Today is a weekday");
78 mainPage.reloadData();
79 //checkNetworkStatus();
82 logUtility.logMessage("Update not triggered: Today is not a weekday");
88 id: stockQuoteDataModel
102 id: stockQuotesDelegate
105 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
107 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
111 mainPage.selectedSymbol = symbol;
112 uiLoader.sourceComponent = stockDetailsComponent;
113 titleBar.buttonType = "Back";
114 titleBar.displayMenu = false;
115 toolBar.displayIcons = false;
122 x: 30;y: (wrapper.height - mainPage.fontSizeMed)/2;
123 width: mainPage.componentWidth - 60;
126 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" }
127 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" }
128 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
129 color: change >= 0 ? "#00ff00":"#ff0000";
130 style: Text.Raised; styleColor: "black" }
131 Text { text: volume; width: parent.width * 15/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
132 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: mainPage.fontSizeMed; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
142 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
145 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
147 anchors.verticalCenter: parent.verticalCenter
148 anchors.left: parent.left
149 anchors.leftMargin: 10
150 anchors.right: parent.right
151 text: title; font.pixelSize: mainPage.fontSizeSmall
153 verticalAlignment: Text.AlignVCenter
154 horizontalAlignment: Text.AlignLeft
155 elide: Text.ElideRight;
162 onDoubleClicked: Qt.openUrlExternally(link);
170 width: parent.width; height: mainPage.titleBarHeight;
171 anchors.top: parent.top
172 title: "Markets Today";
174 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
176 onCloseClicked: Qt.quit()
179 uiLoader.sourceComponent = configTickersComponent;
180 titleBar.buttonType = "Back";
181 titleBar.displayMenu = false;
182 toolBar.displayIcons = false;
186 uiLoader.sourceComponent = configParamsComponent;
187 titleBar.buttonType = "Back";
188 titleBar.displayMenu = false;
189 toolBar.displayIcons = false;
193 uiLoader.sourceComponent = stockQuotesUIComponent;
194 titleBar.buttonType = "Close";
195 titleBar.displayMenu = false;
196 toolBar.displayIcons = true;
197 mainPage.initialize();
204 anchors.top: titleBar.bottom
205 anchors.bottom: toolBar.top
210 width: parent.width; height: mainPage.toolBarHeight
211 anchors.bottom: parent.bottom
213 displayNavigation: false
214 onReloadButtonClicked: mainPage.reloadData();
216 onNewsButtonClicked: {
217 uiLoader.sourceComponent = newsComponent;
218 toolBar.displayIcons = true;
219 toolBar.targetContentType = "Stocks";
222 onStocksButtonClicked: {
223 uiLoader.sourceComponent = stockQuotesUIComponent;
224 toolBar.displayIcons = true;
225 toolBar.targetContentType = "News";
231 onQuoteRefreshStarted:{
232 if (!toolBar.updatePending) toolBar.updatePending = true;
234 onQuoteRefreshCompleted:{
235 toolBar.updatePending = false;
243 id: stockQuotesUIComponent
248 anchors.top: parent.top
249 anchors.bottom: footerTextArea.top
255 flickDeceleration: 500
256 model: stockQuoteDataModel
257 delegate: stockQuotesDelegate
259 snapMode: ListView.SnapToItem
264 id: stockStatusMsgArea
267 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
268 verticalCenter: parent.verticalCenter}
274 text: "Loading quotes.."
275 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
276 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
278 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
279 style: Text.Raised; styleColor: "black"
283 onQuoteRefreshCompleted: {
285 stockStatusMsgArea.visible = false;
286 listViewWrapper.visible = true;
289 stockStatusText.text = strMessage;
290 listViewWrapper.visible = false;
291 stockStatusMsgArea.visible = true;
303 anchors.bottom: parent.bottom
307 text: mainPage.lastUpdatedTimeStamp
308 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
309 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
311 style: Text.Raised; styleColor: "black"
315 id: footerMessageTimer
319 footerMessage.text = mainPage.lastUpdatedTimeStamp;
325 onQuoteRefreshCompleted:{
327 footerMessage.text = "Double-tap on a row to display more details.";
328 footerMessageTimer.start();
331 footerMessage.text = mainPage.lastUpdatedTimeStamp;
340 id: stockDetailsComponent
341 StockDetailsComponent {
342 symbol: selectedSymbol
343 onLogRequest: logUtility.logMessage(strMessage)
353 anchors.top: parent.top
354 anchors.bottom: parent.bottom
360 flickDeceleration: 500
362 delegate: newsDelegate
364 snapMode: ListView.SnapToItem
369 id: newsStatusMsgArea
372 anchors {left: parent.left; leftMargin: 15; right: parent.right; rightMargin: 15;
373 verticalCenter: parent.verticalCenter}
379 text: "Loading news.."
380 horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter
381 width: parent.width; font.pixelSize: 16; elide: Text.ElideNone;
383 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
384 style: Text.Raised; styleColor: "black"
388 onNewsReloadCompleted: {
390 newsStatusMsgArea.visible = false;
391 newsViewArea.visible = true;
394 newsStatusText.text = strMessage;
395 newsViewArea.visible = false;
396 newsStatusMsgArea.visible = true;
406 id: configTickersComponent
408 ConfigTickersComponent{
409 itemHeight: mainPage.itemHeight
410 componentWidth: mainPage.componentWidth
411 onLogRequest: logUtility.logMessage(strMessage)
416 id: configParamsComponent
417 ConfigParametersComponent{
418 onLogRequest: logUtility.logMessage(strMessage)