gkrellweather-2.0.8/0000755000175000017500000000000011132433446013416 5ustar henryhenrygkrellweather-2.0.8/gkrellweather.c0000644000175000017500000010667211132433446016436 0ustar henryhenry/* --< GKrellWeather 0.2.7 >--{ 20 Mar 2001 }-- * * Author: Franky Lam (franky@frankylam.com) * http://www.frankylam.com/ * */ #include #include #define DEFAULT_STATION_ID "YSSY" #define STYLE_NAME "weather" /* net update status */ static gboolean net_update; static gint style_id; enum { TEM_DISPLAY = 0, DEW_DISPLAY = 1, WIN_DISPLAY = 2, SKY_DISPLAY = 3, NAM_DISPLAY = 4, MAX_DISPLAY = 5, }; static gint panel_state = 0; static gint x_scroll = 0; static gint name_xoff = 0; static gint sky_cond_xoff = 0; static GkrellmChart *chart; static GkrellmMonitor *monitor; static GkrellmPanel *panel; static GkrellmDecal *decal_temperature, *decal_unit1, *decal_humidity, *decal_unit2, *decal_dew_point, *decal_wind_chill, *decal_wind_direction, *decal_wind_speed, *decal_pressure, *decal_name, *decal_sky_cond; static GtkWidget *metric_option, *km_per_hour_option, *beaufort_option, *meter_per_second_option, *mmHg_option, *kPa_option, *hPa_option, *station_option, *url_option, *update_interval_option, *switch_interval_option; static GtkTooltips *weather_tips = 0; static gchar *weather_tips_text; typedef struct { GkrellmTextstyle ts; gint width, height, baseline, y_ink; } Extents; static Extents ext_temperature, ext_unit1, ext_humidity, ext_unit2, ext_dew_point, ext_wind_chill, ext_wind_direction, ext_wind_speed, ext_pressure, ext_name, ext_sky_cond; typedef struct { gchar name[512]; /* station name */ gchar sky_cond[512]; gdouble temperature[2]; /* 0 imperial 1 metric */ gdouble humidity; gdouble pressure[4]; /* 0 imperial 1 mmHg 2 kPa 3 hPa */ gdouble dew_point[2]; gdouble wind_chill[2]; gdouble wind_direction; gdouble wind_speed[4]; /* 0 imperial 1 km/h 2 m/s 3 beaufort */ gint wind_chill_avail; gint sky_cond_avail; } Air; typedef struct { gint chart_visible; gint panel_visible; gint metric; gint update_interval; gint switch_interval; gint wind_chill; /* for later release */ gint windspeed_unit; gint pressure_unit; gchar station[512]; gchar command[512]; /* for later release */ gchar filename[512]; /* for later release */ } Options; static Air air; static Options options; static void string_extents (gchar *string, Extents *ext) { gkrellm_text_extents(ext->ts.font, string, strlen(string), &ext->width, &ext->height, &ext->baseline, &ext->y_ink); } /* reference from wmWeather.c */ static gboolean read_air () { static gchar *c, line[512], str[1024]; static gdouble sgn; static gint i, cursize, spd, scale[] = { 1, 3, 4, 10, 16, 21, 27, 33, 40, 47, 55, 63, 71 }; FILE *fp; char *oldlocale; // decimal point stuff oldlocale = g_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "C"); if ((fp = fopen(options.filename, "r")) != NULL) { fgets(air.name, 512, fp); if (air.name[0] == '\0' || air.name[0] == '\n') { /* GrabWeather could not read data from server */ fclose(fp); setlocale(LC_NUMERIC, oldlocale); g_free(oldlocale); return FALSE; } for (c = air.name; *c && *c != '('; c++); /* extract name */ *(c-1) = '\0'; fgets(line, 512, fp); fgets(air.sky_cond, 512, fp); if (air.sky_cond[0] == '\n') { air.sky_cond_avail = 0; if (panel_state == SKY_DISPLAY) { panel_state = NAM_DISPLAY; gkrellm_make_decal_invisible(panel, decal_sky_cond); gkrellm_make_decal_visible(panel, decal_name); } } else { air.sky_cond_avail = 1; } if (air.sky_cond[strlen(air.sky_cond)-1] == '\n') air.sky_cond[strlen(air.sky_cond)-1] = '\0'; fgets(line, 512, fp); fscanf(fp, "%lf", &air.temperature[0]); air.temperature[1] = (air.temperature[0]-32.0)*5.0/9.0; fscanf(fp, "%lf", &air.dew_point[0]); air.dew_point[1] = (air.dew_point[0]-32.0)*5.0/9.0; fscanf(fp, "%lf", &air.wind_chill[0]); air.wind_chill_avail = (air.wind_chill[0] < -900.0) ? 0 : 1; air.wind_chill[1] = (air.wind_chill[0]-32.0)*5.0/9.0; fscanf(fp, "%lf", &air.pressure[0]); air.pressure[1] = air.pressure[0] * 25.4; air.pressure[2] = air.pressure[0] * 3.38639; air.pressure[3] = air.pressure[0] * 33.8639; fscanf(fp, "%lf", &air.humidity); fscanf(fp, "%lf", &air.wind_direction); fscanf(fp, "%lf", &air.wind_speed[0]); air.wind_speed[1] = air.wind_speed[0] * 1.609; air.wind_speed[2] = air.wind_speed[0] * 0.4473; sgn = (air.wind_speed[0] < 0.0) ? -1.0 : 1.0; spd = (gint)sgn * (gint)air.wind_speed[0]; for (i = 0; i < 13 && spd > scale[i]; i++); air.wind_speed[3] = sgn * (gdouble)i; fclose(fp); } else { air.temperature[0] = -99.0; air.dew_point[0] = -99.0; air.wind_chill[0] = -99.0; air.humidity = -99.0; air.pressure[0] = -99.0; air.wind_direction = -99.0; air.wind_speed[0] = -99.0; } setlocale(LC_NUMERIC, oldlocale); g_free(oldlocale); name_xoff = -gkrellm_gdk_string_width(gkrellm_default_font(1), air.name); sky_cond_xoff = -gkrellm_gdk_string_width(gkrellm_default_font(1), air.sky_cond); // Change tooltips if (weather_tips != NULL) { snprintf(line, 512, "%s/.wmWeatherReports/%s.TXT", getenv("HOME"), options.station); options.station[511] = 0; if ((fp = fopen(line, "r")) != NULL) { g_free(weather_tips_text); cursize = 0; strcpy(str, ""); while (fgets(line, 512, fp)) { if (cursize + strlen(line) >= 1023) { strncat(str, line, 1024 - cursize); break; } else { strcat(str, line); } cursize += strlen(line); } weather_tips_text = g_strdup(str); gtk_tooltips_set_tip(weather_tips, panel->drawing_area, weather_tips_text, NULL); fclose(fp); } } return TRUE; } static void calc_xy (gint i) { gint w; switch (i) { case NAM_DISPLAY: decal_name->x = 2; break; case SKY_DISPLAY: decal_sky_cond->x = 2; break; case WIN_DISPLAY: w = decal_wind_direction->w + decal_wind_speed->w; decal_wind_direction->x = (gkrellm_chart_width() - w + 1) / 2 + 1; decal_wind_speed->x = decal_wind_direction->x + decal_wind_direction->w + 1; break; case DEW_DISPLAY: w = decal_dew_point->w + decal_unit1->w + decal_pressure->w; decal_dew_point->x = (gkrellm_chart_width() - w + 1) / 2; decal_unit1->x = decal_dew_point->x + decal_dew_point->w - 1; decal_wind_chill->x = decal_dew_point->x; decal_pressure->x = decal_unit1->x + decal_unit1->w + 1; break; case TEM_DISPLAY: default: w = decal_temperature->w + decal_unit1->w + decal_humidity->w + decal_unit2->w; decal_temperature->x = -1; decal_unit1->x = decal_temperature->x + decal_temperature->w - 1; decal_unit2->x = gkrellm_chart_width() - decal_unit2->w - 1; decal_humidity->x = decal_unit2->x - decal_humidity->w; break; } } static void draw_panel () { static gchar *compress_direction[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" }; static gchar l1[8], l2[8], *units; static gint v, w, wdx; if (options.panel_visible == FALSE) return; v++; // no worries about overflow calc_xy(panel_state); switch (panel_state) { case NAM_DISPLAY: w = gkrellm_chart_width(); if (x_scroll > name_xoff) x_scroll -= 2; else x_scroll = w; decal_name->x_off = x_scroll; gkrellm_draw_decal_text(panel, decal_name, air.name, w - x_scroll); break; case SKY_DISPLAY: if (air.sky_cond_avail) { w = gkrellm_chart_width(); if (x_scroll > sky_cond_xoff) x_scroll -= 2; else x_scroll = w; decal_sky_cond->x_off = x_scroll; gkrellm_draw_decal_text(panel, decal_sky_cond, air.sky_cond, w - x_scroll); } break; case WIN_DISPLAY: wdx = lrintf((air.wind_direction + 360.0) / 22.5) % 16; gkrellm_draw_decal_text(panel, decal_wind_direction, compress_direction[wdx], wdx); if (options.metric && options.windspeed_unit == 3) { v = lrintf(air.wind_speed[3]); snprintf(l2, 8, "F%d", v); l2[7] = 0; v += 1000; /* to distinguish redraws */ } else { v = lrintf(air.wind_speed[options.metric ? options.windspeed_unit : 0]); snprintf(l2, 8, "%.0d", v); l2[7] = 0; } gkrellm_draw_decal_text(panel, decal_wind_speed, l2, v); break; case DEW_DISPLAY: v = lrintf(air.dew_point[options.metric]); snprintf(l1, 8, "%+4d", v); l1[7] = 0; gkrellm_draw_decal_text(panel, decal_dew_point, l1, v); v = lrintf(air.pressure[options.metric ? options.pressure_unit : 0]); snprintf(l2, 7, "%4d", v); l2[7] = 0; gkrellm_draw_decal_text(panel, decal_pressure, l2, v); units = options.metric ? "C" : "F"; gkrellm_draw_decal_text(panel, decal_unit1, units, options.metric); break; case TEM_DISPLAY: default: v = lrintf(air.temperature[options.metric]); snprintf(l1, 8, "%+4d", v); l1[7] = 0; gkrellm_draw_decal_text(panel, decal_temperature, l1, v); v = lrintf(air.humidity); snprintf(l2, 8, "%3d", v); l2[7] = 0; gkrellm_draw_decal_text(panel, decal_humidity, l2, v); units = options.metric ? "C" : "F"; gkrellm_draw_decal_text(panel, decal_unit1, units, options.metric); gkrellm_draw_decal_text(panel, decal_unit2, "%", 0); } } static void panel_switch (gint new_state) { switch (panel_state) { case NAM_DISPLAY: gkrellm_make_decal_invisible(panel, decal_name); break; case SKY_DISPLAY: gkrellm_make_decal_invisible(panel, decal_sky_cond); break; case WIN_DISPLAY: gkrellm_make_decal_invisible(panel, decal_wind_direction); gkrellm_make_decal_invisible(panel, decal_wind_speed); break; case DEW_DISPLAY: gkrellm_make_decal_invisible(panel, decal_wind_chill); gkrellm_make_decal_invisible(panel, decal_dew_point); gkrellm_make_decal_invisible(panel, decal_pressure); gkrellm_make_decal_invisible(panel, decal_unit1); gkrellm_make_decal_invisible(panel, decal_unit2); break; case TEM_DISPLAY: default: gkrellm_make_decal_invisible(panel, decal_temperature); gkrellm_make_decal_invisible(panel, decal_unit1); gkrellm_make_decal_invisible(panel, decal_humidity); gkrellm_make_decal_invisible(panel, decal_unit2); } panel_state = new_state; draw_panel(); switch (panel_state) { case NAM_DISPLAY: gkrellm_make_decal_visible(panel, decal_name); break; case SKY_DISPLAY: gkrellm_make_decal_visible(panel, decal_sky_cond); break; case WIN_DISPLAY: gkrellm_make_decal_visible(panel, decal_wind_direction); gkrellm_make_decal_visible(panel, decal_wind_speed); break; case DEW_DISPLAY: if (options.wind_chill && air.wind_chill_avail) gkrellm_make_decal_visible(panel, decal_wind_chill); else gkrellm_make_decal_visible(panel, decal_dew_point); gkrellm_make_decal_visible(panel, decal_unit1); gkrellm_make_decal_visible(panel, decal_pressure); break; case TEM_DISPLAY: default: gkrellm_make_decal_visible(panel, decal_temperature); gkrellm_make_decal_visible(panel, decal_unit1); gkrellm_make_decal_visible(panel, decal_humidity); gkrellm_make_decal_visible(panel, decal_unit2); } } static FILE *command_pipe; static void run_command () { if (command_pipe) return; command_pipe = popen(options.command, "r"); if (command_pipe) fcntl(fileno(command_pipe), F_SETFL, O_NONBLOCK); net_update = TRUE; } static gboolean command_done () { gchar buf[64]; while (fread(buf, 1, sizeof(buf) - 1, command_pipe) > 0) ; if (feof(command_pipe)) { pclose(command_pipe); command_pipe = NULL; return TRUE; } return FALSE; } static void update_air () { static gint switch_timer = 0, minute_timer = 0; if (command_pipe) { net_update = command_done() && read_air(); } if(!net_update && GK.timer_ticks % 600 == 0) { run_command(); } if (GK.second_tick && options.switch_interval > 0 && switch_timer++ >= options.switch_interval) { switch_timer = 0; if (panel_state == WIN_DISPLAY && !air.sky_cond_avail) panel_switch (NAM_DISPLAY); else panel_switch ((panel_state+1) % MAX_DISPLAY); } if (GK.minute_tick && ++minute_timer >= options.update_interval) { minute_timer = 0; run_command(); } draw_panel(); gkrellm_draw_panel_layers(panel); } static gint expose_event (GtkWidget *widget, GdkEventExpose *ev) { if (widget == panel->drawing_area) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); } else if (widget == chart->drawing_area) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], chart->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); } return FALSE; } static gint panel_press (GtkWidget *widget, GdkEventButton *ev) { if (ev->button == 2 || ev->button == 3) { if (panel_state == WIN_DISPLAY && !air.sky_cond_avail) panel_switch (NAM_DISPLAY); else panel_switch ((panel_state+1) % MAX_DISPLAY); } return TRUE; } static void create_air (GtkWidget *vbox, gint first_create) { GkrellmStyle *style; gint i; if (first_create) { chart = gkrellm_chart_new0(); panel = gkrellm_panel_new0(); } else { gkrellm_destroy_krell_list(panel); gkrellm_destroy_decal_list(panel); } style = gkrellm_meter_style(style_id); panel->textstyle = gkrellm_meter_alt_textstyle(style_id); ext_temperature.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("+888", &ext_temperature); ext_unit1.ts = *gkrellm_meter_textstyle(style_id); string_extents("C", &ext_unit1); ext_humidity.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("88", &ext_humidity); ext_unit2.ts = *gkrellm_meter_textstyle(style_id); string_extents("%", &ext_unit2); ext_dew_point.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("+888", &ext_dew_point); ext_wind_chill.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("+888", &ext_wind_chill); ext_pressure.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("8888", &ext_pressure); ext_wind_direction.ts = *gkrellm_meter_textstyle(style_id); string_extents("WWW", &ext_wind_direction); ext_wind_speed.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("888", &ext_wind_speed); ext_name.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("Ay", &ext_name); ext_sky_cond.ts = *gkrellm_meter_alt_textstyle(style_id); string_extents("Ay", &ext_sky_cond); decal_temperature = gkrellm_create_decal_text(panel, "+888", &ext_temperature.ts, style, 0, 3, ext_temperature.width + 2); decal_unit1 = gkrellm_create_decal_text(panel, "C", &ext_unit1.ts, style, 0, 3, ext_unit1.width + 2); decal_humidity = gkrellm_create_decal_text(panel, "88", &ext_humidity.ts, style, 0, 3, ext_humidity.width + 4); decal_unit2 = gkrellm_create_decal_text(panel, "%", &ext_unit2.ts, style, 0, 3, ext_unit2.width + 2); decal_dew_point = gkrellm_create_decal_text(panel, "+888", &ext_dew_point.ts, style, 0, 3, ext_dew_point.width + 2); decal_wind_chill = gkrellm_create_decal_text(panel, "+888", &ext_wind_chill.ts, style, 0, 3, ext_wind_chill.width + 2); decal_pressure = gkrellm_create_decal_text(panel, "8888", &ext_pressure.ts, style, 0, 3, ext_pressure.width + 2); decal_wind_direction = gkrellm_create_decal_text(panel, "WWW", &ext_wind_direction.ts, style, 0, 3, ext_wind_direction.width + 2); decal_wind_speed = gkrellm_create_decal_text(panel, "888", &ext_wind_speed.ts, style, 0, 3, ext_wind_speed.width + 2); decal_name = gkrellm_create_decal_text(panel, "Ay", &ext_name.ts, style, 0, 3, gkrellm_chart_width() - 4); decal_sky_cond = gkrellm_create_decal_text(panel, "Ay", &ext_sky_cond.ts, style, 0, 3, gkrellm_chart_width() - 4); if (decal_unit1->h < decal_temperature->h) { decal_unit1->y = decal_temperature->y + decal_temperature->h - decal_unit1->h; if (decal_pressure->h < decal_temperature->h) decal_pressure->y = decal_temperature->y + decal_temperature->h - decal_pressure->h; if (decal_name->h < decal_temperature->h) { decal_name->y = decal_temperature->y + decal_temperature->h - decal_name->h; decal_sky_cond->y = decal_name->y; } } else if (decal_unit1->h > decal_temperature->h) { decal_temperature->y = decal_unit1->y + decal_unit1->h - decal_temperature->h; if (decal_pressure->h < decal_unit1->h) decal_pressure->y = decal_unit1->y + decal_unit1->h - decal_pressure->h; if (decal_name->h < decal_unit1->h) { decal_name->y = decal_unit1->y + decal_unit1->h - decal_name->h; decal_sky_cond->y = decal_name->y; } } decal_unit2->y = decal_unit1->y; decal_dew_point->y = decal_wind_chill->y = decal_temperature->y; decal_humidity->y = decal_wind_speed->y = decal_temperature->y; decal_wind_direction->y = decal_wind_speed->y + decal_wind_speed->h - decal_wind_direction->h; gkrellm_panel_configure(panel, NULL, gkrellm_meter_style(style_id)); gkrellm_panel_create(vbox, monitor, panel); // chart->h = 36; /* gkrellm_create_chart(vbox, chart, DEFAULT_STYLE); */ /* gkrellm_monitor_height_adjust(chart->h + panel->h); */ // gkrellm_monitor_height_adjust(panel->h); if (weather_tips == NULL) { weather_tips = gtk_tooltips_new(); weather_tips_text = g_strdup("GKrellWeather"); gtk_tooltips_set_tip(weather_tips, panel->drawing_area, weather_tips_text, NULL); gtk_tooltips_set_delay(weather_tips, 1000); } x_scroll = 0; for (i = MAX_DISPLAY - 1; i >= 0; i--) { panel_state = i; draw_panel(); } gkrellm_make_decal_invisible(panel, decal_sky_cond); gkrellm_make_decal_invisible(panel, decal_name); gkrellm_make_decal_invisible(panel, decal_dew_point); gkrellm_make_decal_invisible(panel, decal_wind_chill); gkrellm_make_decal_invisible(panel, decal_pressure); gkrellm_make_decal_invisible(panel, decal_wind_direction); gkrellm_make_decal_invisible(panel, decal_wind_speed); gkrellm_make_decal_visible(panel, decal_temperature); gkrellm_make_decal_visible(panel, decal_unit1); gkrellm_make_decal_visible(panel, decal_humidity); gkrellm_make_decal_visible(panel, decal_unit2); if (first_create) { /* gtk_signal_connect(GTK_OBJECT(chart->drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL); */ gtk_signal_connect(GTK_OBJECT(panel->drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL); gtk_signal_connect(GTK_OBJECT(panel->drawing_area), "button_press_event", (GtkSignalFunc) panel_press, NULL); } } #define PLUGIN_CONFIG_KEYWORD "gkrellweather" static void save_air_config (FILE *f) { fprintf(f, "%s chart_visible %d\n", PLUGIN_CONFIG_KEYWORD, options.chart_visible); fprintf(f, "%s panel_visible %d\n", PLUGIN_CONFIG_KEYWORD, options.panel_visible); fprintf(f, "%s metric %d\n", PLUGIN_CONFIG_KEYWORD, options.metric); fprintf(f, "%s update_interval %d\n", PLUGIN_CONFIG_KEYWORD, options.update_interval); fprintf(f, "%s switch_interval %d\n", PLUGIN_CONFIG_KEYWORD, options.switch_interval); fprintf(f, "%s wind_chill %d\n", PLUGIN_CONFIG_KEYWORD, options.wind_chill); fprintf(f, "%s windspeed_unit %d\n", PLUGIN_CONFIG_KEYWORD, options.windspeed_unit); fprintf(f, "%s pressure_unit %d\n", PLUGIN_CONFIG_KEYWORD, options.pressure_unit); fprintf(f, "%s station %s\n", PLUGIN_CONFIG_KEYWORD, options.station); fprintf(f, "%s command %s\n", PLUGIN_CONFIG_KEYWORD, options.command); fprintf(f, "%s filename %s\n", PLUGIN_CONFIG_KEYWORD, options.filename); } static void load_air_config (gchar *arg) { gchar config[64], item[256]; gint n; n = sscanf(arg, "%s %[^\n]", config, item); if (n == 2) { if (strcmp(config, "chart_visible") == 0) sscanf(item, "%d\n", &(options.chart_visible)); if (strcmp(config, "panel_visible") == 0) sscanf(item, "%d\n", &(options.panel_visible)); if (strcmp(config, "metric") == 0) sscanf(item, "%d\n", &(options.metric)); if (strcmp(config, "update_interval") == 0) sscanf(item, "%d\n", &(options.update_interval)); if (strcmp(config, "switch_interval") == 0) sscanf(item, "%d\n", &(options.switch_interval)); if (strcmp(config, "wind_chill") == 0) sscanf(item, "%d\n", &(options.wind_chill)); if (strcmp(config, "windspeed_unit") == 0) sscanf(item, "%d\n", &(options.windspeed_unit)); if (strcmp(config, "pressure_unit") == 0) sscanf(item, "%d\n", &(options.pressure_unit)); if (strcmp(config, "station") == 0) sscanf(item, "%s\n", options.station); if (strcmp(config, "command") == 0) strcpy(options.command, item); if (strcmp(config, "filename") == 0) sscanf(item, "%s\n", options.filename); } } static void apply_air_config (void) { gint old_metric = options.metric; gchar *c; options.metric = GTK_TOGGLE_BUTTON(metric_option)->active; if (old_metric != options.metric) { draw_panel(); gkrellm_draw_panel_layers(panel); } c = g_strdup(gtk_entry_get_text(GTK_ENTRY(station_option))); if (strcmp(options.station, c)) { options.station[0] = c[0]; options.station[1] = c[1]; options.station[2] = c[2]; options.station[3] = c[3]; snprintf(options.command, 512, PREFIX "/bin/GrabWeather %s", options.station); options.command[511] = 0; snprintf(options.filename, 512, "%s/.wmWeatherReports/%s.dat", getenv("HOME"), options.station); options.filename[511] = 0; net_update = FALSE; run_command(); } g_free(c); options.update_interval = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(update_interval_option)); options.switch_interval = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(switch_interval_option)); } static void windspeed_unit_set(GtkWidget *w, gpointer data) { options.windspeed_unit = GPOINTER_TO_INT(data); draw_panel(); gkrellm_draw_panel_layers(panel); } static void pressure_unit_set(GtkWidget *w, gpointer data) { options.pressure_unit = GPOINTER_TO_INT(data); draw_panel(); gkrellm_draw_panel_layers(panel); } static void create_air_tab (GtkWidget *tab) { GtkWidget *laptop, *frame, *ybox, *hbox, *zbox, *vbox, *label, *text, *info_window, *about_label; GtkAdjustment *switch_adjust, *update_adjust; GSList *wind_speed_group = NULL, *pressure_group = NULL; gchar *about_text = NULL; gint i; static gchar *help_text[] = { N_("GKrellWeather shows the current weather under the clock.\n" \ "\n" \ "Right click the panel to toggle between different display:\n" \ "\n" \ " - Temperature, Relative Humidity\n" \ " - DewPoint, Pressure (altimeter)\n" \ " - Wind Direction, Wind Speed\n" \ " - Sky Condition (if available)\n" \ " - Station name\n" \ "\n" \ "Options:\n" \ " switch interval - number of seconds (0 = never)" \ " between switching display\n") }; static gchar url[] = "http://www.nws.noaa.gov/tg/siteloc.shtml"; laptop = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(laptop), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab), laptop, TRUE, TRUE, 0); /* options */ frame = gtk_frame_new(NULL); gtk_container_border_width(GTK_CONTAINER(frame), 3); vbox = gtk_vbox_new(FALSE, 0); gtk_container_border_width(GTK_CONTAINER(vbox), 3); hbox = gtk_hbox_new(FALSE, 0); label = gtk_label_new(_("4 letter Station ID:")); station_option = gtk_entry_new_with_max_length(8); gtk_entry_set_text(GTK_ENTRY(station_option), options.station); gtk_entry_set_editable(GTK_ENTRY(station_option), TRUE); gtk_container_add(GTK_CONTAINER(hbox), label); gtk_container_add(GTK_CONTAINER(hbox), station_option); gtk_container_add(GTK_CONTAINER(vbox), hbox); hbox = gtk_hbox_new(FALSE, 0); label = gtk_label_new(_("Get your station ID at:")); url_option = gtk_entry_new_with_max_length(64); gtk_entry_set_text(GTK_ENTRY(url_option), url); gtk_entry_set_editable(GTK_ENTRY(url_option), FALSE); gtk_container_add(GTK_CONTAINER(hbox), label); gtk_container_add(GTK_CONTAINER(hbox), url_option); gtk_container_add(GTK_CONTAINER(vbox), hbox); hbox = gtk_hbox_new(FALSE, 0); /* check boxes */ zbox = gtk_vbox_new(FALSE, 0); metric_option = gtk_check_button_new_with_label(_("Display in metric unit")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(metric_option), options.metric); gtk_container_add(GTK_CONTAINER(zbox), metric_option); ybox = gtk_hbox_new(FALSE, 0); switch_adjust = (GtkAdjustment *) gtk_adjustment_new((gfloat) options.switch_interval, 0.0, 100.0, 1.0, 5.0, 0.0); switch_interval_option = gtk_spin_button_new(switch_adjust, 1.0, 1); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(switch_interval_option), (guint) 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(switch_interval_option), options.switch_interval); gtk_box_pack_start(GTK_BOX(ybox), switch_interval_option, FALSE, FALSE, 0); label = gtk_label_new(_("switch interval (secs)")); gtk_box_pack_start(GTK_BOX(ybox), label, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(zbox), ybox); ybox = gtk_hbox_new(FALSE, 0); update_adjust = (GtkAdjustment *) gtk_adjustment_new((gfloat) options.update_interval, 0.0, 100.0, 1.0, 5.0, 0.0); update_interval_option = gtk_spin_button_new(update_adjust, 1.0, 1); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(update_interval_option), (guint) 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(update_interval_option), options.update_interval); gtk_box_pack_start(GTK_BOX(ybox), update_interval_option, FALSE, FALSE, 0); label = gtk_label_new(_("update interval (mins)")); gtk_box_pack_start(GTK_BOX(ybox), label, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(zbox), ybox); gtk_container_add(GTK_CONTAINER(hbox), zbox); /* windspeed radio buttons */ zbox = gtk_vbox_new(FALSE, 0); label = gtk_label_new(_("metric windspeed unit:")); gtk_container_add(GTK_CONTAINER(zbox), label); km_per_hour_option = gtk_radio_button_new_with_label(NULL, _("km/h")); wind_speed_group = gtk_radio_button_group( GTK_RADIO_BUTTON(km_per_hour_option)); gtk_container_add(GTK_CONTAINER(zbox), km_per_hour_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(km_per_hour_option), options.windspeed_unit == 1); gtk_signal_connect(GTK_OBJECT(km_per_hour_option), "pressed", (GtkSignalFunc) windspeed_unit_set, GINT_TO_POINTER(1)); meter_per_second_option = gtk_radio_button_new_with_label(wind_speed_group, _("m/s")); wind_speed_group = gtk_radio_button_group( GTK_RADIO_BUTTON(meter_per_second_option)); gtk_container_add(GTK_CONTAINER(zbox), meter_per_second_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(meter_per_second_option), options.windspeed_unit == 2); gtk_signal_connect(GTK_OBJECT(meter_per_second_option), "pressed", (GtkSignalFunc) windspeed_unit_set, GINT_TO_POINTER(2)); beaufort_option = gtk_radio_button_new_with_label(wind_speed_group, _("beaufort")); gtk_container_add(GTK_CONTAINER(zbox), beaufort_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(beaufort_option), options.windspeed_unit == 3); gtk_signal_connect(GTK_OBJECT(beaufort_option), "pressed", (GtkSignalFunc) windspeed_unit_set, GINT_TO_POINTER(3)); gtk_container_add(GTK_CONTAINER(hbox), zbox); /* pressure radio buttons */ zbox = gtk_vbox_new(FALSE, 0); label = gtk_label_new(_("metric pressure unit:")); gtk_container_add(GTK_CONTAINER(zbox), label); mmHg_option = gtk_radio_button_new_with_label(NULL, _("mmHg")); pressure_group = gtk_radio_button_group(GTK_RADIO_BUTTON(mmHg_option)); gtk_container_add(GTK_CONTAINER(zbox), mmHg_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mmHg_option), options.pressure_unit == 1); gtk_signal_connect(GTK_OBJECT(mmHg_option), "pressed", (GtkSignalFunc) pressure_unit_set, GINT_TO_POINTER(1)); kPa_option = gtk_radio_button_new_with_label(pressure_group, _("kPa")); pressure_group = gtk_radio_button_group(GTK_RADIO_BUTTON(kPa_option)); gtk_container_add(GTK_CONTAINER(zbox), kPa_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(kPa_option), options.pressure_unit == 2); gtk_signal_connect(GTK_OBJECT(kPa_option), "pressed", (GtkSignalFunc) pressure_unit_set, GINT_TO_POINTER(2)); hPa_option = gtk_radio_button_new_with_label(pressure_group, _("hPa")); gtk_container_add(GTK_CONTAINER(zbox), hPa_option); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hPa_option), options.pressure_unit == 3); gtk_signal_connect(GTK_OBJECT(hPa_option), "pressed", (GtkSignalFunc) pressure_unit_set, GINT_TO_POINTER(3)); gtk_container_add(GTK_CONTAINER(hbox), zbox); gtk_container_add(GTK_CONTAINER(vbox), hbox); label = gtk_label_new(_("Options")); gtk_container_add(GTK_CONTAINER(frame), vbox); gtk_notebook_append_page(GTK_NOTEBOOK(laptop), frame, label); /* help */ frame = gtk_frame_new(NULL); gtk_container_border_width(GTK_CONTAINER(frame), 3); info_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(info_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(frame), info_window); text = gtk_text_view_new(); for (i=0; i < sizeof(help_text)/sizeof(gchar *); ++i) gkrellm_gtk_text_view_append(text, _(help_text[i])); gtk_container_add(GTK_CONTAINER(info_window), text); label = gtk_label_new(_("Help")); gtk_notebook_append_page(GTK_NOTEBOOK(laptop), frame, label); /* about */ about_text = g_strdup_printf( _("GKrellWeather %s\n" \ "GKrellM weather Plugin\n" \ "\n" \ "Copyright (C) 2001 Franky Lam\n" \ "franky@frankylam.com\n" \ "http://www.frankylam.com/\n" \ "\n" \ "Released under the GNU Public License\n") \ , VERSION ); about_label = gtk_label_new(about_text); g_free(about_text); label = gtk_label_new(_("About")); gtk_notebook_append_page(GTK_NOTEBOOK(laptop), about_label, label); } static GkrellmMonitor air_mon = { "GKrellWeather", /* Name, for config tab. */ 0, /* Id, 0 if a plugin */ create_air, /* The create function */ update_air, /* The update function */ create_air_tab, /* The config tab create function */ apply_air_config, /* Apply the config function */ save_air_config, /* Save user config */ load_air_config, /* Load user config */ PLUGIN_CONFIG_KEYWORD, /* config keyword */ NULL, /* Undefined 2 */ NULL, /* Undefined 1 */ NULL, /* Undefined 0 */ MON_CPU, /* Insert plugin before this monitor. Choose */ /* MON_CLOCK, MON_CPU, MON_PROC, MON_DISK, */ /* MON_INET, MON_NET, MON_FS, MON_MAIL, */ /* MON_APM, or MON_UPTIME */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ }; static void read_default(void) { panel_state = 0; options.chart_visible = FALSE; options.panel_visible = TRUE; options.metric = 1; options.update_interval = 15; options.switch_interval = 0; options.wind_chill = 0; options.windspeed_unit = 1; options.pressure_unit = 1; strcpy(options.station, DEFAULT_STATION_ID); snprintf(options.command, 512, "/usr/share/gkrellm/GrabWeather %s", options.station); options.command[511] = 0; snprintf(options.filename, 512, "%s/.wmWeatherReports/%s.dat", getenv("HOME"), options.station); options.filename[511] = 0; } GkrellmMonitor * gkrellm_init_plugin(void) { #ifdef ENABLE_NLS bind_textdomain_codeset(PACKAGE, "UTF-8"); #endif /* ENABLE_NLS */ style_id = gkrellm_add_meter_style(&air_mon, STYLE_NAME); read_default(); net_update = FALSE; monitor = &air_mon; return &air_mon; } gkrellweather-2.0.8/README0000644000175000017500000000134211132433446014276 0ustar henryhenryGKrellWeather: GKrellM Weather Plugin Author: Franky Lam Homepage: http://www.frankylam.com/ install: make make install (as root) require: - wget or LWP gkrellweather is copyright (c) 2001 by Franky Lam. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. gkrellweather-2.0.8/po/0000755000175000017500000000000011132433446014034 5ustar henryhenrygkrellweather-2.0.8/po/ru.po0000644000175000017500000000546611132433446015035 0ustar henryhenry# This file is distributed under the same license as the PACKAGE package. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # Aleksander , 2003 # msgid "" msgstr "" "Project-Id-Version: gkrellweather-2.0.5\n" "POT-Creation-Date: 2003-03-26 13:18+0200\n" "PO-Revision-Date: 2003-03-26 13:40+0200\n" "Last-Translator: Aleksander \n" "Language-Team: ru \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CP1251\n" "Content-Transfer-Encoding: 8bit\n" #: gkrellweather.c:762 msgid "" "GKrellWeather shows the current weather under the clock.\n" "\n" "Right click the panel to toggle between different display:\n" "\n" " - Temperature, Relative Humidity\n" " - DewPoint, Pressure (altimeter)\n" " - Wind Direction, Wind Speed\n" " - Sky Condition (if available)\n" " - Station name\n" "\n" "Options:\n" " switch interval - number of seconds (0 = never) between switching display\n" msgstr "" "GKrellWeather отображает текущую погоду под часами.\n" "\n" "Щелчок правой кнопки мыши переключает режимы:\n" "\n" " - Температура, Относительная влажность\n" " - Точка росы, Давление \n" " - Направление ветра, Скорость ветра\n" " - Состояние неба (если доступно)\n" " - Название станции\n" "\n" "Опции:\n" " скорость переключение - количество секунд (0 = никогда) между\n" "переключениями режима\n" #: gkrellweather.c:789 msgid "4 letter Station ID:" msgstr "Код станции (4 буквы):" #: gkrellweather.c:798 msgid "Get your station ID at:" msgstr "Получить код на:" #: gkrellweather.c:809 msgid "Display in metric unit" msgstr "Отображать в метрических еденицах" #: gkrellweather.c:823 msgid "switch interval (secs)" msgstr "скорость переключение (сек)" #: gkrellweather.c:836 msgid "update interval (mins)" msgstr "скорость обновления (сек)" #: gkrellweather.c:844 msgid "metric windspeed unit:" msgstr "скорость ветра:" #: gkrellweather.c:847 msgid "km/h" msgstr "км/ч" #: gkrellweather.c:857 msgid "m/s" msgstr "м/с" #: gkrellweather.c:867 msgid "beaufort" msgstr "" #: gkrellweather.c:877 msgid "metric pressure unit:" msgstr "давление:" #: gkrellweather.c:879 msgid "mmHg" msgstr "Мм ртутного столба" #: gkrellweather.c:887 msgid "kPa" msgstr "КПа" #: gkrellweather.c:895 msgid "hPa" msgstr "ГПа" #: gkrellweather.c:905 msgid "Options" msgstr "Настройки" #: gkrellweather.c:922 msgid "Help" msgstr "Помощь" #: gkrellweather.c:927 #, c-format msgid "" "GKrellWeather %s\n" "GKrellM weather Plugin\n" "\n" "Copyright (C) 2001 Franky Lam\n" "franky@frankylam.com\n" "http://www.frankylam.com/\n" "\n" "Released under the GNU Public License\n" msgstr "" "GKrellWeather %s\n" "GKrellM weather Plugin\n" "\n" "Copyright (C) 2001 Franky Lam\n" "franky@frankylam.com\n" "http://www.frankylam.com/\n" "\n" "Распространяется под GNU Public License\n" #: gkrellweather.c:939 msgid "About" msgstr "О программе" gkrellweather-2.0.8/po/README0000644000175000017500000000466611132433446014730 0ustar henryhenry Adding a translation to gkrellweather -------------------------------------- 0) History ---------- This document is taken from the gkrellm source tree and adapted for gkrellweather 1) Extract the strings from the source -------------------------------------- In the gkrellmkam top level directory, create the .po template (.pot): xgettext -k_ -kN_ *.c -o po/gkrellweather.pot 2) Update or create .po files ----------------------------- If there are any existing translations, XX.po files, then merge them: cd po msgmerge XX.po gkrellweather.pot > XX.po.new mv XX.po.new XX.po Or, if this is a new translation, copy the template: cd po cp gkrellweather.pot XX.po 3) Add translations ------------------- Edit XX.po to add translations for new strings, fix broken translations, and touch up fuzzy translations. 4) Make and install gkrellweather with i18n enabled ---------------------------------------------------- If make is run from this directory instead of the top level dir, you must explicitely enable i18n in all the below examples by adding enable_nls=1 to the make command: make enable_nls=1 And for the install step: make install enable_nls=1 i18n will be automatically enabled when make is run from the top level dir. In either case, a make install will for each XX.po file create a XX.mo file and copy it to: $LOCALEDIR/XX/LC_MESSAGES/gkrellweather.mo If there is no LOCALEDIR environment variable, then the default install will be to: /usr/share/locale/XX/LC_MESSAGES/gkrellweather.mo But, if you want a different explicit install directory, do for example: make install LOCALEDIR=/usr/local/share/locale or (for bash) export LOCALEDIR=/usr/local/share/locale make install Other export lines: sh: export LOCALEDIR; LOCALEDIR=/usr/local/share/locale csh: setenv LOCALEDIR /usr/local/share/locale You can also specify the textdomain package name. From bash: make install PACKAGE=gkrellweather2 ============================================================================ Using a translation ------------------- A user must have localizations enabled for a translation to be used. To enable a localization, the LANG environment variable should be set via the command line or the shell login startup files. For example, to see the French translation, a user should be able to: From bash: export LANG=fr_FR or from csh setenv LANG fr_FR If fr_FR does not work, try fr_FR.ISO_8859-1 gkrellweather-2.0.8/po/Makefile0000644000175000017500000000117711132433446015502 0ustar henryhenryMSGFMT = msgfmt SUB_DIRS = FILES_PO:=$(wildcard *.po) FILES_MO:=$(FILES_PO:.po=.mo) LOCALEDIR ?= $(PREFIX)/locale PKGNAME ?= gkrellweather ifeq ($(enable_nls),1) all: mo-files mo-files: $(FILES_MO) install: $(MAKE) all for f in *.mo ; do mkdir -p \ $(INSTALL_PREFIX)$(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES ; \ cp $$f $(INSTALL_PREFIX)$(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES/$(PKGNAME).mo ; done uninstall: for f in $(FILES_MO) ; do \ rm $(INSTALL_PREFIX)$(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES/$(PKGNAME).mo ; done %.mo: %.po $(MSGFMT) -f -v -o $@ $< else all: install: endif clean: $(RM) $(FILES_MO) gkrellweather-2.0.8/ChangeLog0000644000175000017500000000452311132433446015174 0ustar henryhenry2.0.8 * fixed sprintf buffer overflows 2.0.7 * fixed horrible rounding bugs with negative temperatures * removed deprecated GkrellM API functions 2.0.6 * added a Russian translation, thanks to Alex Murygin 2.0.5 * cosmetic fix * changed NOAA url to http for better availability 2.0.4 * really fixed a flaw in locale handling 2.0.3 * fixed a flaw in locale handling 2.0.2 * GrabWeather: passive mode for FTP via LWP * changed the style stuff 2.0.1 * Makefile fixes, added forgotten GrabWeather script 2.0.0 Fri Oct 14 2002 (Jindrich Makovicka) * ported to GkrellM 2.x API * fixed locale problem with floating point scanf * some minor cosmetic fixes 0.2.7 Sun May 20 2001 * fixed buffer overflow problem when station.TXT is too long (contribued by Ben Winslow ) 0.2.6 Thu May 10 2001 * minor changes for network connection problem (contributed by Chris Lemon ) * easier station ID lookup by allowing copy and paste on url 0.2.5 Sun Apr 15 2001 * fixed style setting 0.2.4 Mon Mar 19 2001 * change Makefile for uninstall and install (contribued by Nicolas Lidzborski ) * fixed display problem when humidity is 100% * add tool tip for full weather info 0.2.3b Sun Feb 18 2001 * remove server_alive() to avoid hang * fixed showing Sydney data as initial data * avoid unnecessary redraw of decals (contribued by Bill Wilson ) 0.2.3a Sun Oct 30 2000 * added server_alive() to detect whether Grabweather works (contributed by Chris Lemon ) 0.2.3 Mon Jul 10 2000 * new GrabWeather script (contributed by Maurice Aubrey ) * change font style to fit more digits into panel 0.2.2 Thu Jun 22 2000 * new sky condition display * able to switch display automatically * new option to change interval between auto switching display 0.2.1 Tue Jun 19 2000 * minor changes to make it compiles under 0.10.0 * add options to change Pressure unit * change textstyle for Pressure * fixed flicking when switching between display at the first time. * fixed text width for wind direction 0.2.0 Mon Jun 18 2000 * first release of GKRellWeather gkrellweather-2.0.8/Makefile0000644000175000017500000000324311132433446015060 0ustar henryhenryPKGNAME = gkrellweather VERSION = 2.0.8 CFLAGS = -O2 -std=gnu99 -Wall -fPIC `pkg-config gtk+-2.0 --cflags` LIBS = `pkg-config gtk+-2.0 --libs` LFLAGS = -shared PREFIX = /usr/local LOCALEDIR := $(PREFIX)/share/locale ifeq ($(enable_nls),1) CFLAGS += -DENABLE_NLS -DLOCALEDIR=\"$(LOCALEDIR)\" export enable_nls endif CFLAGS += -DPACKAGE="\"$(PKGNAME)\"" export PKGNAME LOCALEDIR CC = gcc OBJS = gkrellweather.o gkrellweather.so: $(OBJS) (cd po && ${MAKE} all ) $(CC) $(OBJS) -DVERSION=\"$(VERSION)\" -o gkrellweather.so $(LFLAGS) $(LIBS) -lpthread clean: (cd po && ${MAKE} clean ) rm -f *.o core *.so* *.bak *~ gkrellweather.o: gkrellweather.c $(CC) $(CFLAGS) -DPREFIX=\"$(PREFIX)\" -DVERSION=\"$(VERSION)\" -c gkrellweather.c install: (cd po && ${MAKE} install ) if [ -d /usr/lib/gkrellm2/plugins/ ] ; then \ install -c -s -m 644 gkrellweather.so /usr/lib/gkrellm2/plugins/ ; \ elif [ -d $(PREFIX)/lib/gkrellm2/plugins/ ] ; then \ install -c -s -m 644 gkrellweather.so $(PREFIX)/lib/gkrellm2/plugins/ ; \ else \ install -D -c -s -m 644 gkrellweather.so $(PREFIX)/lib/gkrellm2/plugins/gkrellweather.so ; \ fi install -c -m 755 GrabWeather $(PREFIX)/bin uninstall: (cd po && ${MAKE} uninstall ) rm -f /usr/lib/gkrellm2/plugins/gkrellweather.so rm -f $(PREFIX)/lib/gkrellm2/plugins/gkrellweather.so rm -f $(PREFIX)/bin/GrabWeather dist: rm -rf $(PKGNAME)-$(VERSION) mkdir $(PKGNAME)-$(VERSION) cp COPYING ChangeLog Makefile README gkrellweather.c GrabWeather $(PKGNAME)-$(VERSION)/ mkdir $(PKGNAME)-$(VERSION)/po cp po/*.po po/Makefile po/README $(PKGNAME)-$(VERSION)/po/ tar zcf $(PKGNAME)-$(VERSION).tgz $(PKGNAME)-$(VERSION) rm -rf $(PKGNAME)-$(VERSION) gkrellweather-2.0.8/COPYING0000644000175000017500000004312711132433446014460 0ustar henryhenry GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. gkrellweather-2.0.8/GrabWeather0000755000175000017500000001044511132433446015543 0ustar henryhenry#!/usr/bin/perl # # Grabs the latest local weather conditions from the # National Weather Service (NWS). Uses the decoded METAR reports. # # Need to give the 4-character METAR station code on the # Command Line. E.g.; # # GrabWeather YSSY # $ReportDir = '.wmWeatherReports'; #$WeatherSrc = 'ftp://weather.noaa.gov/data/observations/metar/decoded'; $WeatherSrc = 'http://weather.noaa.gov/pub/data/observations/metar/decoded'; use strict; use vars qw( $ReportDir $WeatherSrc ); use IO::File; # # Change to users home directory. We used to dump into /tmp # but using home dir instead avoids multiple users interfering # with one another. (Yeah, we could "unique-ize" the filenames, but # this is easier for now...) # my $home = $ENV{HOME} || (getpwuid($<))[7]; chdir() || chdir($home) or die "chdir '$home' failed: $!"; unless(-e $ReportDir) { mkdir $ReportDir, 0755 or die "unable to mkdir '$ReportDir': $!"; } chdir $ReportDir or die "chdir '$ReportDir' failed: $!"; my $StationID = uc shift @ARGV or die "Usage: $0 \n"; my $HTMLFileName = "$StationID.TXT"; my $URL = "$WeatherSrc/$HTMLFileName"; my $DataFileName = "$StationID.dat"; # Is LWP installed? eval { require LWP::UserAgent }; if ($@) { my $cmd = qq{wget --proxy=off --passive-ftp --tries=0 --quiet } . qq{--output-document=$home/$ReportDir/$HTMLFileName $URL}; `$cmd` == 0 or die "unable to fetch weather: $?"; } else { $ENV{FTP_PASSIVE} = 1; # LWP uses Net::FTP internally. my $ua = new LWP::UserAgent; my $req = new HTTP::Request( GET => $URL ); my $rsp = $ua->request( $req ); die $rsp->status_line unless $rsp->is_success; my $fh = new IO::File "> $home/$ReportDir/$HTMLFileName" or die "unable to write '$home/$ReportDir/$HTMLFileName': $!"; print $fh $rsp->content; close $fh or die "error closing '$home/$ReportDir/$HTMLFileName': $!"; } # # Parse HTML File. # my %stats = ( temp => -99.0, chill => -99.0, dew_point => -99.0, pressure => -99.0, humidity => -99.0, universal_time => '99:99', ); my $fh = new IO::File $HTMLFileName or die "unable to read '$HTMLFileName': $!"; chomp($stats{station_info} = <$fh>); chomp($stats{update_time} = <$fh>); while (<$fh>){ chomp; $stats{sky_conditions} = $1, next if /Sky conditions: (.*)/; $stats{temp} = $1, next if /Temperature:\s*(\-{0,1}[0-9.]{1,}).*/; $stats{chill} = $1, next if /Windchill:\s*(\-{0,1}[0-9.]{1,}).*/; $stats{dew_point} = $1, next if /Dew Point:\s*(\-{0,1}[0-9.]{1,}).*/; $stats{pressure} = $1, next if /Pressure \(.*\):\s*([0-9.]{2,}).*/; $stats{humidity} = $1, next if /Relative Humidity:\s*(\d{1,})\%.*/; $stats{coded_metar} = $1, next if /ob: (.*)/; } close $fh or die "error closing '$HTMLFileName': $!"; # # Isolate the Wind groups out of the coded METAR report. # There may be two groups - the normal one and a variability set. # $stats{wind_group} = $stats{coded_metar}; $stats{wind_group} =~ s/ RMK\s.*$//; $stats{var_flag} = 1 if $stats{wind_group} =~ /\d+(KT|MPS)\s\d+V\d+\s/; if ($stats{wind_group} =~ /\s(\w{3})(?:(\d+)G)?(\d+)(KT|MPS)\s/) { @stats{qw( direction speed1 speed2 )} = ($1, $2, $3); if ($4 eq 'MPS') { $stats{speed1} *= 1.942 if defined $stats{speed1}; $stats{speed2} *= 1.942; } } # # Get the Time out of the coded Metar Report. # if ($stats{coded_metar} =~ /$StationID \d+?(\d{2})(\d{2})Z/) { $stats{universal_time} = "$1:$2"; } # # Write out the stuff we need to the Data File. This is the file that will # be read by GKrellWeather. # my $fh = new IO::File ">$DataFileName" or die "unable to write '$DataFileName': $!"; print $fh map { "$stats{$_}\n" } qw( station_info update_time sky_conditions universal_time temp dew_point chill pressure humidity ); if (not exists $stats{direction}) { print $fh "-99\n"; } elsif ($stats{direction} =~ /VRB/) { print $fh "99\n"; } elsif ($stats{var_flag}) { print $fh $stats{direction} * -1, "\n"; } else { print $fh $stats{direction} + 0, "\n"; } if (not $stats{direction}) { print $fh "-99\n"; } elsif (defined $stats{speed1} and defined $stats{speed2}) { my $ave_speed = (($stats{speed1} + $stats{speed2})/2.0) * 1.15155; print $fh "-$ave_speed\n"; } else { print $fh $stats{speed2} * 1.15155, "\n"; } close $fh or die "error closing '$DataFileName': $!";