summaryrefslogtreecommitdiff
path: root/noncore
authorllornkcor <llornkcor>2002-11-05 01:10:38 (UTC)
committer llornkcor <llornkcor>2002-11-05 01:10:38 (UTC)
commit9ac6d0a443c417158e3f2acf2de0629c51b6511c (patch) (unidiff)
treee9791e964d950a49c43b05459e0710b5aa8d5dae /noncore
parent4efdcbfa9ae55ba42b10b5003c9e524b2e1f0eef (diff)
downloadopie-9ac6d0a443c417158e3f2acf2de0629c51b6511c.zip
opie-9ac6d0a443c417158e3f2acf2de0629c51b6511c.tar.gz
opie-9ac6d0a443c417158e3f2acf2de0629c51b6511c.tar.bz2
pthread stuff.
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro2
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp195
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h16
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
@@ -20,7 +20,7 @@ INCLUDEPATH += $(OPIEDIR)/include \
20DEPENDPATH += $(OPIEDIR)/include \ 20DEPENDPATH += $(OPIEDIR)/include \
21 ../ ../library 21 ../ ../library
22 22
23LIBS+= -lqpe -lopie 23LIBS+= -lqpe -lopie -lpthread
24TMAKE_CFLAGS += -D__UNIX__ 24TMAKE_CFLAGS += -D__UNIX__
25 25
26DESTDIR = $(OPIEDIR)/plugins/today 26DESTDIR = $(OPIEDIR)/plugins/today
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
@@ -14,6 +14,7 @@
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>
@@ -23,59 +24,32 @@
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
34extern "C" { 36extern "C" {
35#include "libstocks/stocks.h" 37#include "libstocks/stocks.h"
36} 38}
37 39
38#include "stocktickerpluginwidget.h" 40#include <pthread.h>
39
40StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name)
41 : QWidget(parent, name ) {
42 init();
43 startTimer(1000);
44}
45
46StockTickerPluginWidget::~StockTickerPluginWidget() {
47}
48 41
49void 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
61void 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()); 44QString output;
70 45OTicker *stocktickerTicker;
71 stocktickerTicker->setText( output );
72}
73 46
74void StockTickerPluginWidget::getStocks( const char *blah) { 47void 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
@@ -101,8 +75,29 @@ void StockTickerPluginWidget::getStocks( const char *blah) {
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
@@ -217,38 +212,118 @@ void StockTickerPluginWidget::getStocks( const char *blah) {
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
223void StockTickerPluginWidget::DefProxy(void) { 219StockTickerPluginWidget::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 */ 226StockTickerPluginWidget::~StockTickerPluginWidget() {
228 /* Checks for "http_proxy" environment variable */ 227}
229 proxy = getenv("http_proxy"); 228
230 if(proxy) { 229void 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 } 239void 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
255void 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
276void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) {
277 killTimer(e->timerId());
278 checkConnection();
279}
280
281void 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
244void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { 298void 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
313void 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
@@ -18,6 +18,7 @@
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>
@@ -33,12 +34,6 @@
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
42class QTimer; 37class QTimer;
43 38
44class StockTickerPluginWidget : public QWidget { 39class StockTickerPluginWidget : public QWidget {
@@ -48,16 +43,17 @@ class StockTickerPluginWidget : public QWidget {
48public: 43public:
49 StockTickerPluginWidget( QWidget *parent, const char *name ); 44 StockTickerPluginWidget( QWidget *parent, const char *name );
50 ~StockTickerPluginWidget(); 45 ~StockTickerPluginWidget();
51 QString output;
52 46
53protected slots: 47protected slots:
54 void doStocks(); 48 void doStocks();
55 49 void isConnected();
50 void socketError(int);
51 void checkConnection();
56private: 52private:
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};