summaryrefslogtreecommitdiffstats
path: root/kweather/metar_parser.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2023-06-01 16:30:11 +0300
committerMavridis Philippe <[email protected]>2023-06-14 17:42:21 +0300
commitfe6de6f4bc8a0a7d86c2c3dc6413170214206cff (patch)
treed86bbc14c9c16c52b9d2b5b750de15ece38c7c5a /kweather/metar_parser.cpp
parent6b56a1befc9f510d4467cd5652cbb8fb49563070 (diff)
downloadtdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.tar.gz
tdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.zip
KWeather: improve icon loading and other fixes
- Fix pixelated icons (issue #19) - Fix "network offline" state - Add helper `bool weatherDataAvailable(TQString stationID)` DCOP function - Fix compatibility with old DCOP function signatures - Prevent double "Network is offline" strings in weather data. This commit introduces some new and renamed DCOP calls. Old function signatures are kept for compatibility, but are mraked as deprecated. Signed-off-by: Mavridis Philippe <[email protected]> (cherry picked from commit bc71670331e16b15fc30214cb85c409b8c91bb9c)
Diffstat (limited to 'kweather/metar_parser.cpp')
-rw-r--r--kweather/metar_parser.cpp77
1 files changed, 33 insertions, 44 deletions
diff --git a/kweather/metar_parser.cpp b/kweather/metar_parser.cpp
index 9aa2c8b..b582300 100644
--- a/kweather/metar_parser.cpp
+++ b/kweather/metar_parser.cpp
@@ -58,7 +58,6 @@ void MetarParser::reset()
{
// Initialize the WeatherInfo structure
weatherInfo.theWeather = TQString();
- weatherInfo.iconPath = TQString();
weatherInfo.clouds = 0;
weatherInfo.windMPH = 0;
weatherInfo.tempC = 0;
@@ -78,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)
@@ -259,7 +261,7 @@ bool MetarParser::parseCurrent(const TQString &s)
if (sCode.contains("DZ"))
{
phenomena = i18n("Drizzle");
- saveIconNamePath( WeatherIcon::LightRain, false );
+ saveIconData( WeatherIcon::LightRain, false );
}
else if (sCode.contains("RA"))
{
@@ -274,32 +276,32 @@ bool MetarParser::parseCurrent(const TQString &s)
else if (sCode.contains("SG"))
{
phenomena = i18n("Snow Grains");
- saveIconNamePath( WeatherIcon::Snow, false, 4 );
+ saveIconData( WeatherIcon::Snow, false, 4 );
}
else if (sCode.contains("IC"))
{
phenomena = i18n("Ice Crystals");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (sCode.contains("PE"))
{
phenomena = i18n("Ice Pellets");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (s.contains("GR"))
{
phenomena = i18n("Hail");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (sCode.contains("GS"))
{
phenomena = i18n("Small Hail Pellets");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (s.contains("UP"))
{
phenomena = i18n("Unknown Precipitation");
- saveIconNamePath( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
+ saveIconData( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
}
else if (sCode.contains("BR"))
{
@@ -728,17 +730,17 @@ void MetarParser::calcCurrentIcon()
if (weatherInfo.theWeather.isEmpty())
{
if (weatherInfo.clouds == 0)
- saveIconNamePath( WeatherIcon::Sunny, night );
+ saveIconData( WeatherIcon::Sunny, night );
else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2)
- saveIconNamePath( WeatherIcon::Cloudy, night, 1 );
+ saveIconData( WeatherIcon::Cloudy, night, 1 );
else if ( weatherInfo.clouds > 2 && weatherInfo.clouds <= 4)
- saveIconNamePath( WeatherIcon::Cloudy, night, 2 );
+ saveIconData( WeatherIcon::Cloudy, night, 2 );
else if ( weatherInfo.clouds > 4 && weatherInfo.clouds <= 8)
- saveIconNamePath( WeatherIcon::Cloudy, night, 3 );
+ saveIconData( WeatherIcon::Cloudy, night, 3 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63)
- saveIconNamePath( WeatherIcon::Cloudy, night, 4 );
+ saveIconData( WeatherIcon::Cloudy, night, 4 );
else
- saveIconNamePath( WeatherIcon::Cloudy, night, 5 );
+ 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)
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 1 );
+ saveIconData( WeatherIcon::Thunderstorm, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 2 );
+ saveIconData( WeatherIcon::Thunderstorm, night, 2 );
else
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 3 );
+ 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)
- saveIconNamePath( WeatherIcon::Showers, night, 1 );
+ saveIconData( WeatherIcon::Showers, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- saveIconNamePath( WeatherIcon::Showers, night, 2 );
+ saveIconData( WeatherIcon::Showers, night, 2 );
else
- saveIconNamePath( WeatherIcon::Showers, night, 3 );
+ 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)
- saveIconNamePath( WeatherIcon::Snow, night, 1 );
+ saveIconData( WeatherIcon::Snow, night, 1 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds <= 16)
- saveIconNamePath( WeatherIcon::Snow, night, 2 );
+ saveIconData( WeatherIcon::Snow, night, 2 );
else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24)
- saveIconNamePath( WeatherIcon::Snow, night, 3 );
+ saveIconData( WeatherIcon::Snow, night, 3 );
else
- saveIconNamePath( WeatherIcon::Snow, night, 5 );
+ saveIconData( WeatherIcon::Snow, night, 5 );
}
else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" )
{
if ( weatherInfo.clouds >= 63 )
- saveIconNamePath( WeatherIcon::Cloudy, night, 5 );
+ saveIconData( WeatherIcon::Cloudy, night, 5 );
else if ( weatherInfo.theWeather == "mist" )
- saveIconNamePath( WeatherIcon::Mist, night );
+ saveIconData( WeatherIcon::Mist, night );
else if ( weatherInfo.theWeather == "fog" )
- saveIconNamePath( WeatherIcon::Fog, night );
+ saveIconData( WeatherIcon::Fog, night );
}
kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: "
@@ -861,23 +863,10 @@ bool MetarParser::isNight(const TQString &stationID) const
}
}
-void MetarParser::saveIconNamePath( int condition, bool night, int strength )
+void MetarParser::saveIconData( int condition, bool night, int strength )
{
- if( strength != 0 )
- {
- // Ranged
- WeatherIcon* wi = new WeatherIcon( condition, night, strength );
- weatherInfo.iconName = wi->name();
- weatherInfo.iconPath = wi->path();
- delete wi;
- }
- else
- {
- // Simple
- WeatherIcon* wi = new WeatherIcon( condition, night );
- weatherInfo.iconName = wi->name();
- weatherInfo.iconPath = wi->path();
- delete wi;
- }
+ weatherInfo.wiCondition = condition;
+ weatherInfo.wiStrength = strength;
+ weatherInfo.wiNight = night;
}