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