diff options
Diffstat (limited to 'kweather/metar_parser.cpp')
-rw-r--r-- | kweather/metar_parser.cpp | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/kweather/metar_parser.cpp b/kweather/metar_parser.cpp index 44e2c73..b582300 100644 --- a/kweather/metar_parser.cpp +++ b/kweather/metar_parser.cpp @@ -28,6 +28,7 @@ email : jratke@comcast.net #include "metar_parser.h" #include "stationdatabase.h" +#include "weather_icon.h" #include "sun.h" // Temperature conversion macros @@ -76,6 +77,9 @@ void MetarParser::reset() weatherInfo.qsHeatIndex = TQString(); weatherInfo.qsWindDirection = TQString(); weatherInfo.stationNeedsMaintenance = false; + weatherInfo.wiCondition = 0; + weatherInfo.wiStrength = 0; + weatherInfo.wiNight = false; } struct WeatherInfo MetarParser::processData(const TQString &stationID, const TQString &metar) @@ -257,7 +261,7 @@ bool MetarParser::parseCurrent(const TQString &s) if (sCode.contains("DZ")) { phenomena = i18n("Drizzle"); - weatherInfo.theWeather = "light_rain"; + saveIconData( WeatherIcon::LightRain, false ); } else if (sCode.contains("RA")) { @@ -272,32 +276,32 @@ bool MetarParser::parseCurrent(const TQString &s) else if (sCode.contains("SG")) { phenomena = i18n("Snow Grains"); - weatherInfo.theWeather = "snow4"; + saveIconData( WeatherIcon::Snow, false, 4 ); } else if (sCode.contains("IC")) { phenomena = i18n("Ice Crystals"); - weatherInfo.theWeather = "hail"; + saveIconData( WeatherIcon::Hail, false ); } else if (sCode.contains("PE")) { phenomena = i18n("Ice Pellets"); - weatherInfo.theWeather = "hail"; + saveIconData( WeatherIcon::Hail, false ); } else if (s.contains("GR")) { phenomena = i18n("Hail"); - weatherInfo.theWeather = "hail"; + saveIconData( WeatherIcon::Hail, false ); } else if (sCode.contains("GS")) { phenomena = i18n("Small Hail Pellets"); - weatherInfo.theWeather = "hail"; + saveIconData( WeatherIcon::Hail, false ); } else if (s.contains("UP")) { phenomena = i18n("Unknown Precipitation"); - weatherInfo.theWeather = iconName("shower1"); + saveIconData( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1); } else if (sCode.contains("BR")) { @@ -721,24 +725,22 @@ bool MetarParser::parseStationNeedsMaintenance(const TQString &s) void MetarParser::calcCurrentIcon() { - // Default to overcast clouds - if ( weatherInfo.clouds == -1 ) - weatherInfo.clouds = 64; + bool night = isNight( weatherInfo.reportLocation ); if (weatherInfo.theWeather.isEmpty()) { if (weatherInfo.clouds == 0) - weatherInfo.theWeather = iconName("sunny"); + saveIconData( WeatherIcon::Sunny, night ); else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2) - weatherInfo.theWeather = iconName("cloudy1"); + saveIconData( WeatherIcon::Cloudy, night, 1 ); else if ( weatherInfo.clouds > 2 && weatherInfo.clouds <= 4) - weatherInfo.theWeather = iconName("cloudy2"); + saveIconData( WeatherIcon::Cloudy, night, 2 ); else if ( weatherInfo.clouds > 4 && weatherInfo.clouds <= 8) - weatherInfo.theWeather = iconName("cloudy3"); + saveIconData( WeatherIcon::Cloudy, night, 3 ); else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63) - weatherInfo.theWeather = iconName( "cloudy4" ); + saveIconData( WeatherIcon::Cloudy, night, 4 ); else - weatherInfo.theWeather = "cloudy5"; + saveIconData( WeatherIcon::Cloudy, night, 5 ); } else if (weatherInfo.theWeather == "tstorm") { @@ -746,11 +748,11 @@ void MetarParser::calcCurrentIcon() weatherInfo.clouds = 30; if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10) - weatherInfo.theWeather = iconName("tstorm1"); + saveIconData( WeatherIcon::Thunderstorm, night, 1 ); else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20) - weatherInfo.theWeather = iconName("tstorm2"); + saveIconData( WeatherIcon::Thunderstorm, night, 2 ); else - weatherInfo.theWeather = "tstorm3"; + saveIconData( WeatherIcon::Thunderstorm, night, 3 ); } else if (weatherInfo.theWeather == "shower") { @@ -758,11 +760,11 @@ void MetarParser::calcCurrentIcon() weatherInfo.clouds = 30; if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10) - weatherInfo.theWeather = iconName("shower1"); + saveIconData( WeatherIcon::Showers, night, 1 ); else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20) - weatherInfo.theWeather = iconName("shower2"); + saveIconData( WeatherIcon::Showers, night, 2 ); else - weatherInfo.theWeather = "shower3"; + saveIconData( WeatherIcon::Showers, night, 3 ); } else if (weatherInfo.theWeather == "snow") { @@ -770,22 +772,22 @@ void MetarParser::calcCurrentIcon() weatherInfo.clouds = 30; if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 8) - weatherInfo.theWeather = iconName("snow1"); + saveIconData( WeatherIcon::Snow, night, 1 ); else if ( weatherInfo.clouds > 8 && weatherInfo.clouds <= 16) - weatherInfo.theWeather = iconName("snow2"); + saveIconData( WeatherIcon::Snow, night, 2 ); else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24) - weatherInfo.theWeather = iconName("snow3"); + saveIconData( WeatherIcon::Snow, night, 3 ); else - weatherInfo.theWeather = "snow5"; + saveIconData( WeatherIcon::Snow, night, 5 ); } - else if (isNight(weatherInfo.reportLocation) && weatherInfo.theWeather == "mist") - weatherInfo.theWeather = "mist_night"; - else if (isNight(weatherInfo.reportLocation) && weatherInfo.theWeather == "fog") - weatherInfo.theWeather = "fog_night"; else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" ) { if ( weatherInfo.clouds >= 63 ) - weatherInfo.theWeather = "cloudy5"; + saveIconData( WeatherIcon::Cloudy, night, 5 ); + else if ( weatherInfo.theWeather == "mist" ) + saveIconData( WeatherIcon::Mist, night ); + else if ( weatherInfo.theWeather == "fog" ) + saveIconData( WeatherIcon::Fog, night ); } kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: " @@ -861,13 +863,10 @@ bool MetarParser::isNight(const TQString &stationID) const } } -TQString MetarParser::iconName( const TQString &icon ) const +void MetarParser::saveIconData( int condition, bool night, int strength ) { - TQString _iconName = icon; - - if ( isNight( weatherInfo.reportLocation ) ) - _iconName += "_night"; - - return _iconName; + weatherInfo.wiCondition = condition; + weatherInfo.wiStrength = strength; + weatherInfo.wiNight = night; } |