summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
Unidiff
Diffstat (limited to 'noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp88
1 files changed, 57 insertions, 31 deletions
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
index c3ca52d..fedc79c 100644
--- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
@@ -9,114 +9,129 @@
9 * * 9 * *
10 * This program is free software; you can redistribute it and/or modify * 10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by * 11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or * 12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. * 13 * (at your option) any later version. *
14 * * 14 * *
15 ***************************************************************************/ 15 ***************************************************************************/
16 16
17#include <qlayout.h> 17#include <qlayout.h>
18 18
19#include <qpe/config.h> 19#include <qpe/config.h>
20 20
21#include <opie/oticker.h> 21#include <opie/oticker.h>
22 22
23extern "C" { 23extern "C" {
24#include "libstocks/stocks.h" 24#include "libstocks/stocks.h"
25} 25}
26 26
27#include <pthread.h> 27#include <pthread.h>
28 28
29#include "stocktickerpluginwidget.h" 29#include "stocktickerpluginwidget.h"
30 30
31QString output; 31QString output;
32OTicker *stocktickerTicker; 32OTicker *stocktickerTicker;
33 QCString stock_liste;
34 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck;
35 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck;
36 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck;
33 37
34void getStocks(char *blah) { 38void getStocks(char *blah) {
35 39
36// stocktickerTicker->setText( "Downloading stock data."); 40// stocktickerTicker->setText( "Downloading stock data.");
37 stock *stocks_quotes=NULL; 41 stock *stocks_quotes=NULL;
38 stock *stocks_tmp; 42 stock *stocks_tmp;
39 QCString stock_liste = blah; 43 stock_liste = blah;
40 ::free ( blah ); 44 ::free ( blah );
41 // char *stock_liste = (char *)blah->latin1(); 45 // char *stock_liste = (char *)blah->latin1();
42 qDebug("%s", stock_liste.data() ); 46 // qDebug("%s", stock_liste.data() );
43 QString tempString;
44 output = ""; 47 output = "";
45 48 QString tempString;
46 libstocks_return_code error; 49 libstocks_return_code error;
47 50
48 Config cfg( "stockticker"); 51// Config cfg( "stockticker");
49 cfg.setGroup( "Fields" ); 52// cfg.setGroup( "Fields" );
50 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck; 53// bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck;
51 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck; 54// bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck;
52 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck; 55// bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck;
53 56
54 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false; 57 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false;
55 58
56 dotimeCheck=cfg.readBoolEntry("timeCheck",1); 59 dotimeCheck=1;
57 dodateCheck=cfg.readBoolEntry("dateCheck",1); 60 dodateCheck=1;
58 dosymbolCheck=cfg.readBoolEntry("symbolCheck",1); 61 dosymbolCheck=1;
59 donameCheck=cfg.readBoolEntry("nameCheck",1); 62 donameCheck=1;
60 docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1); 63 docurrentPriceCheck=1;
61 dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1); 64 dolastPriceCheck=1;
62 doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1); 65 doopenPriceCheck=1;
63 dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1); 66 dominPriceCheck=1;
64 domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); 67 domaxPriceCheck=1;
65 dovariationCheck=cfg.readBoolEntry("variationCheck",1); 68 dovariationCheck=1;
66 dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); 69 dovolumeCheck=1;
70
71// dotimeCheck=cfg.readBoolEntry("timeCheck",1);
72// dodateCheck=cfg.readBoolEntry("dateCheck",1);
73// dosymbolCheck=cfg.readBoolEntry("symbolCheck",1);
74// donameCheck=cfg.readBoolEntry("nameCheck",1);
75// docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1);
76// dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1);
77// doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1);
78// dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1);
79// domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1);
80// dovariationCheck=cfg.readBoolEntry("variationCheck",1);
81// dovolumeCheck=cfg.readBoolEntry("volumeCheck",1);
67 82
68// DefProxy(); 83// DefProxy();
69 { 84 // {
70 char *proxy; 85 char *proxy;
71 libstocks_return_code error; 86 // libstocks_return_code error;
72 87
73 /* Proxy support */ 88 /* Proxy support */
74 /* Checks for "http_proxy" environment variable */ 89 /* Checks for "http_proxy" environment variable */
75 proxy = getenv("http_proxy"); 90 proxy = getenv("http_proxy");
76 if(proxy) { 91 if(proxy) {
77 /* printf("proxy set\n"); */ 92 /* printf("proxy set\n"); */
78 error = set_proxy(proxy); 93 error = set_proxy(proxy);
79 if (error) { 94 if (error) {
80 printf("Proxy error (%d)\n", error); 95// printf("Proxy error (%d)\n", error);
81 QString tempString; 96// QString tempString2;
82 tempString.sprintf("Proxy error (%d)\n", error); 97// tempString2.sprintf("Proxy error (%d)\n", error);
83 output = tempString; 98// output = tempString2;
99 // delete tempString2;
84 return; 100 return;
85// exit(1); 101// exit(1);
86 } 102 }
87 } 103 }
88 } 104 ::free(proxy);
89// char *stock_liste = (char *)blah; 105 // }
90 /* Get the stocks and process errors */ 106 /* Get the stocks and process errors */
91 error = get_stocks( stock_liste.data(), &stocks_quotes); 107 error = get_stocks( stock_liste.data(), &stocks_quotes);
92 108
93 if (error) { 109 if (error) {
94 printf("Error in getting stocks (%d)\n", error); 110 printf("Error in getting stocks (%d)\n", error);
95 tempString.sprintf("Error in getting stocks (%d)\n", error); 111 tempString.sprintf("Error in getting stocks (%d)\n", error);
96 output =tempString; 112 output =tempString;
97 return; 113 return;
98// exit(1);
99 } 114 }
100 115
101 stocks_tmp = stocks_quotes; 116 stocks_tmp = stocks_quotes;
102 117
103 /* Displays the stocks */ 118 /* Displays the stocks */
104 while(stocks_tmp!=0){ 119 while(stocks_tmp!=0){
105 120
106 if (stocks_tmp->Time) { 121 if (stocks_tmp->Time) {
107// printf("%s ", stocks_tmp->Time); 122// printf("%s ", stocks_tmp->Time);
108 tempString.sprintf("| %s ", stocks_tmp->Time); 123 tempString.sprintf("| %s ", stocks_tmp->Time);
109 tempString.replace(QRegExp("\""),""); 124 tempString.replace(QRegExp("\""),"");
110 if( dotimeCheck) 125 if( dotimeCheck)
111 output +=tempString; 126 output +=tempString;
112 } 127 }
113 if (stocks_tmp->Date) { 128 if (stocks_tmp->Date) {
114// printf("%s ", stocks_tmp->Date); 129// printf("%s ", stocks_tmp->Date);
115 tempString.sprintf("| %s ", stocks_tmp->Date); 130 tempString.sprintf("| %s ", stocks_tmp->Date);
116 tempString.replace(QRegExp("\""),""); 131 tempString.replace(QRegExp("\""),"");
117 if(dodateCheck) 132 if(dodateCheck)
118 output +=tempString; 133 output +=tempString;
119 } 134 }
120// printf("\n"); 135// printf("\n");
121 136
122// printf("----------------------------------------\n"); 137// printf("----------------------------------------\n");
@@ -178,124 +193,135 @@ void getStocks(char *blah) {
178 193
179// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice); 194// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice);
180 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice); 195 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice);
181 if(domaxPriceCheck) 196 if(domaxPriceCheck)
182 output +=tempString; 197 output +=tempString;
183 198
184// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage); 199// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage);
185 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage); 200 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage);
186 if(dovariationCheck) 201 if(dovariationCheck)
187 output +=tempString; 202 output +=tempString;
188 203
189// printf("| Volume | %-9d |\n", stocks_tmp->Volume); 204// printf("| Volume | %-9d |\n", stocks_tmp->Volume);
190 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume); 205 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume);
191 if(dovolumeCheck) 206 if(dovolumeCheck)
192 output +=tempString; 207 output +=tempString;
193 208
194// printf("----------------------------------------\n\n"); 209// printf("----------------------------------------\n\n");
195 tempString.sprintf("||==++==|"); 210 tempString.sprintf("||==++==|");
196 output +=tempString; 211 output +=tempString;
197 212
198 /* Simple function which help to browse in the stocks list */ 213 /* Simple function which help to browse in the stocks list */
199 stocks_tmp = next_stock(stocks_tmp); 214 stocks_tmp = next_stock(stocks_tmp);
200 } 215 }
201 216
217 stocktickerTicker->setText( output.latin1() );
218
202 /* frees stocks */ 219 /* frees stocks */
203 free_stocks(stocks_quotes); 220 free_stocks(stocks_quotes);
204 stocktickerTicker->setText( output.latin1() ); 221 free_stocks(stocks_tmp);
205 222
223 stock_liste="";
224 //delete stock_liste;
225 tempString="";
226 output="";
206} 227}
207 228
208StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) 229StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name)
209 : QWidget(parent, name ) { 230 : QWidget(parent, name ) {
210 init(); 231 init();
211 startTimer(1000); 232 startTimer(1000);
212 233
213 stocktickerTicker->setTextFormat(Qt::RichText); 234 stocktickerTicker->setTextFormat(Qt::RichText);
214// checkConnection(); 235// checkConnection();
215} 236}
216 237
217StockTickerPluginWidget::~StockTickerPluginWidget() { 238StockTickerPluginWidget::~StockTickerPluginWidget() {
218} 239}
219 240
220void StockTickerPluginWidget::init() { 241void StockTickerPluginWidget::init() {
221 242
222 QHBoxLayout* layout = new QHBoxLayout( this ); 243 QHBoxLayout* layout = new QHBoxLayout( this );
223 stocktickerTicker = new OTicker(this); 244 stocktickerTicker = new OTicker(this);
224// stocktickerTicker->setMinimumHeight(15); 245// stocktickerTicker->setMinimumHeight(15);
225 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() )); 246 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() ));
226 layout->addWidget( stocktickerTicker); 247 layout->addWidget( stocktickerTicker);
227 wasError = true; 248 wasError = true;
228} 249}
229 250
230void StockTickerPluginWidget::doStocks() { 251void StockTickerPluginWidget::doStocks() {
231 Config cfg( "stockticker"); 252 Config cfg( "stockticker");
232 cfg.setGroup( "Symbols" ); 253 cfg.setGroup( "Symbols" );
233 symbollist=""; 254 symbollist="";
234 symbollist = cfg.readEntry("Symbols", ""); 255 symbollist = cfg.readEntry("Symbols", "");
235 symbollist.replace(QRegExp(" "),"+");//seperated by + 256 symbollist.replace(QRegExp(" "),"+");//seperated by +
236 257
237 cfg.setGroup("Timer"); 258 cfg.setGroup("Timer");
238 stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50)); 259 stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50));
239 stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10)); 260 stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10));
240 261
241 if (!symbollist.isEmpty()) { 262 if (!symbollist.isEmpty()) {
242 pthread_t thread1; 263 pthread_t thread1;
243 char *blah = ::strdup(symbollist.latin1()); 264 char *blah = ::strdup(symbollist.latin1());
244 pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, (void *) blah); 265 pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, (void *) blah);
266 pthread_detach( thread1);
267
268 //::free((void*)thread1);
269 //getStocks(blah);
245 } 270 }
246} 271}
247 272
248void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { 273void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) {
249 killTimer(e->timerId()); 274 killTimer(e->timerId());
250 checkConnection(); 275 checkConnection();
251} 276}
252 277
253void StockTickerPluginWidget::checkConnection() { 278void StockTickerPluginWidget::checkConnection() {
254// qDebug("checking connection"); 279// qDebug("checking connection");
255// Sock = new QSocket( this ); 280// Sock = new QSocket( this );
256 281
257// if( wasError) 282// if( wasError)
258// stocktickerTicker->setText("Checking connection"); 283// stocktickerTicker->setText("Checking connection");
259 284
260// if(Sock->state() == QSocket::Idle) { 285// if(Sock->state() == QSocket::Idle) {
261// Sock->connectToHost("finance.yahoo.com", 80); 286// Sock->connectToHost("finance.yahoo.com", 80);
262// connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) ); 287// connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) );
263// connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) ); 288// connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) );
264// } else { 289// } else {
265// qDebug("State is not Idle"); 290// qDebug("State is not Idle");
266 isConnected(); 291 isConnected();
267// } 292// }
268} 293}
269 294
270void StockTickerPluginWidget::isConnected() { 295void StockTickerPluginWidget::isConnected() {
271// qDebug("We connect, so ok to grab stocks"); 296// qDebug("We connect, so ok to grab stocks");
297 if(this->isVisible())
272 doStocks(); 298 doStocks();
273 299
274 Config cfg( "stockticker"); 300 Config cfg( "stockticker");
275 cfg.setGroup("Timer"); 301 cfg.setGroup("Timer");
276 timerDelay= cfg.readNumEntry("Delay",0); 302 timerDelay= cfg.readNumEntry("Delay",0);
277 if(timerDelay > 0) 303 if(timerDelay > 0)
278 startTimer(timerDelay*60000); 304 startTimer(timerDelay*60000);
279 qDebug("timer set for %d",(timerDelay*60000)/60000); 305 // qDebug("timer set for %d",(timerDelay*60000)/60000);
280 wasError = false; 306 wasError = false;
281 307
282// Sock->close(); 308// Sock->close();
283} 309}
284 310
285void StockTickerPluginWidget::socketError(int errcode) { 311void StockTickerPluginWidget::socketError(int errcode) {
286 switch(errcode) { 312 switch(errcode) {
287 case QSocket::ErrConnectionRefused: 313 case QSocket::ErrConnectionRefused:
288 output = tr("Connection refused."); 314 output = tr("Connection refused.");
289 break; 315 break;
290 case QSocket::ErrHostNotFound: 316 case QSocket::ErrHostNotFound:
291 output = tr("Could not find server."); 317 output = tr("Could not find server.");
292 break; 318 break;
293 case QSocket::ErrSocketRead : 319 case QSocket::ErrSocketRead :
294 output = tr("Socket read error."); 320 output = tr("Socket read error.");
295 break; 321 break;
296 }; 322 };
297 stocktickerTicker->setText( output ); 323 stocktickerTicker->setText( output );
298 wasError = true; 324 wasError = true;
299// Sock->close(); 325// Sock->close();
300 326
301} 327}