summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp13
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
@@ -1,313 +1,314 @@
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 char *blah) { 47void 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);
128 tempString.replace(QRegExp("\""),""); 129 tempString.replace(QRegExp("\""),"");
129 if(dodateCheck) 130 if(dodateCheck)
130 output +=tempString; 131 output +=tempString;
131 } 132 }
132// printf("\n"); 133// printf("\n");
133 134
134// printf("----------------------------------------\n"); 135// printf("----------------------------------------\n");
135 136
136 if ( strlen(stocks_tmp->Symbol) > 20 ) { 137 if ( strlen(stocks_tmp->Symbol) > 20 ) {
137// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol); 138// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol);
138 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 139 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
139 if(dosymbolCheck) 140 if(dosymbolCheck)
140 output +=tempString; 141 output +=tempString;
141 } 142 }
142 else { 143 else {
143// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol); 144// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol);
144 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 145 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
145 if(dosymbolCheck) 146 if(dosymbolCheck)
146 output +=tempString; 147 output +=tempString;
147 } 148 }
148 149
149 if (stocks_tmp->Name) { 150 if (stocks_tmp->Name) {
150 if ( strlen(stocks_tmp->Name) > 20 ) { 151 if ( strlen(stocks_tmp->Name) > 20 ) {
151// printf("| Name %.20s |\n",stocks_tmp->Name); 152// printf("| Name %.20s |\n",stocks_tmp->Name);
152 tempString.sprintf("| Name %s ",stocks_tmp->Name); 153 tempString.sprintf("| Name %s ",stocks_tmp->Name);
153 tempString.stripWhiteSpace(); 154 tempString.stripWhiteSpace();
154 if(donameCheck) 155 if(donameCheck)
155 output +=tempString; 156 output +=tempString;
156 } else { 157 } else {
157// printf("| Name | %-20s |\n",stocks_tmp->Name); 158// printf("| Name | %-20s |\n",stocks_tmp->Name);
158 tempString.sprintf("| Name %s ",stocks_tmp->Name); 159 tempString.sprintf("| Name %s ",stocks_tmp->Name);
159 tempString.stripWhiteSpace(); 160 tempString.stripWhiteSpace();
160 if(donameCheck) 161 if(donameCheck)
161 output +=tempString; 162 output +=tempString;
162 } 163 }
163 } 164 }
164 else { 165 else {
165// printf("| Name | |\n"); 166// printf("| Name | |\n");
166 tempString.sprintf("| Name | |"); 167 tempString.sprintf("| Name | |");
167 if(donameCheck) 168 if(donameCheck)
168 output +=tempString; 169 output +=tempString;
169 } 170 }
170 171
171// printf("| Price | %-7.2f |\n", stocks_tmp->CurrentPrice); 172// printf("| Price | %-7.2f |\n", stocks_tmp->CurrentPrice);
172 tempString.sprintf("| Price %-7.2f ", stocks_tmp->CurrentPrice); 173 tempString.sprintf("| Price %-7.2f ", stocks_tmp->CurrentPrice);
173 if(docurrentPriceCheck) 174 if(docurrentPriceCheck)
174 output +=tempString; 175 output +=tempString;
175 176
176// printf("| Yesterday | %-7.2f |\n",stocks_tmp->LastPrice); 177// printf("| Yesterday | %-7.2f |\n",stocks_tmp->LastPrice);
177 tempString.sprintf("| Yesterday %-7.2f ",stocks_tmp->LastPrice); 178 tempString.sprintf("| Yesterday %-7.2f ",stocks_tmp->LastPrice);
178 if(dolastPriceCheck) 179 if(dolastPriceCheck)
179 output +=tempString; 180 output +=tempString;
180 181
181// printf("| Open | %-7.2f |\n",stocks_tmp->OpenPrice); 182// printf("| Open | %-7.2f |\n",stocks_tmp->OpenPrice);
182 tempString.sprintf("| Open %-7.2f ",stocks_tmp->OpenPrice); 183 tempString.sprintf("| Open %-7.2f ",stocks_tmp->OpenPrice);
183 if(doopenPriceCheck) 184 if(doopenPriceCheck)
184 output +=tempString; 185 output +=tempString;
185 186
186// printf("| Min | %-7.2f |\n", stocks_tmp->MinPrice); 187// printf("| Min | %-7.2f |\n", stocks_tmp->MinPrice);
187 tempString.sprintf("| Min %-7.2f ", stocks_tmp->MinPrice); 188 tempString.sprintf("| Min %-7.2f ", stocks_tmp->MinPrice);
188 if(dominPriceCheck) 189 if(dominPriceCheck)
189 output +=tempString; 190 output +=tempString;
190 191
191// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice); 192// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice);
192 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice); 193 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice);
193 if(domaxPriceCheck) 194 if(domaxPriceCheck)
194 output +=tempString; 195 output +=tempString;
195 196
196// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage); 197// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage);
197 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage); 198 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage);
198 if(dovariationCheck) 199 if(dovariationCheck)
199 output +=tempString; 200 output +=tempString;
200 201
201// printf("| Volume | %-9d |\n", stocks_tmp->Volume); 202// printf("| Volume | %-9d |\n", stocks_tmp->Volume);
202 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume); 203 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume);
203 if(dovolumeCheck) 204 if(dovolumeCheck)
204 output +=tempString; 205 output +=tempString;
205 206
206// printf("----------------------------------------\n\n"); 207// printf("----------------------------------------\n\n");
207 tempString.sprintf("||==++==|"); 208 tempString.sprintf("||==++==|");
208 output +=tempString; 209 output +=tempString;
209 210
210 /* Simple function which help to browse in the stocks list */ 211 /* Simple function which help to browse in the stocks list */
211 stocks_tmp = next_stock(stocks_tmp); 212 stocks_tmp = next_stock(stocks_tmp);
212 } 213 }
213 214
214 /* frees stocks */ 215 /* frees stocks */
215 free_stocks(stocks_quotes); 216 free_stocks(stocks_quotes);
216 stocktickerTicker->setText( output.latin1() ); 217 stocktickerTicker->setText( output.latin1() );
217 218
218} 219}
219 220
220StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) 221StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name)
221 : QWidget(parent, name ) { 222 : QWidget(parent, name ) {
222 init(); 223 init();
223 startTimer(1000); 224 startTimer(1000);
224 225
225 stocktickerTicker->setTextFormat(Qt::RichText); 226 stocktickerTicker->setTextFormat(Qt::RichText);
226// checkConnection(); 227// checkConnection();
227} 228}
228 229
229StockTickerPluginWidget::~StockTickerPluginWidget() { 230StockTickerPluginWidget::~StockTickerPluginWidget() {
230} 231}
231 232
232void StockTickerPluginWidget::init() { 233void 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
242void StockTickerPluginWidget::doStocks() { 243void 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
260void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { 261void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) {
261 killTimer(e->timerId()); 262 killTimer(e->timerId());
262 checkConnection(); 263 checkConnection();
263} 264}
264 265
265void StockTickerPluginWidget::checkConnection() { 266void 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}
281 282
282void StockTickerPluginWidget::isConnected() { 283void StockTickerPluginWidget::isConnected() {
283// qDebug("We connect, so ok to grab stocks"); 284// qDebug("We connect, so ok to grab stocks");
284 doStocks(); 285 doStocks();
285 286
286 Config cfg( "stockticker"); 287 Config cfg( "stockticker");
287 cfg.setGroup("Timer"); 288 cfg.setGroup("Timer");
288 timerDelay= cfg.readNumEntry("Delay",0); 289 timerDelay= cfg.readNumEntry("Delay",0);
289 if(timerDelay > 0) 290 if(timerDelay > 0)
290 startTimer(timerDelay*60000); 291 startTimer(timerDelay*60000);
291 qDebug("timer set for %d",(timerDelay*60000)/60000); 292 qDebug("timer set for %d",(timerDelay*60000)/60000);
292 wasError = false; 293 wasError = false;
293 294
294// Sock->close(); 295// Sock->close();
295} 296}
296 297
297void StockTickerPluginWidget::socketError(int errcode) { 298void StockTickerPluginWidget::socketError(int errcode) {
298 switch(errcode) { 299 switch(errcode) {
299 case QSocket::ErrConnectionRefused: 300 case QSocket::ErrConnectionRefused:
300 output = tr("Connection refused."); 301 output = tr("Connection refused.");
301 break; 302 break;
302 case QSocket::ErrHostNotFound: 303 case QSocket::ErrHostNotFound:
303 output = tr("Could not find server."); 304 output = tr("Could not find server.");
304 break; 305 break;
305 case QSocket::ErrSocketRead : 306 case QSocket::ErrSocketRead :
306 output = tr("Socket read error."); 307 output = tr("Socket read error.");
307 break; 308 break;
308 }; 309 };
309 stocktickerTicker->setText( output ); 310 stocktickerTicker->setText( output );
310 wasError = true; 311 wasError = true;
311// Sock->close(); 312// Sock->close();
312 313
313} 314}