summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kweather/weather_icon.cpp356
-rw-r--r--kweather/weather_icon.h3
-rw-r--r--kweather/weatherservice.cpp2
3 files changed, 294 insertions, 67 deletions
diff --git a/kweather/weather_icon.cpp b/kweather/weather_icon.cpp
index 21e94cf..05461ee 100644
--- a/kweather/weather_icon.cpp
+++ b/kweather/weather_icon.cpp
@@ -1,59 +1,95 @@
+#include <kstandarddirs.h>
#include <kiconloader.h>
+#include <kdebug.h>
#include "weather_icon.h"
WeatherIcon::WeatherIcon( int condition, bool night )
{
- TQString name;
iconLoader = new TDEIconLoader("kweather");
+ TQStringList fallback;
switch( condition )
{
-
case Sunny:
{
- name = "weather-clear";
- iconName = ( night ? name.append("-night") : name );
- return;
+ if( night )
+ {
+ fallback << "weather-clear-night"; //xdg, kweather
+ }
+ fallback << "weather-clear"; // xdg, kweather
+
+ break;
}
case Fog:
{
- name = "weather-fog";
if( night )
{
- TQString night_icon = name + "-night";
- if( iconExists(night_icon) )
- name = night_icon;
+ fallback << "weather-fog-night"; // themes, kweather
}
- iconName = name;
- return;
+ fallback << "weather-fog"; // xdg, kweather
+
+ break;
}
case Mist:
{
- name = "weather-mist";
if( night )
{
- TQString night_icon = name + "-night";
- if( iconExists(night_icon) )
- name = night_icon;
+ fallback << "weather-mist-night"; // themes, kweather
+ }
+ fallback << "weather-mist"; // themes, kweather
+
+ if( night )
+ {
+ fallback << "weather-fog-night"; // themes, kweather
}
- iconName = name;
- return;
+ fallback << "weather-fog"; // xdg, kweather
+
+ break;
+ }
+
+ case Overcast:
+ {
+ fallback << "weather-overcast"; // xdg, kweather
+
+ break;
}
- case Overcast: { iconName = "weather-overcast"; return; }
- case Hail: { iconName = "weather-freezing-rain"; return; }
- case LightRain: { iconName = "weather-showers-scattered"; return; }
- case Sleet: { iconName = "weather-snow-rain"; return; }
+ 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");
- TQString name;
+ TQStringList fallback;
switch ( condition )
{
@@ -61,120 +97,312 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
switch ( strength )
{
- case 1: { name = "weather-few-clouds"; break; }
+ case 1:
+ {
+ if( night )
+ {
+ fallback << "weather-few-clouds-night"; // xdg, kweather
+ }
+ fallback << "weather-few-clouds"; // xdg, kweather
+
+ break;
+ }
case 2:
{
- name = "weather-moderate-clouds";
- if (! iconExists(name) )
+ if( night )
{
- name = "weather-few-clouds";
+ 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: { name = "weather-clouds"; 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:
{
- name = "weather-ample-clouds";
- if (! iconExists(name) )
+ if( night )
{
- name = "weather-clouds";
+ 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: { iconName = "weather-many-clouds"; return; }
- default: { iconName = "weather-clouds"; return; }
+ 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;
+ }
}
- iconName = name.append( night ? "-night" : "" );
- return;
+ break;
}
case Showers:
{
switch ( strength )
{
- case 1: { name = "weather-showers-scattered"; break; }
- case 2: { name = "weather-showers"; break; }
+ 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: { iconName = "weather-showers"; return; }
+ default:
+ {
+ fallback << "weather-showers"; // xdg, kweather
+
+ break;
+ }
}
- iconName = name.append( night ? "-night" : "-day" );
- return;
+ break;
}
case Snow:
{
switch( strength )
{
- case 1: { name = "weather-snow-scattered"; break; }
+ 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
+
+ break;
+ }
case 2:
{
- name = "weather-snow-moderate";
- TQString test_icon = name + "-day";
- if (! iconExists(test_icon) )
+ if( night )
+ {
+ fallback << "weather-snow-moderate-night"; // kweather
+ }
+ else
{
- name = "weather-snow-scattered";
+ 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
+
break;
}
+
case 3:
{
- name = "weather-snow-ample";
- TQString test_icon = name + "-day";
- if ( iconExists(test_icon) )
+ if( night )
+ {
+ fallback << "weather-snow-ample-night"; // kweather
+ }
+ else
{
- break;
+ fallback << "weather-snow-ample-day"; // kweather
}
+
+ fallback << "weather-snow-ample"; // kweather
+
+
+ fallback << "weather-snow"; // xdg, kweather
+
+ break;
}
- case 4: { iconName = "weather-snow-scattered"; return; }
+
+ case 4:
+ {
+ fallback << "weather-snow-scattered"; // xdg, kweather
+
+ break;
+ }
+
case 5:
- default: { iconName = "weather-snow"; return; }
+ default:
+ {
+ fallback << "weather-snow"; // xdg, kweather
+
+ break;
+ }
}
- iconName = name.append( night ? "-night" : "-day" );
- return;
+ break;
}
case Thunderstorm:
switch ( strength )
{
- case 1: { name = "weather-storm"; break; }
+ 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:
{
- name = "weather-storm-moderate";
- TQString test_icon = name + "-day";
- if (! iconExists(test_icon) )
+ 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
{
- name = "weather-storm";
+ fallback << "weather-storm-day"; // themes, kweather
}
+ fallback << "weather-storm"; // xdg, kweather
+
break;
}
case 3:
- default: { iconName = "weather-storm"; return; }
+ default:
+ {
+ fallback << "weather-storm"; // xdg, kweather
+
+ break;
+ }
}
- iconName = name.append( night ? "-night" : "-day" );
- return;
+ 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 )
+ if( inTheme )
{
- return iconLoader->theme()->iconPath(icon, TDEIcon::SizeMedium, TDEIcon::MatchExact).isValid();
+ return !( iconLoader->iconPath(icon, TDEIcon::Desktop, true).isNull() );
}
else
{
- return !(iconLoader->iconPath(icon, TDEIcon::SizeMedium, true).isNull());
+ return !( locate( "data", "kweather/" + icon + ".png" ).isNull() );
}
-}
+} \ No newline at end of file
diff --git a/kweather/weather_icon.h b/kweather/weather_icon.h
index 732e266..3ae8ddc 100644
--- a/kweather/weather_icon.h
+++ b/kweather/weather_icon.h
@@ -13,8 +13,9 @@ class WeatherIcon {
TQString& name() { return iconName; }
private:
+ TQString findIcon( TQStringList fallback );
bool iconExists( TQString& icon, bool inTheme = true );
TDEIconLoader* iconLoader;
- TQString iconName = unknown();
+ TQString iconName;
};
diff --git a/kweather/weatherservice.cpp b/kweather/weatherservice.cpp
index c02ca3b..f7e23d6 100644
--- a/kweather/weatherservice.cpp
+++ b/kweather/weatherservice.cpp
@@ -151,10 +151,8 @@ TQString WeatherService::iconFileName(const TQString &stationID)
{
TQString _name = m_weatherLib->iconName(stationID);
TQString icon = kapp->iconLoader()->iconPath(_name, TDEIcon::Desktop, true);
- kdDebug(12006) << "icon: " << icon << endl;
if( icon.isNull() )
{
- kdDebug(12006) << "fallback!" << endl;
icon = locate( "data", "kweather/" + _name + ".png" );
}
return icon;