summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-10-31 00:09:31 (UTC)
committer llornkcor <llornkcor>2002-10-31 00:09:31 (UTC)
commit5a08fd92ac139820e1a1202d0b4b67190f24ccdb (patch) (unidiff)
treee9c0692cf445a886cd529b60f8e535922a7f5d4d
parentad396dd7b58fc772423f95be050f645fc7a6d9b9 (diff)
downloadopie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.zip
opie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.tar.gz
opie-5a08fd92ac139820e1a1202d0b4b67190f24ccdb.tar.bz2
added - initial check in
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/.cvsignore3
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.c402
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.h36
-rw-r--r--noncore/todayplugins/stockticker/libstocks/currency.c66
-rw-r--r--noncore/todayplugins/stockticker/libstocks/history.c149
-rw-r--r--noncore/todayplugins/stockticker/libstocks/http.c300
-rw-r--r--noncore/todayplugins/stockticker/libstocks/http.h35
-rw-r--r--noncore/todayplugins/stockticker/libstocks/lists.c123
-rw-r--r--noncore/todayplugins/stockticker/libstocks/lists.h35
-rw-r--r--noncore/todayplugins/stockticker/libstocks/stocks.c347
-rw-r--r--noncore/todayplugins/stockticker/libstocks/stocks.h116
-rw-r--r--noncore/todayplugins/stockticker/opie-today-stocktickerplugin.control8
-rw-r--r--noncore/todayplugins/stockticker/stockticker.pro2
-rw-r--r--noncore/todayplugins/stockticker/stockticker/.cvsignore3
-rw-r--r--noncore/todayplugins/stockticker/stockticker/inputDialog.cpp143
-rw-r--r--noncore/todayplugins/stockticker/stockticker/inputDialog.h30
-rw-r--r--noncore/todayplugins/stockticker/stockticker/main.cpp25
-rw-r--r--noncore/todayplugins/stockticker/stockticker/stockticker.pro10
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/.cvsignore3
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro27
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.cpp56
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.h47
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.cpp45
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.h40
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.cpp239
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h62
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/stocktimerpluginwidget.h45
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/ticker.cpp93
-rw-r--r--noncore/todayplugins/stockticker/stocktickerlib/ticker.h32
29 files changed, 2522 insertions, 0 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/.cvsignore b/noncore/todayplugins/stockticker/libstocks/.cvsignore
new file mode 100644
index 0000000..c9bb88e
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/.cvsignore
@@ -0,0 +1,3 @@
1Makefile*
2moc_*
3*.moc \ No newline at end of file
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c
new file mode 100644
index 0000000..99a44e4
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/csv.c
@@ -0,0 +1,402 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __CSV_C__
22
23#include <string.h>
24#include <stdlib.h>
25#include <stdio.h>
26
27#ifdef __WINDOWS__
28#include <mbstring.h>
29#endif
30
31#include "csv.h"
32#include "stocks.h"
33#include "lists.h"
34
35#define DATE_LENGTH 7 /*YYMMDD*/
36
37const char *months[12]=
38{
39 "Jan",
40 "Feb",
41 "Mar",
42 "Apr",
43 "May",
44 "Jun",
45 "Jul",
46 "Aug",
47 "Sep",
48 "Oct",
49 "Nov",
50 "Dec"
51};
52
53/*****************************************************************************/
54/* Replacement of the strtok function. This one forgets "delim" when it is */
55/* between two commas. */
56/* Thanks to Julio Lucas who has told me the bug and has proposed me a patch */
57/*****************************************************************************/
58char *csv_strtok(char *s, char *delim)
59{
60 static char *next=NULL;
61 char *temp, *first;
62 int comma=0;
63
64 if (s!=NULL) first=s;
65 else first=next;
66
67 temp=first;
68 if (*temp=='\0') return NULL;
69
70 while (*temp!='\0' && ((*temp!=*delim) || comma))
71 {
72 if (*temp=='"') comma ^= 1;
73 temp++;
74 }
75
76 if (*temp=='\0') next=temp;
77 else
78 {
79 *temp='\0';
80 next=temp+1;
81 }
82
83 return first;
84}
85
86/*****************************************************************************/
87/* Parses the csv file and return a list of stocks structure. */
88/* *csv points on the csv file in memory */
89/* count defines the country, because csv depends on the country */
90/*****************************************************************************/
91stock *parse_csv_file(char *csv)
92{
93 char *line;
94 char *end_line;
95
96 char *ptr;
97
98 char *date;
99 char *time;
100 char *name;
101 char *symbol;
102
103 stock *StockPtr=NULL;
104 stock *LastStockPtr=NULL;
105
106 /* Used to return the pointer to the list */
107 stock *FirstStockPtr=NULL;
108
109 /* used to see if symbol is valid */
110 int valid;
111 char *test;
112
113 line = csv;
114 end_line = csv;
115
116 while ((end_line = strstr(line, "\n")))
117 {
118 *end_line = 0;
119
120 /* Check if symbol valid */
121 /* if 1 "N/A" then ok because Indices have N/A for volume */
122 /* if 4 "N/A" then ok because Mutual funds have */
123 /* if 5 "N/A" then ok because currencies have */
124 /* So if >5 then stock not valid */
125
126 test = line;
127 valid = 0;
128 while ( (test = strstr(test, "N/A")) )
129 {
130 valid ++;
131 test = test +3;
132 }
133
134 if (valid < 6)
135 {
136 /* This Symbol is valid */
137
138 StockPtr = malloc_stock();
139
140 ptr = csv_strtok(line, ",");
141 if (!ptr) return 0;
142
143 symbol = (char *)malloc(strlen(ptr)+1);
144 if (symbol==NULL)
145 {
146 fprintf(stderr,"Memory allocating error (%s line %d)\n"
147 ,__FILE__, __LINE__);
148 exit(1);
149 }
150 strcpy((char *)(symbol), ptr);
151 StockPtr->Symbol = symbol;
152
153 ptr = csv_strtok(NULL, ",");
154 if (!ptr) return 0;
155
156 name = (char *)malloc(strlen(ptr)+1);
157 if (name==NULL)
158 {
159 fprintf(stderr,"Memory allocating error (%s line %d)\n"
160 ,__FILE__, __LINE__);
161 exit(1);
162 }
163 strcpy((char *)(name), ptr);
164 StockPtr->Name = name;
165
166 ptr = csv_strtok(NULL, ",");
167 if (!ptr) return 0;
168 sscanf(ptr,"%f",&(StockPtr->CurrentPrice));
169
170 ptr = csv_strtok(NULL, ",");
171 if (!ptr) return 0;
172
173 date = (char *)malloc(strlen(ptr)+1);
174 if (date==NULL)
175 {
176 fprintf(stderr,"Memory allocating error (%s line %d)\n"
177 ,__FILE__, __LINE__);
178 exit(1);
179 }
180 strcpy((char *)(date), ptr);
181 StockPtr->Date = date;
182
183 ptr = csv_strtok(NULL, ",");
184 if (!ptr) return 0;
185
186 time = (char *)malloc(strlen(ptr)+1);
187 if (time==NULL)
188 {
189 fprintf(stderr,"Memory allocating error (%s line %d)\n"
190 ,__FILE__, __LINE__);
191 exit(1);
192 }
193 strcpy((char *)(time), ptr);
194 StockPtr->Time = time;
195
196 ptr = csv_strtok(NULL, ",");
197 if (!ptr) return 0;
198 sscanf(ptr,"%f",&(StockPtr->Variation));
199
200 StockPtr->Pourcentage = 100 * StockPtr->Variation /
201 (StockPtr->CurrentPrice - StockPtr->Variation);
202
203 StockPtr->LastPrice = StockPtr->CurrentPrice - StockPtr->Variation;
204
205 ptr = csv_strtok(NULL, ",");
206 if (!ptr) return 0;
207 sscanf(ptr,"%f",&(StockPtr->OpenPrice));
208
209 ptr = csv_strtok(NULL, ",");
210 if (!ptr) return 0;
211 sscanf(ptr,"%f",&(StockPtr->MaxPrice));
212
213 ptr = csv_strtok(NULL, ",");
214 if (!ptr) return 0;
215 sscanf(ptr,"%f",&(StockPtr->MinPrice));
216
217 ptr = csv_strtok(NULL, ",");
218 if (!ptr) return 0;
219 StockPtr->Volume = atoi(ptr);
220
221 if( !FirstStockPtr )
222 {
223 FirstStockPtr = StockPtr;
224 StockPtr->PreviousStock = 0;
225 }
226
227 StockPtr->NextStock = 0;
228
229 if (LastStockPtr)
230 {
231 LastStockPtr->NextStock = StockPtr;
232 StockPtr->PreviousStock = LastStockPtr;
233 }
234
235 LastStockPtr = StockPtr;
236
237 }
238 else
239 {
240 /* this symbol is not valid */
241 /* Set the stock struct just with Symbol, all other are NULL */
242 /* This can be used to see if the symbol has been reached are not */
243
244 StockPtr = malloc_stock();
245
246 ptr = csv_strtok(line, ",");
247 if (!ptr) return 0;
248
249 symbol = (char *)malloc(strlen(ptr)+1);
250 if (symbol==NULL)
251 {
252 fprintf(stderr,"Memory allocating error (%s line %d)\n"
253 ,__FILE__, __LINE__);
254 exit(1);
255 }
256 strcpy((char *)(symbol), ptr);
257 StockPtr->Symbol = symbol;
258
259 if( !FirstStockPtr )
260 {
261 FirstStockPtr = StockPtr;
262 StockPtr->PreviousStock = 0;
263 }
264
265 StockPtr->NextStock = 0;
266
267 if (LastStockPtr)
268 {
269 LastStockPtr->NextStock = StockPtr;
270 StockPtr->PreviousStock = LastStockPtr;
271 }
272
273 LastStockPtr = StockPtr;
274 }
275
276 end_line++;
277 line = end_line;
278
279 }
280
281 return (FirstStockPtr);
282}
283
284/*****************************************************************************/
285/* Parses the history quotes file and return a stock structure list. */
286/*****************************************************************************/
287stock *parse_csv_history_file(char *csv_file)
288{
289
290 char *line;
291 char *end_line;
292 char *ptr;
293
294 int day;
295 char smonth[10];
296 int month;
297 int year;
298
299 char *date;
300
301 int i;
302 int test;
303
304 stock *StockPtr=NULL;
305 stock *LastStockPtr=NULL;
306
307 /* Used to return the pointer to the list */
308 stock *FirstStockPtr=NULL;
309
310 line = csv_file;
311 end_line = csv_file;
312
313 /* do not use the first line */
314 end_line = strstr(line, "\n");
315 *end_line = 0;
316 end_line++;
317 line = end_line;
318
319 while ((end_line = strstr(line, "\n")))
320 {
321 *end_line = 0;
322
323 StockPtr = malloc_stock();
324
325 /* Date */
326 ptr = strtok(line, ",");
327 if (!ptr) return 0;
328
329 sscanf(ptr,"%d-%3s-%d",&day,smonth,&year);
330
331 i=0;
332
333#ifdef __UNIX__
334 while((test=strcasecmp(months[i], smonth))) i++;
335#elif __WINDOWS__
336 while(test=_mbsnbicmp(months[i], smonth, strlen(months[i]))) i++;
337#endif
338
339 month = i+1;
340
341 date = (char *)malloc(DATE_LENGTH);
342 if (date==NULL)
343 {
344 fprintf(stderr,"Memory allocating error (%s line %d)\n"
345 ,__FILE__, __LINE__);
346 exit(1);
347 }
348 sprintf(date,"%.2d%.2d%.2d", year, month, day);
349 StockPtr->Date = date;
350
351 /* Open */
352 ptr = strtok(NULL, ",");
353 if (!ptr) return 0;
354 sscanf(ptr,"%f",&(StockPtr->OpenPrice));
355
356 /* High */
357 ptr = strtok(NULL, ",");
358 if (!ptr) return 0;
359 sscanf(ptr,"%f",&(StockPtr->MaxPrice));
360
361 /* Low */
362 ptr = strtok(NULL, ",");
363 if (!ptr) return 0;
364 sscanf(ptr,"%f",&(StockPtr->MinPrice));
365
366 /* Close */
367 ptr = strtok(NULL, ",");
368 if (!ptr) return 0;
369 sscanf(ptr,"%f",&(StockPtr->LastPrice));
370
371 /* Volume */
372
373 ptr = strtok(NULL, ",");
374 if (!ptr)
375 /* It seems to be an indice */
376 /* No volume for indices */
377 StockPtr->Volume = 0;
378 else
379 StockPtr->Volume = atoi(ptr);
380
381 if( !FirstStockPtr )
382 {
383 FirstStockPtr = StockPtr;
384 StockPtr->PreviousStock = 0;
385 }
386
387 StockPtr->NextStock = 0;
388
389 if (LastStockPtr)
390 {
391 LastStockPtr->NextStock = StockPtr;
392 StockPtr->PreviousStock = LastStockPtr;
393 }
394
395 LastStockPtr = StockPtr;
396
397 end_line++;
398 line = end_line;
399 }
400
401 return (FirstStockPtr);
402}
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.h b/noncore/todayplugins/stockticker/libstocks/csv.h
new file mode 100644
index 0000000..4205c61
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/csv.h
@@ -0,0 +1,36 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#ifndef __CSV_H__
22#define __CSV_H__
23
24#ifndef __CSV_C__
25#define PUBEXT_CSV extern
26#else
27#define PUBEXT_CSV
28#endif
29
30#include "stocks.h"
31
32PUBEXT_CSV stock *parse_csv_file(char *);
33PUBEXT_CSV char *csv_strtok(char *, char *);
34PUBEXT_CSV stock *parse_csv_history_file(char *);
35
36#endif /* __CSV_H__ */
diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c
new file mode 100644
index 0000000..9a08a9d
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/currency.c
@@ -0,0 +1,66 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __CURRENCY_C__
22
23
24#include <stdio.h>
25#include <string.h>
26#include <malloc.h>
27#include <stdlib.h>
28
29#include "stocks.h"
30
31/*****************************************************************************/
32/* returns the currency exchange rate of "from" currency into */
33/* "into" currency. */
34/*****************************************************************************/
35libstocks_return_code get_currency_exchange(char *from,
36 char *into,
37 float *exchange)
38{
39 char *symbol;
40 stock *data;
41 libstocks_return_code error;
42
43 if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL)
44 {
45 fprintf(stderr,"Memory allocating error (%s line %d)\n"
46 ,__FILE__, __LINE__);
47 exit(1);
48 }
49
50 strcpy(symbol, from);
51 strcat(symbol, into);
52 strcat(symbol, "=X");
53
54 error = get_stocks(symbol, &data);
55 if (error)
56 {
57 *exchange = 0;
58 return(error);
59 }
60
61 free_stocks(data);
62
63 *exchange = data->CurrentPrice;
64 return(error);
65
66}
diff --git a/noncore/todayplugins/stockticker/libstocks/history.c b/noncore/todayplugins/stockticker/libstocks/history.c
new file mode 100644
index 0000000..61f57d1
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/history.c
@@ -0,0 +1,149 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __HISTORY_C__
22
23#include <string.h>
24#include <stdlib.h>
25
26#ifdef __WINDOWS__
27#include <malloc.h>
28#endif
29
30#include "stocks.h"
31#include "http.h"
32#include "csv.h"
33
34const char history_stocks_server[]="chart.yahoo.com";
35const char url_history_beg[]="/table.csv?s=";
36
37/*****************************************************************************/
38/* Gets the stock history csv file and return in csv_file the result. */
39/* The stock is defined by its symbol. */
40/* The history file starts at date1 and stops at date2. */
41/*****************************************************************************/
42libstocks_return_code get_history_csv(char *symbol,
43 char *date1,
44 char *date2,
45 char **csv_file)
46{
47 char *data;
48 char url[80];
49
50 char adate[12];
51
52 char *y1, *y2;
53 char *m1, *m2;
54 char *d1, *d2;
55
56 libstocks_return_code error;
57
58 char *test;
59
60 strcpy(url, url_history_beg);
61 strcat(url, symbol);
62
63 strcpy(adate, date1);
64
65 y1=strtok(adate, "/");
66 if(!y1) return ERRDATE;
67 m1 = strtok(NULL, "/");
68 if(!m1) return ERRDATE;
69 d1 = strtok(NULL, "/");
70 if(!m1) return ERRDATE;
71
72 strcat(url, "&a=");
73 strcat(url, m1);
74 strcat(url, "&b=");
75 strcat(url, d1);
76 strcat(url, "&c=");
77 strcat(url, y1);
78
79 strcpy(adate, date2);
80
81 y2=strtok(adate, "/");
82 if(!y2) return ERRDATE;
83 m2 = strtok(NULL, "/");
84 if(!m2) return ERRDATE;
85 d2 = strtok(NULL, "/");
86 if(!d2) return ERRDATE;
87
88 strcat(url, "&d=");
89 strcat(url, m2);
90 strcat(url, "&e=");
91 strcat(url, d2);
92 strcat(url, "&f=");
93 strcat(url, y2);
94 strcat(url, "&g=d&q=q&y=0&x=.csv");
95
96 error=http_get(url, (char *)history_stocks_server, &data);
97 if (error) return error;
98
99 /* tests if data is valid */
100
101 /* The server returns "No data available for symbol" */
102 /* when the stock is not available */
103 test = strstr(data, "No data available");
104 if (test)
105 {
106 free(data);
107 return ERRDATA;
108 }
109
110 /* The server return "No Prices in this date range" */
111 /* when dates have not the good range */
112 test = strstr(data, "No Prices in this date range");
113 if (test)
114 {
115 free(data);
116 return ERRRANG;
117 }
118
119 *csv_file = data;
120
121 return(0);
122}
123
124/*****************************************************************************/
125/* Gets the stock history and return a stock structure list. */
126/* The stock is defined by its symbol. */
127/* The history file starts at date1 and stops at date2. */
128/*****************************************************************************/
129libstocks_return_code get_stock_history(char *symbol,
130 char *date1,
131 char *date2,
132 stock **stock_history)
133{
134 libstocks_return_code error;
135 char *csv_file;
136 stock *stock_parsed;
137
138 error = get_history_csv(symbol, date1, date2, &csv_file);
139 if (error) return error;
140
141 stock_parsed = parse_csv_history_file(csv_file);
142
143 free(csv_file);
144
145 if (!stock_parsed) return ERRPCSV;
146 *stock_history = stock_parsed;
147
148 return(0);
149}
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c
new file mode 100644
index 0000000..462080d
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/http.c
@@ -0,0 +1,300 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __HTTP_C__
22
23#ifdef __UNIX__
24#include <sys/socket.h>
25#include <netinet/in.h>
26#include <arpa/inet.h>
27#include <netdb.h>
28#include <unistd.h>
29#elif __WINDOWS__
30#include <winsock.h>
31#include <mbstring.h>
32#endif
33
34#include <sys/types.h>
35#include <ctype.h>
36#include <string.h>
37#include <stdlib.h>
38#include <stdio.h>
39
40#include "http.h"
41#include "stocks.h"
42
43#define BUF_SIZE 1024
44#define HEADER_MAXBUF 512
45
46/* pointer to proxy server name or NULL */
47char *http_proxy_server=NULL;
48/* proxy server port number or 0 */
49int http_proxy_port=0;
50
51/*****************************************************************************/
52/* Gets the file from http://http_server/http_file */
53/* This function is used to get quotes csv file from yahoo. */
54/* It allocates memory for the file and defines *pdata (the pointer of datas)*/
55/*****************************************************************************/
56libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
57{
58 struct hostent *host; /* structs needed by socket */
59 struct sockaddr_in server;
60 int s; /* socket descriptor */
61 char header[HEADER_MAXBUF]; /* request header */
62 int hlg; /* header length */
63 char buf[BUF_SIZE+1]; /* tempory buffer from socket read */
64 int r; /* number of bytes read by read function */
65 char *data=NULL; /* http server response */
66 int data_lgr; /* http server response length */
67 char *temp; /* pointer used to split header and csv */
68 int error_code; /* error code returned by http server */
69 char *csv_ptr; /* pointer to the csv content */
70 int header_founded; /* test if header is founded */
71
72#ifdef DEBUG
73 printf("*http_get\n");
74#endif
75
76 /* get host info by name :*/
77 if ((host = gethostbyname( http_proxy_server ? http_proxy_server : http_server)))
78 {
79 memset((char *) &server,0, sizeof(server));
80 memmove((char *) &server.sin_addr, host->h_addr, host->h_length);
81 server.sin_family = host->h_addrtype;
82 server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 );
83
84 } else
85 {
86
87#ifdef DEBUG
88 printf(" gethostbyname : NOK\n");
89#endif
90 return ERRHOST;
91 }
92
93 /* create socket */
94 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
95 {
96
97#ifdef DEBUG
98 printf(" create socket : NOK\n");
99#endif
100 return ERRSOCK;
101 }
102
103 setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
104
105 /* connect to server */
106 if (connect(s, &server, sizeof(server)) < 0)
107 {
108#ifdef DEBUG
109 printf(" connect to server : NOK\n");
110#endif
111
112#ifdef __UNIX__
113 close(s);
114#elif __WINDOWS__
115 closesocket(s);
116#endif
117 return ERRCONN;
118 }
119
120 /* create header */
121 if (http_proxy_server)
122 {
123 sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012",
124 http_server, http_file);
125 }
126 else
127 {
128 sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file);
129 }
130
131 hlg=strlen(header);
132
133 /* send header */
134#ifdef __UNIX__
135 if (write(s,header,hlg)!=hlg)
136#elif __WINDOWS__
137 if (send(s,header,hlg, 0)!=hlg)
138#endif
139 {
140#ifdef DEBUG
141 printf(" send header : NOK\n");
142#endif
143 return ERRWHEA;
144 }
145
146 data_lgr = 0;
147 r=1;
148 while(r)
149 {
150 /* Clear Buffer */
151 memset(buf,0,BUF_SIZE+1);
152
153#ifdef __UNIX__
154 r=read(s,buf,BUF_SIZE);
155#elif __WINDOWS__
156 r=recv(s,buf,BUF_SIZE,0);
157#endif
158
159 if (r)
160 {
161 if(!data_lgr)
162 {
163 if((data = malloc(r+1))==NULL)
164 {
165 fprintf(stderr,"Memory allocating error (%s line %d)\n"
166 ,__FILE__, __LINE__);
167 exit(1);
168 }
169
170 memcpy(data,buf,r);
171 data_lgr = r;
172 data[r]=0;
173 }
174 else
175 {
176 if((temp = malloc(r+data_lgr+1))==NULL)
177 {
178 fprintf(stderr,"Memory allocating error (%s line %d)\n"
179 ,__FILE__, __LINE__);
180 exit(1);
181 }
182 memcpy(temp, data, data_lgr);
183 memcpy(temp+data_lgr, buf, r);
184 temp[r+data_lgr]=0;
185 data_lgr += r;
186 free(data);
187 data = temp;
188 }
189 }
190 }
191
192 /* close socket */
193#ifdef __UNIX__
194 close(s);
195#elif __WINDOWS__
196 closesocket(s);
197#endif
198
199#ifdef DEBUG
200 printf("%s\n", data);
201#endif
202
203 /* get headers to test status line */
204 /* and to split headers and content */
205
206 temp = data;
207 header_founded = 0;
208 while( !header_founded )
209 {
210 if (*temp==0) return ERRRHEA;
211
212 if( *temp==0x0A )
213 {
214 /* test if it is the header end */
215 temp ++;
216 if (*temp == 0x0D) temp++;
217 if (*temp == 0x0A) header_founded = 1;
218 }
219 else
220 temp++;
221 }
222
223 *temp = 0;
224 temp++;
225
226 sscanf(data,"HTTP/1.%*d %03d",&error_code);
227
228 if (error_code != 200)
229 {
230#ifdef DEBUG
231 printf(" HTTP error code : %d\n", error_code);
232#endif
233 free(data);
234 return ERRPAHD;
235 }
236
237 if ((csv_ptr = malloc(strlen(temp)+1))==NULL)
238 {
239 free(data);
240 fprintf(stderr,"Memory allocating error (%s line %d)\n"
241 ,__FILE__, __LINE__);
242 exit(1);
243 }
244
245 memcpy(csv_ptr, temp, strlen(temp)+1);
246 free(data);
247
248#ifdef DEBUG
249 printf(" CSV\n");
250 printf("%s,\n", csv_ptr);
251#endif
252
253 *pdata = csv_ptr;
254
255 return 0;
256}
257
258/******************************************************************************/
259/* Set the proxy server to use */
260/******************************************************************************/
261libstocks_return_code set_proxy(char *proxy)
262{
263 char *ptr;
264 char c;
265
266#ifdef DEBUG
267 printf("*set_proxy\n");
268#endif
269
270 /* Parse the proxy URL - It must start with http:// */
271#ifdef __UNIX__
272 if (strncasecmp("http://",proxy,7)) return ERRPROX;
273#elif __WINDOWS__
274 if (_mbsnbicmp("http://",proxy,7)) return ERRPROX;
275#endif
276
277 proxy+=7;
278
279 /* find ":" in the proxy url */
280 ptr = proxy;
281 for (c=*ptr; (c && c!=':');) c=*ptr++;
282
283 /* ptr points just after the ":" or at the end of proxy if : not founded */
284 *(ptr-1)=0; /* clear the ":" */
285
286 http_proxy_server=strdup(proxy);
287
288#ifdef DEBUG
289 printf("http_proxy_server : %s\n", http_proxy_server);
290#endif
291
292 /* get the port number of the url */
293 if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX;
294
295#ifdef DEBUG
296 printf("http_proxy_port : %d\n", http_proxy_port);
297#endif
298
299 return 0;
300}
diff --git a/noncore/todayplugins/stockticker/libstocks/http.h b/noncore/todayplugins/stockticker/libstocks/http.h
new file mode 100644
index 0000000..33346f3
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/http.h
@@ -0,0 +1,35 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __HTTP_H__
23#define __HTTP_H__
24
25#ifndef __HTTP_C__
26#define PUBEXT_HTTP extern
27#else
28#define PUBEXT_HTTP
29#endif
30
31#include "stocks.h"
32
33PUBEXT_HTTP libstocks_return_code http_get(char *, char *, char **);
34
35#endif /* __HTTP_H__ */
diff --git a/noncore/todayplugins/stockticker/libstocks/lists.c b/noncore/todayplugins/stockticker/libstocks/lists.c
new file mode 100644
index 0000000..1ed66b3
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/lists.c
@@ -0,0 +1,123 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __LISTS_C__
22
23#include <malloc.h>
24#include <stdio.h>
25#include <string.h>
26
27#ifdef __WINDOWS__
28#include <stdlib.h>
29#endif
30
31#include "stocks.h"
32#include "lists.h"
33
34/******************************************************************************/
35/* Finds a stock in the stocks list and return the stock pointer. */
36/* *stocks points to the stocks list */
37/* *stock_to_find is the stock to find :)) */
38/******************************************************************************/
39stock *find_stock(stock *stocks, char *stock_to_find)
40{
41 char *test=NULL;
42
43 while(stocks != NULL)
44 {
45 test = strstr(stocks->Symbol, stock_to_find);
46 if(test) return(stocks);
47 stocks = stocks->NextStock;
48 }
49
50 return(0);
51}
52
53/******************************************************************************/
54/* Allocate memory for a stock structure and return the pointer of this */
55/* structure. */
56/******************************************************************************/
57stock *malloc_stock(void)
58{
59 stock *stockptr;
60
61 if((stockptr = (stock *)malloc(sizeof(stock)))==NULL)
62 {
63 fprintf(stderr,"Memory allocating error (%s line %d)\n"
64 ,__FILE__, __LINE__);
65 exit(1);
66 }
67
68 stockptr->Symbol=NULL;
69 stockptr->Name=NULL;
70 stockptr->Time=NULL;
71 stockptr->Date=NULL;
72 stockptr->CurrentPrice=0;
73 stockptr->LastPrice=0;
74 stockptr->OpenPrice=0;
75 stockptr->MinPrice=0;
76 stockptr->MaxPrice=0;
77 stockptr->Variation=0;
78 stockptr->Pourcentage=0;
79 stockptr->Volume=0;
80 stockptr->PreviousStock=0;
81 stockptr->NextStock=0;
82
83 return(stockptr);
84}
85
86/******************************************************************************/
87/* Deallocates a stock structure. */
88/* *stocks_to_free is the pointer of the structure to free */
89/******************************************************************************/
90void free_stocks(stock *stock_to_free)
91{
92 stock *next_stock;
93
94 while(stock_to_free)
95 {
96 next_stock = stock_to_free->NextStock;
97 free(stock_to_free->Symbol);
98 free(stock_to_free->Name);
99 free(stock_to_free->Time);
100 free(stock_to_free->Date);
101 free(stock_to_free);
102 stock_to_free = next_stock;
103 }
104}
105
106/******************************************************************************/
107/* Returns the next stock structure from the list. */
108/* *the_stocks points to the list. */
109/******************************************************************************/
110stock *next_stock(stock *the_stock)
111{
112 return((stock *)(the_stock->NextStock));
113}
114
115/******************************************************************************/
116/* Returns the previous stock structure from the list. */
117/* *the_stocks points to the list. */
118/******************************************************************************/
119stock *previous_stock(stock *the_stock)
120{
121 return((stock *)(the_stock->PreviousStock));
122}
123
diff --git a/noncore/todayplugins/stockticker/libstocks/lists.h b/noncore/todayplugins/stockticker/libstocks/lists.h
new file mode 100644
index 0000000..0132317
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/lists.h
@@ -0,0 +1,35 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#ifndef __LISTS_H__
22#define __LISTS_H__
23
24#ifndef __LISTS_C__
25#define PUBEXT_LISTS extern
26#else
27#define PUBEXT_LISTS
28#endif
29
30#include "stocks.h"
31
32PUBEXT_LISTS stock *malloc_stock(void);
33
34
35#endif /* __LISTS_H */
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.c b/noncore/todayplugins/stockticker/libstocks/stocks.c
new file mode 100644
index 0000000..eb04ba9
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/stocks.c
@@ -0,0 +1,347 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#define __STOCKS_C__
22
23#include <stdio.h>
24#include <string.h>
25#include <malloc.h>
26#include <stdlib.h>
27
28#ifdef __WINDOWS__
29#include <mbstring.h>
30#endif
31
32#include "http.h"
33#include "csv.h"
34
35#include "stocks.h"
36
37/*
38s = symbol
39n = name
40l1 = last trade
41d1 = date
42t1 = time
43c1 = variation
44o = open
45h = higher price
46g = lower price
47v = volume
48*/
49
50const char yahoo_us_stocks_server[]="finance.yahoo.com";
51const char yahoo_eu_stocks_server[]="finance.yahoo.com";
52//const char yahoo_eu_stocks_server[]="fr.finance.yahoo.com";
53
54const char yahoo_url_beg[]="/d/quotes.csv?s=";
55const char yahoo_url_end[]="&f=snl1d1t1c1ohgv&e=.csv";
56
57typedef enum {
58 YAHOO_EUROPE,
59 YAHOO_US
60} yahoo_source;
61
62#define YAHOO_US_EXT_NB 11
63const char *yahoo_us_ext[YAHOO_US_EXT_NB] =
64{
65 ".US", /* United States */
66 ".TO", /* Canada */
67 ".M", /* Canada */
68 ".V", /* Canada */
69 ".AL", /* Canada */
70 ".MX", /* Mexico */
71 ".SA", /* Brasil */
72 ".BA", /* Argentina */
73 ".CR", /* Venezuela */
74 ".SN", /* Chili */
75 ".AX" /* Australia */
76};
77
78/*****************************************************************************/
79/* Finds, according to the symbol extension, the http source of the quotes. */
80/* Actually just finance.yahoo.com and fr.finance.yahoo.com are supported. */
81/* The function returns the country source (US or EUROPE). */
82/*****************************************************************************/
83yahoo_source find_yahoo_source(char *symbol)
84{
85 char *ptr;
86 int i;
87 int test;
88
89 ptr = strrchr(symbol, '.');
90
91 /* If no extension we suppose it is a US stock */
92 if (!ptr) return YAHOO_US;
93
94 /* extension is found */
95
96 /* Test if it is canadian stock */
97 for (i=0; i<YAHOO_US_EXT_NB; i++)
98 {
99
100#ifdef __UNIX__
101 test = strcasecmp(yahoo_us_ext[i], ptr);
102#elif __WINDOWS__
103 test = _mbsnbicmp(yahoo_us_ext[i], ptr, strlen(yahoo_us_ext[i]));
104#endif
105
106 if (!test) return YAHOO_US;
107 }
108
109 /* We suppose now it is a European stock */
110 return YAHOO_EUROPE;
111}
112
113/*****************************************************************************/
114/* Gets quotes csv file, parses the file and create the quotes list */
115/* *stocks points to the stocks to fetch */
116/* *stock_datas points to the beginning of the list */
117/* count allows to connect to all country servers */
118/*****************************************************************************/
119libstocks_return_code download_stocks(char *stocks,
120 stock **stock_datas,
121 yahoo_source source)
122{
123 char *stocks_server=NULL;
124 char *url_beg=NULL;
125 char *url_end=NULL;
126
127 char *url;
128 char *data;
129
130 libstocks_return_code error;
131
132#ifdef DEBUG
133 printf("*download_stocks\n");
134#endif
135
136 switch (source)
137 {
138 case YAHOO_US:
139 stocks_server = (char *)yahoo_us_stocks_server;
140 break;
141
142 case YAHOO_EUROPE:
143 stocks_server = (char *)yahoo_eu_stocks_server;
144 break;
145 default:
146 stocks_server = (char *)yahoo_us_stocks_server;
147 break;
148
149 }
150
151 url_beg = (char *)yahoo_url_beg;
152 url_end = (char *)yahoo_url_end;
153
154 url = (char *)malloc(strlen(url_beg)
155 +strlen(url_end)
156 +strlen(stocks)+1);
157 if (url==NULL)
158 {
159 fprintf(stderr,"Memory allocating error (%s line %d)\n"
160 ,__FILE__, __LINE__);
161 exit(1);
162 }
163
164 strcpy(url, url_beg);
165 strcat(url, stocks);
166 strcat(url, url_end);
167
168 error=http_get(url, stocks_server, &data);
169
170 free(url);
171
172 if (error) return error;
173
174 *stock_datas = parse_csv_file(data);
175
176 free(data);
177
178 if (!(*stock_datas)) return ERRPCSV;
179
180 return 0;
181
182}
183
184/*****************************************************************************/
185/* Gets quotes from yahoo */
186/* Choses to fetch European or US depending on the symbol extension */
187/* and merges the two lists to one */
188/* *stocks points to the stocks to fetch */
189/* *stock_datas points to the beginning of the list */
190/*****************************************************************************/
191libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
192{
193 char *tok_ptr;
194 char *eu_quotes=NULL;
195 char *eu_quotes_temp=NULL;
196 int lgr_eu_quotes=0;
197
198 char *us_quotes=NULL;
199 char *us_quotes_temp=NULL;
200 int lgr_us_quotes=0;
201
202 char *symbol;
203
204 yahoo_source source;
205
206 int lgr_symbol=0;
207
208 libstocks_return_code error;
209
210 stock *stocks_tmp=NULL;
211 stock *stocks_tmp2=NULL;
212 stock *stocks_getted=NULL;
213 stock *last_stock=NULL;
214
215#ifdef DEBUG
216 printf("*get_stocks\n");
217#endif
218
219 /* to preserve stocks */
220 tok_ptr = malloc(strlen(stocks)+1);
221 if(tok_ptr==NULL)
222 {
223 fprintf(stderr,"Memory allocating error (%s line %d)\n"
224 ,__FILE__, __LINE__);
225 exit(1);
226 }
227 strcpy(tok_ptr, stocks);
228
229 while( (symbol = strtok(tok_ptr, "+"))!=0)
230 {
231 /* clear tok_ptr for next strtok */
232 tok_ptr = NULL;
233
234 /* look for "." in the symbol */
235 source = find_yahoo_source(symbol);
236
237 switch (source)
238 {
239 case YAHOO_US:
240
241 if (us_quotes)
242 {
243 lgr_us_quotes = strlen(us_quotes);
244 lgr_symbol = strlen(symbol);
245
246 us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2);
247 if(us_quotes_temp==NULL)
248 {
249 fprintf(stderr,"Memory allocating error (%s line %d)\n"
250 ,__FILE__, __LINE__);
251 exit(1);
252 }
253 strcpy(us_quotes_temp, us_quotes);
254 strcat(us_quotes_temp,"+");
255 strcat(us_quotes_temp,symbol);
256
257 free(us_quotes);
258 us_quotes = us_quotes_temp;
259 }
260 else
261 {
262 us_quotes = malloc(strlen(symbol)+1);
263
264 if(us_quotes==NULL)
265 {
266 fprintf(stderr,"Memory allocating error (%s line %d)\n"
267 ,__FILE__, __LINE__);
268 exit(1);
269 }
270 strcpy(us_quotes, symbol);
271 }
272
273 break;
274
275 case YAHOO_EUROPE:
276
277 if (eu_quotes)
278 {
279 lgr_eu_quotes = strlen(eu_quotes);
280 lgr_symbol = strlen(symbol);
281
282 eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2);
283 if(eu_quotes_temp==NULL)
284 {
285 fprintf(stderr,"Memory allocating error (%s line %d)\n"
286 ,__FILE__, __LINE__);
287 exit(1);
288 }
289 strcpy(eu_quotes_temp, eu_quotes);
290 strcat(eu_quotes_temp, "+");
291 strcat(eu_quotes_temp, symbol);
292
293 free(eu_quotes);
294 eu_quotes = eu_quotes_temp;
295 }
296 else
297 {
298 eu_quotes = malloc(strlen(symbol)+1);
299 if(eu_quotes==NULL)
300 {
301 fprintf(stderr,"Memory allocating error (%s line %d)\n"
302 ,__FILE__, __LINE__);
303 exit(1);
304 }
305 strcpy(eu_quotes, symbol);
306 }
307 break;
308 }
309 }
310
311 free(tok_ptr);
312
313 if (us_quotes)
314 {
315 /* Gets us quotes */
316 error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US);
317 if (error) return error;
318 }
319
320 if (eu_quotes)
321 {
322 /* Gets european quotes */
323 error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE);
324 if (error) return error;
325
326 /* concats lists if needed */
327 if (stocks_tmp)
328 {
329 stocks_tmp2 = stocks_tmp;
330
331 while(stocks_tmp2 != NULL)
332 {
333 last_stock = stocks_tmp2;
334 stocks_tmp2 = next_stock(stocks_tmp2);
335 }
336
337 last_stock->NextStock = stocks_getted;
338 stocks_getted->PreviousStock = last_stock;
339
340 }
341 else (stocks_tmp = stocks_getted);
342 }
343
344 *stock_datas = stocks_tmp;
345
346 return(0);
347}
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.h b/noncore/todayplugins/stockticker/libstocks/stocks.h
new file mode 100644
index 0000000..13250ca
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/libstocks/stocks.h
@@ -0,0 +1,116 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 *
3 * Copyright (C) 2000 Eric Laeuffer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#ifndef __STOCKS_H__
22#define __STOCKS_H__
23
24/* Defines for prototypes */
25#ifndef __LISTS_C__
26#define _LISTS_C_EXT extern
27#else
28#define _LISTS_C_EXT
29#endif /* __LISTS_C__ */
30
31#ifndef __STOCKS_C__
32#define _STOCKS_C_EXT extern
33#else
34#define _STOCKS_C_EXT
35#endif /* __STOCKS_C__ */
36
37#ifndef __HTTP_C__
38#define _HTTP_C_EXT extern
39#else
40#define _HTTP_C_EXT
41#endif /* __HTTP_C__ */
42
43#ifndef __CURRENCY_C__
44#define _CURRENCY_C_EXT extern
45#else
46#define _CURRENCY_C_EXT
47#endif /* __CURRENCY_C__ */
48
49#ifndef __HISTORY_C__
50#define _HISTORY_C_EXT extern
51#else
52#define _HISTORY_C_EXT
53#endif /* __HISTORY_C__ */
54
55typedef struct stockstruct stock;
56
57struct stockstruct {
58 char *Symbol;
59 char *Name;
60 char *Time;
61 char *Date;
62 float CurrentPrice;
63 float LastPrice;
64 float OpenPrice;
65 float MinPrice;
66 float MaxPrice;
67 float Variation;
68 float Pourcentage;
69 int Volume;
70 stock *PreviousStock;
71 stock *NextStock;
72};
73
74/* Errors generates by the library */
75typedef enum {
76 NOERR = 0, /* No error */
77 ERRHOST = 1, /* No such host */
78 ERRSOCK = 2, /* Can't create socket */
79 ERRCONN = 3, /* Can't connect to host */
80 ERRWHEA = 4, /* Write error on socket while writing */
81 ERRRHEA = 5, /* Cannot find header in http response */
82 ERRPAHD = 7, /* Invalid answer from data server */
83 ERRPCSV = 8, /* Error in parsing csv file */
84 ERRPROX = 20, /* Bad proxy url */
85 ERRDATE = 30, /* Bad date format */
86 ERRDATA = 40, /* No data available */
87 ERRRANG = 50 /* No prices for this date range */
88
89} libstocks_return_code;
90
91_LISTS_C_EXT stock *next_stock(stock *);
92_LISTS_C_EXT stock *previous_stock(stock *);
93_LISTS_C_EXT void free_stocks(stock *);
94_LISTS_C_EXT stock *find_stock(stock *stocks, char *);
95
96_STOCKS_C_EXT libstocks_return_code get_stocks(const char *, stock **);
97
98_HTTP_C_EXT libstocks_return_code set_proxy(char *);
99
100
101_CURRENCY_C_EXT libstocks_return_code get_currency_exchange(char *,
102 char *,
103 float *);
104
105_HISTORY_C_EXT libstocks_return_code get_history_csv(char *,
106 char *,
107 char *,
108 char **);
109
110_HISTORY_C_EXT libstocks_return_code get_stock_history(char *,
111 char *,
112 char *,
113 stock **);
114
115
116#endif /* __STOCKS_H__ */
diff --git a/noncore/todayplugins/stockticker/opie-today-stocktickerplugin.control b/noncore/todayplugins/stockticker/opie-today-stocktickerplugin.control
new file mode 100644
index 0000000..ddfe9b0
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/opie-today-stocktickerplugin.control
@@ -0,0 +1,8 @@
1Files: plugins/today/libtodaystocktickerplugin.so* bin/stockticker
2Priority: optional
3Section: opie/applications
4Maintainer: ljp <llornkcor@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: qt-embedded (>=$QTE_VERSION), opie-today
8Description: stockticker plugin for today
diff --git a/noncore/todayplugins/stockticker/stockticker.pro b/noncore/todayplugins/stockticker/stockticker.pro
new file mode 100644
index 0000000..96319da
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker.pro
@@ -0,0 +1,2 @@
1TEMPLATE = subdirs
2unix:SUBDIRS = stockticker stocktickerlib
diff --git a/noncore/todayplugins/stockticker/stockticker/.cvsignore b/noncore/todayplugins/stockticker/stockticker/.cvsignore
new file mode 100644
index 0000000..c9bb88e
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker/.cvsignore
@@ -0,0 +1,3 @@
1Makefile*
2moc_*
3*.moc \ No newline at end of file
diff --git a/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp b/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp
new file mode 100644
index 0000000..ad841f2
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker/inputDialog.cpp
@@ -0,0 +1,143 @@
1#include "inputDialog.h"
2
3#include <qapplication.h>
4
5#include <qcheckbox.h>
6#include <qlayout.h>
7#include <qlineedit.h>
8#include <qlayout.h>
9#include <qvariant.h>
10#include <qpushbutton.h>
11#include <qwhatsthis.h>
12#include <qlabel.h>
13#include <qpe/config.h>
14#include <qstringlist.h>
15#include <qmainwindow.h>
16
17
18InputDialog::InputDialog( )
19 : QMainWindow( 0x0, 0x0, WStyle_ContextHelp ) {
20 setCaption( tr("Enter Stock Symbols"));
21
22 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
23
24 QGridLayout *layout = new QGridLayout( this );
25 layout->setSpacing(6);
26 layout->setMargin( 2);
27
28 LineEdit1 = new QLineEdit( this, "LineEdit1" );
29 LineEdit1->setFocus();
30 QWhatsThis::add( LineEdit1, tr("Enter the stock symbols you want to be shown here."));
31
32 layout->addMultiCellWidget( LineEdit1, 0, 0, 0, 3);
33
34 Config cfg( "stockticker");
35 cfg.setGroup( "Symbols" );
36 QString symbollist;
37 symbollist = cfg.readEntry("Symbols", "");
38 LineEdit1->setText(symbollist);
39
40 QLabel *label;
41 label = new QLabel(this);
42 label->setText( tr("Enter stock symbols seperated\nby a space."));
43 label->setMaximumHeight(60);
44 layout->addMultiCellWidget( label, 1, 1, 0, 3);
45
46 cfg.setGroup( "Fields" );
47
48 timeCheck= new QCheckBox ( "Time",this );
49 timeCheck->setChecked( cfg.readBoolEntry("timeCheck",1));
50 layout->addMultiCellWidget(timeCheck, 2, 2, 0, 0 );
51 QWhatsThis::add( timeCheck, tr("Toggles Time Field"));
52
53 dateCheck= new QCheckBox ( "Date", this );
54 dateCheck->setChecked( cfg.readBoolEntry("dateCheck",1));
55 layout->addMultiCellWidget( dateCheck, 2, 2, 1, 1 );
56 QWhatsThis::add(dateCheck, tr("Toggles date field"));
57
58 symbolCheck= new QCheckBox ( "Symbol", this );
59 symbolCheck->setChecked( cfg.readBoolEntry("symbolCheck",1));
60 layout->addMultiCellWidget( symbolCheck, 3, 3, 0, 0 );
61 QWhatsThis::add(symbolCheck, tr("Toggles Symbol field"));
62
63 nameCheck= new QCheckBox ( "Name", this );
64 nameCheck->setChecked( cfg.readBoolEntry("nameCheck",1));
65 layout->addMultiCellWidget( nameCheck, 3, 3, 1, 1 );
66 QWhatsThis::add(nameCheck, tr("Toggles Name field"));
67
68 currentPriceCheck= new QCheckBox ( "Current Price", this );
69 currentPriceCheck->setChecked( cfg.readBoolEntry("currentPriceCheck",1));
70 layout->addMultiCellWidget( currentPriceCheck, 4, 4, 0, 0 );
71 QWhatsThis::add(currentPriceCheck, tr("Toggles current Price field"));
72
73
74 lastPriceCheck= new QCheckBox ( "Last Price", this );
75 lastPriceCheck->setChecked( cfg.readBoolEntry("lastPriceCheck",1));
76 layout->addMultiCellWidget(lastPriceCheck, 4, 4, 1, 1);
77 QWhatsThis::add(lastPriceCheck, tr("Toggles last price field"));
78
79 openPriceCheck= new QCheckBox ( "Open Price", this);
80 openPriceCheck->setChecked( cfg.readBoolEntry("openPriceCheck",1));
81 layout->addMultiCellWidget( openPriceCheck, 5, 5, 0, 0 );
82 QWhatsThis::add(openPriceCheck, tr("Toggles opening price field"));
83
84 minPriceCheck= new QCheckBox ( "Min Price", this );
85 minPriceCheck->setChecked( cfg.readBoolEntry("minPriceCheck",1));
86 layout->addMultiCellWidget( minPriceCheck, 5, 5, 1, 1);
87 QWhatsThis::add(minPriceCheck, tr("Toggles minamum price field"));
88
89 maxPriceCheck= new QCheckBox ( "Max Price", this);
90 maxPriceCheck->setChecked( cfg.readBoolEntry("maxPriceCheck",1));
91 layout->addMultiCellWidget( maxPriceCheck, 6, 6, 0, 0 );
92 QWhatsThis::add(maxPriceCheck, tr("Toggles maximum price field"));
93
94 variationCheck= new QCheckBox ( "Variation", this );
95 variationCheck->setChecked( cfg.readBoolEntry("variationCheck",1));
96 layout->addMultiCellWidget( variationCheck, 6, 6, 1, 1 );
97 QWhatsThis::add(variationCheck, tr("Toggles daily variation field"));
98
99 volumeCheck= new QCheckBox ( "Volume", this );
100 volumeCheck->setChecked( cfg.readBoolEntry("volumeCheck",1));
101 layout->addMultiCellWidget( volumeCheck , 7, 7, 0, 0);
102 QWhatsThis::add(volumeCheck, tr("Toggles volume field"));
103
104
105 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
106 layout->addItem( spacer, 8, 0 );
107
108}
109
110QString InputDialog::text() const {
111 return LineEdit1->text();
112}
113
114InputDialog::~InputDialog() {
115}
116
117void InputDialog::cleanUp(){
118 Config cfg( "stockticker");
119 cfg.setGroup( "Symbols" );
120 QString outText = text().upper();
121 outText.stripWhiteSpace();
122 cfg.writeEntry("Symbols", outText );
123 qDebug( "<<<<<<<<<<<>>>>>>>>>>>>"+text());
124
125 cfg.setGroup( "Fields" );
126
127 cfg.writeEntry("timeCheck",timeCheck->isChecked());
128 cfg.writeEntry("dateCheck",dateCheck->isChecked());
129 cfg.writeEntry("symbolCheck",symbolCheck->isChecked());
130 cfg.writeEntry("nameCheck",nameCheck->isChecked());
131 cfg.writeEntry("currentPriceCheck",currentPriceCheck->isChecked());
132 cfg.writeEntry("lastPriceCheck",lastPriceCheck->isChecked());
133 cfg.writeEntry("openPriceCheck",openPriceCheck->isChecked());
134 cfg.writeEntry("minPriceCheck",minPriceCheck->isChecked());
135 cfg.writeEntry("maxPriceCheck",maxPriceCheck->isChecked());
136 cfg.writeEntry("variationCheck",variationCheck->isChecked());
137 cfg.writeEntry("volumeCheck",volumeCheck->isChecked());
138
139
140 cfg.write();
141}
142
143
diff --git a/noncore/todayplugins/stockticker/stockticker/inputDialog.h b/noncore/todayplugins/stockticker/stockticker/inputDialog.h
new file mode 100644
index 0000000..8fda6ad
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker/inputDialog.h
@@ -0,0 +1,30 @@
1
2#ifndef INPUTDIALOG_H
3#define INPUTDIALOG_H
4
5#include <qvariant.h>
6#include <qdialog.h>
7#include <qmainwindow.h>
8
9class QLineEdit;
10class QCheckBox;
11
12class InputDialog : public QMainWindow {
13 Q_OBJECT
14
15public:
16 InputDialog( );
17// InputDialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
18 ~InputDialog();
19 QString text()const;
20
21private:
22 QLineEdit* LineEdit1;
23 QCheckBox *timeCheck, *dateCheck, *symbolCheck, *nameCheck, *currentPriceCheck, *lastPriceCheck, *openPriceCheck, *minPriceCheck, *maxPriceCheck, *variationCheck, *volumeCheck;
24private slots:
25 void cleanUp();
26protected slots:
27
28};
29
30#endif // INPUTDIALOG_H
diff --git a/noncore/todayplugins/stockticker/stockticker/main.cpp b/noncore/todayplugins/stockticker/stockticker/main.cpp
new file mode 100644
index 0000000..da8da66
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker/main.cpp
@@ -0,0 +1,25 @@
1
2/***************************************************************************
3 main.cpp - description
4 -------------------
5 begin : March 10, 2002
6 copyright : (C) 2002 by llornkcor
7 email : ljp@llornkcor.com
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 ***************************************************************************/
13#include <qpe/qpeapplication.h>
14#include "inputDialog.h"
15
16int main(int argc, char *argv[])
17{
18 QPEApplication a(argc, argv);
19
20 InputDialog input;
21 a.showMainWidget( &input);
22 return a.exec();
23}
24
25
diff --git a/noncore/todayplugins/stockticker/stockticker/stockticker.pro b/noncore/todayplugins/stockticker/stockticker/stockticker.pro
new file mode 100644
index 0000000..0e970f1
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stockticker/stockticker.pro
@@ -0,0 +1,10 @@
1TEMPLATE = app
2CONFIG = qt warn_on release
3HEADERS = inputDialog.h
4SOURCES = inputDialog.cpp main.cpp
5INTERFACES =
6TARGET = stockticker
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS+= -lqpe
10DESTDIR = $(OPIEDIR)/bin
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/.cvsignore b/noncore/todayplugins/stockticker/stocktickerlib/.cvsignore
new file mode 100644
index 0000000..c9bb88e
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/.cvsignore
@@ -0,0 +1,3 @@
1Makefile*
2moc_*
3*.moc \ No newline at end of file
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro
new file mode 100644
index 0000000..28ef072
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerlib.pro
@@ -0,0 +1,27 @@
1TEMPLATE = lib
2CONFIG -= moc
3CONFIG += qt debug
4
5HEADERS = stocktickerplugin.h stocktickeruginimpl.h stocktickerpluginwidget.h ticker.h \
6 ../libstocks/csv.h \
7 ../libstocks/http.h \
8 ../libstocks/lists.h \
9 ../libstocks/stocks.h
10SOURCES = stocktickerplugin.cpp stocktickerpluginimpl.cpp stocktickerpluginwidget.cpp ticker.cpp \
11 ../libstocks/csv.c \
12 ../libstocks/currency.c \
13 ../libstocks/history.c \
14 ../libstocks/http.c \
15 ../libstocks/lists.c \
16 ../libstocks/stocks.c
17
18INCLUDEPATH += $(OPIEDIR)/include \
19 ../ ../library
20DEPENDPATH += $(OPIEDIR)/include \
21 ../ ../library
22
23LIBS+= -lqpe -lopie
24TMAKE_CFLAGS += -D__UNIX__
25
26DESTDIR = $(OPIEDIR)/plugins/today
27TARGET = todaystocktickerplugin
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.cpp
new file mode 100644
index 0000000..82dfb13
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.cpp
@@ -0,0 +1,56 @@
1/*
2 * stocktickerplugin.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
18#include "stocktickerplugin.h"
19#include "stocktickerpluginwidget.h"
20
21
22StockTickerPlugin::StockTickerPlugin() {
23}
24
25StockTickerPlugin::~StockTickerPlugin() {
26}
27
28QString StockTickerPlugin::pluginName() const {
29 return QObject::tr( "StockTicker plugin" );
30}
31
32double StockTickerPlugin::versionNumber() const {
33 return 0.6;
34}
35
36QString StockTickerPlugin::pixmapNameWidget() const {
37 return "pass";
38}
39
40QWidget* StockTickerPlugin::widget( QWidget * wid ) {
41 return new StockTickerPluginWidget( wid, "StockTicker " );
42}
43
44QString StockTickerPlugin::pixmapNameConfig() const {
45 return 0l;
46}
47
48TodayConfigWidget* StockTickerPlugin::configWidget( QWidget* wid ) {
49 return 0l;
50}
51
52QString StockTickerPlugin::appName() const {
53 return "stockticker";
54}
55
56
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.h b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.h
new file mode 100644
index 0000000..9f174bf
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerplugin.h
@@ -0,0 +1,47 @@
1/*
2 * stocktickerplugin.h
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
18#ifndef STOCKTICKER_PLUGIN_H
19#define STOCKTICKER_PLUGIN_H
20
21#include <qstring.h>
22#include <qwidget.h>
23
24#include <opie/tododb.h>
25#include <opie/oclickablelabel.h>
26
27#include <opie/todayplugininterface.h>
28#include <opie/todayconfigwidget.h>
29
30class StockTickerPlugin : public TodayPluginObject {
31
32public:
33 StockTickerPlugin();
34 ~StockTickerPlugin();
35
36 QString pluginName() const;
37 double versionNumber() const;
38 QString pixmapNameWidget() const;
39 QWidget* widget(QWidget *);
40 QString pixmapNameConfig() const;
41 TodayConfigWidget* configWidget(QWidget *);
42 QString appName() const;
43
44
45};
46
47#endif
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.cpp b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.cpp
new file mode 100644
index 0000000..9a640d4
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.cpp
@@ -0,0 +1,45 @@
1/*
2 * stocktickerpluginimpl.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
18
19#include "stocktickerplugin.h"
20#include "stocktickerpluginimpl.h"
21
22StockTickerPluginImpl::StockTickerPluginImpl() {
23 stocktickerPlugin = new StockTickerPlugin();
24}
25
26StockTickerPluginImpl::~StockTickerPluginImpl() {
27}
28
29
30TodayPluginObject* StockTickerPluginImpl::guiPart() {
31 return stocktickerPlugin;
32}
33
34QRESULT StockTickerPluginImpl::queryInterface( const QUuid & uuid, QUnknownInterface **iface ) {
35 *iface = 0;
36 if ( ( uuid == IID_QUnknown ) || ( uuid == IID_TodayPluginInterface ) ) {
37 *iface = this, (*iface)->addRef();
38 }
39 return QS_OK;
40
41}
42
43Q_EXPORT_INTERFACE() {
44 Q_CREATE_INSTANCE( StockTickerPluginImpl );
45}
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.h b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.h
new file mode 100644
index 0000000..300c545
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginimpl.h
@@ -0,0 +1,40 @@
1/*
2 * stocktickerpluginimpl.h
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#ifndef STOCKTICKER_PLUGIN_IMPL_H
18#define STOCKTICKER_PLUGIN_IMPL_H
19
20#include <opie/todayplugininterface.h>
21
22class StockTickerPlugin;
23
24class StockTickerPluginImpl : public TodayPluginInterface{
25
26public:
27 StockTickerPluginImpl();
28 virtual ~StockTickerPluginImpl();
29
30 QRESULT queryInterface( const QUuid &, QUnknownInterface** );
31 Q_REFCOUNT
32
33 virtual TodayPluginObject *guiPart();
34
35private:
36 StockTickerPlugin *stocktickerPlugin;
37 ulong ref;
38};
39
40#endif
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}
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h
new file mode 100644
index 0000000..6524ae4
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktickerpluginwidget.h
@@ -0,0 +1,62 @@
1/*
2 * stocktickerpluginwidget.h
3 *
4 * copyright : (c) 2002 by L.J. Potter
5 * email : lornkcor@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
18#ifndef STOCKTICKERL_PLUGIN_WIDGET_H
19#define STOCKTICKERL_PLUGIN_WIDGET_H
20
21#include <qstring.h>
22#include <qwidget.h>
23#include <qlineedit.h>
24
25#include <opie/tododb.h>
26#include <opie/oclickablelabel.h>
27
28#include <sys/types.h>
29#include <sys/uio.h>
30#include <unistd.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35#include "ticker.h"
36
37/* extern "C" { */
38/* #include "stocks.h" */
39/* } */
40
41class StockTickerPluginWidget : public QWidget {
42
43 Q_OBJECT
44
45public:
46 StockTickerPluginWidget( QWidget *parent, const char *name );
47 ~StockTickerPluginWidget();
48 QString output;
49
50protected slots:
51 void doStocks();
52
53private:
54 Ticker *stocktickerTicker;
55
56 void init();
57 void getStocks( const char *stock_liste);
58 void DefProxy(void);
59
60};
61
62#endif
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/stocktimerpluginwidget.h b/noncore/todayplugins/stockticker/stocktickerlib/stocktimerpluginwidget.h
new file mode 100644
index 0000000..2feef80
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/stocktimerpluginwidget.h
@@ -0,0 +1,45 @@
1/*
2 * mailpluginwidget.h
3 *
4 * copyright : (c) 2002 by Maximilian Reiß
5 * email : harlekin@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
18#ifndef MAIL_PLUGIN_WIDGET_H
19#define MAIL_PLUGIN_WIDGET_H
20
21#include <qstring.h>
22#include <qwidget.h>
23
24#include <opie/tododb.h>
25#include <opie/oclickablelabel.h>
26
27class MailPluginWidget : public QWidget {
28
29 Q_OBJECT
30
31
32public:
33 MailPluginWidget( QWidget *parent, const char *name );
34 ~MailPluginWidget();
35
36protected slots:
37 void startMail();
38
39private:
40 OClickableLabel *mailLabel;
41 void readConfig();
42 void getInfo();
43};
44
45#endif
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/ticker.cpp b/noncore/todayplugins/stockticker/stocktickerlib/ticker.cpp
new file mode 100644
index 0000000..6e6273b
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/ticker.cpp
@@ -0,0 +1,93 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31
32*/
33
34#include <qpe/qpeapplication.h>
35#include <qpe/resource.h>
36#include <qpe/config.h>
37
38#include <qwidget.h>
39#include <qpixmap.h>
40#include <qbutton.h>
41#include <qpainter.h>
42#include <qframe.h>
43#include <qlayout.h>
44#include <qdir.h>
45#include <stdlib.h>
46#include <stdio.h>
47
48#include "ticker.h"
49
50Ticker::Ticker( QWidget* parent=0 ) : QFrame( parent ) {
51 setFrameStyle( NoFrame/*WinPanel | Sunken */);
52}
53
54Ticker::~Ticker() {
55}
56
57void Ticker::setText( const QString& text ) {
58
59 pos = 0; // reset it everytime the text is changed
60 scrollText = text;
61
62 int pixelLen = fontMetrics().width( text );
63 QPixmap pm( pixelLen, contentsRect().height() );
64 pm.fill( QColor( 167, 212, 167 ) );
65 QPainter pmp( &pm );
66 pmp.setPen( Qt::black );
67 pmp.drawText( 0, 0, pixelLen, contentsRect().height(), AlignVCenter, scrollText );
68 pmp.end();
69 scrollTextPixmap = pm;
70
71 killTimers();
72 if ( pixelLen > contentsRect().width() )
73 startTimer( 50 );
74 update();
75}
76
77
78void Ticker::timerEvent( QTimerEvent * ) {
79 pos = ( pos <= 0 ) ? scrollTextPixmap.width() : pos - 1;
80 repaint( FALSE );
81}
82
83void Ticker::drawContents( QPainter *p ) {
84 int pixelLen = scrollTextPixmap.width();
85 p->drawPixmap( pos, contentsRect().y(), scrollTextPixmap );
86 if ( pixelLen > contentsRect().width() ) // Scrolling
87 p->drawPixmap( pos - pixelLen, contentsRect().y(), scrollTextPixmap );
88}
89
90void Ticker::mouseReleaseEvent( QMouseEvent * e) {
91 qDebug("<<<<<<<>>>>>>>>>");
92 emit mousePressed();
93}
diff --git a/noncore/todayplugins/stockticker/stocktickerlib/ticker.h b/noncore/todayplugins/stockticker/stocktickerlib/ticker.h
new file mode 100644
index 0000000..3b68928
--- a/dev/null
+++ b/noncore/todayplugins/stockticker/stocktickerlib/ticker.h
@@ -0,0 +1,32 @@
1#ifndef TICKER_H
2#define TICKER_H
3
4#include <qwidget.h>
5#include <qpainter.h>
6#include <qdrawutil.h>
7#include <qpixmap.h>
8#include <qstring.h>
9#include <qslider.h>
10#include <qframe.h>
11#include <qlineedit.h>
12
13class Ticker : public QFrame {
14 Q_OBJECT
15
16public:
17 Ticker( QWidget* parent=0 );
18 ~Ticker();
19 void setText( const QString& text ) ;
20signals:
21 void mousePressed();
22protected:
23 void timerEvent( QTimerEvent * );
24 void drawContents( QPainter *p );
25 void mouseReleaseEvent ( QMouseEvent *);
26private:
27 QString scrollText;
28 QPixmap scrollTextPixmap;
29 int pos;//, pixelLen;
30};
31
32#endif