summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-20 16:53:04 (UTC)
committer llornkcor <llornkcor>2002-11-20 16:53:04 (UTC)
commit95f1c2be3c6de39935f0b0b8ac19046c5ef29fb5 (patch) (unidiff)
tree4cc9020584b4c377f7bdf6210f40b6a18c451628
parentf028217d1bae612e6e88b34f640e4fe4dd020a5a (diff)
downloadopie-95f1c2be3c6de39935f0b0b8ac19046c5ef29fb5.zip
opie-95f1c2be3c6de39935f0b0b8ac19046c5ef29fb5.tar.gz
opie-95f1c2be3c6de39935f0b0b8ac19046c5ef29fb5.tar.bz2
simpler char * to thread
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
index 0d90d0f..5ddf03c 100644
--- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
@@ -1,147 +1,148 @@
1/* 1/*
2 * stocktickerpluginwidget.cpp 2 * stocktickerpluginwidget.cpp
3 * 3 *
4 * copyright : (c) 2002 by L.J. Potter 4 * copyright : (c) 2002 by L.J. Potter
5 * email : llornkcor@handhelds.org 5 * email : llornkcor@handhelds.org
6 * 6 *
7 */ 7 */
8/*************************************************************************** 8/***************************************************************************
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 <qsocket.h> 17#include <qsocket.h>
18#include <qvaluelist.h> 18#include <qvaluelist.h>
19#include <qtl.h> 19#include <qtl.h>
20#include <qstring.h> 20#include <qstring.h>
21#include <qstringlist.h> 21#include <qstringlist.h>
22#include <qobject.h> 22#include <qobject.h>
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
36extern "C" { 36extern "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
44QString output; 44QString output;
45OTicker *stocktickerTicker; 45OTicker *stocktickerTicker;
46 46
47void getStocks( const QString *blah) { 47void getStocks( const 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 qDebug("%s", blah->latin1()); 52 char *stock_liste = blah;
53 // char *stock_liste = (char *)blah->latin1();
54 qDebug("%s", stock_liste );
53 QString tempString; 55 QString tempString;
54 output = ""; 56 output = "";
55 57
56 libstocks_return_code error; 58 libstocks_return_code error;
57 59
58 Config cfg( "stockticker"); 60 Config cfg( "stockticker");
59 cfg.setGroup( "Fields" ); 61 cfg.setGroup( "Fields" );
60 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck; 62 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck;
61 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck; 63 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck;
62 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck; 64 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck;
63 65
64 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false; 66 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false;
65 67
66 dotimeCheck=cfg.readBoolEntry("timeCheck",1); 68 dotimeCheck=cfg.readBoolEntry("timeCheck",1);
67 dodateCheck=cfg.readBoolEntry("dateCheck",1); 69 dodateCheck=cfg.readBoolEntry("dateCheck",1);
68 dosymbolCheck=cfg.readBoolEntry("symbolCheck",1); 70 dosymbolCheck=cfg.readBoolEntry("symbolCheck",1);
69 donameCheck=cfg.readBoolEntry("nameCheck",1); 71 donameCheck=cfg.readBoolEntry("nameCheck",1);
70 docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1); 72 docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1);
71 dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1); 73 dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1);
72 doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1); 74 doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1);
73 dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1); 75 dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1);
74 domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); 76 domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1);
75 dovariationCheck=cfg.readBoolEntry("variationCheck",1); 77 dovariationCheck=cfg.readBoolEntry("variationCheck",1);
76 dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); 78 dovolumeCheck=cfg.readBoolEntry("volumeCheck",1);
77 79
78// DefProxy(); 80// DefProxy();
79 { 81 {
80 char *proxy; 82 char *proxy;
81 libstocks_return_code error; 83 libstocks_return_code error;
82 84
83 /* Proxy support */ 85 /* Proxy support */
84 /* Checks for "http_proxy" environment variable */ 86 /* Checks for "http_proxy" environment variable */
85 proxy = getenv("http_proxy"); 87 proxy = getenv("http_proxy");
86 if(proxy) { 88 if(proxy) {
87 /* printf("proxy set\n"); */ 89 /* printf("proxy set\n"); */
88 error = set_proxy(proxy); 90 error = set_proxy(proxy);
89 if (error) { 91 if (error) {
90 printf("Proxy error (%d)\n", error); 92 printf("Proxy error (%d)\n", error);
91 QString tempString; 93 QString tempString;
92 tempString.sprintf("Proxy error (%d)\n", error); 94 tempString.sprintf("Proxy error (%d)\n", error);
93 output = tempString; 95 output = tempString;
94 return; 96 return;
95// exit(1); 97// exit(1);
96 } 98 }
97 } 99 }
98 } 100 }
99 char *stock_liste = (char *)blah->latin1();
100// char *stock_liste = (char *)blah; 101// char *stock_liste = (char *)blah;
101 /* Get the stocks and process errors */ 102 /* Get the stocks and process errors */
102 error = get_stocks( stock_liste, &stocks_quotes); 103 error = get_stocks( stock_liste, &stocks_quotes);
103 104
104 if (error) { 105 if (error) {
105 printf("Error in getting stocks (%d)\n", error); 106 printf("Error in getting stocks (%d)\n", error);
106 tempString.sprintf("Error in getting stocks (%d)\n", error); 107 tempString.sprintf("Error in getting stocks (%d)\n", error);
107 output =tempString; 108 output =tempString;
108 return; 109 return;
109// exit(1); 110// exit(1);
110 } 111 }
111 112
112 stocks_tmp = stocks_quotes; 113 stocks_tmp = stocks_quotes;
113 114
114 /* Displays the stocks */ 115 /* Displays the stocks */
115 while(stocks_tmp!=0){ 116 while(stocks_tmp!=0){
116 117
117 if (stocks_tmp->Time) { 118 if (stocks_tmp->Time) {
118// printf("%s ", stocks_tmp->Time); 119// printf("%s ", stocks_tmp->Time);
119 tempString.sprintf("| %s ", stocks_tmp->Time); 120 tempString.sprintf("| %s ", stocks_tmp->Time);
120 tempString.replace(QRegExp("\""),""); 121 tempString.replace(QRegExp("\""),"");
121 if( dotimeCheck) 122 if( dotimeCheck)
122 output +=tempString; 123 output +=tempString;
123 } 124 }
124 if (stocks_tmp->Date) { 125 if (stocks_tmp->Date) {
125// printf("%s ", stocks_tmp->Date); 126// printf("%s ", stocks_tmp->Date);
126 tempString.sprintf("| %s ", stocks_tmp->Date); 127 tempString.sprintf("| %s ", stocks_tmp->Date);
127 tempString.replace(QRegExp("\""),""); 128 tempString.replace(QRegExp("\""),"");
128 if(dodateCheck) 129 if(dodateCheck)
129 output +=tempString; 130 output +=tempString;
130 } 131 }
131// printf("\n"); 132// printf("\n");
132 133
133// printf("----------------------------------------\n"); 134// printf("----------------------------------------\n");
134 135
135 if ( strlen(stocks_tmp->Symbol) > 20 ) { 136 if ( strlen(stocks_tmp->Symbol) > 20 ) {
136// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol); 137// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol);
137 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 138 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
138 if(dosymbolCheck) 139 if(dosymbolCheck)
139 output +=tempString; 140 output +=tempString;
140 } 141 }
141 else { 142 else {
142// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol); 143// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol);
143 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 144 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
144 if(dosymbolCheck) 145 if(dosymbolCheck)
145 output +=tempString; 146 output +=tempString;
146 } 147 }
147 148
@@ -206,97 +207,98 @@ void getStocks( const QString *blah) {
206 tempString.sprintf("||==++==|"); 207 tempString.sprintf("||==++==|");
207 output +=tempString; 208 output +=tempString;
208 209
209 /* Simple function which help to browse in the stocks list */ 210 /* Simple function which help to browse in the stocks list */
210 stocks_tmp = next_stock(stocks_tmp); 211 stocks_tmp = next_stock(stocks_tmp);
211 } 212 }
212 213
213 /* frees stocks */ 214 /* frees stocks */
214 free_stocks(stocks_quotes); 215 free_stocks(stocks_quotes);
215 stocktickerTicker->setText( output.latin1() ); 216 stocktickerTicker->setText( output.latin1() );
216 217
217} 218}
218 219
219StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) 220StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name)
220 : QWidget(parent, name ) { 221 : QWidget(parent, name ) {
221 init(); 222 init();
222 startTimer(1000); 223 startTimer(1000);
223 224
224 stocktickerTicker->setTextFormat(Qt::RichText); 225 stocktickerTicker->setTextFormat(Qt::RichText);
225// checkConnection(); 226// checkConnection();
226} 227}
227 228
228StockTickerPluginWidget::~StockTickerPluginWidget() { 229StockTickerPluginWidget::~StockTickerPluginWidget() {
229} 230}
230 231
231void StockTickerPluginWidget::init() { 232void StockTickerPluginWidget::init() {
232 233
233 QHBoxLayout* layout = new QHBoxLayout( this ); 234 QHBoxLayout* layout = new QHBoxLayout( this );
234 stocktickerTicker = new OTicker(this); 235 stocktickerTicker = new OTicker(this);
235// stocktickerTicker->setMinimumHeight(15); 236// stocktickerTicker->setMinimumHeight(15);
236 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() )); 237 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( checkConnection() ));
237 layout->addWidget( stocktickerTicker); 238 layout->addWidget( stocktickerTicker);
238 wasError = true; 239 wasError = true;
239} 240}
240 241
241void StockTickerPluginWidget::doStocks() { 242void StockTickerPluginWidget::doStocks() {
242 Config cfg( "stockticker"); 243 Config cfg( "stockticker");
243 cfg.setGroup( "Symbols" ); 244 cfg.setGroup( "Symbols" );
244 symbollist=""; 245 symbollist="";
245 symbollist = cfg.readEntry("Symbols", ""); 246 symbollist = cfg.readEntry("Symbols", "");
246 symbollist.replace(QRegExp(" "),"+");//seperated by + 247 symbollist.replace(QRegExp(" "),"+");//seperated by +
247 248
248 cfg.setGroup("Timer"); 249 cfg.setGroup("Timer");
249 stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50)); 250 stocktickerTicker->setUpdateTime( cfg.readNumEntry("ScrollSpeed",50));
250 stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10)); 251 stocktickerTicker->setScrollLength( cfg.readNumEntry("ScrollLength",10));
251 252
252 if (!symbollist.isEmpty()) { 253 if (!symbollist.isEmpty()) {
253 pthread_t thread1; 254 pthread_t thread1;
254 pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, &symbollist); 255 char *blah = symbollist.latin1();
256 pthread_create(&thread1,NULL, (void * (*)(void *))getStocks, blah);
255 } 257 }
256} 258}
257 259
258void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { 260void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) {
259 killTimer(e->timerId()); 261 killTimer(e->timerId());
260 checkConnection(); 262 checkConnection();
261} 263}
262 264
263void StockTickerPluginWidget::checkConnection() { 265void StockTickerPluginWidget::checkConnection() {
264// qDebug("checking connection"); 266// qDebug("checking connection");
265// Sock = new QSocket( this ); 267// Sock = new QSocket( this );
266 268
267// if( wasError) 269// if( wasError)
268// stocktickerTicker->setText("Checking connection"); 270// stocktickerTicker->setText("Checking connection");
269 271
270// if(Sock->state() == QSocket::Idle) { 272// if(Sock->state() == QSocket::Idle) {
271// Sock->connectToHost("finance.yahoo.com", 80); 273// Sock->connectToHost("finance.yahoo.com", 80);
272// connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) ); 274// connect( Sock, SIGNAL( error(int) ), SLOT(socketError(int)) );
273// connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) ); 275// connect( Sock, SIGNAL( hostFound() ), SLOT(isConnected()) );
274// } else { 276// } else {
275// qDebug("State is not Idle"); 277// qDebug("State is not Idle");
276 isConnected(); 278 isConnected();
277// } 279// }
278} 280}
279 281
280void StockTickerPluginWidget::isConnected() { 282void StockTickerPluginWidget::isConnected() {
281// qDebug("We connect, so ok to grab stocks"); 283// qDebug("We connect, so ok to grab stocks");
282 doStocks(); 284 doStocks();
283 285
284 Config cfg( "stockticker"); 286 Config cfg( "stockticker");
285 cfg.setGroup("Timer"); 287 cfg.setGroup("Timer");
286 timerDelay= cfg.readNumEntry("Delay",0); 288 timerDelay= cfg.readNumEntry("Delay",0);
287 if(timerDelay > 0) 289 if(timerDelay > 0)
288 startTimer(timerDelay*60000); 290 startTimer(timerDelay*60000);
289 qDebug("timer set for %d",(timerDelay*60000)/60000); 291 qDebug("timer set for %d",(timerDelay*60000)/60000);
290 wasError = false; 292 wasError = false;
291 293
292// Sock->close(); 294// Sock->close();
293} 295}
294 296
295void StockTickerPluginWidget::socketError(int errcode) { 297void StockTickerPluginWidget::socketError(int errcode) {
296 switch(errcode) { 298 switch(errcode) {
297 case QSocket::ErrConnectionRefused: 299 case QSocket::ErrConnectionRefused:
298 output = tr("Connection refused."); 300 output = tr("Connection refused.");
299 break; 301 break;
300 case QSocket::ErrHostNotFound: 302 case QSocket::ErrHostNotFound:
301 output = tr("Could not find server."); 303 output = tr("Could not find server.");
302 break; 304 break;