diff options
Diffstat (limited to 'kweather/weather_icon.cpp')
-rw-r--r-- | kweather/weather_icon.cpp | 132 |
1 files changed, 89 insertions, 43 deletions
diff --git a/kweather/weather_icon.cpp b/kweather/weather_icon.cpp index e358833..8cd2520 100644 --- a/kweather/weather_icon.cpp +++ b/kweather/weather_icon.cpp @@ -1,12 +1,92 @@ +#include <tqpair.h> + #include <kstandarddirs.h> #include <kiconloader.h> #include <kdebug.h> #include "weather_icon.h" -WeatherIcon::WeatherIcon( int condition, bool night ) +WeatherIconPrivate* WeatherIconPrivate::s_instance = 0; + +WeatherIconPrivate::WeatherIconPrivate() { iconLoader = new TDEIconLoader("kweather"); +} + +WeatherIconPrivate::~WeatherIconPrivate() +{ + delete iconLoader; +} + +WeatherIconPrivate* WeatherIconPrivate::instance() +{ + if ( s_instance == 0 ) + s_instance = new WeatherIconPrivate(); + + return s_instance; +} + +void WeatherIconPrivate::useIconTheme( bool use ) +{ + m_useIconTheme = use; +} + +bool WeatherIconPrivate::usingIconTheme() +{ + return m_useIconTheme; +} + +TQPair<TQString,TQString> WeatherIconPrivate::findIcon( TQStringList fallback ) +{ + kdDebug() << "[WeatherIcon::findIcon] use icon theme? " << m_useIconTheme << endl; + if( m_useIconTheme ) + { + // Check in theme + for ( TQStringList::Iterator icon = fallback.begin(); icon != fallback.end(); ++icon ) + { + kdDebug() << "[WeatherIcon::findIcon] Searching for `" << *icon << "` in theme" << endl; + TQString iPath = iconPath(*icon, true); + if( !( iPath.isNull() ) ) + { + kdDebug() << "[WeatherIcon::findIcon] FOUND `" << *icon << "` in theme: " << iPath << endl; + return qMakePair(*icon, iPath); + } + } + } + + // Check in kweather fallback + for ( TQStringList::Iterator icon = fallback.begin(); icon != fallback.end(); ++icon ) + { + kdDebug() << "[WeatherIcon::findIcon] Searching for `" << *icon << "` in kweather icons" << endl; + TQString iPath = iconPath(*icon, false); + if( !( iPath.isNull() ) ) + { + kdDebug() << "[WeatherIcon::findIcon] FOUND `" << *icon << "` in kweather icons: " << iPath << endl; + return qMakePair(*icon, iPath); + } + } + return qMakePair(WeatherIcon::unknown(), iconPath(WeatherIcon::unknown())); +} + +TQString WeatherIconPrivate::iconPath( TQString icon, bool inTheme ) +{ + if( inTheme ) + { + return iconLoader->iconPath(icon, TDEIcon::Desktop, true); + } + else + { + return locate( "data", "kweather/" + icon + ".png" ); + } +} + +TQString WeatherIconPrivate::iconPath( TQString icon ) +{ + return iconPath(icon, m_useIconTheme); +} + +WeatherIcon::WeatherIcon( int condition, bool night ) +{ TQStringList fallback; switch( condition ) @@ -82,13 +162,14 @@ WeatherIcon::WeatherIcon( int condition, bool night ) } } - iconName = findIcon(fallback); + TQPair<TQString,TQString> foundIcon = WeatherIconPrivate::instance()->findIcon(fallback); + iconName = foundIcon.first; + iconPath = foundIcon.second; return; } WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength ) { - iconLoader = new TDEIconLoader("kweather"); TQStringList fallback; switch ( condition ) @@ -367,48 +448,13 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength ) break; } - iconName = findIcon(fallback); + TQPair<TQString,TQString> foundIcon = WeatherIconPrivate::instance()->findIcon(fallback); + iconName = foundIcon.first; + iconPath = foundIcon.second; 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() ); - } -} + iconName = TQString::null; +}
\ No newline at end of file |