author | sandman <sandman> | 2002-12-18 18:59:05 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-12-18 18:59:05 (UTC) |
commit | 7f98b97ff4b112ddc7025b34649a4ed331b37548 (patch) (unidiff) | |
tree | 8deb6016e20ad84b99b5bf2a65cbac332e4b9e1c | |
parent | 25dfde78e47780c3357f8e25d8c873131fbf446d (diff) | |
download | opie-7f98b97ff4b112ddc7025b34649a4ed331b37548.zip opie-7f98b97ff4b112ddc7025b34649a4ed331b37548.tar.gz opie-7f98b97ff4b112ddc7025b34649a4ed331b37548.tar.bz2 |
Parameter passing to the thread reworked a bit
-rw-r--r-- | noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp index 5ddf03c..a740b58 100644 --- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp +++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp | |||
@@ -23,105 +23,106 @@ | |||
23 | #include <qlayout.h> | 23 | #include <qlayout.h> |
24 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | 28 | ||
29 | #include <qpe/config.h> | 29 | #include <qpe/config.h> |
30 | #include <qpe/timestring.h> | 30 | #include <qpe/timestring.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | #include <qpe/network.h> | 32 | #include <qpe/network.h> |
33 | 33 | ||
34 | #include <opie/oticker.h> | 34 | #include <opie/oticker.h> |
35 | 35 | ||
36 | extern "C" { | 36 | extern "C" { |
37 | #include "libstocks/stocks.h" | 37 | #include "libstocks/stocks.h" |
38 | } | 38 | } |
39 | 39 | ||
40 | #include <pthread.h> | 40 | #include <pthread.h> |
41 | 41 | ||
42 | #include "stocktickerpluginwidget.h" | 42 | #include "stocktickerpluginwidget.h" |
43 | 43 | ||
44 | QString output; | 44 | QString output; |
45 | OTicker *stocktickerTicker; | 45 | OTicker *stocktickerTicker; |
46 | 46 | ||
47 | void getStocks( const char *blah) { | 47 | void getStocks(char *blah) { |
48 | 48 | ||
49 | // stocktickerTicker->setText( "Downloading stock data."); | 49 | // stocktickerTicker->setText( "Downloading stock data."); |
50 | stock *stocks_quotes=NULL; | 50 | stock *stocks_quotes=NULL; |
51 | stock *stocks_tmp; | 51 | stock *stocks_tmp; |
52 | char *stock_liste = blah; | 52 | QCString stock_liste = blah; |
53 | ::free ( blah ); | ||
53 | // char *stock_liste = (char *)blah->latin1(); | 54 | // char *stock_liste = (char *)blah->latin1(); |
54 | qDebug("%s", stock_liste ); | 55 | qDebug("%s", stock_liste.data() ); |
55 | QString tempString; | 56 | QString tempString; |
56 | output = ""; | 57 | output = ""; |
57 | 58 | ||
58 | libstocks_return_code error; | 59 | libstocks_return_code error; |
59 | 60 | ||
60 | Config cfg( "stockticker"); | 61 | Config cfg( "stockticker"); |
61 | cfg.setGroup( "Fields" ); | 62 | cfg.setGroup( "Fields" ); |
62 | bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck; | 63 | bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck; |
63 | bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck; | 64 | bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck; |
64 | bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck; | 65 | bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck; |
65 | 66 | ||
66 | dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false; | 67 | dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false; |
67 | 68 | ||
68 | dotimeCheck=cfg.readBoolEntry("timeCheck",1); | 69 | dotimeCheck=cfg.readBoolEntry("timeCheck",1); |
69 | dodateCheck=cfg.readBoolEntry("dateCheck",1); | 70 | dodateCheck=cfg.readBoolEntry("dateCheck",1); |
70 | dosymbolCheck=cfg.readBoolEntry("symbolCheck",1); | 71 | dosymbolCheck=cfg.readBoolEntry("symbolCheck",1); |
71 | donameCheck=cfg.readBoolEntry("nameCheck",1); | 72 | donameCheck=cfg.readBoolEntry("nameCheck",1); |
72 | docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1); | 73 | docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1); |
73 | dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1); | 74 | dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1); |
74 | doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1); | 75 | doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1); |
75 | dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1); | 76 | dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1); |
76 | domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); | 77 | domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); |
77 | dovariationCheck=cfg.readBoolEntry("variationCheck",1); | 78 | dovariationCheck=cfg.readBoolEntry("variationCheck",1); |
78 | dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); | 79 | dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); |
79 | 80 | ||
80 | // DefProxy(); | 81 | // DefProxy(); |
81 | { | 82 | { |
82 | char *proxy; | 83 | char *proxy; |
83 | libstocks_return_code error; | 84 | libstocks_return_code error; |
84 | 85 | ||
85 | /* Proxy support */ | 86 | /* Proxy support */ |
86 | /* Checks for "http_proxy" environment variable */ | 87 | /* Checks for "http_proxy" environment variable */ |
87 | proxy = getenv("http_proxy"); | 88 | proxy = getenv("http_proxy"); |
88 | if(proxy) { | 89 | if(proxy) { |
89 | /* printf("proxy set\n"); */ | 90 | /* printf("proxy set\n"); */ |
90 | error = set_proxy(proxy); | 91 | error = set_proxy(proxy); |
91 | if (error) { | 92 | if (error) { |
92 | printf("Proxy error (%d)\n", error); | 93 | printf("Proxy error (%d)\n", error); |
93 | QString tempString; | 94 | QString tempString; |
94 | tempString.sprintf("Proxy error (%d)\n", error); | 95 | tempString.sprintf("Proxy error (%d)\n", error); |
95 | output = tempString; | 96 | output = tempString; |
96 | return; | 97 | return; |
97 | // exit(1); | 98 | // exit(1); |
98 | } | 99 | } |
99 | } | 100 | } |
100 | } | 101 | } |
101 | // char *stock_liste = (char *)blah; | 102 | // char *stock_liste = (char *)blah; |
102 | /* Get the stocks and process errors */ | 103 | /* Get the stocks and process errors */ |
103 | error = get_stocks( stock_liste, &stocks_quotes); | 104 | error = get_stocks( stock_liste.data(), &stocks_quotes); |
104 | 105 | ||
105 | if (error) { | 106 | if (error) { |
106 | printf("Error in getting stocks (%d)\n", error); | 107 | printf("Error in getting stocks (%d)\n", error); |
107 | tempString.sprintf("Error in getting stocks (%d)\n", error); | 108 | tempString.sprintf("Error in getting stocks (%d)\n", error); |
108 | output =tempString; | 109 | output =tempString; |
109 | return; | 110 | return; |
110 | // exit(1); | 111 | // exit(1); |
111 | } | 112 | } |
112 | 113 | ||
113 | stocks_tmp = stocks_quotes; | 114 | stocks_tmp = stocks_quotes; |
114 | 115 | ||
115 | /* Displays the stocks */ | 116 | /* Displays the stocks */ |
116 | while(stocks_tmp!=0){ | 117 | while(stocks_tmp!=0){ |
117 | 118 | ||
118 | if (stocks_tmp->Time) { | 119 | if (stocks_tmp->Time) { |
119 | // printf("%s ", stocks_tmp->Time); | 120 | // printf("%s ", stocks_tmp->Time); |
120 | tempString.sprintf("| %s ", stocks_tmp->Time); | 121 | tempString.sprintf("| %s ", stocks_tmp->Time); |
121 | tempString.replace(QRegExp("\""),""); | 122 | tempString.replace(QRegExp("\""),""); |
122 | if( dotimeCheck) | 123 | if( dotimeCheck) |
123 | output +=tempString; | 124 | output +=tempString; |
124 | } | 125 | } |
125 | if (stocks_tmp->Date) { | 126 | if (stocks_tmp->Date) { |
126 | // printf("%s ", stocks_tmp->Date); | 127 | // printf("%s ", stocks_tmp->Date); |
127 | tempString.sprintf("| %s ", stocks_tmp->Date); | 128 | tempString.sprintf("| %s ", stocks_tmp->Date); |
@@ -231,50 +232,50 @@ StockTickerPluginWidget::~StockTickerPluginWidget() { | |||
231 | 232 | ||
232 | void StockTickerPluginWidget::init() { | 233 | void StockTickerPluginWidget::init() { |
233 | 234 | ||
234 | QHBoxLayout* layout = new QHBoxLayout( this ); | 235 | QHBoxLayout* layout = new QHBoxLayout( this ); |
235 | stocktickerTicker = new OTicker(this); | 236 | stocktickerTicker = new OTicker(this); |
236 | // stocktickerTicker->setMinimumHeight(15); | 237 | // stocktickerTicker->setMinimumHeight(15); |
237 | connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() )); | 238 | connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() )); |
238 | layout->addWidget( stocktickerTicker); | 239 | layout->addWidget( stocktickerTicker); |
239 | wasError = true; | 240 | wasError = true; |
240 | } | 241 | } |
241 | 242 | ||
242 | void StockTickerPluginWidget::doStocks() { | 243 | void StockTickerPluginWidget::doStocks() { |
243 | Config cfg( "stockticker"); | 244 | Config cfg( "stockticker"); |
244 | cfg.setGroup( "Symbols" ); | 245 | cfg.setGroup( "Symbols" ); |
245 | symbollist=""; | 246 | symbollist=""; |
246 | symbollist = cfg.readEntry("Symbols", ""); | 247 | symbollist = cfg.readEntry("Symbols", ""); |
247 | symbollist.replace(QRegExp(" "),"+");//seperated by + | 248 | symbollist.replace(QRegExp(" "),"+");//seperated by + |
248 | 249 | ||
249 | cfg.setGroup("Timer"); | 250 | cfg.setGroup("Timer"); |
250 | stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50)); | 251 | stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50)); |
251 | stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10)); | 252 | stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10)); |
252 | 253 | ||
253 | if (!symbollist.isEmpty()) { | 254 | if (!symbollist.isEmpty()) { |
254 | pthread_t thread1; | 255 | pthread_t thread1; |
255 | char *blah = symbollist.latin1(); | 256 | char *blah = ::strdup(symbollist.latin1()); |
256 | pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, blah); | 257 | pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, (void *) blah); |
257 | } | 258 | } |
258 | } | 259 | } |
259 | 260 | ||
260 | void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { | 261 | void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { |
261 | killTimer(e->timerId()); | 262 | killTimer(e->timerId()); |
262 | checkConnection(); | 263 | checkConnection(); |
263 | } | 264 | } |
264 | 265 | ||
265 | void StockTickerPluginWidget::checkConnection() { | 266 | void StockTickerPluginWidget::checkConnection() { |
266 | // qDebug("checking connection"); | 267 | // qDebug("checking connection"); |
267 | // Sock = new QSocket( this ); | 268 | // Sock = new QSocket( this ); |
268 | 269 | ||
269 | // if( wasError) | 270 | // if( wasError) |
270 | // stocktickerTicker->setText("Checking connection"); | 271 | // stocktickerTicker->setText("Checking connection"); |
271 | 272 | ||
272 | // if(Sock->state() == QSocket::Idle) { | 273 | // if(Sock->state() == QSocket::Idle) { |
273 | // Sock->connectToHost("finance.yahoo.com", 80); | 274 | // Sock->connectToHost("finance.yahoo.com", 80); |
274 | // connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) ); | 275 | // connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) ); |
275 | // connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) ); | 276 | // connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) ); |
276 | // } else { | 277 | // } else { |
277 | // qDebug("State is not Idle"); | 278 | // qDebug("State is not Idle"); |
278 | isConnected(); | 279 | isConnected(); |
279 | // } | 280 | // } |
280 | } | 281 | } |