3 files changed, 142 insertions, 71 deletions
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro index 4b7b177..13c846b 100644 --- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro +++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro | |||
@@ -19,9 +19,9 @@ INCLUDEPATH += $(OPIEDIR)/include \ | |||
19 | ../ ../library | 19 | ../ ../library |
20 | DEPENDPATH += $(OPIEDIR)/include \ | 20 | DEPENDPATH += $(OPIEDIR)/include \ |
21 | ../ ../library | 21 | ../ ../library |
22 | 22 | ||
23 | LIBS+= -lqpe -lopie | 23 | LIBS+= -lqpe -lopie -lpthread |
24 | TMAKE_CFLAGS += -D__UNIX__ | 24 | TMAKE_CFLAGS += -D__UNIX__ |
25 | 25 | ||
26 | DESTDIR = $(OPIEDIR)/plugins/today | 26 | DESTDIR = $(OPIEDIR)/plugins/today |
27 | TARGET = todaystocktickerplugin | 27 | TARGET = todaystocktickerplugin |
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp index 8830472..572a720 100644 --- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp +++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp | |||
@@ -13,8 +13,9 @@ | |||
13 | * (at your option) any later version. * | 13 | * (at your option) any later version. * |
14 | * * | 14 | * * |
15 | ***************************************************************************/ | 15 | ***************************************************************************/ |
16 | 16 | ||
17 | #include <qsocket.h> | ||
17 | #include <qvaluelist.h> | 18 | #include <qvaluelist.h> |
18 | #include <qtl.h> | 19 | #include <qtl.h> |
19 | #include <qstring.h> | 20 | #include <qstring.h> |
20 | #include <qstringlist.h> | 21 | #include <qstringlist.h> |
@@ -22,61 +23,34 @@ | |||
22 | #include <qlayout.h> | 23 | #include <qlayout.h> |
23 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
24 | #include <qregexp.h> | 25 | #include <qregexp.h> |
25 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include <qmessagebox.h> | ||
26 | 28 | ||
27 | #include <qpe/config.h> | 29 | #include <qpe/config.h> |
28 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
29 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | #include <qpe/network.h> | ||
30 | 33 | ||
31 | #include <opie/oticker.h> | 34 | #include <opie/oticker.h> |
32 | //#include "ticker.h" | ||
33 | 35 | ||
34 | extern "C" { | 36 | extern "C" { |
35 | #include "libstocks/stocks.h" | 37 | #include "libstocks/stocks.h" |
36 | } | 38 | } |
37 | 39 | ||
38 | #include "stocktickerpluginwidget.h" | 40 | #include <pthread.h> |
39 | |||
40 | StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) | ||
41 | : QWidget(parent, name ) { | ||
42 | init(); | ||
43 | startTimer(1000); | ||
44 | } | ||
45 | |||
46 | StockTickerPluginWidget::~StockTickerPluginWidget() { | ||
47 | } | ||
48 | 41 | ||
49 | void StockTickerPluginWidget::init() { | 42 | #include "stocktickerpluginwidget.h" |
50 | |||
51 | QHBoxLayout* layout = new QHBoxLayout( this ); | ||
52 | |||
53 | stocktickerTicker = new OTicker(this); | ||
54 | stocktickerTicker->setMinimumHeight(15); | ||
55 | connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( doStocks() )); | ||
56 | |||
57 | layout->addWidget( stocktickerTicker); | ||
58 | |||
59 | } | ||
60 | |||
61 | void StockTickerPluginWidget::doStocks() { | ||
62 | Config cfg( "stockticker"); | ||
63 | cfg.setGroup( "Symbols" ); | ||
64 | QString symbollist; | ||
65 | symbollist = cfg.readEntry("Symbols", ""); | ||
66 | symbollist.replace(QRegExp(" "),"+");//seperated by + | ||
67 | // qDebug(symbollist); | ||
68 | 43 | ||
69 | getStocks( symbollist.latin1()); | 44 | QString output; |
70 | 45 | OTicker *stocktickerTicker; | |
71 | stocktickerTicker->setText( output ); | ||
72 | } | ||
73 | 46 | ||
74 | void StockTickerPluginWidget::getStocks( const char *blah) { | 47 | void getStocks( const QString *blah) { |
75 | 48 | ||
49 | // stocktickerTicker->setText( "Downloading stock data."); | ||
76 | stock *stocks_quotes=NULL; | 50 | stock *stocks_quotes=NULL; |
77 | stock *stocks_tmp; | 51 | stock *stocks_tmp; |
78 | 52 | qDebug("%s", blah->latin1()); | |
79 | QString tempString; | 53 | QString tempString; |
80 | output = ""; | 54 | output = ""; |
81 | 55 | ||
82 | libstocks_return_code error; | 56 | libstocks_return_code error; |
@@ -100,10 +74,31 @@ void StockTickerPluginWidget::getStocks( const char *blah) { | |||
100 | domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); | 74 | domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); |
101 | dovariationCheck=cfg.readBoolEntry("variationCheck",1); | 75 | dovariationCheck=cfg.readBoolEntry("variationCheck",1); |
102 | dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); | 76 | dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); |
103 | 77 | ||
104 | DefProxy(); | 78 | // DefProxy(); |
105 | char *stock_liste = (char *)blah; | 79 | { |
80 | char *proxy; | ||
81 | libstocks_return_code error; | ||
82 | |||
83 | /* Proxy support */ | ||
84 | /* Checks for "http_proxy" environment variable */ | ||
85 | proxy = getenv("http_proxy"); | ||
86 | if(proxy) { | ||
87 | /* printf("proxy set\n"); */ | ||
88 | error = set_proxy(proxy); | ||
89 | if (error) { | ||
90 | printf("Proxy error (%d)\n", error); | ||
91 | QString tempString; | ||
92 | tempString.sprintf("Proxy error (%d)\n", error); | ||
93 | output = tempString; | ||
94 | return; | ||
95 | // exit(1); | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | char *stock_liste = (char *)blah->latin1(); | ||
100 | // char *stock_liste = (char *)blah; | ||
106 | /* Get the stocks and process errors */ | 101 | /* Get the stocks and process errors */ |
107 | error = get_stocks( stock_liste, &stocks_quotes); | 102 | error = get_stocks( stock_liste, &stocks_quotes); |
108 | 103 | ||
109 | if (error) { | 104 | if (error) { |
@@ -216,39 +211,119 @@ void StockTickerPluginWidget::getStocks( const char *blah) { | |||
216 | } | 211 | } |
217 | 212 | ||
218 | /* frees stocks */ | 213 | /* frees stocks */ |
219 | free_stocks(stocks_quotes); | 214 | free_stocks(stocks_quotes); |
215 | stocktickerTicker->setText( output ); | ||
220 | 216 | ||
221 | } | 217 | } |
222 | 218 | ||
223 | void StockTickerPluginWidget::DefProxy(void) { | 219 | StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) |
224 | char *proxy; | 220 | : QWidget(parent, name ) { |
225 | libstocks_return_code error; | 221 | init(); |
222 | startTimer(1000); | ||
223 | // checkConnection(); | ||
224 | } | ||
226 | 225 | ||
227 | /* Proxy support */ | 226 | StockTickerPluginWidget::~StockTickerPluginWidget() { |
228 | /* Checks for "http_proxy" environment variable */ | 227 | } |
229 | proxy = getenv("http_proxy"); | 228 | |
230 | if(proxy) { | 229 | void StockTickerPluginWidget::init() { |
231 | /* printf("proxy set\n"); */ | 230 | |
232 | error = set_proxy(proxy); | 231 | QHBoxLayout* layout = new QHBoxLayout( this ); |
233 | if (error) { | 232 | stocktickerTicker = new OTicker(this); |
234 | // printf("Proxy error (%d)\n", error); | 233 | stocktickerTicker->setMinimumHeight(15); |
235 | QString tempString; | 234 | connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() )); |
236 | tempString.sprintf("Proxy error (%d)\n", error); | 235 | layout->addWidget( stocktickerTicker); |
237 | output = tempString; | 236 | wasError = true; |
238 | return; | 237 | } |
239 | // exit(1); | 238 | |
240 | } | 239 | void StockTickerPluginWidget::doStocks() { |
240 | Config cfg( "stockticker"); | ||
241 | cfg.setGroup( "Symbols" ); | ||
242 | QString symbollist; | ||
243 | symbollist = cfg.readEntry("Symbols", ""); | ||
244 | symbollist.replace(QRegExp(" "),"+");//seperated by + | ||
245 | |||
246 | // qDebug(symbollist); | ||
247 | if (!symbollist.isEmpty()) { | ||
248 | pthread_t thread1; | ||
249 | pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, &symbollist); | ||
241 | } | 250 | } |
251 | // pthread_join(thread1,NULL); | ||
252 | // getStocks( symbollist.latin1() ); | ||
253 | } | ||
254 | |||
255 | void StockTickerPluginWidget::DefProxy(void) { | ||
256 | // char *proxy; | ||
257 | // libstocks_return_code error; | ||
258 | |||
259 | // /* Proxy support */ | ||
260 | // /* Checks for "http_proxy" environment variable */ | ||
261 | // proxy = getenv("http_proxy"); | ||
262 | // if(proxy) { | ||
263 | // /* printf("proxy set\n"); */ | ||
264 | // error = set_proxy(proxy); | ||
265 | // if (error) { | ||
266 | // // printf("Proxy error (%d)\n", error); | ||
267 | // QString tempString; | ||
268 | // tempString.sprintf("Proxy error (%d)\n", error); | ||
269 | // output = tempString; | ||
270 | // return; | ||
271 | // // exit(1); | ||
272 | // } | ||
273 | // } | ||
274 | } | ||
275 | |||
276 | void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { | ||
277 | killTimer(e->timerId()); | ||
278 | checkConnection(); | ||
279 | } | ||
280 | |||
281 | void StockTickerPluginWidget::checkConnection() { | ||
282 | // qDebug("checking connection"); | ||
283 | // Sock = new QSocket( this ); | ||
284 | |||
285 | // if( wasError) | ||
286 | // stocktickerTicker->setText("Checking connection"); | ||
287 | |||
288 | // if(Sock->state() == QSocket::Idle) { | ||
289 | // Sock->connectToHost("finance.yahoo.com", 80); | ||
290 | // connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) ); | ||
291 | // connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) ); | ||
292 | // } else { | ||
293 | // qDebug("State is not Idle"); | ||
294 | isConnected(); | ||
295 | // } | ||
242 | } | 296 | } |
243 | 297 | ||
244 | void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { | 298 | void StockTickerPluginWidget::isConnected() { |
245 | killTimer(e->timerId()); | 299 | // qDebug("We connect, so ok to grab stocks"); |
246 | doStocks(); | 300 | doStocks(); |
301 | |||
247 | Config cfg( "stockticker"); | 302 | Config cfg( "stockticker"); |
248 | cfg.setGroup("Timer"); | 303 | cfg.setGroup("Timer"); |
249 | timerDelay= cfg.readNumEntry("Delay",0); | 304 | timerDelay= cfg.readNumEntry("Delay",0); |
250 | if(timerDelay > 0) | 305 | if(timerDelay > 0) |
251 | startTimer(timerDelay*60000); | 306 | startTimer(timerDelay*60000); |
252 | qDebug("timer set for %d",(timerDelay*60000)/60000); | 307 | qDebug("timer set for %d",(timerDelay*60000)/60000); |
253 | 308 | wasError = false; | |
309 | |||
310 | // Sock->close(); | ||
311 | } | ||
312 | |||
313 | void StockTickerPluginWidget::socketError(int errcode) { | ||
314 | switch(errcode) { | ||
315 | case QSocket::ErrConnectionRefused: | ||
316 | output = tr("Connection refused."); | ||
317 | break; | ||
318 | case QSocket::ErrHostNotFound: | ||
319 | output = tr("Could not find server."); | ||
320 | break; | ||
321 | case QSocket::ErrSocketRead : | ||
322 | output = tr("Socket read error."); | ||
323 | break; | ||
324 | }; | ||
325 | stocktickerTicker->setText( output ); | ||
326 | wasError = true; | ||
327 | // Sock->close(); | ||
328 | |||
254 | } | 329 | } |
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h index 26472fa..c8de806 100644 --- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h +++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h | |||
@@ -17,8 +17,9 @@ | |||
17 | 17 | ||
18 | #ifndef STOCKTICKERL_PLUGIN_WIDGET_H | 18 | #ifndef STOCKTICKERL_PLUGIN_WIDGET_H |
19 | #define STOCKTICKERL_PLUGIN_WIDGET_H | 19 | #define STOCKTICKERL_PLUGIN_WIDGET_H |
20 | 20 | ||
21 | #include <qsocket.h> | ||
21 | #include <qstring.h> | 22 | #include <qstring.h> |
22 | #include <qwidget.h> | 23 | #include <qwidget.h> |
23 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
24 | 25 | ||
@@ -32,14 +33,8 @@ | |||
32 | #include <stdio.h> | 33 | #include <stdio.h> |
33 | #include <stdlib.h> | 34 | #include <stdlib.h> |
34 | #include <string.h> | 35 | #include <string.h> |
35 | 36 | ||
36 | //#include "ticker.h" | ||
37 | |||
38 | /* extern "C" { */ | ||
39 | /* #include "stocks.h" */ | ||
40 | /* } */ | ||
41 | |||
42 | class QTimer; | 37 | class QTimer; |
43 | 38 | ||
44 | class StockTickerPluginWidget : public QWidget { | 39 | class StockTickerPluginWidget : public QWidget { |
45 | 40 | ||
@@ -47,18 +42,19 @@ class StockTickerPluginWidget : public QWidget { | |||
47 | 42 | ||
48 | public: | 43 | public: |
49 | StockTickerPluginWidget( QWidget *parent, const char *name ); | 44 | StockTickerPluginWidget( QWidget *parent, const char *name ); |
50 | ~StockTickerPluginWidget(); | 45 | ~StockTickerPluginWidget(); |
51 | QString output; | ||
52 | 46 | ||
53 | protected slots: | 47 | protected slots: |
54 | void doStocks(); | 48 | void doStocks(); |
55 | 49 | void isConnected(); | |
50 | void socketError(int); | ||
51 | void checkConnection(); | ||
56 | private: | 52 | private: |
57 | OTicker *stocktickerTicker; | 53 | bool wasError; |
54 | QSocket *Sock; | ||
58 | void timerEvent( QTimerEvent * ); | 55 | void timerEvent( QTimerEvent * ); |
59 | void init(); | 56 | void init(); |
60 | void getStocks( const char *stock_liste); | ||
61 | void DefProxy(void); | 57 | void DefProxy(void); |
62 | int timerDelay; | 58 | int timerDelay; |
63 | }; | 59 | }; |
64 | 60 | ||