1 | #ifndef WEATHER_H |
---|
2 | #define WEATHER_H |
---|
3 | |
---|
4 | struct weather |
---|
5 | { |
---|
6 | char* city; |
---|
7 | char* date; |
---|
8 | char* day0; |
---|
9 | char* day0_low; |
---|
10 | char* day0_high; |
---|
11 | char* day0_condition; |
---|
12 | char* day0_icon; |
---|
13 | char* day0_temp; |
---|
14 | char* day0_humidity; |
---|
15 | char* day0_wind; |
---|
16 | char* day1; |
---|
17 | char* day1_low; |
---|
18 | char* day1_high; |
---|
19 | char* day1_condition; |
---|
20 | char* day1_icon; |
---|
21 | char* day2; |
---|
22 | char* day2_low; |
---|
23 | char* day2_high; |
---|
24 | char* day2_condition; |
---|
25 | char* day2_icon; |
---|
26 | char* day3; |
---|
27 | char* day3_low; |
---|
28 | char* day3_high; |
---|
29 | char* day3_condition; |
---|
30 | char* day3_icon; |
---|
31 | }; |
---|
32 | |
---|
33 | int writeweather(const char *filename, struct skin* listbox); |
---|
34 | |
---|
35 | char* readweather(const char* filename, struct skin* weather, struct skin* listbox) |
---|
36 | { |
---|
37 | debug(1000, "in"); |
---|
38 | FILE *fd = NULL; |
---|
39 | char *fileline = NULL; |
---|
40 | char *location = NULL; |
---|
41 | struct skin* tmp = NULL; |
---|
42 | int len = 0; |
---|
43 | |
---|
44 | if(weather == NULL || listbox == NULL) return NULL; |
---|
45 | |
---|
46 | fileline = malloc(MINMALLOC); |
---|
47 | if(fileline == NULL) |
---|
48 | { |
---|
49 | err("no memory"); |
---|
50 | return NULL; |
---|
51 | } |
---|
52 | |
---|
53 | fd = fopen(filename, "r"); |
---|
54 | if(fd == NULL) |
---|
55 | { |
---|
56 | perr("can't open %s", filename); |
---|
57 | free(fileline); |
---|
58 | return NULL; |
---|
59 | } |
---|
60 | |
---|
61 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
62 | { |
---|
63 | if(fileline[0] == '#' || fileline[0] == '\n') |
---|
64 | continue; |
---|
65 | len = strlen(fileline) - 1; |
---|
66 | if(len >= 0 && fileline[len] == '\n') |
---|
67 | fileline[len] = '\0'; |
---|
68 | len--; |
---|
69 | if(len >= 0 && fileline[len] == '\r') |
---|
70 | fileline[len] = '\0'; |
---|
71 | |
---|
72 | tmp = addlistbox(weather, listbox, tmp, 1); |
---|
73 | if(tmp != NULL) |
---|
74 | { |
---|
75 | changetext(tmp, fileline); |
---|
76 | changename(tmp, fileline); |
---|
77 | if(location == NULL) |
---|
78 | { |
---|
79 | location = ostrcat(location, fileline, 1, 0); |
---|
80 | location = ostrshrink(location); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | free(fileline); |
---|
87 | fclose(fd); |
---|
88 | return location; |
---|
89 | } |
---|
90 | |
---|
91 | void freeweather(struct weather* node) |
---|
92 | { |
---|
93 | if(node == NULL) return; |
---|
94 | |
---|
95 | free(node->city); node->city = NULL; |
---|
96 | free(node->date); node->date = NULL; |
---|
97 | |
---|
98 | free(node->day0); node->day0 = NULL; |
---|
99 | free(node->day0_low); node->day0_low = NULL; |
---|
100 | free(node->day0_high); node->day0_high = NULL; |
---|
101 | free(node->day0_condition); node->day0_condition = NULL; |
---|
102 | free(node->day0_icon); node->day0_icon = NULL; |
---|
103 | free(node->day0_temp); node->day0_temp = NULL; |
---|
104 | free(node->day0_humidity); node->day0_humidity = NULL; |
---|
105 | free(node->day0_wind); node->day0_wind = NULL; |
---|
106 | |
---|
107 | free(node->day1); node->day1 = NULL; |
---|
108 | free(node->day1_low); node->day1_low = NULL; |
---|
109 | free(node->day1_high); node->day1_high = NULL; |
---|
110 | free(node->day1_condition); node->day1_condition = NULL; |
---|
111 | free(node->day1_icon); node->day1_icon = NULL; |
---|
112 | |
---|
113 | free(node->day2); node->day2 = NULL; |
---|
114 | free(node->day2_low); node->day2_low = NULL; |
---|
115 | free(node->day2_high); node->day2_high = NULL; |
---|
116 | free(node->day2_condition); node->day2_condition = NULL; |
---|
117 | free(node->day2_icon); node->day2_icon = NULL; |
---|
118 | |
---|
119 | free(node->day3); node->day3 = NULL; |
---|
120 | free(node->day3_low); node->day3_low = NULL; |
---|
121 | free(node->day3_high); node->day3_high = NULL; |
---|
122 | free(node->day3_condition); node->day3_condition = NULL; |
---|
123 | free(node->day3_icon); node->day3_icon = NULL; |
---|
124 | |
---|
125 | free(node); node = NULL; |
---|
126 | } |
---|
127 | |
---|
128 | struct weather* getweather(char* location) |
---|
129 | { |
---|
130 | struct weather* weather = NULL; |
---|
131 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL; |
---|
132 | char* tmpsearch = NULL; |
---|
133 | |
---|
134 | if(location == NULL) return NULL; |
---|
135 | |
---|
136 | tmpsearch = ostrcat("data.aspx?weadegreetype=C&culture=de-DE&weasearchstr=", location, 0, 0); |
---|
137 | //tmpsearch = ostrcat("ig/api?weather=", location, 0, 0); |
---|
138 | //TODO: implement auto language (from titan.cfg) |
---|
139 | //tmpsearch = ostrcat(tmpsearch, "&hl=de", 1, 0); |
---|
140 | //tmpsearch = stringreplacechar(tmpsearch, ' ', '+'); |
---|
141 | |
---|
142 | tmpstr = gethttp("weather.service.msn.com", tmpsearch, 80, NULL, NULL, 5000, NULL, 0); |
---|
143 | //tmpstr = gethttp("www.google.com", tmpsearch, 80, NULL, NULL, 5000, NULL, 0); |
---|
144 | |
---|
145 | free(tmpsearch); tmpsearch = NULL; |
---|
146 | |
---|
147 | if(tmpstr != NULL) |
---|
148 | { |
---|
149 | weather = (struct weather*)malloc(sizeof(struct weather)); |
---|
150 | if(weather == NULL) |
---|
151 | { |
---|
152 | err("no mem"); |
---|
153 | free(tmpstr); tmpstr = NULL; |
---|
154 | return NULL; |
---|
155 | } |
---|
156 | memset(weather, 0, sizeof(struct weather)); |
---|
157 | |
---|
158 | tmpstr1 = tmpstr; |
---|
159 | tmpstr2 = tmpstr; |
---|
160 | |
---|
161 | tmpstr2 = ostrstr(tmpstr1, "<weather weatherlocationcode="); |
---|
162 | if(tmpstr2 != NULL) |
---|
163 | { |
---|
164 | tmpstr1 = tmpstr2 + 5; |
---|
165 | weather->city = getxmlentry(tmpstr2, "weatherlocationname="); |
---|
166 | } |
---|
167 | |
---|
168 | tmpstr2 = ostrstr(tmpstr1, "<current_conditions>"); |
---|
169 | tmpstr2 = ostrstr(tmpstr1, "<current "); |
---|
170 | if(tmpstr2 != NULL) |
---|
171 | { |
---|
172 | tmpstr1 = tmpstr2 + 5; |
---|
173 | weather->day0_temp = getxmlentry(tmpstr2, "temperature="); |
---|
174 | weather->date = getxmlentry(tmpstr2, "date="); |
---|
175 | weather->day0_humidity = getxmlentry(tmpstr2, "humidity="); |
---|
176 | weather->day0_wind = getxmlentry(tmpstr2, "windspeed="); |
---|
177 | } |
---|
178 | |
---|
179 | tmpstr2 = ostrstr(tmpstr1, "<forecast "); |
---|
180 | if(tmpstr2 != NULL) |
---|
181 | { |
---|
182 | tmpstr1 = tmpstr2 + 5; |
---|
183 | weather->day0_low = getxmlentry(tmpstr2, "low="); |
---|
184 | weather->day0_high = getxmlentry(tmpstr2, "high="); |
---|
185 | weather->day0_icon = getxmlentry(tmpstr2, "skycodeday="); |
---|
186 | weather->day0_condition = getxmlentry(tmpstr2, "skytextday="); |
---|
187 | weather->day0 = getxmlentry(tmpstr2, " shortday="); |
---|
188 | } |
---|
189 | |
---|
190 | tmpstr2 = ostrstr(tmpstr1, "<forecast "); |
---|
191 | if(tmpstr2 != NULL) |
---|
192 | { |
---|
193 | tmpstr1 = tmpstr2 + 5; |
---|
194 | weather->day1_low = getxmlentry(tmpstr2, "low="); |
---|
195 | weather->day1_high = getxmlentry(tmpstr2, "high="); |
---|
196 | weather->day1_icon = getxmlentry(tmpstr2, "skycodeday="); |
---|
197 | weather->day1_condition = getxmlentry(tmpstr2, "skytextday="); |
---|
198 | weather->day1 = getxmlentry(tmpstr2, " shortday="); |
---|
199 | } |
---|
200 | |
---|
201 | tmpstr2 = ostrstr(tmpstr1, "<forecast "); |
---|
202 | if(tmpstr2 != NULL) |
---|
203 | { |
---|
204 | tmpstr1 = tmpstr2 + 5; |
---|
205 | weather->day2_low = getxmlentry(tmpstr2, "low="); |
---|
206 | weather->day2_high = getxmlentry(tmpstr2, "high="); |
---|
207 | weather->day2_icon = getxmlentry(tmpstr2, "skycodeday="); |
---|
208 | weather->day2_condition = getxmlentry(tmpstr2, "skytextday="); |
---|
209 | weather->day2 = getxmlentry(tmpstr2, " shortday="); |
---|
210 | } |
---|
211 | |
---|
212 | tmpstr2 = ostrstr(tmpstr1, "<forecast "); |
---|
213 | if(tmpstr2 != NULL) |
---|
214 | { |
---|
215 | tmpstr1 = tmpstr2 + 5; |
---|
216 | weather->day3_low = getxmlentry(tmpstr2, "low="); |
---|
217 | weather->day3_high = getxmlentry(tmpstr2, "high="); |
---|
218 | weather->day3_icon = getxmlentry(tmpstr2, "skycodeday="); |
---|
219 | weather->day3_condition = getxmlentry(tmpstr2, "skytextday="); |
---|
220 | weather->day3 = getxmlentry(tmpstr2, " shortday="); |
---|
221 | } |
---|
222 | |
---|
223 | free(tmpstr); tmpstr = NULL; |
---|
224 | } |
---|
225 | |
---|
226 | return weather; |
---|
227 | } |
---|
228 | |
---|
229 | void changeweatherpic(struct skin* node, char* icon) |
---|
230 | { |
---|
231 | |
---|
232 | /* |
---|
233 | 0 => 'thunderstorm', |
---|
234 | 1 => 'thunderstorm', |
---|
235 | 2 => 'thunderstorm', |
---|
236 | 3 => 'thunderstorm', |
---|
237 | 4 => 'thunderstorm', |
---|
238 | 5 => 'rain_snow', |
---|
239 | 6 => 'sleet', |
---|
240 | 7 => 'rain_snow', |
---|
241 | 8 => 'icy', |
---|
242 | 9 => 'icy', |
---|
243 | 10 => 'rain_snow', |
---|
244 | 11 => 'showers', |
---|
245 | 12 => 'rain', |
---|
246 | 13 => 'flurries', |
---|
247 | 14 => 'snow', |
---|
248 | 15 => 'snow', |
---|
249 | 16 => 'snow', |
---|
250 | 17 => 'thunderstorm', |
---|
251 | 18 => 'showers', |
---|
252 | 19 => 'dust', |
---|
253 | 20 => 'fog', |
---|
254 | 21 => 'haze', |
---|
255 | 22 => 'haze', |
---|
256 | 23 => 'windy', |
---|
257 | 24 => 'windy', |
---|
258 | 25 => 'icy', |
---|
259 | 26 => 'cloudy', |
---|
260 | 27 => 'mostly_cloudy', |
---|
261 | 28 => 'mostly_cloudy', |
---|
262 | 29 => 'partly_cloudy', |
---|
263 | 30 => 'partly_cloudy', |
---|
264 | 31 => 'sunny', |
---|
265 | 32 => 'sunny', |
---|
266 | 33 => 'mostly_sunny', |
---|
267 | 34 => 'mostly_sunny', |
---|
268 | 35 => 'thunderstorm', |
---|
269 | 36 => 'hot', |
---|
270 | 37 => 'chance_of_tstorm', |
---|
271 | 38 => 'chance_of_tstorm', |
---|
272 | 39 => 'chance_of_rain', |
---|
273 | 40 => 'showers', |
---|
274 | 41 - 'chance_of_snow', |
---|
275 | 42 => 'snow', |
---|
276 | 43 => 'snow', |
---|
277 | 44 => 'na', |
---|
278 | 45 => 'chance_of_rain', |
---|
279 | 46 => 'chance_of_snow', |
---|
280 | 47 => 'chance_of_tstorm'); |
---|
281 | */ |
---|
282 | |
---|
283 | if(icon == NULL) |
---|
284 | return; |
---|
285 | |
---|
286 | else if(ostrstr(icon, "10") != NULL) |
---|
287 | changepic(node, "%pluginpath%/weather/skin/chance_of_snow.png"); |
---|
288 | else if(ostrstr(icon, "11") != NULL) |
---|
289 | changepic(node, "%pluginpath%/weather/skin/showers.png"); |
---|
290 | else if(ostrstr(icon, "12") != NULL) |
---|
291 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
292 | else if(ostrstr(icon, "13") != NULL) |
---|
293 | changepic(node, "%pluginpath%/weather/skin/flurries.png"); |
---|
294 | else if(ostrstr(icon, "14") != NULL) |
---|
295 | changepic(node, "%pluginpath%/weather/skin/snow.png"); |
---|
296 | else if(ostrstr(icon, "15") != NULL) |
---|
297 | changepic(node, "%pluginpath%/weather/skin/snow.png"); |
---|
298 | else if(ostrstr(icon, "16") != NULL) |
---|
299 | changepic(node, "%pluginpath%/weather/skin/snow.png"); |
---|
300 | else if(ostrstr(icon, "17") != NULL) |
---|
301 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
302 | else if(ostrstr(icon, "18") != NULL) |
---|
303 | changepic(node, "%pluginpath%/weather/skin/showers.png"); |
---|
304 | else if(ostrstr(icon, "19") != NULL) |
---|
305 | changepic(node, "%pluginpath%/weather/skin/fog.png"); |
---|
306 | else if(ostrstr(icon, "20") != NULL) |
---|
307 | changepic(node, "%pluginpath%/weather/skin/fog.png"); |
---|
308 | else if(ostrstr(icon, "21") != NULL) |
---|
309 | changepic(node, "%pluginpath%/weather/skin/fog.png"); |
---|
310 | else if(ostrstr(icon, "22") != NULL) |
---|
311 | changepic(node, "%pluginpath%/weather/skin/fog.png"); |
---|
312 | else if(ostrstr(icon, "23") != NULL) |
---|
313 | changepic(node, "%pluginpath%/weather/skin/chance_of_storm.png"); |
---|
314 | else if(ostrstr(icon, "24") != NULL) |
---|
315 | changepic(node, "%pluginpath%/weather/skin/chance_of_storm.png"); |
---|
316 | else if(ostrstr(icon, "25") != NULL) |
---|
317 | changepic(node, "%pluginpath%/weather/skin/icy.png"); |
---|
318 | else if(ostrstr(icon, "26") != NULL) |
---|
319 | changepic(node, "%pluginpath%/weather/skin/cloudy.png"); |
---|
320 | else if(ostrstr(icon, "27") != NULL) |
---|
321 | changepic(node, "%pluginpath%/weather/skin/partly_cloudy.png"); |
---|
322 | else if(ostrstr(icon, "28") != NULL) |
---|
323 | changepic(node, "%pluginpath%/weather/skin/partly_cloudy.png"); |
---|
324 | else if(ostrstr(icon, "29") != NULL) |
---|
325 | changepic(node, "%pluginpath%/weather/skin/partly_cloudy.png"); |
---|
326 | else if(ostrstr(icon, "30") != NULL) |
---|
327 | changepic(node, "%pluginpath%/weather/skin/partly_cloudy.png"); |
---|
328 | else if(ostrstr(icon, "31") != NULL) |
---|
329 | changepic(node, "%pluginpath%/weather/skin/sunny.png"); |
---|
330 | else if(ostrstr(icon, "32") != NULL) |
---|
331 | changepic(node, "%pluginpath%/weather/skin/sunny.png"); |
---|
332 | else if(ostrstr(icon, "33") != NULL) |
---|
333 | changepic(node, "%pluginpath%/weather/skin/mostly_sunny.png"); |
---|
334 | else if(ostrstr(icon, "34") != NULL) |
---|
335 | changepic(node, "%pluginpath%/weather/skin/mostly_sunny.png"); |
---|
336 | else if(ostrstr(icon, "35") != NULL) |
---|
337 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
338 | else if(ostrstr(icon, "36") != NULL) |
---|
339 | changepic(node, "%pluginpath%/weather/skin/sunny.png"); |
---|
340 | else if(ostrstr(icon, "37") != NULL) |
---|
341 | changepic(node, "%pluginpath%/weather/skin/chance_of_storm.png"); |
---|
342 | else if(ostrstr(icon, "38") != NULL) |
---|
343 | changepic(node, "%pluginpath%/weather/skin/chance_of_storm.png"); |
---|
344 | else if(ostrstr(icon, "39") != NULL) |
---|
345 | changepic(node, "%pluginpath%/weather/skin/chance_of_rain.png"); |
---|
346 | else if(ostrstr(icon, "40") != NULL) |
---|
347 | changepic(node, "%pluginpath%/weather/skin/showers.png"); |
---|
348 | else if(ostrstr(icon, "41") != NULL) |
---|
349 | changepic(node, "%pluginpath%/weather/skin/chance_of_snow.png"); |
---|
350 | else if(ostrstr(icon, "42") != NULL) |
---|
351 | changepic(node, "%pluginpath%/weather/skin/snow.png"); |
---|
352 | else if(ostrstr(icon, "43") != NULL) |
---|
353 | changepic(node, "%pluginpath%/weather/skin/snow.png"); |
---|
354 | else if(ostrstr(icon, "44") != NULL) |
---|
355 | changepic(node, "%pluginpath%/weather/skin/xxxx.png"); |
---|
356 | else if(ostrstr(icon, "45") != NULL) |
---|
357 | changepic(node, "%pluginpath%/weather/skin/chance_of_rain.png"); |
---|
358 | else if(ostrstr(icon, "46") != NULL) |
---|
359 | changepic(node, "%pluginpath%/weather/skin/chance_of_snow.png"); |
---|
360 | else if(ostrstr(icon, "47") != NULL) |
---|
361 | changepic(node, "%pluginpath%/weather/skin/chance_of_rain.png"); |
---|
362 | else if(ostrstr(icon, "0") != NULL) |
---|
363 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
364 | else if(ostrstr(icon, "1") != NULL) |
---|
365 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
366 | else if(ostrstr(icon, "2") != NULL) |
---|
367 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
368 | else if(ostrstr(icon, "3") != NULL) |
---|
369 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
370 | else if(ostrstr(icon, "4") != NULL) |
---|
371 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
372 | else if(ostrstr(icon, "5") != NULL) |
---|
373 | changepic(node, "%pluginpath%/weather/skin/chance_of_snow.png"); |
---|
374 | else if(ostrstr(icon, "6") != NULL) |
---|
375 | changepic(node, "%pluginpath%/weather/skin/rain.png"); |
---|
376 | else if(ostrstr(icon, "7") != NULL) |
---|
377 | changepic(node, "%pluginpath%/weather/skin/chance_of_snow.png"); |
---|
378 | else if(ostrstr(icon, "8") != NULL) |
---|
379 | changepic(node, "%pluginpath%/weather/skin/icy.png"); |
---|
380 | else if(ostrstr(icon, "9") != NULL) |
---|
381 | changepic(node, "%pluginpath%/weather/skin/icy.png"); |
---|
382 | } |
---|
383 | |
---|
384 | void screenweather() |
---|
385 | { |
---|
386 | int rcret = 0; |
---|
387 | struct skin* weather = getscreen("weather"); |
---|
388 | struct skin* listbox = getscreennode(weather, "listbox"); |
---|
389 | struct skin* date = getscreennode(weather, "date"); |
---|
390 | struct skin* day0 = getscreennode(weather, "day0"); |
---|
391 | struct skin* day0_low = getscreennode(weather, "day0_low"); |
---|
392 | struct skin* day0_high = getscreennode(weather, "day0_high"); |
---|
393 | struct skin* day0_condition = getscreennode(weather, "day0_condition"); |
---|
394 | struct skin* day0_icon = getscreennode(weather, "day0_icon"); |
---|
395 | struct skin* day1 = getscreennode(weather, "day1"); |
---|
396 | struct skin* day1_low = getscreennode(weather, "day1_low"); |
---|
397 | struct skin* day1_high = getscreennode(weather, "day1_high"); |
---|
398 | struct skin* day1_condition = getscreennode(weather, "day1_condition"); |
---|
399 | struct skin* day1_icon = getscreennode(weather, "day1_icon"); |
---|
400 | struct skin* day2 = getscreennode(weather, "day2"); |
---|
401 | struct skin* day2_low = getscreennode(weather, "day2_low"); |
---|
402 | struct skin* day2_high = getscreennode(weather, "day2_high"); |
---|
403 | struct skin* day2_condition = getscreennode(weather, "day2_condition"); |
---|
404 | struct skin* day2_icon = getscreennode(weather, "day2_icon"); |
---|
405 | struct skin* day3 = getscreennode(weather, "day3"); |
---|
406 | struct skin* day3_low = getscreennode(weather, "day3_low"); |
---|
407 | struct skin* day3_high = getscreennode(weather, "day3_high"); |
---|
408 | struct skin* day3_condition = getscreennode(weather, "day3_condition"); |
---|
409 | struct skin* day3_icon = getscreennode(weather, "day3_icon"); |
---|
410 | struct weather* node = NULL; |
---|
411 | char* tmpstr = NULL, *location = NULL; |
---|
412 | |
---|
413 | location = readweather(getconfig("weatherfile", NULL), weather, listbox); |
---|
414 | addscreenrc(weather, listbox); |
---|
415 | |
---|
416 | start: |
---|
417 | |
---|
418 | tmpstr = ostrcat(_("Weather"), " - ", 0, 0); |
---|
419 | tmpstr = ostrcat(tmpstr, location, 1, 0); |
---|
420 | changetitle(weather, tmpstr); |
---|
421 | free(tmpstr); tmpstr = NULL; |
---|
422 | |
---|
423 | node = getweather(location); |
---|
424 | free(location); location = NULL; |
---|
425 | |
---|
426 | if(node != NULL) |
---|
427 | { |
---|
428 | changetext(date, node->date); |
---|
429 | |
---|
430 | tmpstr = ostrcat(_("Day: "), node->day0, 0, 0); |
---|
431 | changetext(day0, tmpstr); |
---|
432 | free(tmpstr); tmpstr = NULL; |
---|
433 | |
---|
434 | tmpstr = ostrcat(_("Lowest temp: "), node->day0_low, 0, 0); |
---|
435 | changetext(day0_low, tmpstr); |
---|
436 | free(tmpstr); tmpstr = NULL; |
---|
437 | |
---|
438 | tmpstr = ostrcat(_("Highest temp: "), node->day0_high, 0, 0); |
---|
439 | changetext(day0_high, tmpstr); |
---|
440 | free(tmpstr); tmpstr = NULL; |
---|
441 | |
---|
442 | tmpstr = ostrcat(_("Condition: "), node->day0_condition, 0, 0); |
---|
443 | changetext(day0_condition, tmpstr); |
---|
444 | free(tmpstr); tmpstr = NULL; |
---|
445 | |
---|
446 | changeweatherpic(day0_icon, node->day0_icon); |
---|
447 | |
---|
448 | tmpstr = ostrcat(_("Day: "), node->day1, 0, 0); |
---|
449 | changetext(day1, tmpstr); |
---|
450 | free(tmpstr); tmpstr = NULL; |
---|
451 | |
---|
452 | tmpstr = ostrcat(_("Lowest temp: "), node->day1_low, 0, 0); |
---|
453 | changetext(day1_low, tmpstr); |
---|
454 | free(tmpstr); tmpstr = NULL; |
---|
455 | |
---|
456 | tmpstr = ostrcat(_("Highest temp: "), node->day1_high, 0, 0); |
---|
457 | changetext(day1_high, tmpstr); |
---|
458 | free(tmpstr); tmpstr = NULL; |
---|
459 | |
---|
460 | tmpstr = ostrcat(_("Condition: "), node->day1_condition, 0, 0); |
---|
461 | changetext(day1_condition, tmpstr); |
---|
462 | free(tmpstr); tmpstr = NULL; |
---|
463 | |
---|
464 | changeweatherpic(day1_icon, node->day1_icon); |
---|
465 | |
---|
466 | tmpstr = ostrcat(_("Day: "), node->day2, 0, 0); |
---|
467 | changetext(day2, tmpstr); |
---|
468 | free(tmpstr); tmpstr = NULL; |
---|
469 | |
---|
470 | tmpstr = ostrcat(_("Lowest temp: "), node->day2_low, 0, 0); |
---|
471 | changetext(day2_low, tmpstr); |
---|
472 | free(tmpstr); tmpstr = NULL; |
---|
473 | |
---|
474 | tmpstr = ostrcat(_("Highest temp: "), node->day2_high, 0, 0); |
---|
475 | changetext(day2_high, tmpstr); |
---|
476 | free(tmpstr); tmpstr = NULL; |
---|
477 | |
---|
478 | tmpstr = ostrcat(_("Condition: "), node->day2_condition, 0, 0); |
---|
479 | changetext(day2_condition, tmpstr); |
---|
480 | free(tmpstr); tmpstr = NULL; |
---|
481 | |
---|
482 | changeweatherpic(day2_icon, node->day2_icon); |
---|
483 | |
---|
484 | tmpstr = ostrcat(_("Day: "), node->day3, 0, 0); |
---|
485 | changetext(day3, tmpstr); |
---|
486 | free(tmpstr); tmpstr = NULL; |
---|
487 | |
---|
488 | tmpstr = ostrcat(_("Lowest temp: "), node->day3_low, 0, 0); |
---|
489 | changetext(day3_low, tmpstr); |
---|
490 | free(tmpstr); tmpstr = NULL; |
---|
491 | |
---|
492 | tmpstr = ostrcat(_("Highest temp: "), node->day3_high, 0, 0); |
---|
493 | changetext(day3_high, tmpstr); |
---|
494 | free(tmpstr); tmpstr = NULL; |
---|
495 | |
---|
496 | tmpstr = ostrcat(_("Condition: "), node->day3_condition, 0, 0); |
---|
497 | changetext(day3_condition, tmpstr); |
---|
498 | free(tmpstr); tmpstr = NULL; |
---|
499 | |
---|
500 | changeweatherpic(day3_icon, node->day3_icon); |
---|
501 | } |
---|
502 | |
---|
503 | drawscreen(weather, 0, 0); |
---|
504 | |
---|
505 | while(1) |
---|
506 | { |
---|
507 | rcret = waitrc(weather, 0, 0); |
---|
508 | |
---|
509 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
510 | |
---|
511 | if(rcret == getrcconfigint("rcred", NULL)) |
---|
512 | { |
---|
513 | free(location); location = NULL; |
---|
514 | location = textinput("Location", NULL); |
---|
515 | if(location != NULL) |
---|
516 | { |
---|
517 | struct skin* tmp = addlistbox(weather, listbox, NULL, 1); |
---|
518 | if(tmp != NULL) |
---|
519 | { |
---|
520 | changetext(tmp, location); |
---|
521 | changename(tmp, location); |
---|
522 | } |
---|
523 | } |
---|
524 | drawscreen(weather, 0, 0); |
---|
525 | if(location == NULL) |
---|
526 | continue; |
---|
527 | free(location); location = NULL; |
---|
528 | } |
---|
529 | |
---|
530 | if(rcret == getrcconfigint("rcok", NULL)) |
---|
531 | { |
---|
532 | writeweather(getconfig("weatherfile", NULL), listbox); |
---|
533 | continue; |
---|
534 | } |
---|
535 | |
---|
536 | if(listbox->select != NULL && rcret == getrcconfigint("rcgreen", NULL)) |
---|
537 | { |
---|
538 | delscreennode(weather, listbox->select->name); |
---|
539 | listbox->select = NULL; |
---|
540 | drawscreen(weather, 0, 0); |
---|
541 | } |
---|
542 | |
---|
543 | if(listbox->select != NULL) |
---|
544 | { |
---|
545 | freeweather(node); node = NULL; |
---|
546 | location = ostrcat(location, listbox->select->text, 1, 0); |
---|
547 | goto start; |
---|
548 | } |
---|
549 | } |
---|
550 | |
---|
551 | delownerrc(weather); |
---|
552 | delmarkedscreennodes(weather, 1); |
---|
553 | freeweather(node); node = NULL; |
---|
554 | clearscreen(weather); |
---|
555 | } |
---|
556 | |
---|
557 | int writeweather(const char *filename, struct skin* listbox) |
---|
558 | { |
---|
559 | debug(1000, "in"); |
---|
560 | FILE *fd = NULL; |
---|
561 | struct skin* node = listbox; |
---|
562 | int ret = 0; |
---|
563 | |
---|
564 | fd = fopen(filename, "w"); |
---|
565 | if(fd == NULL) |
---|
566 | { |
---|
567 | perr("can't open %s", filename); |
---|
568 | return 1; |
---|
569 | } |
---|
570 | |
---|
571 | while(node != NULL) |
---|
572 | { |
---|
573 | if(node->del == 1) |
---|
574 | { |
---|
575 | ret = fprintf(fd, "%s\n", node->text); |
---|
576 | if(ret < 0) |
---|
577 | { |
---|
578 | perr("writting file %s", filename); |
---|
579 | } |
---|
580 | } |
---|
581 | node = node->next; |
---|
582 | } |
---|
583 | |
---|
584 | fclose(fd); |
---|
585 | debug(1000, "out"); |
---|
586 | return 0; |
---|
587 | } |
---|
588 | |
---|
589 | #endif |
---|