summaryrefslogtreecommitdiffstats
path: root/kweather/weather_icon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kweather/weather_icon.cpp')
-rw-r--r--kweather/weather_icon.cpp125
1 files changed, 54 insertions, 71 deletions
diff --git a/kweather/weather_icon.cpp b/kweather/weather_icon.cpp
index 59f55da..bce9073 100644
--- a/kweather/weather_icon.cpp
+++ b/kweather/weather_icon.cpp
@@ -36,59 +36,67 @@ bool WeatherIconPrivate::usingIconTheme()
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;
- if( m_useIconTheme )
+ if (m_useIconTheme)
{
// Check in theme
- 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;
- TQString iPath = iconPath(*icon, true);
- if( !( iPath.isNull() ) )
+ TQString iPath = iconPath(*icon, size, true);
+ if (!iPath.isNull())
{
kdDebug(12006) << "[findIcon] Found `" << *icon << "` in theme: " << iPath << endl;
- return qMakePair(*icon, iPath);
+ iconData = { *icon, iPath, true, size };
+ return iconData;
}
}
}
// Check in kweather 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;
- TQString iPath = iconPath(*icon, false);
- if( !( iPath.isNull() ) )
+ TQString iPath = iconPath(*icon, size, false);
+ if (!iPath.isEmpty())
{
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 )
- {
- return iconLoader->iconPath(icon, TDEIcon::Desktop, true);
+ TQString path = TQString::null;
+ if (inTheme) {
+ 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 )
{
- TQStringList fallback;
-
switch( condition )
{
case Sunny:
@@ -98,7 +106,6 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback << "weather-clear-night"; //xdg, kweather
}
fallback << "weather-clear"; // xdg, kweather
-
break;
}
@@ -109,7 +116,6 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback << "weather-fog-night"; // themes, kweather
}
fallback << "weather-fog"; // xdg, kweather
-
break;
}
@@ -126,14 +132,12 @@ WeatherIcon::WeatherIcon( int condition, bool night )
fallback << "weather-fog-night"; // themes, kweather
}
fallback << "weather-fog"; // xdg, kweather
-
break;
}
case Overcast:
{
fallback << "weather-overcast"; // xdg, kweather
-
break;
}
@@ -142,14 +146,12 @@ WeatherIcon::WeatherIcon( int condition, bool night )
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;
}
@@ -157,21 +159,13 @@ WeatherIcon::WeatherIcon( int condition, bool night )
{
fallback << "weather-snow-rain"; // themes, kweather
fallback << "weather-snow"; // xdg, kweather
-
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 )
{
- TQStringList fallback;
-
switch ( condition )
{
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"; // xdg, kweather
-
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"; // xdg, kweather
-
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"; // xdg, kweather
-
break;
}
@@ -229,30 +220,23 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
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: {
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;
}
}
-
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"; // xdg, kweather
-
break;
}
@@ -286,9 +268,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
fallback << "weather-showers-day"; // themes, kweather
}
-
fallback << "weather-showers"; // xdg, kweather
-
break;
}
@@ -296,7 +276,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
default:
{
fallback << "weather-showers"; // xdg, kweather
-
break;
}
}
@@ -320,9 +299,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
}
fallback << "weather-snow-scattered"; // xdg, kweather
-
fallback << "weather-snow"; // workaround for some themes
-
break;
}
case 2:
@@ -348,9 +325,7 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
}
fallback << "weather-snow-scattered"; // xdg, kweather
-
fallback << "weather-snow"; // workaround for some themes
-
break;
}
@@ -364,21 +339,15 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
{
fallback << "weather-snow-ample-day"; // kweather
}
-
fallback << "weather-snow-ample"; // kweather
-
-
fallback << "weather-snow"; // xdg, kweather
-
break;
}
case 4:
{
fallback << "weather-snow-scattered"; // xdg, kweather
-
fallback << "weather-snow"; // workaround for some themes
-
break;
}
@@ -386,7 +355,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
default:
{
fallback << "weather-snow"; // xdg, kweather
-
break;
}
}
@@ -408,7 +376,6 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback << "weather-storm-day"; // themes, kweather
}
fallback << "weather-storm"; // xdg, kweather
-
break;
}
@@ -433,28 +400,44 @@ WeatherIcon::WeatherIcon( int condition, bool night, unsigned int strength )
fallback << "weather-storm-day"; // themes, kweather
}
fallback << "weather-storm"; // xdg, kweather
-
break;
}
case 3:
default:
{
fallback << "weather-storm"; // xdg, kweather
-
break;
}
}
-
break;
}
+}
- TQPair<TQString,TQString> foundIcon = WeatherIconPrivate::instance()->findIcon(fallback);
- iconName = foundIcon.first;
- iconPath = foundIcon.second;
- return;
+// Unknown weather conditions
+WeatherIcon::WeatherIcon() {
+ fallback << "weather-none-available";
}
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;
} \ No newline at end of file