diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2021-12-12 15:50:37 +0200 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2022-01-14 12:39:01 +0200 |
commit | 6668b34bc5deb36e73aa45e0457ed6740f828efd (patch) | |
tree | f2ff95858cc06d5eaad187b6750717a58a175a60 /kweather/weather_icon.cpp | |
parent | 67e995b6fc4da17811aefb7c8d841c9812e4eec9 (diff) | |
download | tdetoys-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 <mavridisf@gmail.com>
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 |