diff options
Diffstat (limited to 'kweather/weatherlib.cpp')
-rw-r--r-- | kweather/weatherlib.cpp | 97 |
1 files changed, 76 insertions, 21 deletions
diff --git a/kweather/weatherlib.cpp b/kweather/weatherlib.cpp index c628d77..31e6c5a 100644 --- a/kweather/weatherlib.cpp +++ b/kweather/weatherlib.cpp @@ -34,11 +34,13 @@ email : geiseri@msoe.edu #include <unistd.h> #include <tdeapplication.h> #include <kpassivepopup.h> +#include <tdeconfig.h> #include "metar_parser.h" #include "stationdatabase.h" #include "sun.h" #include "weatherlib.h" +#include "weather_icon.h" #include "weatherlib.moc" @@ -88,6 +90,12 @@ WeatherLib::WeatherLib(StationDatabase *stationDB, TQObject *parent, const char m_StationDb = stationDB; data.setAutoDelete( true ); + + // Initialize correct icon setting + TDEConfig *conf = new TDEConfig("weather_panelappletrc"); + conf->setGroup("General Options"); + WeatherIconPrivate::instance()->useIconTheme(conf->readBoolEntry("use_icon_theme", true)); + delete conf; } WeatherLib::~WeatherLib() @@ -177,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 @@ -209,8 +221,8 @@ void WeatherLib::getData(Data *d, bool force /* try even if host was down last t d->job = TDEIO::file_copy( url, local, -1, true, false, false); d->job->addMetaData("cache", "reload"); // Make sure to get fresh info - connect( d->job, TQT_SIGNAL( result( TDEIO::Job *)), - TQT_SLOT(slotCopyDone(TDEIO::Job *))); + connect( d->job, TQ_SIGNAL( result( TDEIO::Job *)), + TQ_SLOT(slotCopyDone(TDEIO::Job *))); kdDebug( 12006 ) << "Copying " << url.prettyURL() << " to " << local.prettyURL() << endl; emit fileUpdating(d->wi.reportLocation); @@ -269,31 +281,68 @@ TQString WeatherLib::windChill(const TQString &stationID){ return d->wi.qsWindChill; } -TQString WeatherLib::iconName(const TQString &stationID){ +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; + } - TQString result("dunno"); - - // isEmpty is true for null or 0 length strings - if ( !stationID.isEmpty() ) - { - Data *d = findData(stationID); - result = d->wi.theWeather; + if (result.isEmpty()) + result = WeatherIcon::unknown(iconSize).name; + + return result; +} + +TQString WeatherLib::iconName(const TQString &stationID) { + return iconName(stationID, IconSize(TDEIcon::Panel)); +} + +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.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; + + WeatherIcon* wi; + if (d->wi.wiStrength != 0) // Ranged condition + wi = new WeatherIcon(condition, night, strength); + + else // Simple condition + wi = new WeatherIcon(condition, night); - 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); - } + 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 */ @@ -320,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 |