Add weather_forecast object
[monky] / src / text_object.h
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  *
3  * Conky, a system monitor, based on torsmo
4  *
5  * Any original torsmo code is licensed under the BSD license
6  *
7  * All code written since the fork of torsmo is licensed under the GPL
8  *
9  * Please see COPYING for details
10  *
11  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
13  *      (see AUTHORS)
14  * All rights reserved.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 #ifndef _TEXT_OBJECT_H
30 #define _TEXT_OBJECT_H
31
32 #include "config.h"             /* for the defines */
33 #include "timed_thread.h"       /* timed_thread */
34
35 #ifdef TCP_PORT_MONITOR
36 #include "tcp-portmon.h"        /* tcp_port_monitor_data */
37 #endif
38
39 #include "mail.h"               /* local_mail_s */
40 #include "fs.h"                 /* struct fs_stat */
41
42 #ifdef NVIDIA
43 #include "nvidia.h"             /* nvidia_s */
44 #endif
45
46 enum text_object_type {
47         OBJ_read_tcp,
48         OBJ_addr,
49 #if defined(__linux__)
50         OBJ_addrs,
51 #endif /* __linux__ */
52 #ifndef __OpenBSD__
53         OBJ_acpiacadapter,
54         OBJ_adt746xcpu,
55         OBJ_adt746xfan,
56         OBJ_acpifan,
57         OBJ_acpitemp,
58         OBJ_battery,
59         OBJ_battery_time,
60         OBJ_battery_percent,
61         OBJ_battery_bar,
62         OBJ_battery_short,
63 #endif /* !__OpenBSD__ */
64         OBJ_buffers,
65         OBJ_cached,
66         OBJ_color,
67         OBJ_color0,
68         OBJ_color1,
69         OBJ_color2,
70         OBJ_color3,
71         OBJ_color4,
72         OBJ_color5,
73         OBJ_color6,
74         OBJ_color7,
75         OBJ_color8,
76         OBJ_color9,
77         OBJ_conky_version,
78         OBJ_conky_build_date,
79         OBJ_conky_build_arch,
80         OBJ_font,
81         OBJ_cpu,
82         OBJ_cpubar,
83 #ifdef X11
84         OBJ_cpugauge,
85         OBJ_cpugraph,
86         OBJ_loadgraph,
87 #endif /* X11 */
88         OBJ_diskio,
89         OBJ_diskio_read,
90         OBJ_diskio_write,
91 #ifdef X11
92         OBJ_diskiograph,
93         OBJ_diskiograph_read,
94         OBJ_diskiograph_write,
95 #endif /* X11 */
96         OBJ_downspeed,
97         OBJ_downspeedf,
98 #ifdef X11
99         OBJ_downspeedgraph,
100 #endif /* X11 */
101         OBJ_else,
102         OBJ_endif,
103         OBJ_eval,
104         OBJ_image,
105         OBJ_exec,
106         OBJ_execi,
107         OBJ_texeci,
108         OBJ_execbar,
109         OBJ_execibar,
110 #ifdef X11
111         OBJ_execgauge,
112         OBJ_execgraph,
113         OBJ_execigraph,
114         OBJ_execigauge,
115 #endif /* X11 */
116         OBJ_execp,
117         OBJ_execpi,
118         OBJ_freq,
119         OBJ_freq_g,
120         OBJ_fs_bar,
121         OBJ_fs_bar_free,
122         OBJ_fs_free,
123         OBJ_fs_free_perc,
124         OBJ_fs_size,
125         OBJ_fs_type,
126         OBJ_fs_used,
127         OBJ_fs_used_perc,
128         OBJ_goto,
129         OBJ_tab,
130         OBJ_hr,
131         OBJ_offset,
132         OBJ_voffset,
133         OBJ_alignr,
134         OBJ_alignc,
135         OBJ_i2c,
136         OBJ_platform,
137         OBJ_hwmon,
138 #if defined(__linux__)
139         OBJ_disk_protect,
140         OBJ_i8k_version,
141         OBJ_i8k_bios,
142         OBJ_i8k_serial,
143         OBJ_i8k_cpu_temp,
144         OBJ_i8k_left_fan_status,
145         OBJ_i8k_right_fan_status,
146         OBJ_i8k_left_fan_rpm,
147         OBJ_i8k_right_fan_rpm,
148         OBJ_i8k_ac_status,
149         OBJ_i8k_buttons_status,
150 #if defined(IBM)
151         OBJ_ibm_fan,
152         OBJ_ibm_temps,
153         OBJ_ibm_volume,
154         OBJ_ibm_brightness,
155         OBJ_smapi,
156 #ifdef X11
157         OBJ_smapi_bat_bar,
158 #endif /* X11 */
159         OBJ_smapi_bat_perc,
160         OBJ_smapi_bat_temp,
161         OBJ_smapi_bat_power,
162         OBJ_if_smapi_bat_installed,
163 #endif /* IBM */
164         /* information from sony_laptop kernel module
165          * /sys/devices/platform/sony-laptop */
166         OBJ_sony_fanspeed,
167         OBJ_if_gw,
168         OBJ_ioscheduler,
169         OBJ_gw_iface,
170         OBJ_gw_ip,
171         OBJ_laptop_mode,
172         OBJ_pb_battery,
173         OBJ_voltage_mv,
174         OBJ_voltage_v,
175         OBJ_wireless_essid,
176         OBJ_wireless_mode,
177         OBJ_wireless_bitrate,
178         OBJ_wireless_ap,
179         OBJ_wireless_link_qual,
180         OBJ_wireless_link_qual_max,
181         OBJ_wireless_link_qual_perc,
182         OBJ_wireless_link_bar,
183 #endif /* __linux__ */
184 #if defined(__FreeBSD__) || defined(__linux__)
185         OBJ_if_up,
186 #endif
187         OBJ_if_empty,
188         OBJ_if_match,
189         OBJ_if_existing,
190         OBJ_if_mounted,
191         OBJ_if_running,
192         OBJ_if_updatenr,
193         OBJ_top,
194         OBJ_top_mem,
195         OBJ_top_time,
196 #ifdef IOSTATS
197         OBJ_top_io,
198 #endif
199         OBJ_tail,
200         OBJ_head,
201         OBJ_lines,
202         OBJ_words,
203         OBJ_kernel,
204         OBJ_loadavg,
205         OBJ_machine,
206         OBJ_mails,
207         OBJ_new_mails,
208         OBJ_seen_mails,
209         OBJ_unseen_mails,
210         OBJ_flagged_mails,
211         OBJ_unflagged_mails,
212         OBJ_forwarded_mails,
213         OBJ_unforwarded_mails,
214         OBJ_replied_mails,
215         OBJ_unreplied_mails,
216         OBJ_draft_mails,
217         OBJ_trashed_mails,
218         OBJ_mboxscan,
219         OBJ_mem,
220         OBJ_memeasyfree,
221         OBJ_memfree,
222 #ifdef X11
223         OBJ_memgauge,
224         OBJ_memgraph,
225 #endif /* X11 */
226         OBJ_membar,
227         OBJ_memmax,
228         OBJ_memperc,
229         OBJ_mixer,
230         OBJ_mixerl,
231         OBJ_mixerr,
232 #ifdef X11
233         OBJ_mixerbar,
234         OBJ_mixerlbar,
235         OBJ_mixerrbar,
236 #endif /* X11 */
237         OBJ_if_mixer_mute,
238 #ifdef X11
239         OBJ_monitor,
240         OBJ_monitor_number,
241         OBJ_desktop,
242         OBJ_desktop_number,
243         OBJ_desktop_name,
244 #endif /* X11 */
245         OBJ_nameserver,
246         OBJ_nodename,
247         OBJ_nvidia,
248         OBJ_pre_exec,
249         OBJ_processes,
250         OBJ_running_processes,
251         OBJ_shadecolor,
252         OBJ_outlinecolor,
253         OBJ_stippled_hr,
254         OBJ_swap,
255         OBJ_swapfree,
256         OBJ_swapbar,
257         OBJ_swapmax,
258         OBJ_swapperc,
259         OBJ_sysname,
260         OBJ_text,
261         OBJ_time,
262         OBJ_utime,
263         OBJ_tztime,
264         OBJ_totaldown,
265         OBJ_totalup,
266         OBJ_updates,
267         OBJ_upspeed,
268         OBJ_upspeedf,
269 #ifdef X11
270         OBJ_upspeedgraph,
271 #endif /* X11 */
272         OBJ_uptime,
273         OBJ_uptime_short,
274         OBJ_user_names,
275         OBJ_user_terms,
276         OBJ_user_times,
277         OBJ_user_number,
278         OBJ_imap_messages,
279         OBJ_imap_unseen,
280         OBJ_pop3_unseen,
281         OBJ_pop3_used,
282 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
283                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
284         OBJ_apm_adapter,
285         OBJ_apm_battery_time,
286         OBJ_apm_battery_life,
287 #endif /* __FreeBSD__ __OpenBSD__ */
288 #ifdef __OpenBSD__
289         OBJ_obsd_sensors_temp,
290         OBJ_obsd_sensors_fan,
291         OBJ_obsd_sensors_volt,
292         OBJ_obsd_vendor,
293         OBJ_obsd_product,
294 #endif /* __OpenBSD__ */
295 #ifdef MPD
296         OBJ_mpd_title,
297         OBJ_mpd_artist,
298         OBJ_mpd_album,
299         OBJ_mpd_random,
300         OBJ_mpd_repeat,
301         OBJ_mpd_vol,
302         OBJ_mpd_bitrate,
303         OBJ_mpd_status,
304         OBJ_mpd_bar,
305         OBJ_mpd_elapsed,
306         OBJ_mpd_length,
307         OBJ_mpd_track,
308         OBJ_mpd_name,
309         OBJ_mpd_file,
310         OBJ_mpd_percent,
311         OBJ_mpd_smart,
312         OBJ_if_mpd_playing,
313 #endif /* MPD */
314 #ifdef MOC
315         OBJ_moc_state,
316         OBJ_moc_file,
317         OBJ_moc_title,
318         OBJ_moc_artist,
319         OBJ_moc_song,
320         OBJ_moc_album,
321         OBJ_moc_totaltime,
322         OBJ_moc_timeleft,
323         OBJ_moc_curtime,
324         OBJ_moc_bitrate,
325         OBJ_moc_rate,
326 #endif /* MOC */
327 #ifdef XMMS2
328         OBJ_xmms2_artist,
329         OBJ_xmms2_album,
330         OBJ_xmms2_title,
331         OBJ_xmms2_genre,
332         OBJ_xmms2_comment,
333         OBJ_xmms2_url,
334         OBJ_xmms2_date,
335         OBJ_xmms2_tracknr,
336         OBJ_xmms2_bitrate,
337         OBJ_xmms2_id,
338         OBJ_xmms2_duration,
339         OBJ_xmms2_elapsed,
340         OBJ_xmms2_size,
341         OBJ_xmms2_percent,
342         OBJ_xmms2_status,
343 #ifdef X11
344         OBJ_xmms2_bar,
345 #endif /* X11 */
346         OBJ_xmms2_smart,
347         OBJ_xmms2_playlist,
348         OBJ_xmms2_timesplayed,
349         OBJ_if_xmms2_connected,
350 #endif /* XMMS2 */
351 #ifdef AUDACIOUS
352         OBJ_audacious_status,
353         OBJ_audacious_title,
354         OBJ_audacious_length,
355         OBJ_audacious_length_seconds,
356         OBJ_audacious_position,
357         OBJ_audacious_position_seconds,
358         OBJ_audacious_bitrate,
359         OBJ_audacious_frequency,
360         OBJ_audacious_channels,
361         OBJ_audacious_filename,
362         OBJ_audacious_playlist_length,
363         OBJ_audacious_playlist_position,
364         OBJ_audacious_main_volume,
365 #ifdef X11
366         OBJ_audacious_bar,
367 #endif /* X11 */
368 #endif /* AUDACIOUS */
369 #ifdef BMPX
370         OBJ_bmpx_title,
371         OBJ_bmpx_artist,
372         OBJ_bmpx_album,
373         OBJ_bmpx_track,
374         OBJ_bmpx_uri,
375         OBJ_bmpx_bitrate,
376 #endif /* BMPX */
377 #ifdef EVE
378         OBJ_eve,
379 #endif /* EVE */
380 #ifdef HAVE_CURL
381         OBJ_curl,
382 #endif /* HAVE_CURL */
383 #ifdef RSS
384         OBJ_rss,
385 #endif /* RSS */
386 #ifdef WEATHER
387         OBJ_weather,
388         OBJ_weather_forecast,
389 #endif /* WEATHER */
390 #ifdef HAVE_LUA
391         OBJ_lua,
392         OBJ_lua_parse,
393         OBJ_lua_bar,
394 #ifdef X11
395         OBJ_lua_graph,
396         OBJ_lua_gauge,
397 #endif /* X11 */
398 #endif /* HAVE_LUA */
399 #ifdef TCP_PORT_MONITOR
400         OBJ_tcp_portmon,
401 #endif /* TCP_PORT_MONITOR */
402 #ifdef HAVE_ICONV
403         OBJ_iconv_start,
404         OBJ_iconv_stop,
405 #endif /* HAVE_ICONV */
406 #ifdef HDDTEMP
407         OBJ_hddtemp,
408 #endif /* HDDTEMP */
409         OBJ_include,
410         OBJ_blink,
411         OBJ_to_bytes,
412         OBJ_scroll,
413         OBJ_combine,
414         OBJ_entropy_avail,
415         OBJ_entropy_perc,
416         OBJ_entropy_poolsize,
417         OBJ_entropy_bar,
418 #ifdef APCUPSD
419         OBJ_apcupsd,
420         OBJ_apcupsd_name,
421         OBJ_apcupsd_model,
422         OBJ_apcupsd_upsmode,
423         OBJ_apcupsd_cable,
424         OBJ_apcupsd_status,
425         OBJ_apcupsd_linev,
426         OBJ_apcupsd_load,
427         OBJ_apcupsd_loadbar,
428 #ifdef X11
429         OBJ_apcupsd_loadgraph,
430         OBJ_apcupsd_loadgauge,
431 #endif /* X11 */
432         OBJ_apcupsd_charge,
433         OBJ_apcupsd_timeleft,
434         OBJ_apcupsd_temp,
435         OBJ_apcupsd_lastxfer,
436 #endif /* APCUPSD */
437 };
438
439 struct text_object {
440         struct text_object *next, *prev;        /* doubly linked list of text objects */
441         struct text_object *sub;                /* for objects parsing text into objects */
442         union {
443                 char *s;                /* some string */
444                 int i;                  /* some integer */
445                 long l;                 /* some other integer */
446                 unsigned int sensor;
447                 struct net_stat *net;
448                 struct fs_stat *fs;
449                 struct diskio_stat *diskio;
450                 unsigned char loadavg[3];
451                 unsigned int cpu_index;
452                 struct mail_s *mail;
453
454                 struct {
455                         char *args;
456                         char *output;
457                 } mboxscan;
458
459                 struct {
460                         char *tz;       /* timezone variable */
461                         char *fmt;      /* time display formatting */
462                 } tztime;
463
464                 struct {
465                         struct fs_stat *fs;
466                         int w, h;
467                 } fsbar;                /* 3 */
468
469 #ifdef X11
470                 struct {
471                         int l;
472                         int w, h;
473                 } mixerbar;             /* 3 */
474 #endif
475
476                 struct {
477                         int fd;
478                         int arg;
479                         char devtype[256];
480                         char type[64];
481                         float factor, offset;
482                 } sysfs;
483
484                 struct {
485                         struct text_object *next;
486                         char *s;
487                         int i;
488                         char *str;
489                 } ifblock;
490
491                 struct {
492                         int num;
493                         int type;
494                         int was_parsed;
495                         char *s;
496                 } top;
497
498                 struct {
499                         int wantedlines;
500                         char *logfile;
501                         char *buffer;
502                         int current_use;
503                         int max_uses;
504                 } headtail;
505
506                 struct {
507                         double last_update;
508                         float interval;
509                         char *cmd;
510                         char *buffer;
511                         double data;
512                 } execi;                /* 5 */
513
514                 struct {
515                         float interval;
516                         char *cmd;
517                         char *buffer;
518                         double data;
519                         timed_thread *p_timed_thread;
520                 } texeci;
521
522                 struct {
523                         int a, b;
524                 } pair;                 /* 2 */
525 #ifdef TCP_PORT_MONITOR
526                 struct tcp_port_monitor_data tcp_port_monitor;
527 #endif
528 #ifdef HDDTEMP
529                 struct {
530                         char *addr;
531                         int port;
532                         char *dev;
533                         double update_time;
534                         char *temp;
535                 } hddtemp;              /* 2 */
536 #endif
537 #ifdef EVE
538                 struct {
539                         char *apikey;
540                         char *charid;
541                         char *userid;
542                 } eve;
543 #endif
544 #ifdef HAVE_CURL
545                 struct {
546                         char *uri;
547                         float interval;
548                 } curl;
549 #endif
550 #ifdef RSS
551                 struct {
552                         char *uri;
553                         char *action;
554                         int act_par;
555                         float interval;
556                         unsigned int nrspaces;
557                 } rss;
558 #endif
559 #ifdef WEATHER
560                 struct {
561                         char *uri;
562                         char *data_type;
563                         int interval;
564                 } weather;
565 #endif
566 #ifdef XOAP
567                 struct {
568                         char *uri;
569                         unsigned int day;
570                         char *data_type;
571                         int interval;
572                 } weather_forecast;
573 #endif
574                 struct {
575                         char *text;
576                         unsigned int show;
577                         unsigned int step;
578                         unsigned int start;
579                         long resetcolor;
580                 } scroll;
581
582                 struct {
583                         char *left;
584                         char *seperation;
585                         char *right;
586                 } combine;
587
588                 struct {
589                         char *host;
590                         unsigned int port;
591                 } read_tcp;
592
593                 struct local_mail_s local_mail;
594 #ifdef NVIDIA
595                 struct nvidia_s nvidia;
596 #endif /* NVIDIA */
597
598         } data;
599         int type;
600         int a, b;
601         long line;
602         unsigned int c, d, e;
603         float f;
604         char char_a, char_b;
605 };
606
607 /* text object list helpers */
608 int append_object(struct text_object *root, struct text_object *obj);
609
610 /* ifblock helpers
611  *
612  * Opaque is a pointer to the address of the ifblock stack's top object.
613  * Calling clients should pass the address of a defined void pointer which
614  * was initialised to NULL (empty stack).
615  * */
616 int obj_be_ifblock_if(void **opaque, struct text_object *);
617 int obj_be_ifblock_else(void **opaque, struct text_object *);
618 int obj_be_ifblock_endif(void **opaque, struct text_object *);
619 int ifblock_stack_empty(void **opaque);
620
621 #endif /* _TEXT_OBJECT_H */