summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
index cc1bbbb..a7f98be 100644
--- a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp
@@ -1,256 +1,260 @@
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 <qvaluelist.h> 17#include <qvaluelist.h>
18#include <qtl.h> 18#include <qtl.h>
19#include <qstring.h> 19#include <qstring.h>
20#include <qstringlist.h> 20#include <qstringlist.h>
21#include <qobject.h> 21#include <qobject.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qlineedit.h> 23#include <qlineedit.h>
24#include <qregexp.h> 24#include <qregexp.h>
25#include <qtimer.h> 25#include <qtimer.h>
26 26
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/timestring.h> 28#include <qpe/timestring.h>
29#include <qpe/qcopenvelope_qws.h> 29#include <qpe/qcopenvelope_qws.h>
30 30
31#include "ticker.h" 31#include "ticker.h"
32 32
33extern "C" { 33extern "C" {
34#include "libstocks/stocks.h" 34#include "libstocks/stocks.h"
35} 35}
36 36
37#include "stocktickerpluginwidget.h" 37#include "stocktickerpluginwidget.h"
38 38
39StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name) 39StockTickerPluginWidget::StockTickerPluginWidget( QWidget *parent, const char* name)
40 : QWidget(parent, name ) { 40 : QWidget(parent, name ) {
41 init(); 41 init();
42 startTimer(1000); 42 startTimer(1000);
43} 43}
44 44
45StockTickerPluginWidget::~StockTickerPluginWidget() { 45StockTickerPluginWidget::~StockTickerPluginWidget() {
46} 46}
47 47
48void StockTickerPluginWidget::init() { 48void StockTickerPluginWidget::init() {
49 49
50 QHBoxLayout* layout = new QHBoxLayout( this ); 50 QHBoxLayout* layout = new QHBoxLayout( this );
51 51
52 stocktickerTicker = new Ticker(this); 52 stocktickerTicker = new Ticker(this);
53 stocktickerTicker->setMinimumHeight(15); 53 stocktickerTicker->setMinimumHeight(15);
54 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( doStocks() )); 54 connect( stocktickerTicker, SIGNAL( mousePressed()), this, SLOT( doStocks() ));
55 55
56 layout->addWidget( stocktickerTicker); 56 layout->addWidget( stocktickerTicker);
57// Config cfg( "stockticker");
58// cfg.setGroup("Timer");
59// timerDelay= cfg.readNumEntry("Delay",0);
60// if(timerDelay > 0 )
61// startTimer(timerDelay*60000);
62// qDebug("timer ^ set for %d",(timerDelay*60000)/60000);
57 63
58 Config cfg( "stockticker");
59 cfg.setGroup("Timer");
60 timerDelay= cfg.readNumEntry("Delay",0);
61 if(timerDelay > 0)
62 startTimer(timerDelay*60000);
63
64} 64}
65 65
66void StockTickerPluginWidget::doStocks() { 66void StockTickerPluginWidget::doStocks() {
67
68 Config cfg( "stockticker"); 67 Config cfg( "stockticker");
68
69 cfg.setGroup( "Symbols" ); 69 cfg.setGroup( "Symbols" );
70 QString symbollist; 70 QString symbollist;
71 symbollist = cfg.readEntry("Symbols", ""); 71 symbollist = cfg.readEntry("Symbols", "");
72 symbollist.replace(QRegExp(" "),"+");//seperated by + 72 symbollist.replace(QRegExp(" "),"+");//seperated by +
73// qDebug(symbollist); 73// qDebug(symbollist);
74 74
75 getStocks( symbollist.latin1()); 75 getStocks( symbollist.latin1());
76 76
77 stocktickerTicker->setText( output ); 77 stocktickerTicker->setText( output );
78} 78}
79 79
80void StockTickerPluginWidget::getStocks( const char *blah) { 80void StockTickerPluginWidget::getStocks( const char *blah) {
81 81
82 stock *stocks_quotes=NULL; 82 stock *stocks_quotes=NULL;
83 stock *stocks_tmp; 83 stock *stocks_tmp;
84 84
85 QString tempString; 85 QString tempString;
86 output = ""; 86 output = "";
87 87
88 libstocks_return_code error; 88 libstocks_return_code error;
89 89
90 Config cfg( "stockticker"); 90 Config cfg( "stockticker");
91 cfg.setGroup( "Fields" ); 91 cfg.setGroup( "Fields" );
92 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck; 92 bool dotimeCheck, dodateCheck, dosymbolCheck, donameCheck;
93 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck; 93 bool docurrentPriceCheck, dolastPriceCheck, doopenPriceCheck;
94 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck; 94 bool dominPriceCheck, domaxPriceCheck, dovariationCheck, dovolumeCheck;
95 95
96 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false; 96 dotimeCheck=dodateCheck=dosymbolCheck=donameCheck= docurrentPriceCheck=dolastPriceCheck=doopenPriceCheck=dominPriceCheck=domaxPriceCheck=dovariationCheck=dovolumeCheck=false;
97 97
98 dotimeCheck=cfg.readBoolEntry("timeCheck",1); 98 dotimeCheck=cfg.readBoolEntry("timeCheck",1);
99 dodateCheck=cfg.readBoolEntry("dateCheck",1); 99 dodateCheck=cfg.readBoolEntry("dateCheck",1);
100 dosymbolCheck=cfg.readBoolEntry("symbolCheck",1); 100 dosymbolCheck=cfg.readBoolEntry("symbolCheck",1);
101 donameCheck=cfg.readBoolEntry("nameCheck",1); 101 donameCheck=cfg.readBoolEntry("nameCheck",1);
102 docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1); 102 docurrentPriceCheck=cfg.readBoolEntry("currentPriceCheck",1);
103 dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1); 103 dolastPriceCheck=cfg.readBoolEntry("lastPriceCheck",1);
104 doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1); 104 doopenPriceCheck=cfg.readBoolEntry("openPriceCheck",1);
105 dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1); 105 dominPriceCheck=cfg.readBoolEntry("minPriceCheck",1);
106 domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1); 106 domaxPriceCheck=cfg.readBoolEntry("maxPriceCheck",1);
107 dovariationCheck=cfg.readBoolEntry("variationCheck",1); 107 dovariationCheck=cfg.readBoolEntry("variationCheck",1);
108 dovolumeCheck=cfg.readBoolEntry("volumeCheck",1); 108 dovolumeCheck=cfg.readBoolEntry("volumeCheck",1);
109 109
110 DefProxy(); 110 DefProxy();
111 char *stock_liste = (char *)blah; 111 char *stock_liste = (char *)blah;
112 /* Get the stocks and process errors */ 112 /* Get the stocks and process errors */
113 error = get_stocks( stock_liste, &stocks_quotes); 113 error = get_stocks( stock_liste, &stocks_quotes);
114 114
115 if (error) { 115 if (error) {
116 printf("Error in getting stocks (%d)\n", error); 116 printf("Error in getting stocks (%d)\n", error);
117 tempString.sprintf("Error in getting stocks (%d)\n", error); 117 tempString.sprintf("Error in getting stocks (%d)\n", error);
118 output =tempString; 118 output =tempString;
119 return; 119 return;
120// exit(1); 120// exit(1);
121 } 121 }
122 122
123 stocks_tmp = stocks_quotes; 123 stocks_tmp = stocks_quotes;
124 124
125 /* Displays the stocks */ 125 /* Displays the stocks */
126 while(stocks_tmp!=0){ 126 while(stocks_tmp!=0){
127 127
128 if (stocks_tmp->Time) { 128 if (stocks_tmp->Time) {
129// printf("%s ", stocks_tmp->Time); 129// printf("%s ", stocks_tmp->Time);
130 tempString.sprintf("| %s ", stocks_tmp->Time); 130 tempString.sprintf("| %s ", stocks_tmp->Time);
131 tempString.replace(QRegExp("\""),""); 131 tempString.replace(QRegExp("\""),"");
132 if( dotimeCheck) 132 if( dotimeCheck)
133 output +=tempString; 133 output +=tempString;
134 } 134 }
135 if (stocks_tmp->Date) { 135 if (stocks_tmp->Date) {
136// printf("%s ", stocks_tmp->Date); 136// printf("%s ", stocks_tmp->Date);
137 tempString.sprintf("| %s ", stocks_tmp->Date); 137 tempString.sprintf("| %s ", stocks_tmp->Date);
138 tempString.replace(QRegExp("\""),""); 138 tempString.replace(QRegExp("\""),"");
139 if(dodateCheck) 139 if(dodateCheck)
140 output +=tempString; 140 output +=tempString;
141 } 141 }
142// printf("\n"); 142// printf("\n");
143 143
144// printf("----------------------------------------\n"); 144// printf("----------------------------------------\n");
145 145
146 if ( strlen(stocks_tmp->Symbol) > 20 ) { 146 if ( strlen(stocks_tmp->Symbol) > 20 ) {
147// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol); 147// printf("| Symbol | %.20s |\n",stocks_tmp->Symbol);
148 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 148 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
149 if(dosymbolCheck) 149 if(dosymbolCheck)
150 output +=tempString; 150 output +=tempString;
151 } 151 }
152 else { 152 else {
153// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol); 153// printf("| Symbol | %-20s |\n",stocks_tmp->Symbol);
154 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol); 154 tempString.sprintf("| Symbol %s ",stocks_tmp->Symbol);
155 if(dosymbolCheck) 155 if(dosymbolCheck)
156 output +=tempString; 156 output +=tempString;
157 } 157 }
158 158
159 if (stocks_tmp->Name) { 159 if (stocks_tmp->Name) {
160 if ( strlen(stocks_tmp->Name) > 20 ) { 160 if ( strlen(stocks_tmp->Name) > 20 ) {
161// printf("| Name %.20s |\n",stocks_tmp->Name); 161// printf("| Name %.20s |\n",stocks_tmp->Name);
162 tempString.sprintf("| Name %s ",stocks_tmp->Name); 162 tempString.sprintf("| Name %s ",stocks_tmp->Name);
163 tempString.stripWhiteSpace(); 163 tempString.stripWhiteSpace();
164 if(donameCheck) 164 if(donameCheck)
165 output +=tempString; 165 output +=tempString;
166 } else { 166 } else {
167// printf("| Name | %-20s |\n",stocks_tmp->Name); 167// printf("| Name | %-20s |\n",stocks_tmp->Name);
168 tempString.sprintf("| Name %s ",stocks_tmp->Name); 168 tempString.sprintf("| Name %s ",stocks_tmp->Name);
169 tempString.stripWhiteSpace(); 169 tempString.stripWhiteSpace();
170 if(donameCheck) 170 if(donameCheck)
171 output +=tempString; 171 output +=tempString;
172 } 172 }
173 } 173 }
174 else { 174 else {
175// printf("| Name | |\n"); 175// printf("| Name | |\n");
176 tempString.sprintf("| Name | |"); 176 tempString.sprintf("| Name | |");
177 if(donameCheck) 177 if(donameCheck)
178 output +=tempString; 178 output +=tempString;
179 } 179 }
180 180
181// printf("| Price | %-7.2f |\n", stocks_tmp->CurrentPrice); 181// printf("| Price | %-7.2f |\n", stocks_tmp->CurrentPrice);
182 tempString.sprintf("| Price %-7.2f ", stocks_tmp->CurrentPrice); 182 tempString.sprintf("| Price %-7.2f ", stocks_tmp->CurrentPrice);
183 if(docurrentPriceCheck) 183 if(docurrentPriceCheck)
184 output +=tempString; 184 output +=tempString;
185 185
186// printf("| Yesterday | %-7.2f |\n",stocks_tmp->LastPrice); 186// printf("| Yesterday | %-7.2f |\n",stocks_tmp->LastPrice);
187 tempString.sprintf("| Yesterday %-7.2f ",stocks_tmp->LastPrice); 187 tempString.sprintf("| Yesterday %-7.2f ",stocks_tmp->LastPrice);
188 if(dolastPriceCheck) 188 if(dolastPriceCheck)
189 output +=tempString; 189 output +=tempString;
190 190
191// printf("| Open | %-7.2f |\n",stocks_tmp->OpenPrice); 191// printf("| Open | %-7.2f |\n",stocks_tmp->OpenPrice);
192 tempString.sprintf("| Open %-7.2f ",stocks_tmp->OpenPrice); 192 tempString.sprintf("| Open %-7.2f ",stocks_tmp->OpenPrice);
193 if(doopenPriceCheck) 193 if(doopenPriceCheck)
194 output +=tempString; 194 output +=tempString;
195 195
196// printf("| Min | %-7.2f |\n", stocks_tmp->MinPrice); 196// printf("| Min | %-7.2f |\n", stocks_tmp->MinPrice);
197 tempString.sprintf("| Min %-7.2f ", stocks_tmp->MinPrice); 197 tempString.sprintf("| Min %-7.2f ", stocks_tmp->MinPrice);
198 if(dominPriceCheck) 198 if(dominPriceCheck)
199 output +=tempString; 199 output +=tempString;
200 200
201// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice); 201// printf("| Max | %-7.2f |\n",stocks_tmp->MaxPrice);
202 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice); 202 tempString.sprintf("| Max %-7.2f ",stocks_tmp->MaxPrice);
203 if(domaxPriceCheck) 203 if(domaxPriceCheck)
204 output +=tempString; 204 output +=tempString;
205 205
206// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage); 206// printf("| Var | %-6.2f (%5.2f %%) |\n", stocks_tmp->Variation, stocks_tmp->Pourcentage);
207 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage); 207 tempString.sprintf("| Var %-6.2f (%5.2f %%) ", stocks_tmp->Variation, stocks_tmp->Pourcentage);
208 if(dovariationCheck) 208 if(dovariationCheck)
209 output +=tempString; 209 output +=tempString;
210 210
211// printf("| Volume | %-9d |\n", stocks_tmp->Volume); 211// printf("| Volume | %-9d |\n", stocks_tmp->Volume);
212 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume); 212 tempString.sprintf("| Volume %-9d ", stocks_tmp->Volume);
213 if(dovolumeCheck) 213 if(dovolumeCheck)
214 output +=tempString; 214 output +=tempString;
215 215
216// printf("----------------------------------------\n\n"); 216// printf("----------------------------------------\n\n");
217 tempString.sprintf("||==++==|"); 217 tempString.sprintf("||==++==|");
218 output +=tempString; 218 output +=tempString;
219 219
220 /* Simple function which help to browse in the stocks list */ 220 /* Simple function which help to browse in the stocks list */
221 stocks_tmp = next_stock(stocks_tmp); 221 stocks_tmp = next_stock(stocks_tmp);
222 } 222 }
223 223
224 /* frees stocks */ 224 /* frees stocks */
225 free_stocks(stocks_quotes); 225 free_stocks(stocks_quotes);
226 226
227} 227}
228 228
229void StockTickerPluginWidget::DefProxy(void) { 229void StockTickerPluginWidget::DefProxy(void) {
230 char *proxy; 230 char *proxy;
231 libstocks_return_code error; 231 libstocks_return_code error;
232 232
233 /* Proxy support */ 233 /* Proxy support */
234 /* Checks for "http_proxy" environment variable */ 234 /* Checks for "http_proxy" environment variable */
235 proxy = getenv("http_proxy"); 235 proxy = getenv("http_proxy");
236 if(proxy) { 236 if(proxy) {
237 /* printf("proxy set\n"); */ 237 /* printf("proxy set\n"); */
238 error = set_proxy(proxy); 238 error = set_proxy(proxy);
239 if (error) { 239 if (error) {
240// printf("Proxy error (%d)\n", error); 240// printf("Proxy error (%d)\n", error);
241 QString tempString; 241 QString tempString;
242 tempString.sprintf("Proxy error (%d)\n", error); 242 tempString.sprintf("Proxy error (%d)\n", error);
243 output = tempString; 243 output = tempString;
244 return; 244 return;
245// exit(1); 245// exit(1);
246 } 246 }
247 } 247 }
248} 248}
249 249
250void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) { 250void StockTickerPluginWidget::timerEvent( QTimerEvent *e ) {
251 qDebug("timer");
252 killTimer(e->timerId()); 251 killTimer(e->timerId());
253 doStocks(); 252 doStocks();
253 Config cfg( "stockticker");
254 cfg.setGroup("Timer");
255 timerDelay= cfg.readNumEntry("Delay",0);
254 if(timerDelay > 0) 256 if(timerDelay > 0)
255 startTimer(timerDelay*60000); 257 startTimer(timerDelay*60000);
258 qDebug("timer set for %d",(timerDelay*60000)/60000);
259
256} 260}