diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2023-06-01 16:30:11 +0300 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2023-06-14 17:42:21 +0300 |
commit | fe6de6f4bc8a0a7d86c2c3dc6413170214206cff (patch) | |
tree | d86bbc14c9c16c52b9d2b5b750de15ece38c7c5a /kweather/weatherlib.cpp | |
parent | 6b56a1befc9f510d4467cd5652cbb8fb49563070 (diff) | |
download | tdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.tar.gz tdetoys-fe6de6f4bc8a0a7d86c2c3dc6413170214206cff.zip |
KWeather: improve icon loading and other fixes
- Fix pixelated icons (issue #19)
- Fix "network offline" state
- Add helper `bool weatherDataAvailable(TQString stationID)` DCOP function
- Fix compatibility with old DCOP function signatures
- Prevent double "Network is offline" strings in weather data.
This commit introduces some new and renamed DCOP calls. Old function signatures
are kept for compatibility, but are mraked as deprecated.
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
(cherry picked from commit bc71670331e16b15fc30214cb85c409b8c91bb9c)
Diffstat (limited to 'kweather/weatherlib.cpp')
-rw-r--r-- | kweather/weatherlib.cpp | 91 |
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 |