Merge branch 'master' into weather-forecast
authorCesare Tirabassi <norsetto@ubuntu.com>
Mon, 3 Aug 2009 17:59:36 +0000 (19:59 +0200)
committerCesare Tirabassi <norsetto@ubuntu.com>
Mon, 3 Aug 2009 17:59:36 +0000 (19:59 +0200)
1  2 
doc/variables.xml
src/conky.c

diff --combined doc/variables.xml
              </command>
              <option>(color)</option>
          </term>
-         <listitem>Change drawing color to color 
+         <listitem>Change drawing color to 'color' which is a name of
+         a color or a hexcode preceded with # (for example #0A1B2C ).
+         If you use ncurses only the following colors are supported:
+       red,green,yellow,blue,magenta,cyan,black,white.
          <para /></listitem>
      </varlistentry>
      <varlistentry>
      <varlistentry>
          <term>
              <command>
 +                <option>weather_forecast</option>
 +            </command>
 +            <option>URI locID day data_type
 +            (interval_in_minutes)</option>
 +        </term>
 +        <listitem>
 +            <para>Download, parse and display weather forecast data
 +          for a given day (daytime only).</para>
 +            <para>For the 'URI', for the time being only
 +            http://xoap.weather.com/weather/local/ is
 +          supported. See 'weather' above for details of usage</para>
 +            <para>'locID', see 'weather' above.</para>
 +            <para>'day' is a number from 0 (today) to 4 (3 days
 +            after tomorrow).</para>
 +            <para>'data_type' must be one of the following:</para>
 +            <simplelist>
 +                <member>
 +                    <command>low</command>
 +                                      <option>Minimun temperature (you can use the
 +                    'temperature_unit' config setting to change
 +                    units)</option>
 +              </member>
 +                <member>
 +                    <command>high</command>
 +                                      <option>Maximum temperature (you can use the
 +                    'temperature_unit' config setting to change
 +                    units)</option>
 +              </member>
 +                <member>
 +                    <command>icon</command>
 +                    <option>Weather icon. Can be used together with the
 +                    icon kit provided upon registering to the weather.com
 +                    service</option>
 +              </member>
 +                <member>
 +                    <command>forecast</command>
 +                    <option>Weather forecast (sunny, rainy, etc.)</option>
 +              </member>
 +                <member>
 +                    <command>wind_speed</command>
 +                    <option>Wind speed in km/h</option>
 +                </member>
 +                <member>
 +                    <command>wind_dir</command>
 +                    <option>Wind direction</option>
 +                </member>
 +                <member>
 +                    <command>wind_dir_DEG</command>
 +                    <option>Compass wind direction</option>
 +                </member>
 +                <member>
 +                    <command>humidity</command>
 +                    <option>Relative humidity in %</option>
 +                </member>
 +                <member>
 +                    <command>precipitation</command>
 +                    <option>Probability of having a
 +                                      precipitation (in %)</option>
 +                </member>
 +            </simplelist>
 +            <para>'delay_in_minutes' (optional, default 150) cannot
 +            be lower than 150 min.</para>
 +            <para>This object is threaded, and once a thread is
 +            created it can't be explicitely destroyed. One thread
 +            will run for each URI specified. You can use any
 +            protocol that Curl supports.</para>
 +            <para>Note that these variables are still EXPERIMENTAL
 +            and can be subject to many future changes.</para>
 +      </listitem>
 +    </varlistentry>
 +    <varlistentry>
 +        <term>
 +            <command>
                  <option>wireless_ap</option>
              </command>
              <option>(net)</option>
diff --combined src/conky.c
@@@ -68,9 -68,6 +68,9 @@@
  #ifdef NCURSES
  #include <ncurses.h>
  #endif
 +#ifdef XOAP
 +#include <libxml/parser.h>
 +#endif /* XOAP */
  
  /* local headers */
  #include "algebra.h"
@@@ -995,12 -992,6 +995,12 @@@ static void free_text_objects(struct te
                                free(data.weather.data_type);
                                break;
  #endif
 +#ifdef XOAP
 +                      case OBJ_weather_forecast:
 +                              free(data.weather_forecast.uri);
 +                              free(data.weather_forecast.data_type);
 +                              break;
 +#endif
  #ifdef HAVE_LUA
                        case OBJ_lua:
                        case OBJ_lua_parse:
@@@ -1789,6 -1780,30 +1789,30 @@@ static struct text_object *construct_te
                        current_text_color = obj->data.l;
                }
  #endif /* X11 */
+ #ifdef NCURSES
+               if (output_methods & TO_NCURSES) {
+                       obj->data.l = COLOR_WHITE;
+                       if(arg) {
+                               if(strcasecmp(arg, "red") == 0) {
+                                       obj->data.l = COLOR_RED;
+                               }else if(strcasecmp(arg, "green") == 0) {
+                                       obj->data.l = COLOR_GREEN;
+                               }else if(strcasecmp(arg, "yellow") == 0) {
+                                       obj->data.l = COLOR_YELLOW;
+                               }else if(strcasecmp(arg, "blue") == 0) {
+                                       obj->data.l = COLOR_BLUE;
+                               }else if(strcasecmp(arg, "magenta") == 0) {
+                                       obj->data.l = COLOR_MAGENTA;
+                               }else if(strcasecmp(arg, "cyan") == 0) {
+                                       obj->data.l = COLOR_CYAN;
+                               }else if(strcasecmp(arg, "black") == 0) {
+                                       obj->data.l = COLOR_BLACK;
+                               }
+                       }
+                       current_text_color = obj->data.l;
+                       init_pair(obj->data.l, obj->data.l, COLOR_BLACK);
+               }
+ #endif /* NCURSES */
        END OBJ(color0, 0)
                obj->data.l = color0;
                current_text_color = obj->data.l;
                        argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
  
                        if (argc >= 3) {
 -                              if (process_weather_uri(uri, locID)) {
 +                              if (process_weather_uri(uri, locID, 0)) {
                                        free(data_type);
                                        free(uri);
                                        free(locID);
                        CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
                }
  #endif
 +#ifdef XOAP
 +      END OBJ(weather_forecast, 0)
 +              if (arg) {
 +                      int argc;
 +                      unsigned int day;
 +                      float interval = 0;
 +                      char *locID = (char *) malloc(9 * sizeof(char));
 +                      char *uri = (char *) malloc(128 * sizeof(char));
 +                      char *data_type = (char *) malloc(32 * sizeof(char));
 +
 +                      argc = sscanf(arg, "%119s %8s %1u %31s %f", uri, locID, &day, data_type, &interval);
 +
 +                      if (argc >= 4) {
 +                              if (process_weather_uri(uri, locID, 1)) {
 +                                      free(data_type);
 +                                      free(uri);
 +                                      free(locID);
 +                                      CRIT_ERR(obj, free_at_crash, \
 +                                                      "could not recognize the weather forecast uri");
 +                              }
 +
 +                              obj->data.weather_forecast.uri = uri;
 +                              obj->data.weather_forecast.data_type = data_type;
 +
 +                              /* Limit the day between 0 (today) and FORECAST_DAYS */
 +                              if (day >= FORECAST_DAYS) {
 +                                      day = FORECAST_DAYS-1;
 +                              }
 +                              obj->data.weather_forecast.day = day;
 +
 +                              /* Limit the data retrieval interval to 2 hours and an half */
 +                              if (interval < 150) {
 +                                      interval = 150;
 +                              }
 +
 +                              /* Convert to seconds */
 +                              obj->data.weather_forecast.interval = interval * 60;
 +                              free(locID);
 +
 +                              DBGP("weather_forecast: fetching %s for day %d from %s every %d seconds", \
 +                                       data_type, day, uri, obj->data.weather_forecast.interval);
 +                      } else {
 +                              free(data_type);
 +                              free(uri);
 +                              free(locID);
 +                              CRIT_ERR(obj, free_at_crash, "wrong number of arguments for $weather_forecast");
 +                      }
 +              } else {
 +                      CRIT_ERR(obj, free_at_crash, "weather_forecast needs arguments: <uri> <locID> <day> <data_type> [interval in minutes]");
 +              }
 +#endif
  #ifdef HAVE_LUA
        END OBJ(lua, 0)
                if (arg) {
@@@ -4158,9 -4122,11 +4182,11 @@@ static void generate_text_internal(cha
                                new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
                                                obj->e, 1, obj->char_a, obj->char_b);
                        }
+ #endif /* X11 */
                        OBJ(color) {
                                new_fg(p, obj->data.l);
                        }
+ #ifdef X11
                        OBJ(color0) {
                                new_fg(p, color0);
                        }
                                }
                        }
  #endif
 +#ifdef XOAP
 +                      OBJ(weather_forecast) {
 +                              if (obj->data.weather_forecast.uri != NULL) {
 +                                      weather_forecast_process_info(p, p_max_size, obj->data.weather_forecast.uri, obj->data.weather_forecast.day, obj->data.weather_forecast.data_type, obj->data.weather_forecast.interval);
 +                              } else {
 +                                      NORM_ERR("error processing weather forecast data, check that you have a valid XOAP key if using XOAP.");
 +                              }
 +                      }
 +#endif
  #ifdef HAVE_LUA
                        OBJ(lua) {
                                char *str = llua_getstring(obj->data.s);
@@@ -6543,15 -6500,23 +6569,23 @@@ static int text_size_updater(char *s, i
        last_font_height = font_height();
        return special_index;
  }
+ #endif /* X11 */
  
  static inline void set_foreground_color(long c)
  {
-       if ((output_methods & TO_X) == 0)
-               return;
-       current_color = c;
-       XSetForeground(display, window.gc, c);
- }
+ #ifdef X11
+       if (output_methods & TO_X) {
+               current_color = c;
+               XSetForeground(display, window.gc, c);
+       }
  #endif /* X11 */
+ #ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               attron(COLOR_PAIR(c));
+       }
+ #endif /* NCURSES */
+       return;
+ }
  
  static void draw_string(const char *s)
  {
        }
  #ifdef NCURSES
        if ((output_methods & TO_NCURSES) && draw_mode == FG) {
-               printw("%s\n", s_with_newlines);
+               printw("%s", s_with_newlines);
        }
  #endif
        free(s_with_newlines);
        memcpy(tmpstring1, s, text_buffer_size);
  }
  
- #ifdef X11
  int draw_each_line_inner(char *s, int special_index, int last_special_applied)
  {
+ #ifdef X11
        int font_h = font_height();
        int cur_y_add = 0;
+ #endif /* X11 */
        char *recurse = 0;
        char *p = s;
        int last_special_needed = -1;
        int orig_special_index = special_index;
  
+ #ifdef X11
        cur_x = text_start_x;
        cur_y += font_ascent();
+ #endif /* X11 */
  
        while (*p) {
                if (*p == SECRIT_MULTILINE_CHAR) {
                        break;
                }
                if (*p == SPECIAL_CHAR || last_special_applied > -1) {
+ #ifdef X11
                        int w = 0;
+ #endif /* X11 */
  
                        /* draw string before special, unless we're dealing multiline
                         * specials */
                        }
                        /* draw special */
                        switch (specials[special_index].type) {
+ #ifdef X11
                                case HORIZONTAL_LINE:
                                {
                                        int h = specials[special_index].height;
                                        font_h = font_height();
                                        break;
                                }
+ #endif /* X11 */
                                case FG:
                                        if (draw_mode == FG) {
                                                set_foreground_color(specials[special_index].arg);
                                        }
                                        break;
  
+ #ifdef X11
                                case BG:
                                        if (draw_mode == BG) {
                                                set_foreground_color(specials[special_index].arg);
                                        last_special_needed = special_index;
                                        break;
                                }
+ #endif /* X11 */
                        }
  
+ #ifdef X11
                        cur_x += w;
+ #endif /* X11 */
  
                        if (special_index != last_special_applied) {
                                special_index++;
                p++;
        }
  
+ #ifdef X11
        cur_y += cur_y_add;
+ #endif /* X11 */
        draw_string(s);
+ #ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               printw("\n");
+       }
+ #endif /* NCURSES */
+ #ifdef X11
        cur_y += font_descent();
+ #endif /* X11 */
        if (recurse && *recurse) {
                special_index = draw_each_line_inner(recurse, special_index, last_special_needed);
                *(recurse - 1) = SECRIT_MULTILINE_CHAR;
        }
        return special_index;
  }
- #endif /* X11 */
  
  static int draw_line(char *s, int special_index)
  {
  #ifdef X11
-       if ((output_methods & TO_X) == 0) {
- #endif /* X11 */
-               draw_string(s);
-               //'special_index - special_index' instead of 0 otherwise gcc complains about not using special_index when build without X11
-               return special_index - special_index;
- #ifdef X11
+       if (output_methods & TO_X) {
+               return draw_each_line_inner(s, special_index, -1);
        }
-       /* find specials and draw stuff */
-       return draw_each_line_inner(s, special_index, -1);
  #endif /* X11 */
+ #ifdef NCURSES
+       if (output_methods & TO_NCURSES) {
+               return draw_each_line_inner(s, special_index, -1);
+       }
+ #endif /* NCURSES */
+       draw_string(s);
+       //'special_index - special_index' instead of 0 otherwise gcc complains about not using special_index when build without X11
+       return special_index - special_index;
  }
  
  static void draw_text(void)
        }
        setup_fonts();
  #endif /* X11 */
+ #ifdef NCURSES
+       init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
+       attron(COLOR_PAIR(COLOR_WHITE));
+ #endif /* NCURSES */
        for_each_line(text_buffer, draw_line);
  #if defined(HAVE_LUA) && defined(X11)
        llua_draw_post_hook();
@@@ -7856,9 -7845,6 +7914,9 @@@ void clean_up(void *memtofree1, void* m
        llua_shutdown_hook();
        llua_close();
  #endif /* HAVE_LUA */
 +#ifdef XOAP
 +      xmlCleanupParser();
 +#endif /* XOAP */
  
        if (specials) {
                for (i = 0; i < special_count; i++) {
@@@ -8568,6 -8554,7 +8626,7 @@@ char load_config_file(const char *f
                CONF("out_to_ncurses") {
                        if(string_to_bool(value)) {
                                initscr();
+                               start_color();
                                output_methods |= TO_NCURSES;
                        }
                }
@@@ -9484,9 -9471,6 +9543,9 @@@ void initialisation(int argc, char **ar
  #ifdef HAVE_LUA
        llua_setup_info(&info, update_interval);
  #endif /* HAVE_LUA */
 +#ifdef XOAP
 +      xmlInitParser();
 +#endif /* XOAP */
  
        /* Set signal handlers */
        act.sa_handler = signal_handler;