|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
#include "weather_icon.h"
|
|
|
|
|
|
|
|
WeatherIcon::WeatherIcon( int condition, bool night )
|
|
|
|
{
|
|
|
|
iconLoader = new TDEIconLoader("kweather");
|
|
|
|
TQStringList fallback;
|
|
|
|
|
|
|
|
switch( condition )
|
|
|
|
{
|
|
|
|
case Sunny:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-clear-night"; //xdg, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-clear"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Fog:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-fog-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-fog"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Mist:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-mist-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-mist"; // themes, kweather
|
|
|
|
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-fog-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-fog"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Overcast:
|
|
|
|
{
|
|
|
|
fallback << "weather-overcast"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Hail:
|
|
|
|
{
|
|
|
|
fallback << "weather-hail"; // themes
|
|
|
|
fallback << "weather-freezing-rain"; // themes, kweather
|
|
|
|
fallback << "weather-snow"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LightRain:
|
|
|
|
{
|
|
|
|
fallback << "weather-showers-scattered"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Sleet:
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-rain"; // themes, kweather
|
|
|
|
fallback << "weather-snow"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iconName = findIcon(fallback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
|
|
|
|
{
|
|
|
|
iconLoader = new TDEIconLoader("kweather");
|
|
|
|
TQStringList fallback;
|
|
|
|
|
|
|
|
switch ( condition )
|
|
|
|
{
|
|
|
|
case Cloudy:
|
|
|
|
{
|
|
|
|
switch ( strength )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-few-clouds-night"; // xdg, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-few-clouds"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-moderate-clouds-night"; // kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-moderate-clouds"; // kweather
|
|
|
|
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-few-clouds-night"; // xdg, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-few-clouds"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-clouds-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-clouds"; // themes, kweather
|
|
|
|
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-few-clouds-night"; // xdg, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-few-clouds"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-ample-clouds-night"; // kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-ample-clouds"; // kweather
|
|
|
|
|
|
|
|
fallback << "weather-many-clouds"; // themes, kweather
|
|
|
|
|
|
|
|
fallback << "weather-overcast"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5: {
|
|
|
|
fallback << "weather-many-clouds"; // themes, kweather
|
|
|
|
|
|
|
|
fallback << "weather-overcast"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
fallback << "weather-clouds"; // themes, kweather
|
|
|
|
|
|
|
|
fallback << "weather-few-clouds"; // xdg, kweather
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Showers:
|
|
|
|
{
|
|
|
|
switch ( strength )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-showers-scattered-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-showers-scattered-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-showers-scattered"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-showers-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-showers-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-showers"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fallback << "weather-showers"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Snow:
|
|
|
|
{
|
|
|
|
switch( strength )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-scattered-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-scattered-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-snow-scattered"; // xdg, kweather
|
|
|
|
|
|
|
|
fallback << "weather-snow"; // workaround for some themes
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-moderate-night"; // kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-moderate-day"; // kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-snow-moderate"; // kweather
|
|
|
|
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-scattered-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-scattered-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-snow-scattered"; // xdg, kweather
|
|
|
|
|
|
|
|
fallback << "weather-snow"; // workaround for some themes
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-ample-night"; // kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-ample-day"; // kweather
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback << "weather-snow-ample"; // kweather
|
|
|
|
|
|
|
|
|
|
|
|
fallback << "weather-snow"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
fallback << "weather-snow-scattered"; // xdg, kweather
|
|
|
|
|
|
|
|
fallback << "weather-snow"; // workaround for some themes
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fallback << "weather-snow"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Thunderstorm:
|
|
|
|
switch ( strength )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-storm"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-moderate-night"; // kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-moderate-day"; // kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-storm-moderate"; // kweather
|
|
|
|
|
|
|
|
if( night )
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-night"; // themes, kweather
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fallback << "weather-storm-day"; // themes, kweather
|
|
|
|
}
|
|
|
|
fallback << "weather-storm"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fallback << "weather-storm"; // xdg, kweather
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconName = findIcon(fallback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WeatherIcon::~WeatherIcon()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
TQString WeatherIcon::findIcon( TQStringList fallback )
|
|
|
|
{
|
|
|
|
// Check in theme
|
|
|
|
for ( TQStringList::Iterator icon = fallback.begin(); icon != fallback.end(); ++icon )
|
|
|
|
{
|
|
|
|
kdDebug() << "[WeatherIcon::findIcon] Searching for `" << *icon << "` in theme" << endl;
|
|
|
|
if( iconExists(*icon) )
|
|
|
|
{
|
|
|
|
kdDebug() << "[WeatherIcon::findIcon] FOUND `" << *icon << "` in theme" << endl;
|
|
|
|
return *icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check in kweather fallback
|
|
|
|
for ( TQStringList::Iterator icon = fallback.begin(); icon != fallback.end(); ++icon )
|
|
|
|
{
|
|
|
|
kdDebug() << "[WeatherIcon::findIcon] Searching for `" << *icon << "` in kweather icons" << endl;
|
|
|
|
if( iconExists(*icon, false) )
|
|
|
|
{
|
|
|
|
kdDebug() << "[WeatherIcon::findIcon] FOUND `" << *icon << "` in kweather icons" << endl;
|
|
|
|
return *icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WeatherIcon::iconExists( TQString& icon, bool inTheme )
|
|
|
|
{
|
|
|
|
if( inTheme )
|
|
|
|
{
|
|
|
|
return !( iconLoader->iconPath(icon, TDEIcon::Desktop, true).isNull() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return !( locate( "data", "kweather/" + icon + ".png" ).isNull() );
|
|
|
|
}
|
|
|
|
}
|