summaryrefslogtreecommitdiffstats
path: root/kweather/metar_parser.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <[email protected]>2021-12-12 15:50:37 +0200
committerMavridis Philippe <[email protected]>2022-01-14 12:39:01 +0200
commit6668b34bc5deb36e73aa45e0457ed6740f828efd (patch)
treef2ff95858cc06d5eaad187b6750717a58a175a60 /kweather/metar_parser.cpp
parent67e995b6fc4da17811aefb7c8d841c9812e4eec9 (diff)
downloadtdetoys-6668b34bc5deb36e73aa45e0457ed6740f828efd.tar.gz
tdetoys-6668b34bc5deb36e73aa45e0457ed6740f828efd.zip
Implemented icon theme option.
Changes in this commit include: * The option itself; * A method of updating the option right after Apply or Ok is pressed in the settings dialog; * A new WeatherIconPrivate class to store the methods previously in WeatherIcons, as well as the settings; * Improved icon name helper function in METAR parser; * A few cleanups to the WeatherIcon class. Signed-off-by: Mavridis Philippe <[email protected]>
Diffstat (limited to 'kweather/metar_parser.cpp')
-rw-r--r--kweather/metar_parser.cpp63
1 files changed, 32 insertions, 31 deletions
diff --git a/kweather/metar_parser.cpp b/kweather/metar_parser.cpp
index 7ec252d..9456095 100644
--- a/kweather/metar_parser.cpp
+++ b/kweather/metar_parser.cpp
@@ -58,6 +58,7 @@ void MetarParser::reset()
{
// Initialize the WeatherInfo structure
weatherInfo.theWeather = TQString();
+ weatherInfo.iconPath = TQString();
weatherInfo.clouds = 0;
weatherInfo.windMPH = 0;
weatherInfo.tempC = 0;
@@ -258,7 +259,7 @@ bool MetarParser::parseCurrent(const TQString &s)
if (sCode.contains("DZ"))
{
phenomena = i18n("Drizzle");
- weatherInfo.theWeather = iconName( WeatherIcon::LightRain, false );
+ getIcon( WeatherIcon::LightRain, false );
}
else if (sCode.contains("RA"))
{
@@ -273,32 +274,32 @@ bool MetarParser::parseCurrent(const TQString &s)
else if (sCode.contains("SG"))
{
phenomena = i18n("Snow Grains");
- weatherInfo.theWeather = iconName( WeatherIcon::Snow, false, 4 );
+ getIcon( WeatherIcon::Snow, false, 4 );
}
else if (sCode.contains("IC"))
{
phenomena = i18n("Ice Crystals");
- weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
+ getIcon( WeatherIcon::Hail, false );
}
else if (sCode.contains("PE"))
{
phenomena = i18n("Ice Pellets");
- weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
+ getIcon( WeatherIcon::Hail, false );
}
else if (s.contains("GR"))
{
phenomena = i18n("Hail");
- weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
+ getIcon( WeatherIcon::Hail, false );
}
else if (sCode.contains("GS"))
{
phenomena = i18n("Small Hail Pellets");
- weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
+ getIcon( WeatherIcon::Hail, false );
}
else if (s.contains("UP"))
{
phenomena = i18n("Unknown Precipitation");
- weatherInfo.theWeather = iconName( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
+ getIcon( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
}
else if (sCode.contains("BR"))
{
@@ -727,17 +728,17 @@ void MetarParser::calcCurrentIcon()
if (weatherInfo.theWeather.isEmpty())
{
if (weatherInfo.clouds == 0)
- weatherInfo.theWeather = iconName( WeatherIcon::Sunny, night );
+ getIcon( WeatherIcon::Sunny, night );
else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2)
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 1 );
+ getIcon( WeatherIcon::Cloudy, night, 1 );
else if ( weatherInfo.clouds > 2 && weatherInfo.clouds <= 4)
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 2 );
+ getIcon( WeatherIcon::Cloudy, night, 2 );
else if ( weatherInfo.clouds > 4 && weatherInfo.clouds <= 8)
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 3 );
+ getIcon( WeatherIcon::Cloudy, night, 3 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63)
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 4 );
+ getIcon( WeatherIcon::Cloudy, night, 4 );
else
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 );
+ getIcon( WeatherIcon::Cloudy, night, 5 );
}
else if (weatherInfo.theWeather == "tstorm")
{
@@ -745,11 +746,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 1 );
+ getIcon( WeatherIcon::Thunderstorm, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 2 );
+ getIcon( WeatherIcon::Thunderstorm, night, 2 );
else
- weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 3 );
+ getIcon( WeatherIcon::Thunderstorm, night, 3 );
}
else if (weatherInfo.theWeather == "shower")
{
@@ -757,11 +758,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 1 );
+ getIcon( WeatherIcon::Showers, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 2 );
+ getIcon( WeatherIcon::Showers, night, 2 );
else
- weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 3 );
+ getIcon( WeatherIcon::Showers, night, 3 );
}
else if (weatherInfo.theWeather == "snow")
{
@@ -769,22 +770,22 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 8)
- weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 1 );
+ getIcon( WeatherIcon::Snow, night, 1 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds <= 16)
- weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 2 );
+ getIcon( WeatherIcon::Snow, night, 2 );
else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24)
- weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 3 );
+ getIcon( WeatherIcon::Snow, night, 3 );
else
- weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 5 );
+ getIcon( WeatherIcon::Snow, night, 5 );
}
else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" )
{
if ( weatherInfo.clouds >= 63 )
- weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 );
+ getIcon( WeatherIcon::Cloudy, night, 5 );
else if ( weatherInfo.theWeather == "mist" )
- weatherInfo.theWeather = iconName( WeatherIcon::Mist, night );
+ getIcon( WeatherIcon::Mist, night );
else if ( weatherInfo.theWeather == "fog" )
- weatherInfo.theWeather = iconName( WeatherIcon::Fog, night );
+ getIcon( WeatherIcon::Fog, night );
}
kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: "
@@ -860,23 +861,23 @@ bool MetarParser::isNight(const TQString &stationID) const
}
}
-TQString MetarParser::iconName( int condition, bool night, int strength ) const
+void MetarParser::getIcon( int condition, bool night, int strength )
{
- TQString _iconName;
if( strength != 0 )
{
// Ranged
WeatherIcon* wi = new WeatherIcon( condition, night, strength );
- _iconName = wi->name();
+ weatherInfo.iconName = wi->name();
+ weatherInfo.iconPath = wi->path();
delete wi;
}
else
{
// Simple
WeatherIcon* wi = new WeatherIcon( condition, night );
- _iconName = wi->name();
+ weatherInfo.iconName = wi->name();
+ weatherInfo.iconPath = wi->path();
delete wi;
}
- return _iconName;
}