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/Common.js" as Common
13 import "Library/js/CoreLogic.js" as CoreLib
18 signal showConfigInNewWindow
19 signal showStockDetails(string strSymbol)
20 signal quoteRefreshStarted
21 signal quoteRefreshCompleted
22 signal quoteRefreshFailed(string strMessage)
23 signal checkNetworkStatus
25 property int itemHeight: 50
26 property int titleBarHeight: 60
27 property int toolBarHeight: 40
28 property int componentWidth: mainPage.width
29 property int autoUpdateInterval: 300000
30 property bool updateWeekDaysOnly: false
31 property bool updateOnSavedNetworksOnly: false
32 property string rssURL: "http://finance.yahoo.com/rss/topfinstories"
33 property string lastUpdatedTimeStamp
34 property bool isDesktopWidget
35 //property string selectedSymbol:"YHOO"
36 property string selectedSymbol:sharedContext.getStockSymbol()
38 function reloadData(){
39 CoreLib.reloadQuotes();
43 function initialize(){
44 var componentToDisplay = sharedContext.getComponentToDisplay();
45 if (componentToDisplay === "StockQuoteDetails"){
46 uiLoader.sourceComponent = stockDetailsComponent;
47 titleBar.buttonType = "Close";
48 titleBar.displayMenu = false;
49 toolBar.displayIcons = false;
52 DBUtility.initialize();
54 uiLoader.sourceComponent = stockQuotesUIComponent;
58 Component.onCompleted: {
64 interval: autoUpdateInterval
65 //running: (autoUpdateInterval == 0? false:true)
68 if (!updateWeekDaysOnly){
69 logUtility.logMessage("Allowed to update all days of the week");
70 mainPage.reloadData();
71 //checkNetworkStatus();
73 else if (Common.isTodayAWeekDay()){
74 logUtility.logMessage("Today is a weekday");
75 mainPage.reloadData();
76 //checkNetworkStatus();
79 logUtility.logMessage("Update not triggered: Today is not a weekday");
85 id: stockQuoteDataModel
99 id: stockQuotesDelegate
102 id: wrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
104 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: wrapper.height - 2; width: wrapper.width; y: 1
110 anchors {right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter}
112 source: "Library/images/information.png"
114 anchors.fill: parent;
116 //console.log("Image clicked");
117 mainPage.selectedSymbol = symbol;
118 uiLoader.sourceComponent = stockDetailsComponent;
119 titleBar.buttonType = "Back";
120 titleBar.displayMenu = false;
121 toolBar.displayIcons = false;
129 informationIcon.visible = true;
130 //console.log("Rectangle clicked");
137 width: mainPage.componentWidth - 60;
140 Text { text: stockName; width: parent.width * 30/100; font.pixelSize: 18; font.bold: true; elide: Text.ElideRight; color: "white"; style: Text.Raised; styleColor: "black" }
141 Text { text: lastTradedPrice; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
142 Text { text: change !== ""? (change + " ("+changePercentage+")"):""; width: parent.width * 25/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideRight
143 color: if(change >= 0){"green";} else {"red";}
144 style: Text.Raised; styleColor: "black" }
145 Text { text: volume; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
146 Text { text: marketCap; width: parent.width * 15/100; font.pixelSize: 18; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "#cccccc"; style: Text.Raised; styleColor: "black" }
156 id: newsWrapper; width: mainPage.componentWidth; height: mainPage.itemHeight
159 Rectangle { color: "black"; opacity: index % 2 ? 0.2 : 0.4; height: newsWrapper.height - 2; width: newsWrapper.width; y: 1 }
161 anchors.verticalCenter: parent.verticalCenter
162 anchors.left: parent.left
163 anchors.leftMargin: 10
164 anchors.right: parent.right
165 text: title; font.pixelSize: 18
167 verticalAlignment: Text.AlignVCenter
168 horizontalAlignment: Text.AlignLeft
169 elide: Text.ElideRight;
176 onClicked: Qt.openUrlExternally(link);
184 width: parent.width; height: mainPage.titleBarHeight;
185 anchors.top: parent.top
186 title: "Markets Today";
188 z: 5 //required to keep Titlebar and Menu buttons on top of everything else
190 onCloseClicked: Qt.quit()
193 uiLoader.sourceComponent = configTickersComponent;
194 titleBar.buttonType = "Back";
195 titleBar.displayMenu = false;
196 toolBar.displayIcons = false;
200 uiLoader.sourceComponent = configParamsComponent;
201 titleBar.buttonType = "Back";
202 titleBar.displayMenu = false;
203 toolBar.displayIcons = false;
207 uiLoader.sourceComponent = stockQuotesUIComponent;
208 titleBar.buttonType = "Close";
209 titleBar.displayMenu = false;
210 toolBar.displayIcons = true;
211 mainPage.initialize();
218 anchors.top: titleBar.bottom
219 anchors.bottom: toolBar.top
224 width: parent.width; height: mainPage.toolBarHeight
225 anchors.bottom: parent.bottom
227 displayNavigation: false
228 onReloadButtonClicked: mainPage.reloadData();
230 onNewsButtonClicked: {
231 uiLoader.sourceComponent = newsComponent;
232 toolBar.displayIcons = true;
233 toolBar.targetContentType = "Stocks";
236 onStocksButtonClicked: {
237 uiLoader.sourceComponent = stockQuotesUIComponent;
238 toolBar.displayIcons = true;
239 toolBar.targetContentType = "News";
245 onQuoteRefreshStarted:{
246 if (!toolBar.updatePending) toolBar.updatePending = true;
248 onQuoteRefreshCompleted:{
249 toolBar.updatePending = false;
257 id: stockQuotesUIComponent
262 anchors.top: parent.top
263 anchors.bottom: footerText.top
269 flickDeceleration: 500
270 model: stockQuoteDataModel
271 delegate: stockQuotesDelegate
273 snapMode: ListView.SnapToItem
282 anchors.bottom: parent.bottom
286 text: mainPage.lastUpdatedTimeStamp
287 horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
288 width: parent.width; font.pixelSize: 12; elide: Text.ElideRight;
290 style: Text.Raised; styleColor: "black"
294 onQuoteRefreshCompleted:{
295 timeStamp.text = mainPage.lastUpdatedTimeStamp;
304 id: stockDetailsComponent
305 StockDetailsComponent {
306 symbol: selectedSymbol
307 onLogRequest: logUtility.logMessage(strMessage)
316 anchors.top: parent.top
317 anchors.bottom: parent.bottom
323 flickDeceleration: 500
325 delegate: newsDelegate
327 snapMode: ListView.SnapToItem
334 id: configTickersComponent
336 ConfigTickersComponent{
337 itemHeight: mainPage.itemHeight
338 componentWidth: mainPage.componentWidth
339 onLogRequest: logUtility.logMessage(strMessage)
344 id: configParamsComponent
345 ConfigParametersComponent{
346 onLogRequest: logUtility.logMessage(strMessage)