@ -36,8 +36,11 @@ bool WeatherIconPrivate::usingIconTheme()
return m_useIconTheme ;
return m_useIconTheme ;
}
}
TQPair < TQString , TQString > WeatherIconPrivate : : findIcon ( TQStringList fallback )
/** Returns the name of the best matching icon, either from the icon theme or the KWeather icons */
struct WeatherSingleIconData WeatherIconPrivate : : findIcon ( TQStringList fallback , uint size )
{
{
struct WeatherSingleIconData iconData ;
kdDebug ( 12006 ) < < " [findIcon] Use icon theme? " < < m_useIconTheme < < endl ;
kdDebug ( 12006 ) < < " [findIcon] Use icon theme? " < < m_useIconTheme < < endl ;
if ( m_useIconTheme )
if ( m_useIconTheme )
{
{
@ -45,11 +48,12 @@ TQPair<TQString,TQString> WeatherIconPrivate::findIcon( TQStringList fallback )
for ( TQStringList : : Iterator icon = fallback . begin ( ) ; icon ! = fallback . end ( ) ; + + icon )
for ( TQStringList : : Iterator icon = fallback . begin ( ) ; icon ! = fallback . end ( ) ; + + icon )
{
{
kdDebug ( 12006 ) < < " [findIcon] Searching for ` " < < * icon < < " ` in theme " < < endl ;
kdDebug ( 12006 ) < < " [findIcon] Searching for ` " < < * icon < < " ` in theme " < < endl ;
TQString iPath = iconPath ( * icon , true ) ;
TQString iPath = iconPath ( * icon , size , true ) ;
if ( ! ( iPath . isNull ( ) ) )
if ( ! iPath . isNull ( ) )
{
{
kdDebug ( 12006 ) < < " [findIcon] Found ` " < < * icon < < " ` in theme: " < < iPath < < endl ;
kdDebug ( 12006 ) < < " [findIcon] Found ` " < < * icon < < " ` in theme: " < < iPath < < endl ;
return qMakePair ( * icon , iPath ) ;
iconData = { * icon , iPath , true , size } ;
return iconData ;
}
}
}
}
}
}
@ -58,37 +62,41 @@ TQPair<TQString,TQString> WeatherIconPrivate::findIcon( TQStringList fallback )
for ( TQStringList : : Iterator icon = fallback . begin ( ) ; icon ! = fallback . end ( ) ; + + icon )
for ( TQStringList : : Iterator icon = fallback . begin ( ) ; icon ! = fallback . end ( ) ; + + icon )
{
{
kdDebug ( 12006 ) < < " [findIcon] Searching for ` " < < * icon < < " ` in kweather icons " < < endl ;
kdDebug ( 12006 ) < < " [findIcon] Searching for ` " < < * icon < < " ` in kweather icons " < < endl ;
TQString iPath = iconPath ( * icon , false ) ;
TQString iPath = iconPath ( * icon , size , false ) ;
if ( ! ( iPath . isNull ( ) ) )
if ( ! iPath . isEmpty ( ) )
{
{
kdDebug ( 12006 ) < < " [findIcon] Found ` " < < * icon < < " ` in kweather icons: " < < iPath < < endl ;
kdDebug ( 12006 ) < < " [findIcon] Found ` " < < * icon < < " ` in kweather icons: " < < iPath < < endl ;
return qMakePair ( * icon , iPath ) ;
iconData = { * icon , iPath , false , size } ;
return iconData ;
}
}
}
}
return qMakePair ( WeatherIcon : : unknown ( ) , iconPath ( WeatherIcon : : unknown ( ) ) ) ;
return WeatherIcon : : unknown ( size ) ;
}
}
TQString WeatherIconPrivate : : iconPath ( TQString icon , bool inTheme )
TQString WeatherIconPrivate : : iconPath ( TQString icon , uint size , bool inTheme )
{
{
if ( inTheme )
TQString path = TQString : : null ;
{
if ( inTheme ) {
return iconLoader - > iconPath ( icon , TDEIcon : : Desktop , true ) ;
path = iconLoader - > iconPath ( icon , size , true ) ;
if ( path . isEmpty ( ) ) {
// maybe there is a scalable icon?
path = iconLoader - > iconPath ( icon , 0 , true ) ;
}
}
else
{
return locate ( " data " , " kweather/ " + icon + " .png " ) ;
}
}
else {
path = locate ( " data " , " kweather/ " + icon + " .png " ) ;
}
return path ;
}
}
TQString WeatherIconPrivate : : iconPath ( TQString icon )
TQString WeatherIconPrivate : : iconPath ( TQString icon , uint size )
{
{
return iconPath ( icon , m_useIconTheme) ;
return iconPath ( icon , size, m_useIconTheme) ;
}
}
WeatherIcon : : WeatherIcon ( int condition , bool night )
WeatherIcon : : WeatherIcon ( int condition , bool night )
{
{
TQStringList fallback ;
switch ( condition )
switch ( condition )
{
{
case Sunny :
case Sunny :
@ -98,7 +106,6 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback < < " weather-clear-night " ; //xdg, kweather
fallback < < " weather-clear-night " ; //xdg, kweather
}
}
fallback < < " weather-clear " ; // xdg, kweather
fallback < < " weather-clear " ; // xdg, kweather
break ;
break ;
}
}
@ -109,7 +116,6 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback < < " weather-fog-night " ; // themes, kweather
fallback < < " weather-fog-night " ; // themes, kweather
}
}
fallback < < " weather-fog " ; // xdg, kweather
fallback < < " weather-fog " ; // xdg, kweather
break ;
break ;
}
}
@ -126,14 +132,12 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback < < " weather-fog-night " ; // themes, kweather
fallback < < " weather-fog-night " ; // themes, kweather
}
}
fallback < < " weather-fog " ; // xdg, kweather
fallback < < " weather-fog " ; // xdg, kweather
break ;
break ;
}
}
case Overcast :
case Overcast :
{
{
fallback < < " weather-overcast " ; // xdg, kweather
fallback < < " weather-overcast " ; // xdg, kweather
break ;
break ;
}
}
@ -142,14 +146,12 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback < < " weather-hail " ; // themes
fallback < < " weather-hail " ; // themes
fallback < < " weather-freezing-rain " ; // themes, kweather
fallback < < " weather-freezing-rain " ; // themes, kweather
fallback < < " weather-snow " ; // xdg, kweather
fallback < < " weather-snow " ; // xdg, kweather
break ;
break ;
}
}
case LightRain :
case LightRain :
{
{
fallback < < " weather-showers-scattered " ; // xdg, kweather
fallback < < " weather-showers-scattered " ; // xdg, kweather
break ;
break ;
}
}
@ -157,21 +159,13 @@ WeatherIcon::WeatherIcon( int condition, bool night )
{
{
fallback < < " weather-snow-rain " ; // themes, kweather
fallback < < " weather-snow-rain " ; // themes, kweather
fallback < < " weather-snow " ; // xdg, kweather
fallback < < " weather-snow " ; // xdg, kweather
break ;
break ;
}
}
}
}
TQPair < TQString , TQString > foundIcon = WeatherIconPrivate : : instance ( ) - > findIcon ( fallback ) ;
iconName = foundIcon . first ;
iconPath = foundIcon . second ;
return ;
}
}
WeatherIcon : : WeatherIcon ( int condition , bool night , unsigned int strength )
WeatherIcon : : WeatherIcon ( int condition , bool night , unsigned int strength )
{
{
TQStringList fallback ;
switch ( condition )
switch ( condition )
{
{
case Cloudy :
case Cloudy :
@ -185,7 +179,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-few-clouds-night " ; // xdg, kweather
fallback < < " weather-few-clouds-night " ; // xdg, kweather
}
}
fallback < < " weather-few-clouds " ; // xdg, kweather
fallback < < " weather-few-clouds " ; // xdg, kweather
break ;
break ;
}
}
@ -202,7 +195,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-few-clouds-night " ; // xdg, kweather
fallback < < " weather-few-clouds-night " ; // xdg, kweather
}
}
fallback < < " weather-few-clouds " ; // xdg, kweather
fallback < < " weather-few-clouds " ; // xdg, kweather
break ;
break ;
}
}
@ -218,7 +210,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-few-clouds-night " ; // xdg, kweather
fallback < < " weather-few-clouds-night " ; // xdg, kweather
}
}
fallback < < " weather-few-clouds " ; // xdg, kweather
fallback < < " weather-few-clouds " ; // xdg, kweather
break ;
break ;
}
}
@ -229,30 +220,23 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-ample-clouds-night " ; // kweather
fallback < < " weather-ample-clouds-night " ; // kweather
}
}
fallback < < " weather-ample-clouds " ; // kweather
fallback < < " weather-ample-clouds " ; // kweather
fallback < < " weather-many-clouds " ; // themes, kweather
fallback < < " weather-many-clouds " ; // themes, kweather
fallback < < " weather-overcast " ; // xdg, kweather
fallback < < " weather-overcast " ; // xdg, kweather
break ;
break ;
}
}
case 5 : {
case 5 : {
fallback < < " weather-many-clouds " ; // themes, kweather
fallback < < " weather-many-clouds " ; // themes, kweather
fallback < < " weather-overcast " ; // xdg, kweather
fallback < < " weather-overcast " ; // xdg, kweather
break ;
break ;
}
}
default : {
default : {
fallback < < " weather-clouds " ; // themes, kweather
fallback < < " weather-clouds " ; // themes, kweather
fallback < < " weather-few-clouds " ; // xdg, kweather
fallback < < " weather-few-clouds " ; // xdg, kweather
break ;
break ;
}
}
}
}
break ;
break ;
}
}
@ -270,9 +254,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
{
fallback < < " weather-showers-scattered-day " ; // themes, kweather
fallback < < " weather-showers-scattered-day " ; // themes, kweather
}
}
fallback < < " weather-showers-scattered " ; // xdg, kweather
fallback < < " weather-showers-scattered " ; // xdg, kweather
break ;
break ;
}
}
@ -286,9 +268,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
{
fallback < < " weather-showers-day " ; // themes, kweather
fallback < < " weather-showers-day " ; // themes, kweather
}
}
fallback < < " weather-showers " ; // xdg, kweather
fallback < < " weather-showers " ; // xdg, kweather
break ;
break ;
}
}
@ -296,7 +276,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
default :
default :
{
{
fallback < < " weather-showers " ; // xdg, kweather
fallback < < " weather-showers " ; // xdg, kweather
break ;
break ;
}
}
}
}
@ -320,9 +299,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
}
}
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow " ; // workaround for some themes
fallback < < " weather-snow " ; // workaround for some themes
break ;
break ;
}
}
case 2 :
case 2 :
@ -348,9 +325,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
}
}
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow " ; // workaround for some themes
fallback < < " weather-snow " ; // workaround for some themes
break ;
break ;
}
}
@ -364,21 +339,15 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
{
fallback < < " weather-snow-ample-day " ; // kweather
fallback < < " weather-snow-ample-day " ; // kweather
}
}
fallback < < " weather-snow-ample " ; // kweather
fallback < < " weather-snow-ample " ; // kweather
fallback < < " weather-snow " ; // xdg, kweather
fallback < < " weather-snow " ; // xdg, kweather
break ;
break ;
}
}
case 4 :
case 4 :
{
{
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow-scattered " ; // xdg, kweather
fallback < < " weather-snow " ; // workaround for some themes
fallback < < " weather-snow " ; // workaround for some themes
break ;
break ;
}
}
@ -386,7 +355,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
default :
default :
{
{
fallback < < " weather-snow " ; // xdg, kweather
fallback < < " weather-snow " ; // xdg, kweather
break ;
break ;
}
}
}
}
@ -408,7 +376,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-storm-day " ; // themes, kweather
fallback < < " weather-storm-day " ; // themes, kweather
}
}
fallback < < " weather-storm " ; // xdg, kweather
fallback < < " weather-storm " ; // xdg, kweather
break ;
break ;
}
}
@ -433,28 +400,44 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback < < " weather-storm-day " ; // themes, kweather
fallback < < " weather-storm-day " ; // themes, kweather
}
}
fallback < < " weather-storm " ; // xdg, kweather
fallback < < " weather-storm " ; // xdg, kweather
break ;
break ;
}
}
case 3 :
case 3 :
default :
default :
{
{
fallback < < " weather-storm " ; // xdg, kweather
fallback < < " weather-storm " ; // xdg, kweather
break ;
break ;
}
}
}
}
break ;
break ;
}
}
}
TQPair < TQString , TQString > foundIcon = WeatherIconPrivate : : instance ( ) - > findIcon ( fallback ) ;
// Unknown weather conditions
iconName = foundIcon . first ;
WeatherIcon : : WeatherIcon ( ) {
iconPath = foundIcon . second ;
fallback < < " weather-none-available " ;
return ;
}
}
WeatherIcon : : ~ WeatherIcon ( )
WeatherIcon : : ~ WeatherIcon ( )
{
{
iconName = TQString : : null ;
}
struct WeatherSingleIconData WeatherIcon : : iconData ( uint size ) {
return WeatherIconPrivate : : instance ( ) - > findIcon ( fallback , size ) ;
}
struct WeatherSingleIconData WeatherIcon : : unknown ( uint size ) {
WeatherIcon * unknown = new WeatherIcon ( ) ;
struct WeatherSingleIconData unknownData = unknown - > iconData ( size ) ;
delete unknown ;
return unknownData ;
}
// convenience functions
TQString WeatherIcon : : name ( uint size ) {
return iconData ( size ) . name ;
}
TQString WeatherIcon : : path ( uint size ) {
return iconData ( size ) . path ;
}
}