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>
pull/18/head
Mavridis Philippe 3 years ago
parent 67e995b6fc
commit 6668b34bc5
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -71,6 +71,8 @@ KCMWeather::KCMWeather( TQWidget *parent, const char *name )
TQT_SLOT( reportLocationChanged() ) ); TQT_SLOT( reportLocationChanged() ) );
connect( mWidget->m_textColor, TQT_SIGNAL( changed(const TQColor &) ), connect( mWidget->m_textColor, TQT_SIGNAL( changed(const TQColor &) ),
TQT_SLOT( textColorChanged(const TQColor &) ) ); TQT_SLOT( textColorChanged(const TQColor &) ) );
connect( mWidget->m_iconTheme, TQT_SIGNAL( released( int ) ),
TQT_SLOT( changed() ) );
TDEAboutData *about = new TDEAboutData( TDEAboutData *about = new TDEAboutData(
I18N_NOOP( "kcmweather" ), I18N_NOOP( "kcmweather" ),
@ -182,6 +184,9 @@ void KCMWeather::load()
mWidget->m_viewMode->setButton( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) ); mWidget->m_viewMode->setButton( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) );
changeViewMode( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) ); changeViewMode( config.readNumEntry( "smallview_mode", dockwidget::ShowAll ) );
mWidget->m_iconTheme->setButton( config.readBoolEntry("use_icon_theme", true) ? 0 : 1 );
emit changed( false ); emit changed( false );
} }
@ -202,6 +207,9 @@ void KCMWeather::save()
config.writeEntry( "report_location", loc); config.writeEntry( "report_location", loc);
config.writeEntry( "smallview_mode", mViewMode ); config.writeEntry( "smallview_mode", mViewMode );
config.writeEntry( "use_icon_theme", mWidget->m_iconTheme->selectedId() == 0 );
config.sync(); config.sync();
emit changed( false ); emit changed( false );

@ -216,6 +216,7 @@ void kweather::loadPrefs(){
fileName = kcConfig->readPathEntry("log_file_name"); fileName = kcConfig->readPathEntry("log_file_name");
reportLocation = kcConfig->readEntry("report_location"); reportLocation = kcConfig->readEntry("report_location");
mViewMode = kcConfig->readNumEntry("smallview_mode", dockwidget::ShowAll); mViewMode = kcConfig->readNumEntry("smallview_mode", dockwidget::ShowAll);
setUseIconTheme(kcConfig->readBoolEntry("use_icon_theme", true));
static TQColor black(TQt::black); static TQColor black(TQt::black);
mTextColor = kcConfig->readColorEntry("textColor", &black); mTextColor = kcConfig->readColorEntry("textColor", &black);
@ -231,9 +232,23 @@ void kweather::savePrefs(){
kcConfig->writeEntry("report_location", reportLocation); kcConfig->writeEntry("report_location", reportLocation);
kcConfig->writeEntry("smallview_mode", mViewMode); kcConfig->writeEntry("smallview_mode", mViewMode);
kcConfig->writePathEntry("log_file_name", fileName ); kcConfig->writePathEntry("log_file_name", fileName );
kcConfig->writeEntry("use_icon_theme", useIconTheme );
kcConfig->sync(); kcConfig->sync();
} }
void kweather::setUseIconTheme( bool use )
{
useIconTheme = use;
if ( !mWeatherService )
initDCOP();
DCOPRef ws( "KWeatherService", "WeatherService" );
DCOPReply reply = ws.call( "useIconTheme", useIconTheme );
if( ! reply.isValid() )
kdDebug() << "[kweather::setUseIconTheme] DCOP call failed" << endl;
}
void kweather::showWeather() void kweather::showWeather()
{ {
kdDebug(12004) << "Show weather" << endl; kdDebug(12004) << "Show weather" << endl;
@ -332,6 +347,10 @@ void kweather::slotPrefsAccepted()
dockWidget->setLocationCode(reportLocation); dockWidget->setLocationCode(reportLocation);
dockWidget->setViewMode(mViewMode); dockWidget->setViewMode(mViewMode);
setUseIconTheme(useIconTheme);
slotUpdateNow();
setLabelColor(); setLabelColor();
emit updateLayout(); emit updateLayout();

@ -68,13 +68,15 @@ private: // Private methods
void showWeather(); void showWeather();
void writeLogEntry(); void writeLogEntry();
void mousePressEvent(TQMouseEvent *e); void mousePressEvent(TQMouseEvent *e);
void setUseIconTheme(bool use);
bool attach(); bool attach();
TQString reportLocation; TQString reportLocation;
TQString fileName; TQString fileName;
TQString metarData; TQString metarData;
bool logOn; bool logOn;
bool useIconTheme;
bool mFirstRun; bool mFirstRun;
int mViewMode; int mViewMode;
TQTimer *timeOut; TQTimer *timeOut;

@ -58,6 +58,7 @@ void MetarParser::reset()
{ {
// Initialize the WeatherInfo structure // Initialize the WeatherInfo structure
weatherInfo.theWeather = TQString(); weatherInfo.theWeather = TQString();
weatherInfo.iconPath = TQString();
weatherInfo.clouds = 0; weatherInfo.clouds = 0;
weatherInfo.windMPH = 0; weatherInfo.windMPH = 0;
weatherInfo.tempC = 0; weatherInfo.tempC = 0;
@ -258,7 +259,7 @@ bool MetarParser::parseCurrent(const TQString &s)
if (sCode.contains("DZ")) if (sCode.contains("DZ"))
{ {
phenomena = i18n("Drizzle"); phenomena = i18n("Drizzle");
weatherInfo.theWeather = iconName( WeatherIcon::LightRain, false ); getIcon( WeatherIcon::LightRain, false );
} }
else if (sCode.contains("RA")) else if (sCode.contains("RA"))
{ {
@ -273,32 +274,32 @@ bool MetarParser::parseCurrent(const TQString &s)
else if (sCode.contains("SG")) else if (sCode.contains("SG"))
{ {
phenomena = i18n("Snow Grains"); phenomena = i18n("Snow Grains");
weatherInfo.theWeather = iconName( WeatherIcon::Snow, false, 4 ); getIcon( WeatherIcon::Snow, false, 4 );
} }
else if (sCode.contains("IC")) else if (sCode.contains("IC"))
{ {
phenomena = i18n("Ice Crystals"); phenomena = i18n("Ice Crystals");
weatherInfo.theWeather = iconName( WeatherIcon::Hail, false ); getIcon( WeatherIcon::Hail, false );
} }
else if (sCode.contains("PE")) else if (sCode.contains("PE"))
{ {
phenomena = i18n("Ice Pellets"); phenomena = i18n("Ice Pellets");
weatherInfo.theWeather = iconName( WeatherIcon::Hail, false ); getIcon( WeatherIcon::Hail, false );
} }
else if (s.contains("GR")) else if (s.contains("GR"))
{ {
phenomena = i18n("Hail"); phenomena = i18n("Hail");
weatherInfo.theWeather = iconName( WeatherIcon::Hail, false ); getIcon( WeatherIcon::Hail, false );
} }
else if (sCode.contains("GS")) else if (sCode.contains("GS"))
{ {
phenomena = i18n("Small Hail Pellets"); phenomena = i18n("Small Hail Pellets");
weatherInfo.theWeather = iconName( WeatherIcon::Hail, false ); getIcon( WeatherIcon::Hail, false );
} }
else if (s.contains("UP")) else if (s.contains("UP"))
{ {
phenomena = i18n("Unknown Precipitation"); 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")) else if (sCode.contains("BR"))
{ {
@ -727,17 +728,17 @@ void MetarParser::calcCurrentIcon()
if (weatherInfo.theWeather.isEmpty()) if (weatherInfo.theWeather.isEmpty())
{ {
if (weatherInfo.clouds == 0) if (weatherInfo.clouds == 0)
weatherInfo.theWeather = iconName( WeatherIcon::Sunny, night ); getIcon( WeatherIcon::Sunny, night );
else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2) 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) 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) 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) else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63)
weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 4 ); getIcon( WeatherIcon::Cloudy, night, 4 );
else else
weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 ); getIcon( WeatherIcon::Cloudy, night, 5 );
} }
else if (weatherInfo.theWeather == "tstorm") else if (weatherInfo.theWeather == "tstorm")
{ {
@ -745,11 +746,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30; weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10) 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) else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 2 ); getIcon( WeatherIcon::Thunderstorm, night, 2 );
else else
weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 3 ); getIcon( WeatherIcon::Thunderstorm, night, 3 );
} }
else if (weatherInfo.theWeather == "shower") else if (weatherInfo.theWeather == "shower")
{ {
@ -757,11 +758,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30; weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10) 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) else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 2 ); getIcon( WeatherIcon::Showers, night, 2 );
else else
weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 3 ); getIcon( WeatherIcon::Showers, night, 3 );
} }
else if (weatherInfo.theWeather == "snow") else if (weatherInfo.theWeather == "snow")
{ {
@ -769,22 +770,22 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30; weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 8) 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) 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) else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24)
weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 3 ); getIcon( WeatherIcon::Snow, night, 3 );
else else
weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 5 ); getIcon( WeatherIcon::Snow, night, 5 );
} }
else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" ) else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" )
{ {
if ( weatherInfo.clouds >= 63 ) if ( weatherInfo.clouds >= 63 )
weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 ); getIcon( WeatherIcon::Cloudy, night, 5 );
else if ( weatherInfo.theWeather == "mist" ) else if ( weatherInfo.theWeather == "mist" )
weatherInfo.theWeather = iconName( WeatherIcon::Mist, night ); getIcon( WeatherIcon::Mist, night );
else if ( weatherInfo.theWeather == "fog" ) else if ( weatherInfo.theWeather == "fog" )
weatherInfo.theWeather = iconName( WeatherIcon::Fog, night ); getIcon( WeatherIcon::Fog, night );
} }
kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: " 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 ) if( strength != 0 )
{ {
// Ranged // Ranged
WeatherIcon* wi = new WeatherIcon( condition, night, strength ); WeatherIcon* wi = new WeatherIcon( condition, night, strength );
_iconName = wi->name(); weatherInfo.iconName = wi->name();
weatherInfo.iconPath = wi->path();
delete wi; delete wi;
} }
else else
{ {
// Simple // Simple
WeatherIcon* wi = new WeatherIcon( condition, night ); WeatherIcon* wi = new WeatherIcon( condition, night );
_iconName = wi->name(); weatherInfo.iconName = wi->name();
weatherInfo.iconPath = wi->path();
delete wi; delete wi;
} }
return _iconName;
} }

@ -32,6 +32,8 @@ struct WeatherInfo
{ {
/** The current weather state outside */ /** The current weather state outside */
TQString theWeather; TQString theWeather;
TQString iconName;
TQString iconPath;
int clouds; int clouds;
float windMPH; float windMPH;
float tempC; float tempC;
@ -92,7 +94,7 @@ class MetarParser
void calcCurrentIcon(); void calcCurrentIcon();
void calcWindChill(); void calcWindChill();
bool isNight(const TQString &stationID) const; bool isNight(const TQString &stationID) const;
TQString iconName( int condition, bool night, int strength = 0 ) const; void getIcon( int condition, bool night, int strength = 0 );
/* /*
* Reset the internal WeatherInfo struct of the class so that * Reset the internal WeatherInfo struct of the class so that

@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>429</width> <width>761</width>
<height>341</height> <height>464</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -27,6 +27,9 @@
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="caption">
<string>prefsDialogData</string>
</property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>TabFocus</enum> <enum>TabFocus</enum>
</property> </property>
@ -50,7 +53,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>GroupBoxPanel</enum> <enum>NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>Sunken</enum> <enum>Sunken</enum>
@ -67,7 +70,7 @@
<cstring>TextLabel1_4_2_2</cstring> <cstring>TextLabel1_4_2_2</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Location:</string> <string>Lo&amp;cation:</string>
</property> </property>
<property name="buddy" stdset="0"> <property name="buddy" stdset="0">
<cstring>m_reportLocation</cstring> <cstring>m_reportLocation</cstring>
@ -152,7 +155,10 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Show icon only</string> <string>Show icon onl&amp;y</string>
</property>
<property name="accel">
<string>Alt+Y</string>
</property> </property>
<property name="buttonGroupId"> <property name="buttonGroupId">
<number>1</number> <number>1</number>
@ -171,6 +177,9 @@
<property name="text"> <property name="text">
<string>Show &amp;icon and temperature</string> <string>Show &amp;icon and temperature</string>
</property> </property>
<property name="accel">
<string>Alt+I</string>
</property>
<property name="buttonGroupId"> <property name="buttonGroupId">
<number>2</number> <number>2</number>
</property> </property>
@ -180,7 +189,7 @@
<cstring>CheckBox10</cstring> <cstring>CheckBox10</cstring>
</property> </property>
<property name="text"> <property name="text">
<string>Show icon, temperature, &amp;wind and pressure information</string> <string>Show icon, temperature, wind &amp;and pressure information</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
@ -271,6 +280,44 @@
</widget> </widget>
</grid> </grid>
</widget> </widget>
<widget class="TQButtonGroup">
<property name="name">
<cstring>m_iconTheme</cstring>
</property>
<property name="title">
<string>Weather Icon</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQRadioButton">
<property name="name">
<cstring>m_systemIcons</cstring>
</property>
<property name="text">
<string>&amp;Use system icon theme</string>
</property>
<property name="accel">
<string>Alt+U</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="TQRadioButton">
<property name="name">
<cstring>m_kweatherIcons</cstring>
</property>
<property name="text">
<string>Use &amp;KWeather theme</string>
</property>
<property name="accel">
<string>Alt+K</string>
</property>
</widget>
</vbox>
</widget>
<widget class="TQGroupBox"> <widget class="TQGroupBox">
<property name="name"> <property name="name">
<cstring>groupBox3</cstring> <cstring>groupBox3</cstring>
@ -320,7 +367,7 @@
</property> </property>
<property name="sizeHint"> <property name="sizeHint">
<size> <size>
<width>170</width> <width>637</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -329,8 +376,6 @@
</widget> </widget>
</vbox> </vbox>
</widget> </widget>
<customwidgets>
</customwidgets>
<connections> <connections>
<connection> <connection>
<sender>m_enableLog</sender> <sender>m_enableLog</sender>

@ -1,12 +1,92 @@
#include <tqpair.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include <kiconloader.h> #include <kiconloader.h>
#include <kdebug.h> #include <kdebug.h>
#include "weather_icon.h" #include "weather_icon.h"
WeatherIcon::WeatherIcon( int condition, bool night ) WeatherIconPrivate* WeatherIconPrivate::s_instance = 0;
WeatherIconPrivate::WeatherIconPrivate()
{ {
iconLoader = new TDEIconLoader("kweather"); 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; TQStringList fallback;
switch( condition ) 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; return;
} }
WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength ) WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{ {
iconLoader = new TDEIconLoader("kweather");
TQStringList fallback; TQStringList fallback;
switch ( condition ) switch ( condition )
@ -367,48 +448,13 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
break; break;
} }
iconName = findIcon(fallback); TQPair<TQString,TQString> foundIcon = WeatherIconPrivate::instance()->findIcon(fallback);
iconName = foundIcon.first;
iconPath = foundIcon.second;
return; return;
} }
WeatherIcon::~WeatherIcon() WeatherIcon::~WeatherIcon()
{}
TQString WeatherIcon::findIcon( TQStringList fallback )
{ {
// Check in theme iconName = TQString::null;
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() );
}
}

@ -1,5 +1,28 @@
class TDEIconLoader; class TDEIconLoader;
class WeatherIconPrivate {
friend class WeatherIcon;
public:
WeatherIconPrivate();
~WeatherIconPrivate();
static WeatherIconPrivate* instance();
void useIconTheme( bool use );
bool usingIconTheme();
TQString iconPath( TQString icon, bool inTheme );
TQString iconPath( TQString icon );
private:
static WeatherIconPrivate* s_instance;
TDEIconLoader* iconLoader;
bool m_useIconTheme;
TQPair<TQString,TQString> findIcon( TQStringList fallback );
};
class WeatherIcon { class WeatherIcon {
public: public:
enum SimpleCondition { Sunny, Fog, Mist, Overcast, Hail, LightRain, Sleet }; enum SimpleCondition { Sunny, Fog, Mist, Overcast, Hail, LightRain, Sleet };
@ -10,12 +33,10 @@ class WeatherIcon {
~WeatherIcon(); ~WeatherIcon();
static TQString unknown() { return "weather-none-available"; }; static TQString unknown() { return "weather-none-available"; };
TQString& name() { return iconName; } TQString name() { return iconName; }
TQString path() { return iconPath; }
private: private:
TQString findIcon( TQStringList fallback );
bool iconExists( TQString& icon, bool inTheme = true );
TDEIconLoader* iconLoader;
TQString iconName; TQString iconName;
TQString iconPath;
}; };

@ -272,14 +272,34 @@ TQString WeatherLib::windChill(const TQString &stationID){
TQString WeatherLib::iconName(const TQString &stationID){ TQString WeatherLib::iconName(const TQString &stationID){
TQString result = WeatherIcon::unknown(); TQString result;
// isEmpty is true for null or 0 length strings
if ( !stationID.isEmpty() )
{
Data *d = findData(stationID);
result = d->wi.iconName;
}
if( result == TQString::null )
result = WeatherIcon::unknown();
return result;
}
TQString WeatherLib::iconPath(const TQString &stationID){
TQString result;
// isEmpty is true for null or 0 length strings // isEmpty is true for null or 0 length strings
if ( !stationID.isEmpty() ) if ( !stationID.isEmpty() )
{ {
Data *d = findData(stationID); Data *d = findData(stationID);
result = d->wi.theWeather; result = d->wi.iconPath;
} }
if( result == TQString::null )
result = WeatherIconPrivate::instance()->iconPath(WeatherIcon::unknown());
return result; return result;
} }

@ -48,6 +48,7 @@ class WeatherLib : public TQObject
TQString wind(const TQString &stationID); TQString wind(const TQString &stationID);
TQString pressure(const TQString &stationID); TQString pressure(const TQString &stationID);
TQString iconName(const TQString &stationID); TQString iconName(const TQString &stationID);
TQString iconPath(const TQString &stationID);
TQString date(const TQString &stationID); TQString date(const TQString &stationID);
TQStringList weather(const TQString &stationID); TQStringList weather(const TQString &stationID);
TQString visibility(const TQString &stationID); TQString visibility(const TQString &stationID);

@ -30,6 +30,7 @@
#include "weatherlib.h" #include "weatherlib.h"
#include "weatherservice.h" #include "weatherservice.h"
#include "stationdatabase.h" #include "stationdatabase.h"
#include "weather_icon.h"
#include "sun.h" #include "sun.h"
WeatherService::WeatherService(TQObject *parent, const char *name) : TQObject (parent, name), DCOPObject("WeatherService") WeatherService::WeatherService(TQObject *parent, const char *name) : TQObject (parent, name), DCOPObject("WeatherService")
@ -150,13 +151,18 @@ TQString WeatherService::currentIconString(const TQString &stationID)
TQString WeatherService::iconFileName(const TQString &stationID) TQString WeatherService::iconFileName(const TQString &stationID)
{ {
TQString _name = m_weatherLib->iconName(stationID); return m_weatherLib->iconPath(stationID);
TQString icon = kapp->iconLoader()->iconPath(_name, TDEIcon::Desktop, true); }
if( icon.isNull() )
{ void WeatherService::useIconTheme(bool use)
icon = locate( "data", "kweather/" + _name + ".png" ); {
} kdDebug() << "[!!!] received signal to set useIconTheme to " << use << endl;
return icon; WeatherIconPrivate::instance()->useIconTheme(use);
}
bool WeatherService::usingIconTheme()
{
return WeatherIconPrivate::instance()->usingIconTheme();
} }
TQString WeatherService::date(const TQString &stationID) TQString WeatherService::date(const TQString &stationID)

@ -90,6 +90,9 @@ class WeatherService : public TQObject, public DCOPObject
void addStation(const TQString &stationID); void addStation(const TQString &stationID);
TQStringList listStations(); TQStringList listStations();
TQString stationCode( const TQString &stationName ); TQString stationCode( const TQString &stationName );
void useIconTheme( bool use );
bool usingIconTheme();
void exit(); void exit();

Loading…
Cancel
Save