summaryrefslogtreecommitdiffstats
path: root/kweather/weatherlib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kweather/weatherlib.cpp')
-rw-r--r--kweather/weatherlib.cpp91
1 files changed, 59 insertions, 32 deletions
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