summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kweather/dockwidget.cpp47
-rw-r--r--kweather/dockwidget.h3
-rw-r--r--kweather/metar_parser.cpp77
-rw-r--r--kweather/metar_parser.h9
-rw-r--r--kweather/reportview.cpp5
-rw-r--r--kweather/stationsconfigwidget.cpp6
-rw-r--r--kweather/weather_icon.cpp125
-rw-r--r--kweather/weather_icon.h29
-rw-r--r--kweather/weatherlib.cpp91
-rw-r--r--kweather/weatherlib.h13
-rw-r--r--kweather/weatherservice.cpp35
-rw-r--r--kweather/weatherservice.h14
12 files changed, 252 insertions, 202 deletions
diff --git a/kweather/dockwidget.cpp b/kweather/dockwidget.cpp
index 1d423a5..744ab91 100644
--- a/kweather/dockwidget.cpp
+++ b/kweather/dockwidget.cpp
@@ -29,6 +29,7 @@
#include <kdebug.h>
#include <tdeglobalsettings.h>
#include <tdelocale.h>
+#include <kiconloader.h>
dockwidget::dockwidget(const TQString &location, TQWidget *parent,
const char *name) : TQWidget(parent,name), m_locationCode( location ), m_orientation(Qt::Horizontal )
@@ -39,6 +40,7 @@ dockwidget::dockwidget(const TQString &location, TQWidget *parent,
connect(m_button, TQT_SIGNAL( clicked() ), TQT_SIGNAL( buttonClicked() ));
m_weatherService = new WeatherService_stub( "KWeatherService", "WeatherService" );
+ updateIcon();
}
dockwidget::~dockwidget()
@@ -101,7 +103,7 @@ void dockwidget::showWeather()
m_weatherService->stationName( m_locationCode ) + " (" +
m_weatherService->stationCountry( m_locationCode ) + ")</nobr></center></h3>";
- if ( m_weatherService->currentIconString( m_locationCode ) == "weather-none-available" ) // no data
+ if ( !m_weatherService->weatherDataAvailable(m_locationCode) ) // no data
tip += "<center><nobr>" + i18n("The network is currently offline...") + "</nobr></center>";
tip += TQString("<br><table>"
@@ -143,8 +145,7 @@ void dockwidget::showWeather()
tip += "</qt>";
- // On null or empty location code, or if the station needs maintenance, this will return the dunno icon.
- TQPixmap icon = m_weatherService->icon( m_locationCode );
+ updateIcon();
TQToolTip::remove(this);
TQToolTip::add(this, tip);
@@ -158,7 +159,6 @@ void dockwidget::showWeather()
m_lblWind->setText(wind);
m_lblPres->setText(pressure);
- m_button->setPixmap( icon );
}
void dockwidget::initDock()
@@ -204,13 +204,13 @@ void dockwidget::resizeView( const TQSize &size )
kdDebug(12004) << "Changing to size " << size << endl;
resize(size);
- if ( m_orientation ==Qt::Horizontal ) // Kicker in horizontal mode
+ if ( m_orientation == TQt::Horizontal ) // Kicker in horizontal mode
{
int h = size.height();
if ( m_mode == ShowAll )
{
- if ( h <= 128 ) // left to right layout
+ if ( h <= TDEIcon::SizeEnormous ) // left to right layout
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::LeftToRight);
m_lblTemp->setAlignment(TQt::AlignAuto | TQt::AlignVCenter);
@@ -221,7 +221,7 @@ void dockwidget::resizeView( const TQSize &size )
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
TQFontMetrics fm(m_font);
- h = 128 - (3 * fm.height()); // 3 lines of text below the button
+ h = TDEIcon::SizeEnormous - (3 * fm.height()); // 3 lines of text below the button
m_lblTemp->setAlignment(TQt::AlignCenter);
m_lblWind->setAlignment(TQt::AlignCenter);
m_lblPres->setAlignment(TQt::AlignCenter);
@@ -239,14 +239,14 @@ void dockwidget::resizeView( const TQSize &size )
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
TQFontMetrics fm(m_font);
- h = TQMIN(128, h) - fm.height();
+ h = TQMIN(TDEIcon::SizeEnormous, h) - fm.height();
m_lblTemp->setAlignment(TQt::AlignCenter);
}
m_button->setFixedSize(h, h);
}
else
{
- h = TQMIN(h, 128);
+ h = TQMIN(h, TDEIcon::SizeEnormous);
m_button->setFixedSize(h, h);
}
}
@@ -257,7 +257,7 @@ void dockwidget::resizeView( const TQSize &size )
if ( m_mode == ShowAll )
{
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
m_lblTemp->setAlignment(TQt::AlignCenter);
@@ -279,7 +279,7 @@ void dockwidget::resizeView( const TQSize &size )
}
else if ( m_mode == ShowTempOnly )
{
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
static_cast<TQBoxLayout*>(layout())->setDirection(TQBoxLayout::TopToBottom);
m_lblTemp->setAlignment(TQt::AlignCenter);
@@ -297,7 +297,7 @@ void dockwidget::resizeView( const TQSize &size )
}
else
{
- w = TQMIN(w, 128);
+ w = TQMIN(w, TDEIcon::SizeEnormous);
m_button->setFixedSize(w, w);
}
}
@@ -310,7 +310,7 @@ int dockwidget::widthForHeight(int h)
if ( m_mode == ShowAll )
{
- if ( h <= 128 ) // left to right layout
+ if ( h <= TDEIcon::SizeEnormous ) // left to right layout
{
int pixelSize = h/3 - 3;
pixelSize = TQMIN(pixelSize, fi.pixelSize()); // don't make it too large
@@ -330,7 +330,7 @@ int dockwidget::widthForHeight(int h)
}
TQFontMetrics fm(m_font);
// size of icon
- h = 128 - (3 * fm.height()); // 3 lines of text below the button
+ h = TDEIcon::SizeEnormous - (3 * fm.height()); // 3 lines of text below the button
w = TQMAX(fm.width(m_lblWind->text()), fm.width(m_lblPres->text())) + 1;
w = TQMAX(h, w); // at least width of square icon
}
@@ -357,17 +357,18 @@ int dockwidget::widthForHeight(int h)
}
TQFontMetrics fm(m_font);
// size of icon
- h = TQMIN(128, h) - fm.height();
+ h = TQMIN(TDEIcon::SizeEnormous, h) - fm.height();
w = fm.width(m_lblTemp->text()) + 1;
w = TQMAX(h, w); // at least width of square icon
}
}
else
{
- w = TQMIN(128, h); // don't make it too large
+ w = TQMIN(TDEIcon::SizeEnormous, h); // don't make it too large
}
updateFont();
+ updateIcon();
return w + 4;
}
@@ -380,7 +381,7 @@ int dockwidget::heightForWidth( int w )
TQFontMetrics fmg(TDEGlobalSettings::generalFont());
int maxWidth = fmg.width("888 km/h NNWW"); // a good approximation
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
if ( maxWidth <= w ) // enough space to use global font
{
@@ -415,7 +416,7 @@ int dockwidget::heightForWidth( int w )
TQFontMetrics fmg(TDEGlobalSettings::generalFont());
int maxWidth = fmg.width("888.88 CC"); // a good approximation
- if ( w <= 128 ) // top to bottom
+ if ( w <= TDEIcon::SizeEnormous ) // top to bottom
{
if ( maxWidth <= w ) // enough space to use global font
{
@@ -446,10 +447,11 @@ int dockwidget::heightForWidth( int w )
}
else
{
- h = TQMIN(128, w); // don't make it too large
+ h = TQMIN(TDEIcon::SizeEnormous, w); // don't make it too large
}
updateFont();
+ updateIcon();
return h;
}
@@ -462,4 +464,11 @@ void dockwidget::updateFont()
m_lblPres->setFont(m_font);
}
+void dockwidget::updateIcon()
+{
+ // On null or empty location code, or if the station needs maintenance, this will return the dunno icon.
+ TQPixmap icon = m_weatherService->icon( m_locationCode, m_button->height() );
+ m_button->setPixmap( icon );
+}
+
#include "dockwidget.moc"
diff --git a/kweather/dockwidget.h b/kweather/dockwidget.h
index 01cf4ce..e8e28af 100644
--- a/kweather/dockwidget.h
+++ b/kweather/dockwidget.h
@@ -56,6 +56,7 @@ signals: // Signals
private:
void initDock();
void updateFont();
+ void updateIcon();
int m_mode;
TQString m_locationCode;
@@ -65,7 +66,7 @@ private:
TQLabel *m_lblTemp;
TQLabel *m_lblWind;
TQLabel *m_lblPres;
- Qt::Orientation m_orientation;
+ TQt::Orientation m_orientation;
WeatherService_stub *m_weatherService;
};
diff --git a/kweather/metar_parser.cpp b/kweather/metar_parser.cpp
index 9aa2c8b..b582300 100644
--- a/kweather/metar_parser.cpp
+++ b/kweather/metar_parser.cpp
@@ -58,7 +58,6 @@ void MetarParser::reset()
{
// Initialize the WeatherInfo structure
weatherInfo.theWeather = TQString();
- weatherInfo.iconPath = TQString();
weatherInfo.clouds = 0;
weatherInfo.windMPH = 0;
weatherInfo.tempC = 0;
@@ -78,6 +77,9 @@ void MetarParser::reset()
weatherInfo.qsHeatIndex = TQString();
weatherInfo.qsWindDirection = TQString();
weatherInfo.stationNeedsMaintenance = false;
+ weatherInfo.wiCondition = 0;
+ weatherInfo.wiStrength = 0;
+ weatherInfo.wiNight = false;
}
struct WeatherInfo MetarParser::processData(const TQString &stationID, const TQString &metar)
@@ -259,7 +261,7 @@ bool MetarParser::parseCurrent(const TQString &s)
if (sCode.contains("DZ"))
{
phenomena = i18n("Drizzle");
- saveIconNamePath( WeatherIcon::LightRain, false );
+ saveIconData( WeatherIcon::LightRain, false );
}
else if (sCode.contains("RA"))
{
@@ -274,32 +276,32 @@ bool MetarParser::parseCurrent(const TQString &s)
else if (sCode.contains("SG"))
{
phenomena = i18n("Snow Grains");
- saveIconNamePath( WeatherIcon::Snow, false, 4 );
+ saveIconData( WeatherIcon::Snow, false, 4 );
}
else if (sCode.contains("IC"))
{
phenomena = i18n("Ice Crystals");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (sCode.contains("PE"))
{
phenomena = i18n("Ice Pellets");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (s.contains("GR"))
{
phenomena = i18n("Hail");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (sCode.contains("GS"))
{
phenomena = i18n("Small Hail Pellets");
- saveIconNamePath( WeatherIcon::Hail, false );
+ saveIconData( WeatherIcon::Hail, false );
}
else if (s.contains("UP"))
{
phenomena = i18n("Unknown Precipitation");
- saveIconNamePath( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
+ saveIconData( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
}
else if (sCode.contains("BR"))
{
@@ -728,17 +730,17 @@ void MetarParser::calcCurrentIcon()
if (weatherInfo.theWeather.isEmpty())
{
if (weatherInfo.clouds == 0)
- saveIconNamePath( WeatherIcon::Sunny, night );
+ saveIconData( WeatherIcon::Sunny, night );
else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2)
- saveIconNamePath( WeatherIcon::Cloudy, night, 1 );
+ saveIconData( WeatherIcon::Cloudy, night, 1 );
else if ( weatherInfo.clouds > 2 && weatherInfo.clouds <= 4)
- saveIconNamePath( WeatherIcon::Cloudy, night, 2 );
+ saveIconData( WeatherIcon::Cloudy, night, 2 );
else if ( weatherInfo.clouds > 4 && weatherInfo.clouds <= 8)
- saveIconNamePath( WeatherIcon::Cloudy, night, 3 );
+ saveIconData( WeatherIcon::Cloudy, night, 3 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63)
- saveIconNamePath( WeatherIcon::Cloudy, night, 4 );
+ saveIconData( WeatherIcon::Cloudy, night, 4 );
else
- saveIconNamePath( WeatherIcon::Cloudy, night, 5 );
+ saveIconData( WeatherIcon::Cloudy, night, 5 );
}
else if (weatherInfo.theWeather == "tstorm")
{
@@ -746,11 +748,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 1 );
+ saveIconData( WeatherIcon::Thunderstorm, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 2 );
+ saveIconData( WeatherIcon::Thunderstorm, night, 2 );
else
- saveIconNamePath( WeatherIcon::Thunderstorm, night, 3 );
+ saveIconData( WeatherIcon::Thunderstorm, night, 3 );
}
else if (weatherInfo.theWeather == "shower")
{
@@ -758,11 +760,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- saveIconNamePath( WeatherIcon::Showers, night, 1 );
+ saveIconData( WeatherIcon::Showers, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- saveIconNamePath( WeatherIcon::Showers, night, 2 );
+ saveIconData( WeatherIcon::Showers, night, 2 );
else
- saveIconNamePath( WeatherIcon::Showers, night, 3 );
+ saveIconData( WeatherIcon::Showers, night, 3 );
}
else if (weatherInfo.theWeather == "snow")
{
@@ -770,22 +772,22 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 8)
- saveIconNamePath( WeatherIcon::Snow, night, 1 );
+ saveIconData( WeatherIcon::Snow, night, 1 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds <= 16)
- saveIconNamePath( WeatherIcon::Snow, night, 2 );
+ saveIconData( WeatherIcon::Snow, night, 2 );
else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24)
- saveIconNamePath( WeatherIcon::Snow, night, 3 );
+ saveIconData( WeatherIcon::Snow, night, 3 );
else
- saveIconNamePath( WeatherIcon::Snow, night, 5 );
+ saveIconData( WeatherIcon::Snow, night, 5 );
}
else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" )
{
if ( weatherInfo.clouds >= 63 )
- saveIconNamePath( WeatherIcon::Cloudy, night, 5 );
+ saveIconData( WeatherIcon::Cloudy, night, 5 );
else if ( weatherInfo.theWeather == "mist" )
- saveIconNamePath( WeatherIcon::Mist, night );
+ saveIconData( WeatherIcon::Mist, night );
else if ( weatherInfo.theWeather == "fog" )
- saveIconNamePath( WeatherIcon::Fog, night );
+ saveIconData( WeatherIcon::Fog, night );
}
kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: "
@@ -861,23 +863,10 @@ bool MetarParser::isNight(const TQString &stationID) const
}
}
-void MetarParser::saveIconNamePath( int condition, bool night, int strength )
+void MetarParser::saveIconData( int condition, bool night, int strength )
{
- if( strength != 0 )
- {
- // Ranged
- WeatherIcon* wi = new WeatherIcon( condition, night, strength );
- weatherInfo.iconName = wi->name();
- weatherInfo.iconPath = wi->path();
- delete wi;
- }
- else
- {
- // Simple
- WeatherIcon* wi = new WeatherIcon( condition, night );
- weatherInfo.iconName = wi->name();
- weatherInfo.iconPath = wi->path();
- delete wi;
- }
+ weatherInfo.wiCondition = condition;
+ weatherInfo.wiStrength = strength;
+ weatherInfo.wiNight = night;
}
diff --git a/kweather/metar_parser.h b/kweather/metar_parser.h
index 4f276e8..fd202d8 100644
--- a/kweather/metar_parser.h
+++ b/kweather/metar_parser.h
@@ -32,8 +32,6 @@ struct WeatherInfo
{
/** The current weather state outside */
TQString theWeather;
- TQString iconName;
- TQString iconPath;
int clouds;
float windMPH;
float tempC;
@@ -54,6 +52,11 @@ struct WeatherInfo
TQString qsWindDirection;
TQString reportLocation;
bool stationNeedsMaintenance;
+
+ /* For WeatherIcon */
+ int wiCondition;
+ int wiStrength;
+ bool wiNight;
};
@@ -94,7 +97,7 @@ class MetarParser
void calcCurrentIcon();
void calcWindChill();
bool isNight(const TQString &stationID) const;
- void saveIconNamePath( int condition, bool night, int strength = 0 );
+ void saveIconData( int condition, bool night, int strength = 0 );
/*
* Reset the internal WeatherInfo struct of the class so that
diff --git a/kweather/reportview.cpp b/kweather/reportview.cpp
index 88dadd1..97c308f 100644
--- a/kweather/reportview.cpp
+++ b/kweather/reportview.cpp
@@ -22,6 +22,7 @@
#include <tdehtml_part.h>
#include <tdehtmlview.h>
#include <tdeglobalsettings.h>
+#include <kiconloader.h>
#include <tqvbox.h>
#include <tqpixmap.h>
@@ -46,7 +47,7 @@ reportView::reportView(const TQString &reportLocation)
m_weatherService = new WeatherService_stub( "KWeatherService", "WeatherService" );
- TQPixmap icon = m_weatherService->icon( m_locationCode );
+ TQPixmap icon = m_weatherService->icon( m_locationCode, IconSize(TDEIcon::Panel) );
setIcon( icon );
render();
@@ -89,7 +90,7 @@ void reportView::render(){
TQString sunRiseTime = m_weatherService->sunRiseTime(m_locationCode );
TQString sunSetTime = m_weatherService->sunSetTime(m_locationCode );
TQString date = m_weatherService->date(m_locationCode );
- TQString icon = m_weatherService->iconFileName(m_locationCode );
+ TQString icon = m_weatherService->iconPath(m_locationCode, IconSize(TDEIcon::Panel));
TQStringList cover = m_weatherService->cover(m_locationCode );
TQStringList weather = m_weatherService->weather(m_locationCode );
diff --git a/kweather/stationsconfigwidget.cpp b/kweather/stationsconfigwidget.cpp
index b02d4be..66d7c22 100644
--- a/kweather/stationsconfigwidget.cpp
+++ b/kweather/stationsconfigwidget.cpp
@@ -30,6 +30,7 @@
#include <tdelocale.h>
#include <kpushbutton.h>
#include <kstandarddirs.h>
+#include <kiconloader.h>
#include "stationsconfigwidget.h"
#include "weatherservice_stub.h"
@@ -129,10 +130,7 @@ void StationsConfigWidget::scanStations()
mSelectedStations->clear();
for ( uint i = 0; i < list.count(); ++i ) {
- TQPixmap pm = mService->icon( list[ i ] );
- TQImage img = pm.convertToImage();
- img = img.smoothScale( 22, 22 );
- pm.convertFromImage( img );
+ TQPixmap pm = mService->icon( list[ i ], TDEIcon::SizeSmall );
TQString uid = list[ i ];
if (mStationMap[ uid ].isEmpty())
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
diff --git a/kweather/weather_icon.h b/kweather/weather_icon.h
index f18c472..011fb06 100644
--- a/kweather/weather_icon.h
+++ b/kweather/weather_icon.h
@@ -1,4 +1,11 @@
-class TDEIconLoader;
+#include <kiconloader.h>
+
+struct WeatherSingleIconData {
+ TQString name;
+ TQString path;
+ bool inTheme;
+ uint size;
+};
class WeatherIconPrivate {
friend class WeatherIcon;
@@ -9,18 +16,18 @@ class WeatherIconPrivate {
static WeatherIconPrivate* instance();
- void useIconTheme( bool use );
+ void useIconTheme(bool use);
bool usingIconTheme();
- TQString iconPath( TQString icon, bool inTheme );
- TQString iconPath( TQString icon );
+ TQString iconPath(TQString icon, uint size, bool inTheme);
+ TQString iconPath(TQString icon, uint size);
private:
static WeatherIconPrivate* s_instance;
TDEIconLoader* iconLoader;
bool m_useIconTheme;
- TQPair<TQString,TQString> findIcon( TQStringList fallback );
+ struct WeatherSingleIconData findIcon(TQStringList fallback, uint size);
};
class WeatherIcon {
@@ -30,13 +37,15 @@ class WeatherIcon {
WeatherIcon( int condition /* SimpleCondition */, bool night );
WeatherIcon( int condition /* RangedCondition */, bool night, unsigned int strength );
+ WeatherIcon(); /* Unknown conditions */
~WeatherIcon();
- static TQString unknown() { return "weather-none-available"; };
- TQString name() { return iconName; }
- TQString path() { return iconPath; }
+ static struct WeatherSingleIconData unknown(uint size); // for convenience
+
+ struct WeatherSingleIconData iconData(uint size);
+ TQString name(uint size);
+ TQString path(uint size);
private:
- TQString iconName;
- TQString iconPath;
+ TQStringList fallback;
};
diff --git a/kweather/weatherlib.cpp b/kweather/weatherlib.cpp
index 5ca6640..ca95a31 100644
--- a/kweather/weatherlib.cpp
+++ b/kweather/weatherlib.cpp
@@ -185,8 +185,12 @@ void WeatherLib::slotCopyDone(TDEIO::Job* job)
kdDebug( 12006 ) << "Offline now..." << endl;
d->clear();
d->wi.theWeather = "dunno";
- d->wi.qsCurrentList.append(i18n("The network is currently offline..."));
- d->wi.qsCurrentList.append(i18n("Please update later."));
+
+ TQString offlineStr = i18n("The network is currently offline...");
+ if (!d->wi.qsCurrentList.contains(offlineStr)) {
+ d->wi.qsCurrentList.append(offlineStr);
+ d->wi.qsCurrentList.append(i18n("Please update later."));
+ }
emit fileUpdate(d->wi.reportLocation);
}
else
@@ -277,51 +281,68 @@ TQString WeatherLib::windChill(const TQString &stationID){
return d->wi.qsWindChill;
}
-TQString WeatherLib::iconName(const TQString &stationID){
-
- TQString result;
-
- // isEmpty is true for null or 0 length strings
- if ( !stationID.isEmpty() )
- {
- Data *d = findData(stationID);
- result = d->wi.iconName;
+TQString WeatherLib::iconName(const TQString &stationID, uint iconSize) {
+ TQString result = TQString::null;
+ if (!stationID.isEmpty()) {
+ WeatherIcon *wi = weatherIcon(stationID);
+ result = wi->name(iconSize);
+ delete wi;
}
- if( result == TQString::null )
- result = WeatherIcon::unknown();
+ if (result.isEmpty())
+ result = WeatherIcon::unknown(iconSize).name;
return result;
}
-TQString WeatherLib::iconPath(const TQString &stationID){
+TQString WeatherLib::iconName(const TQString &stationID) {
+ return iconName(stationID, IconSize(TDEIcon::Panel));
+}
- TQString result;
-
- // isEmpty is true for null or 0 length strings
- if ( !stationID.isEmpty() )
- {
- Data *d = findData(stationID);
- result = d->wi.iconPath;
+TQString WeatherLib::iconPath(const TQString &stationID, uint iconSize) {
+ TQString result = TQString::null;
+ if (!stationID.isEmpty()) {
+ WeatherIcon *wi = weatherIcon(stationID);
+ result = wi->path(iconSize);
+ delete wi;
}
- if( result == TQString::null )
- result = WeatherIconPrivate::instance()->iconPath(WeatherIcon::unknown());
+ if (result.isEmpty())
+ result = WeatherIcon::unknown(iconSize).path;
return result;
}
-TQString WeatherLib::date(const TQString &stationID){
+/** Returns a WeatherIcon object for the current weather conditions */
+WeatherIcon* WeatherLib::weatherIcon(const TQString &stationID) {
Data *d = findData(stationID);
+ if (d->wi.theWeather == "dunno")
+ {
+ return new WeatherIcon();
+ }
+
+ int condition = d->wi.wiCondition;
+ int strength = d->wi.wiStrength;
+ bool night = d->wi.wiNight;
- if ( ! d->wi.qsDate.isValid() )
- return "";
- else
- {
- TQDateTime gmtDateTime(d->wi.qsDate, d->wi.qsTime);
- TQDateTime localDateTime = gmtDateTime.addSecs(KRFCDate::localUTCOffset() * 60);
- return TDEGlobal::locale()->formatDateTime(localDateTime, false, false);
- }
+ WeatherIcon* wi;
+ if (d->wi.wiStrength != 0) // Ranged condition
+ wi = new WeatherIcon(condition, night, strength);
+
+ else // Simple condition
+ wi = new WeatherIcon(condition, night);
+
+ return wi;
+}
+
+TQString WeatherLib::date(const TQString &stationID){
+ Data *d = findData(stationID);
+ if (d->wi.qsDate.isValid()) {
+ TQDateTime gmtDateTime(d->wi.qsDate, d->wi.qsTime);
+ TQDateTime localDateTime = gmtDateTime.addSecs(KRFCDate::localUTCOffset() * 60);
+ return TDEGlobal::locale()->formatDateTime(localDateTime, false, false);
+ }
+ return TQString::null;
}
/** Returns the current cover */
@@ -348,6 +369,12 @@ bool WeatherLib::stationNeedsMaintenance(const TQString &stationID)
return d->wi.stationNeedsMaintenance;
}
+bool WeatherLib::weatherDataAvailable(const TQString &stationID)
+{
+ Data *d = findData(stationID);
+ return !(d->wi.theWeather == "dunno");
+}
+
void WeatherLib::update(const TQString &stationID)
{
// Only grab new data if its more than 50 minutes old
diff --git a/kweather/weatherlib.h b/kweather/weatherlib.h
index 5dde37c..0e83d77 100644
--- a/kweather/weatherlib.h
+++ b/kweather/weatherlib.h
@@ -28,12 +28,12 @@ namespace TDEIO
}
class StationDatabase;
+class WeatherIcon;
class WeatherLib : public TQObject
{
Q_OBJECT
-
-
+
public:
class Data;
@@ -48,16 +48,18 @@ class WeatherLib : public TQObject
TQString wind(const TQString &stationID);
TQString pressure(const TQString &stationID);
TQString iconName(const TQString &stationID);
- TQString iconPath(const TQString &stationID);
+ TQString iconName(const TQString &stationID, uint iconSize);
+ TQString iconPath(const TQString &stationID, uint iconSize);
TQString date(const TQString &stationID);
TQStringList weather(const TQString &stationID);
TQString visibility(const TQString &stationID);
TQStringList cover(const TQString &stationID);
bool stationNeedsMaintenance(const TQString &stationID);
-
+ bool weatherDataAvailable(const TQString &stationID);
+
TQStringList stations();
bool isNight(const TQString &stationID) const;
-
+
void update(const TQString &stationID);
void forceUpdate(const TQString &stationID);
void remove(const TQString &stationID);
@@ -72,6 +74,7 @@ class WeatherLib : public TQObject
private:
Data* findData(const TQString &stationID);
+ WeatherIcon* weatherIcon(const TQString &stationID);
void clearData(Data *d);
void getData(Data *d, bool force = false);
void processData(const TQString &metar, Data *d);
diff --git a/kweather/weatherservice.cpp b/kweather/weatherservice.cpp
index aa8454a..e61138b 100644
--- a/kweather/weatherservice.cpp
+++ b/kweather/weatherservice.cpp
@@ -139,18 +139,33 @@ TQString WeatherService::pressure(const TQString &stationID)
return m_weatherLib->pressure(stationID);
}
+TQPixmap WeatherService::icon(const TQString &stationID, uint iconSize)
+{
+ return kapp->iconLoader()->loadIcon(
+ iconPath(stationID, iconSize),
+ TDEIcon::Panel, iconSize
+ );
+}
+
+TQString WeatherService::iconName(const TQString &stationID, uint iconSize)
+{
+ return m_weatherLib->iconName(stationID, iconSize);
+}
+
+TQString WeatherService::iconPath(const TQString &stationID, uint iconSize)
+{
+ return m_weatherLib->iconPath(stationID, iconSize);
+}
+
+/*** (Begin) Deprecated: functions kept for compatibility reasons */
TQPixmap WeatherService::currentIcon(const TQString &stationID)
{
- return icon( stationID );
+ return icon(stationID, IconSize(TDEIcon::Panel));
}
TQPixmap WeatherService::icon(const TQString &stationID)
{
- kdDebug(12006) << "Get the current weather icon.." << endl;
- return kapp->iconLoader()->loadIcon(
- iconFileName(stationID),
- TDEIcon::Desktop
- );
+ return icon(stationID, IconSize(TDEIcon::Panel));
}
TQString WeatherService::currentIconString(const TQString &stationID)
@@ -160,8 +175,9 @@ TQString WeatherService::currentIconString(const TQString &stationID)
TQString WeatherService::iconFileName(const TQString &stationID)
{
- return m_weatherLib->iconPath(stationID);
+ return iconPath(stationID, IconSize(TDEIcon::Panel));
}
+/*** (End) Deprecated: functions kept for compatibility reasons */
void WeatherService::useIconTheme(bool use)
{
@@ -199,6 +215,11 @@ bool WeatherService::stationNeedsMaintenance(const TQString &stationID)
return m_weatherLib->stationNeedsMaintenance(stationID);
}
+bool WeatherService::weatherDataAvailable(const TQString &stationID)
+{
+ return m_weatherLib->weatherDataAvailable(stationID);
+}
+
void WeatherService::update(const TQString &stationID)
{
m_weatherLib->update(stationID);
diff --git a/kweather/weatherservice.h b/kweather/weatherservice.h
index 2ec63be..0efab9a 100644
--- a/kweather/weatherservice.h
+++ b/kweather/weatherservice.h
@@ -61,15 +61,21 @@ class WeatherService : public TQObject, public DCOPObject
TQString windChill(const TQString &stationID);
TQString wind(const TQString &stationID);
TQString pressure(const TQString &stationID);
- TQPixmap currentIcon(const TQString &stationID);
- TQPixmap icon(const TQString &stationID);
- TQString currentIconString(const TQString &stationID);
- TQString iconFileName(const TQString &stationID);
+ TQPixmap icon(const TQString &stationID, uint iconSize);
+ TQString iconName(const TQString &stationID, uint iconSize);
+ TQString iconPath(const TQString &stationID, uint iconSize);
TQString date(const TQString &stationID);
TQString visibility(const TQString &stationID);
TQStringList cover(const TQString &stationID);
TQStringList weather(const TQString &stationID);
bool stationNeedsMaintenance(const TQString &stationID);
+ bool weatherDataAvailable(const TQString &stationID);
+
+ /* compatibility */
+ TQPixmap currentIcon(const TQString &stationID) KDE_DEPRECATED;
+ TQPixmap icon(const TQString &stationID) KDE_DEPRECATED;
+ TQString currentIconString(const TQString &stationID) KDE_DEPRECATED;
+ TQString iconFileName(const TQString &stationID) KDE_DEPRECATED;
TQString stationName(const TQString &stationID);
TQString stationCountry(const TQString &stationID);