From 474f41a511dc70cd524754b8fceeba99d8d36808 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Fri, 19 Mar 2021 06:12:34 +0200 Subject: [PATCH] plasma: remove broken weather data engines reference: https://github.com/fluxer/katana/issues/24 Signed-off-by: Ivailo Monev --- plasma/dataengines/weather/ions/CMakeLists.txt | 2 - .../weather/ions/bbcukmet/CMakeLists.txt | 8 - .../weather/ions/bbcukmet/ion-bbcukmet.desktop | 158 -- .../weather/ions/bbcukmet/ion_bbcukmet.cpp | 964 ---------- .../weather/ions/bbcukmet/ion_bbcukmet.h | 178 -- .../dataengines/weather/ions/envcan/CMakeLists.txt | 8 - .../weather/ions/envcan/ion-envcan.desktop | 153 -- .../dataengines/weather/ions/envcan/ion_envcan.cpp | 1922 -------------------- .../dataengines/weather/ions/envcan/ion_envcan.h | 261 --- 9 files changed, 3654 deletions(-) delete mode 100644 plasma/dataengines/weather/ions/bbcukmet/CMakeLists.txt delete mode 100644 plasma/dataengines/weather/ions/bbcukmet/ion-bbcukmet.desktop delete mode 100644 plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp delete mode 100644 plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h delete mode 100644 plasma/dataengines/weather/ions/envcan/CMakeLists.txt delete mode 100644 plasma/dataengines/weather/ions/envcan/ion-envcan.desktop delete mode 100644 plasma/dataengines/weather/ions/envcan/ion_envcan.cpp delete mode 100644 plasma/dataengines/weather/ions/envcan/ion_envcan.h diff --git a/plasma/dataengines/weather/ions/CMakeLists.txt b/plasma/dataengines/weather/ions/CMakeLists.txt index 055b3e28..6a7390b8 100644 --- a/plasma/dataengines/weather/ions/CMakeLists.txt +++ b/plasma/dataengines/weather/ions/CMakeLists.txt @@ -19,7 +19,5 @@ INSTALL (FILES includes/Ion DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/KDE/Plasma/Weather COMPONENT Devel) # the individual ion plugins -add_subdirectory(bbcukmet) -add_subdirectory(envcan) add_subdirectory(noaa) add_subdirectory(wetter.com) diff --git a/plasma/dataengines/weather/ions/bbcukmet/CMakeLists.txt b/plasma/dataengines/weather/ions/bbcukmet/CMakeLists.txt deleted file mode 100644 index 8c91c663..00000000 --- a/plasma/dataengines/weather/ions/bbcukmet/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -SET (ion_bbcukmet_SRCS ion_bbcukmet.cpp) -kde4_add_plugin(ion_bbcukmet ${ion_bbcukmet_SRCS}) -target_link_libraries (ion_bbcukmet ${KDE4_SOLID_LIBS} weather_ion) - -INSTALL (FILES ion-bbcukmet.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) - -INSTALL (TARGETS ion_bbcukmet DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) - diff --git a/plasma/dataengines/weather/ions/bbcukmet/ion-bbcukmet.desktop b/plasma/dataengines/weather/ions/bbcukmet/ion-bbcukmet.desktop deleted file mode 100644 index 05b234b6..00000000 --- a/plasma/dataengines/weather/ions/bbcukmet/ion-bbcukmet.desktop +++ /dev/null @@ -1,158 +0,0 @@ -[Desktop Entry] -Name=BBC Weather from UK MET Office -Name[ar]=الطقس BBC من مكتب الأرصاد الجوية البريطاني -Name[ast]=Meteoroloxía de la BBC de la Oficina meteorolóxica del Reinu Xuníu -Name[be@latin]=Nadvorje „BBC” ad „UK MET Office” -Name[bg]=Време от BBC (офис UK MET) -Name[bs]=Meteouslovi po Bi‑bi‑siju -Name[ca]=Meteorologia de la BBC des d'UK MET Office -Name[ca@valencia]=Meteorologia de la BBC des d'UK MET Office -Name[cs]=Počasí BBC z britského meteorologického úřadu -Name[csb]=Wiodro BBC z bura UK-MET -Name[da]=BBC Weather fra UK MET-kontoret -Name[de]=BBC-Wetter aus dem UK-MET-Büro -Name[el]=Καιρός του BBC από το γραφείο UK MET -Name[en_GB]=BBC Weather from UK MET Office -Name[eo]=BBC-vetero el UK-MET-oficejo -Name[es]=Meteorología de la BBC de la Oficina meteorológica del Reino Unido -Name[et]=BBC ilmateade Briti ilmateenistusest -Name[eu]=BBCren eguraldia UK MET Office-tik -Name[fi]=BBC:n säätiedot UK MET -toimistolta -Name[fr]=Météo de la BBC venant du « UK MET Office » -Name[fy]=BBC Weather fan UK MET kantoor -Name[ga]=Aimsir BBC ó Oifig UK MET -Name[gl]=Tempo da BBC desde a Oficina meteorolóxica do UK -Name[gu]=UK MET ઓફિસ તરફથી BBC હવામાન -Name[he]=BBC Weather מ־UK MET Office -Name[hi]=यूके एमईटी ऑफ़िस से बीबीसी मौसम -Name[hne]=यूके एमईटी आफिस से बीबीसी मौसम -Name[hr]=BBC vremenska prognoza iz UK MET ureda -Name[hu]=BBC időjárási adatok (UK MET) -Name[ia]=BBC Weather ex Officio UK MET -Name[id]=BBC Weather dari UK MET Office -Name[is]=BBC veður frá UK MET stofnuninni -Name[it]=Meteo BBC dall'ufficio meteorologico UK MET -Name[ja]=英国 Met Office の BBC Weather -Name[kk]=UK MET Оффистің BBC ауа райы болжамы -Name[km]=អាកាសធាតុ BBC ពី​ការិយាល័យ UK MET -Name[kn]=ಬಿಬಿಸಿ ಹವಾಮಾನ ವರದಿ (ಯುಕೆ ಪವನಶಾಸ್ತ್ರ (MET) ಕಛೇರಿಯಿಂದ) -Name[ko]=영국 MET 사무소의 BBC 날씨 -Name[lt]=BBC orai iÅ¡ UK MET Office -Name[lv]=BBC Weather no UK MET Office -Name[mk]=BBC-временска прогноза од канцеларијата на UK MET -Name[ml]=യു കെ മെറ്റ് ഓഫീസില്‍ നിന്നുമുള്ള ബിബിസി കാലാവസ്ഥ -Name[mr]=UK MET ऑफिस पासून BBC हवामान -Name[nb]=BBC vær fra det britiske meteorologi-kontoret -Name[nds]=BBC-Weder vun't engelsche Wederkunn-Kontoor -Name[ne]=यूके एमइटी कार्यालयबाट बीबीसी मौसम -Name[nl]=BBC Weather van UK MET Office -Name[nn]=BBC-vêr frÃ¥ UK MET Office -Name[or]=UK MET କାର୍ଯ୍ୟାଳୟରୁ BBC ପାଣିପାଗ -Name[pa]=UK MET ਆਫਿਸ ਤੋਂ BBC ਮੌਸਮ -Name[pl]=Pogoda BBC z biura UK MET -Name[pt]=Meteorologia da BBC do Escritório MET na GB -Name[pt_BR]=BBC Weather do escritório MET no Reino Unido -Name[ro]=Vremea BBC de la Biroul meteorologic britanic -Name[ru]=BBC Weather от UK MET Office -Name[se]=BBC-dálki UK MET Offices -Name[si]=UK MET කාර්‍යාලය වෙතින් BBC කාලගුණය -Name[sk]=Počasie BBC - UK MET Office -Name[sl]=BBC Weather iz UK MET Office -Name[sr]=Метеоуслови по Би‑би‑сију -Name[sr@ijekavian]=Метеоуслови по Би‑би‑сију -Name[sr@ijekavianlatin]=Meteouslovi po BBC‑u -Name[sr@latin]=Meteouslovi po BBC‑u -Name[sv]=BBC-väder frÃ¥n brittiska meteorologiska departementet -Name[ta]=BBC Weather from UK MET Office -Name[te]=UK MET కార్యాలయం నుండి BBC వాతావరణం -Name[tg]=BBC Weather от UK MET Office -Name[th]=พยากรณ์อากาศของ BBC จากสำนักงาน UK MET -Name[tr]=Ä°ngiltere MET Ofisi'nden BBC Hava Durumu -Name[ug]=UK MET ئىشخانىسى تەمىنلىگەن BBC ھاۋارايى ئۇچۇرى -Name[uk]=Погода BBC з метеорологічного офісу UK -Name[vi]=Thời tiết BBC từ CÆ¡ quan MET UK -Name[wa]=Tins ki fwait BBC do UK MET Office -Name[x-test]=xxBBC Weather from UK MET Officexx -Name[zh_CN]=英国 MET 办公室提供的 BBC 天气报告 -Name[zh_TW]=BBC 天氣報告,從 UK MET 辦公室來 -Comment=XML Data from the UK MET Office -Comment[ar]=معلومات XML من مكتب الأرصاد الجوية البريطاني -Comment[ast]=Datos XML de la Oficina Meteorolóxica del Reinu Xuníu -Comment[be@latin]=Źviestki Å­ farmacie „XML” ad „UK MET Office” -Comment[bg]=XML данни от UK MET -Comment[bs]=IksML podaci Britanskog meteoroloÅ¡kog ofisa -Comment[ca]=Dades XML des d'UK MET Office -Comment[ca@valencia]=Dades XML des d'UK MET Office -Comment[cs]=XML data z britského meteorologického úřadu -Comment[csb]=XML-pòdôwczi z bura UK-MET -Comment[da]=XML-data fra UK MET-kontoret -Comment[de]=XML-Daten aus dem UK-MET-Büro -Comment[el]=Δεδομένα XML από το γραφείο UK MET -Comment[en_GB]=XML Data from the UK MET Office -Comment[eo]=XML-datumoj el la UK-MET-oficejo -Comment[es]=Datos XML de la Oficina Meteorológica del Reino Unido -Comment[et]=Briti ilmateenistuse XML-andmed -Comment[eu]=XML datuak UK MET Office-tik -Comment[fi]=XML-tietoa UK MET -toimistolta -Comment[fr]=Données météo au format XML provenant du « UK MET Office » -Comment[fy]=XML Data fan de UK MET kantoor -Comment[ga]=Sonraí XML ó Oifig UK MET -Comment[gl]=Datos XML da oficina meteorolóxica do UK -Comment[gu]=UK MET ઓફિસ તરફથી XML માહિતી -Comment[he]=מידע ב־XML מ־UK MET Office -Comment[hi]=यूके एमईटी ऑफ़िस से एक्सएमएल डाटा -Comment[hne]=यूके एमईटी आफिस से एक्सएमएल डाटा -Comment[hr]=XML podaci iz UK MET ureda -Comment[hu]=XML adatok a UK MET intézettől -Comment[ia]=Datos XML ex le Officio UK MET -Comment[id]=Data XML dari UK MET Office -Comment[is]=XML veðurgögn frá UK MET stofnuninni -Comment[it]=Dati XML dall'ufficio meteorologico UK MET -Comment[ja]=英国 Met Office の XML データ -Comment[kk]=UK MET Оффистің XML дерегі -Comment[km]=ទិន្នន័យ XML ពី​ការិយាល័យ UK MET -Comment[kn]=ಯುಕೆ ಪವನಶಾಸ್ತ್ರ ಕಛೇರಿ (MET) ಇಂದ XML ದತ್ತ -Comment[ko]=영국 MET 사무소의 XML 데이터 -Comment[lt]=XML duomenys iÅ¡ UK MET Office -Comment[lv]=XML dati no UK MET Office -Comment[mk]=XML-податоци од канцеларијата на UK MET -Comment[ml]=യുകെ മെറ്റ് ഓഫീസില്‍ നിന്നുമുള്ള എക്സ്എംഎല്‍ ഡേറ്റാ -Comment[mr]=UK MET ऑफिस पासून XML माहिती -Comment[nb]=XML-data fra det britiske meteorologi-kontoret -Comment[nds]=XML-Daten vun't engelsche Wederkunn-Kontoor -Comment[ne]=यूके एमईटी कार्यालयबाट एक्सएमएल डेटा -Comment[nl]=XML-gegevens van UK MET Office -Comment[nn]=XML-data frÃ¥ UK MET Office -Comment[or]=UK MET କାର୍ଯ୍ୟାଳୟରୁ XML ତଥ୍ୟ -Comment[pa]=UK MET ਆਫਿਸ ਤੋਂ XML ਡਾਟਾ -Comment[pl]=Dane XML z biura UK MET -Comment[pt]=Dados em XML do Escritório MET na GB -Comment[pt_BR]=Dados em XML do escritório MET no Reino Unido -Comment[ro]=Date XML de la Biroul meteorologic britanic -Comment[ru]=Данные в формате XML от UK MET Office -Comment[se]=XML-dáhtat UK MET Offices -Comment[si]=UK MET කාර්‍යාලය වෙතින් XML දත්ත -Comment[sk]=XML dáta z UK MET Office -Comment[sl]=Podatki XML iz UK MET Office -Comment[sr]=ИксМЛ подаци Британског метеоролошког офиса -Comment[sr@ijekavian]=ИксМЛ подаци Британског метеоролошког офиса -Comment[sr@ijekavianlatin]=XML podaci Britanskog meteoroloÅ¡kog ofisa -Comment[sr@latin]=XML podaci Britanskog meteoroloÅ¡kog ofisa -Comment[sv]=XML-data frÃ¥n brittiska meteorologiska departementet -Comment[ta]=XML Data from the UK MET Office -Comment[te]=UK MET కార్యాలయం నుండి XML డాటా -Comment[tg]=Маълумоти XML аз UK MET Office -Comment[th]=ข้อมูล XML จากสำนักงาน UK MET -Comment[tr]=Ä°ngiltere MET Ofisi'nden XML Verisi -Comment[ug]=UK MET ئىشخانىسى تەمىنلىگەن XML سانلىق-مەلۇمات ئۇچۇرى -Comment[uk]=Дані XML з метеорологічного офісу UK -Comment[wa]=Dinêyes XML dÃ¥ UK MET Office -Comment[x-test]=xxXML Data from the UK MET Officexx -Comment[zh_CN]=英国 MET 办公室提供的 XML 数据 -Comment[zh_TW]=從 UK MET 辦公室來的 XML 資料 -X-KDE-ServiceTypes=Plasma/DataEngine -X-KDE-ParentApp=weatherengine -Type=Service -Icon=noneyet -X-KDE-Library=ion_bbcukmet -X-KDE-PluginInfo-Name=bbcukmet diff --git a/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp b/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp deleted file mode 100644 index 63ea0513..00000000 --- a/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.cpp +++ /dev/null @@ -1,964 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Shawn Starr * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -/* Ion for BBC's Weather from the UK Met Office */ - -#include "ion_bbcukmet.h" - -#include -#include - -// ctor, dtor -UKMETIon::UKMETIon(QObject *parent, const QVariantList &args) - : IonInterface(parent, args) - -{ - Q_UNUSED(args) -} - -UKMETIon::~UKMETIon() -{ - deleteForecasts(); -} - -void UKMETIon::reset() -{ - deleteForecasts(); - m_sourcesToReset = sources(); - updateAllSources(); -} - -void UKMETIon::deleteForecasts() -{ - // Destroy each forecast stored in a QVector - QHash::iterator - it = m_weatherData.begin(), - end = m_weatherData.end(); - for (; it != end; ++it) { - qDeleteAll(it.value().forecasts); - it.value().forecasts.clear(); - } -} - - -// Get the master list of locations to be parsed -void UKMETIon::init() -{ - m_timeEngine = dataEngine("time"); - setInitialized(true); -} - -QMap UKMETIon::setupDayIconMappings(void) const -{ -// ClearDay, FewCloudsDay, PartlyCloudyDay, Overcast, -// Showers, ScatteredShowers, Thunderstorm, Snow, -// FewCloudsNight, PartlyCloudyNight, ClearNight, -// Mist, NotAvailable - - QMap dayList; - dayList["sunny"] = ClearDay; - //dayList["sunny night"] = ClearNight; - dayList["clear"] = ClearDay; - dayList["clar sky"] = ClearDay; - dayList["sunny intervals"] = PartlyCloudyDay; - //dayList["sunny intervals night"] = ClearNight; - dayList["partly cloudy"] = PartlyCloudyDay; - dayList["cloudy"] = Overcast; - dayList["white cloud"] = Overcast; - dayList["grey cloud"] = Overcast; - //dayList["low level cloud"] = NotAvailable; - //dayList["medium level cloud"] = NotAvailable; - //dayList["sandstorm"] = NotAvailable; - dayList["drizzle"] = LightRain; - dayList["misty"] = Mist; - dayList["mist"] = Mist; - dayList["fog"] = Mist; - dayList["foggy"] = Mist; - dayList["tropical storm"] = Thunderstorm; - dayList["hazy"] = NotAvailable; - dayList["light shower"] = Showers; - dayList["light rain shower"] = Showers; - dayList["light showers"] = Showers; - dayList["light rain"] = Showers; - dayList["heavy rain"] = Rain; - dayList["heavy showers"] = Rain; - dayList["heavy shower"] = Rain; - dayList["heavy rain shower"] = Rain; - dayList["thundery shower"] = Thunderstorm; - dayList["thunder storm"] = Thunderstorm; - dayList["cloudy with sleet"] = RainSnow; - dayList["sleet shower"] = RainSnow; - dayList["sleet showers"] = RainSnow; - dayList["sleet"] = RainSnow; - dayList["cloudy with hail"] = Hail; - dayList["hail shower"] = Hail; - dayList["hail showers"] = Hail; - dayList["hail"] = Hail; - dayList["light snow"] = LightSnow; - dayList["light snow shower"] = Flurries; - dayList["light snow showers"] = Flurries; - dayList["cloudy with light snow"] = LightSnow; - dayList["heavy snow"] = Snow; - dayList["heavy snow shower"] = Snow; - dayList["heavy snow showers"] = Snow; - dayList["cloudy with heavy snow"] = Snow; - dayList["na"] = NotAvailable; - return dayList; -} - -QMap UKMETIon::setupNightIconMappings(void) const -{ - QMap nightList; - nightList["clear"] = ClearNight; - nightList["clear sky"] = ClearNight; - nightList["clear intervals"] = PartlyCloudyNight; - nightList["sunny intervals"] = PartlyCloudyDay; // it's not really sunny - nightList["sunny"] = ClearDay; - nightList["cloudy"] = Overcast; - nightList["white cloud"] = Overcast; - nightList["grey cloud"] = Overcast; - nightList["partly cloudy"] = PartlyCloudyNight; - nightList["drizzle"] = LightRain; - nightList["misty"] = Mist; - nightList["mist"] = Mist; - nightList["fog"] = Mist; - nightList["foggy"] = Mist; - nightList["tropical storm"] = Thunderstorm; - nightList["hazy"] = NotAvailable; - nightList["light shower"] = Showers; - nightList["light rain shower"] = Showers; - nightList["light showers"] = Showers; - nightList["light rain"] = Showers; - nightList["heavy rain"] = Rain; - nightList["heavy showers"] = Rain; - nightList["heavy shower"] = Rain; - nightList["heavy rain shower"] = Rain; - nightList["thundery shower"] = Thunderstorm; - nightList["thunder storm"] = Thunderstorm; - nightList["cloudy with sleet"] = NotAvailable; - nightList["sleet shower"] = NotAvailable; - nightList["sleet showers"] = NotAvailable; - nightList["sleet"] = NotAvailable; - nightList["cloudy with hail"] = Hail; - nightList["hail shower"] = Hail; - nightList["hail showers"] = Hail; - nightList["hail"] = Hail; - nightList["light snow"] = LightSnow; - nightList["light snow shower"] = Flurries; - nightList["light snow showers"] = Flurries; - nightList["cloudy with light snow"] = LightSnow; - nightList["heavy snow"] = Snow; - nightList["heavy snow shower"] = Snow; - nightList["heavy snow showers"] = Snow; - nightList["cloudy with heavy snow"] = Snow; - nightList["na"] = NotAvailable; - - return nightList; -} - -QMap const& UKMETIon::dayIcons(void) const -{ - static QMap const dval = setupDayIconMappings(); - return dval; -} - -QMap const& UKMETIon::nightIcons(void) const -{ - static QMap const nval = setupNightIconMappings(); - return nval; -} - -// Get a specific Ion's data -bool UKMETIon::updateIonSource(const QString& source) -{ - // We expect the applet to send the source in the following tokenization: - // ionname|validate|place_name - Triggers validation of place - // ionname|weather|place_name - Triggers receiving weather of place - - QStringList sourceAction = source.split('|'); - - // Guard: if the size of array is not 3 then we have bad data, return an error - if (sourceAction.size() < 3) { - setData(source, "validate", "bbcukmet|malformed"); - return true; - } - - if (sourceAction[1] == "validate" && sourceAction.size() >= 3) { - // Look for places to match - findPlace(sourceAction[2], source); - return true; - } else if (sourceAction[1] == "weather" && sourceAction.size() >= 3) { - if (sourceAction.count() >= 3) { - if (sourceAction[2].isEmpty()) { - setData(source, "validate", "bbcukmet|malformed"); - return true; - } - m_place[QString("bbcukmet|%1").arg(sourceAction[2])].XMLurl = sourceAction[3]; - getXMLData(QString("%1|%2").arg(sourceAction[0]).arg(sourceAction[2])); - return true; - } else { - return false; - } - } else { - setData(source, "validate", "bbcukmet|malformed"); - return true; - } - - return false; -} - -// Gets specific city XML data -void UKMETIon::getXMLData(const QString& source) -{ - foreach (const QString &fetching, m_obsJobList) { - if (fetching == source) { - // already getting this source and awaiting the data - return; - } - } - - KUrl url; - url = m_place[source].XMLurl; - - m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); - m_job->addMetaData("cookies", "none"); // Disable displaying cookies - m_obsJobXml.insert(m_job, new QXmlStreamReader); - m_obsJobList.insert(m_job, source); - - if (m_job) { - connect(m_job, SIGNAL(data(KIO::Job*,QByteArray)), this, - SLOT(observation_slotDataArrived(KIO::Job*,QByteArray))); - connect(m_job, SIGNAL(result(KJob*)), this, SLOT(observation_slotJobFinished(KJob*))); - } -} - -// Parses city list and gets the correct city based on ID number -void UKMETIon::findPlace(const QString& place, const QString& source) -{ - KUrl url; - url = "http://news.bbc.co.uk/weather/util/search/SearchResultsNode.xhtml?&search=" + place + "®ion=world&startIndex=0&count=500"; - - m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); - m_job->addMetaData("cookies", "none"); // Disable displaying cookies - m_jobHtml.insert(m_job, new QByteArray()); - m_jobList.insert(m_job, source); - - if (m_job) { - connect(m_job, SIGNAL(data(KIO::Job*,QByteArray)), this, - SLOT(setup_slotDataArrived(KIO::Job*,QByteArray))); - connect(m_job, SIGNAL(result(KJob*)), this, SLOT(setup_slotJobFinished(KJob*))); - -/* - // Handle redirects for direct hit places. - connect(m_job, SIGNAL(redirection(KIO::Job*,KUrl)), this, - SLOT(setup_slotRedirected(KIO::Job*,KUrl))); -*/ - } -} - -void UKMETIon::getFiveDayForecast(const QString& source) -{ - - KUrl xmlMap(m_place[source].forecastHTMLUrl); - - QString xmlPath = xmlMap.path(); - - int splitIDPos = xmlPath.lastIndexOf('/'); - QString stationID = xmlPath.midRef(splitIDPos + 1).toString(); - m_place[source].XMLforecastURL = "http://newsrss.bbc.co.uk/weather/forecast/" + stationID + "/Next3DaysRSS.xml" + xmlMap.query(); - KUrl url(m_place[source].XMLforecastURL); - - m_job = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); - m_job->addMetaData("cookies", "none"); // Disable displaying cookies - m_forecastJobXml.insert(m_job, new QXmlStreamReader); - m_forecastJobList.insert(m_job, source); - - if (m_job) { - connect(m_job, SIGNAL(data(KIO::Job*,QByteArray)), this, - SLOT(forecast_slotDataArrived(KIO::Job*,QByteArray))); - connect(m_job, SIGNAL(result(KJob*)), this, SLOT(forecast_slotJobFinished(KJob*))); - } -} - -void UKMETIon::readSearchHTMLData(const QString& source, const QByteArray& html) -{ - QTextStream stream(html.data()); - QString line; - QStringList tokens; - QString url; - QString tmp; - int flag = 0; - int counter = 2; - - // "

Vitoria, Brazil

" - QRegExp grabURL("/[a-z]+/[a-z]+/([0-9]+)(\\?[^\"]+)?"); - QRegExp grabPlace(">([^<]*[a-z()])"); // FIXME: It would be better to strip away the extra '>' - - while (!stream.atEnd()) { - line = stream.readLine(); - if (line.contains("

") > 0) { - flag = 1; - } - - if (line.contains("There are no forecasts matching") > 0) { - break; - } - - if (flag) { - - if (grabURL.indexIn(line.trimmed()) > 0) { - url = "http://newsrss.bbc.co.uk/weather/forecast/" + grabURL.cap(1) + "/ObservationsRSS.xml"; - if (grabURL.captureCount() > 1) { - url += grabURL.cap(2); - } - grabPlace.indexIn(line.trimmed()); - tmp = QString("bbcukmet|").append(grabPlace.cap(1)); - - // Duplicate places can exist - if (m_locations.contains(tmp)) { - tmp = QString("bbcukmet|").append(QString("%1 (#%2)").arg(grabPlace.cap(1)).arg(counter)); - counter++; - } - - m_place[tmp].XMLurl = url; - m_place[tmp].place = grabPlace.cap(1); - m_locations.append(tmp); - } - } - - if (line.contains("

") > 0) { - flag = 0; - } - } - - // I stream ok? - //if (stream.status() == QTextStream::Ok) { - //return true; - //} - - validate(source); -} - -// handle when no XML tag is found -void UKMETIon::parseUnknownElement(QXmlStreamReader& xml) const -{ - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - parseUnknownElement(xml); - } - } -} - -void UKMETIon::setup_slotDataArrived(KIO::Job *job, const QByteArray &data) -{ - if (data.isEmpty() || !m_jobHtml.contains(job)) { - return; - } - - m_jobHtml[job]->append(data); -} - -void UKMETIon::setup_slotJobFinished(KJob *job) -{ - if (job->error() == 149) { - setData(m_jobList[job], "validate", QString("bbcukmet|timeout")); - disconnectSource(m_jobList[job], this); - m_jobList.remove(job); - delete m_jobHtml[job]; - m_jobHtml.remove(job); - return; - } - - // If Redirected, don't go to this routine - if (!m_locations.contains(QString("bbcukmet|%1").arg(m_jobList[job]))) { - QByteArray *reader = m_jobHtml.value(job); - if (reader) { - readSearchHTMLData(m_jobList[job], *reader); - } - } - m_jobList.remove(job); - delete m_jobHtml[job]; - m_jobHtml.remove(job); -} - -void UKMETIon::observation_slotDataArrived(KIO::Job *job, const QByteArray &data) -{ - QByteArray local = data; - if (data.isEmpty() || !m_obsJobXml.contains(job)) { - return; - } - - // Send to xml. - m_obsJobXml[job]->addData(local); -} - -void UKMETIon::observation_slotJobFinished(KJob *job) -{ - const QString source = m_obsJobList.value(job); - setData(source, Data()); - - QXmlStreamReader *reader = m_obsJobXml.value(job); - if (reader) { - readObservationXMLData(m_obsJobList[job], *reader); - } - - m_obsJobList.remove(job); - delete m_obsJobXml[job]; - m_obsJobXml.remove(job); - - if (m_sourcesToReset.contains(source)) { - m_sourcesToReset.removeAll(source); - emit forceUpdate(this, source); - } -} - -void UKMETIon::forecast_slotDataArrived(KIO::Job *job, const QByteArray &data) -{ - QByteArray local = data; - if (data.isEmpty() || !m_forecastJobXml.contains(job)) { - return; - } - - // Send to xml. - m_forecastJobXml[job]->addData(local); -} - -void UKMETIon::forecast_slotJobFinished(KJob *job) -{ - setData(m_forecastJobList[job], Data()); - QXmlStreamReader *reader = m_forecastJobXml.value(job); - if (reader) { - readFiveDayForecastXMLData(m_forecastJobList[job], *reader); - } - - m_forecastJobList.remove(job); - delete m_forecastJobXml[job]; - m_forecastJobXml.remove(job); -} - -void UKMETIon::parsePlaceObservation(const QString &source, WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "rss"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "rss") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "channel") { - parseWeatherChannel(source, data, xml); - } - } - } -} - -void UKMETIon::parsePlaceForecast(const QString &source, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "rss"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isStartElement() && xml.name() == "channel") { - parseWeatherForecast(source, xml); - } - } -} - -void UKMETIon::parseWeatherChannel(const QString& source, WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "channel"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "channel") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "title") { - data.stationName = xml.readElementText().split("Observations for")[1].trimmed(); - data.stationName.replace("United Kingdom", i18n("UK")); - data.stationName.replace("United States of America", i18n("USA")); - - } else if (xml.name() == "item") { - parseWeatherObservation(source, data, xml); - } else { - parseUnknownElement(xml); - } - } - } -} - -void UKMETIon::parseWeatherForecast(const QString& source, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "channel"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "channel") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "item") { - parseFiveDayForecast(source, xml); - } else { - parseUnknownElement(xml); - } - } - } -} - -void UKMETIon::parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "item"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "item") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "title") { - QString conditionString = xml.readElementText(); - - // Get the observation time and condition - int splitIndex = conditionString.lastIndexOf(':'); - QStringRef conditionData = conditionString.midRef(splitIndex + 1); // Include ':' - data.obsTime = conditionString.midRef(0, splitIndex).toString(); - - // Friday at 0200 GMT - m_dateFormat = QDateTime::fromString(data.obsTime.split("at")[1].trimmed(), "hhmm 'GMT'"); - data.iconPeriodHour = m_dateFormat.toString("hh").toInt(); - data.iconPeriodMinute = m_dateFormat.toString("mm").toInt(); - - data.condition = conditionData.toString().split('.')[0].trimmed(); - - } else if (xml.name() == "link") { - m_place[source].forecastHTMLUrl = xml.readElementText(); - - } else if (xml.name() == "description") { - QString observeString = xml.readElementText(); - QStringList observeData = observeString.split(':'); -#ifdef __GNUC__ -#warning FIXME: We should make this use a QRegExp but I need some help here :) -spstarr -#endif - - data.temperature_C = observeData[1].split(QChar(176))[0].trimmed(); - - // Temperature might be not available - if (data.temperature_C.contains("N/A")) { - data.temperature_C = i18n("N/A"); - } - - data.windDirection = observeData[2].split(',')[0].trimmed(); - data.windSpeed_miles = observeData[3].split(',')[0].split(' ')[1].remove("mph"); - - data.humidity = observeData[4].split(',')[0].split(' ')[1]; - if (data.humidity.endsWith('%')) { - data.humidity.chop(1); - } - - data.pressure = observeData[5].split(',')[0].split(' ')[1].split("mb")[0]; - data.pressureTendency = observeData[5].split(',')[1].trimmed(); - - data.visibilityStr = observeData[6].trimmed(); - - } else if (xml.name() == "lat") { - const QString ordinate = xml.readElementText(); - data.latitude = ordinate.toDouble(); - } else if (xml.name() == "long") { - const QString ordinate = xml.readElementText(); - data.longitude = ordinate.toDouble(); - } else { - parseUnknownElement(xml); - } - } - } -} - -bool UKMETIon::readObservationXMLData(const QString& source, QXmlStreamReader& xml) -{ - WeatherData data; - bool haveObservation = false; - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "rss") { - parsePlaceObservation(source, data, xml); - haveObservation = true; - } else { - parseUnknownElement(xml); - } - } - - } - - if (!haveObservation) { - return false; - } - m_weatherData[source] = data; - - // Get the 5 day forecast info next. - getFiveDayForecast(source); - - return !xml.error(); -} - -bool UKMETIon::readFiveDayForecastXMLData(const QString& source, QXmlStreamReader& xml) -{ - bool haveFiveDay = false; - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "rss") { - parsePlaceForecast(source, xml); - haveFiveDay = true; - } else { - parseUnknownElement(xml); - } - } - } - if (!haveFiveDay) return false; - updateWeather(source); - return !xml.error(); -} - -void UKMETIon::parseFiveDayForecast(const QString& source, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "item"); - - // Flush out the old forecasts when updating. - m_weatherData[source].forecasts.clear(); - - WeatherData::ForecastInfo *forecast = new WeatherData::ForecastInfo; - QString line; - QString period; - QString summary; - QRegExp high("-?\\d+"); - QRegExp low("-?\\d+"); - while (!xml.atEnd()) { - xml.readNext(); - if (xml.name() == "title") { - line = xml.readElementText().trimmed(); -#ifdef __GNUC__ -#warning FIXME: We should make this all use QRegExps in UKMETIon::parseFiveDayForecast() for forecast -spstarr -#endif - - period = line.split(',')[0].split(':')[0]; - summary = line.split(',')[0].split(':')[1].trimmed(); - high.indexIn(line.split(',')[1]); - low.indexIn(line.split(',')[2]); - - forecast->period = period; - forecast->iconName = getWeatherIcon(dayIcons(), summary.toLower()); - forecast->summary = i18nc("weather forecast", summary.toUtf8()); - kDebug() << "i18n summary string: " << qPrintable(forecast->summary); - forecast->tempHigh = high.cap(0).toInt(); - forecast->tempLow = low.cap(0).toInt(); - m_weatherData[source].forecasts.append(forecast); - forecast = new WeatherData::ForecastInfo; - } - } - delete forecast; -} - -void UKMETIon::validate(const QString& source) -{ - bool beginflag = true; - - if (!m_locations.count()) { - QStringList invalidPlace = source.split('|'); - if (m_place[QString("bbcukmet|%1").arg(invalidPlace[2])].place.isEmpty()) { - setData(source, "validate", QString("bbcukmet|invalid|multiple|%1").arg(invalidPlace[2])); - } - m_locations.clear(); - return; - } else { - QString placeList; - foreach(const QString &place, m_locations) { - if (beginflag) { - placeList.append(QString("%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].XMLurl)); - beginflag = false; - } else { - placeList.append(QString("|place|%1|extra|%2").arg(place.split('|')[1]).arg(m_place[place].XMLurl)); - } - } - if (m_locations.count() > 1) { - setData(source, "validate", QString("bbcukmet|valid|multiple|place|%1").arg(placeList)); - } else { - placeList[0] = placeList[0].toUpper(); - setData(source, "validate", QString("bbcukmet|valid|single|place|%1").arg(placeList)); - } - } - m_locations.clear(); -} - -void UKMETIon::updateWeather(const QString& source) -{ - QString weatherSource = source; - weatherSource.replace("bbcukmet|", "bbcukmet|weather|"); - weatherSource.append(QString("|%1").arg(m_place[source].XMLurl)); - - QMap dataFields; - QStringList fieldList; - QVector forecastList; - int i = 0; - - Plasma::DataEngine::Data data; - - data.insert("Place", place(source)); - data.insert("Station", station(source)); - data.insert("Observation Period", observationTime(source)); - data.insert("Current Conditions", i18nc("weather condition", condition(source).toUtf8())); - kDebug() << "i18n condition string: " << qPrintable(i18nc("weather condition", condition(source).toUtf8())); - - const double lati = periodLatitude(source); - const double longi = periodLongitude(source); - const Plasma::DataEngine::Data timeData = m_timeEngine->query( - QString("Local|Solar|Latitude=%1|Longitude=%2|DateTime=%3") - .arg(lati).arg(longi).arg(m_dateFormat.toString(Qt::ISODate))); - - // Tell applet which icon to use for conditions and provide mapping for condition type to the icons to display - if (timeData["Corrected Elevation"].toDouble() >= 0.0) { - //kDebug() << "Using daytime icons\n"; - data.insert("Condition Icon", getWeatherIcon(dayIcons(), condition(source))); - } else { - data.insert("Condition Icon", getWeatherIcon(nightIcons(), condition(source))); - } - - data.insert("Latitude", lati); - data.insert("Longitude", longi); - - dataFields = humidity(source); - data.insert("Humidity", dataFields["humidity"]); - data.insert("Humidity Field", dataFields["humidityUnit"]); - - data.insert("Visibility", visibility(source)); - - dataFields = temperature(source); - data.insert("Temperature", dataFields["temperature"]); - data.insert("Temperature Unit", dataFields["temperatureUnit"]); - - dataFields = pressure(source); - data.insert("Pressure", dataFields["pressure"]); - data.insert("Pressure Unit", dataFields["pressureUnit"]); - data.insert("Pressure Tendency", dataFields["pressureTendency"]); - - dataFields = wind(source); - data.insert("Wind Speed", dataFields["windSpeed"]); - data.insert("Wind Speed Unit", dataFields["windUnit"]); - data.insert("Wind Direction", dataFields["windDirection"]); - - // 5 Day forecast info - forecastList = forecasts(source); - - // Set number of forecasts per day/night supported - data.insert("Total Weather Days", m_weatherData[source].forecasts.size()); - - foreach(const QString &forecastItem, forecastList) { - fieldList = forecastItem.split('|'); - - data.insert(QString("Short Forecast Day %1").arg(i), QString("%1|%2|%3|%4|%5|%6") \ - .arg(fieldList[0]).arg(fieldList[1]).arg(fieldList[2]).arg(fieldList[3]) \ - .arg(fieldList[4]).arg(fieldList[5])); - i++; - } - - data.insert("Credit", i18n("Supported by backstage.bbc.co.uk / Data from UK MET Office")); - data.insert("Credit Url", m_place[source].forecastHTMLUrl); - - setData(weatherSource, data); -} - -QString UKMETIon::place(const QString& source) const -{ - return m_weatherData[source].stationName; -} - -QString UKMETIon::station(const QString& source) const -{ - return m_weatherData[source].stationName; -} - -QString UKMETIon::observationTime(const QString& source) const -{ - return m_weatherData[source].obsTime; -} - -int UKMETIon::periodHour(const QString& source) const -{ - return m_weatherData[source].iconPeriodHour; -} - -int UKMETIon::periodMinute(const QString& source) const -{ - return m_weatherData[source].iconPeriodMinute; -} - -double UKMETIon::periodLatitude(const QString& source) const -{ - return m_weatherData[source].latitude; -} - -double UKMETIon::periodLongitude(const QString& source) const -{ - return m_weatherData[source].longitude; -} - -QString UKMETIon::condition(const QString& source) const -{ - return (m_weatherData[source].condition); -} - -QMap UKMETIon::temperature(const QString& source) const -{ - QMap temperatureInfo; - - temperatureInfo.insert("temperature", QString(m_weatherData[source].temperature_C)); - temperatureInfo.insert("temperatureUnit", QString::number(KUnitConversion::Celsius)); - return temperatureInfo; -} - -QMap UKMETIon::wind(const QString& source) const -{ - QMap windInfo; - if (m_weatherData[source].windSpeed_miles == "N/A") { - windInfo.insert("windSpeed", i18n("N/A")); - windInfo.insert("windUnit", QString::number(KUnitConversion::NoUnit)); - } else { - windInfo.insert("windSpeed", QString(m_weatherData[source].windSpeed_miles)); - windInfo.insert("windUnit", QString::number(KUnitConversion::MilePerHour)); - } - if (m_weatherData[source].windDirection.isEmpty()) { - windInfo.insert("windDirection", i18n("N/A")); - } else { - windInfo.insert("windDirection", i18nc("wind direction", m_weatherData[source].windDirection.toUtf8())); - } - return windInfo; -} - -QMap UKMETIon::humidity(const QString& source) const -{ - QMap humidityInfo; - if (m_weatherData[source].humidity != "N/A") { - humidityInfo.insert("humidity", m_weatherData[source].humidity); - humidityInfo.insert("humidityUnit", QString::number(KUnitConversion::Percent)); - } else { - humidityInfo.insert("humidity", i18n("N/A")); - humidityInfo.insert("humidityUnit", QString::number(KUnitConversion::NoUnit)); - } - - return humidityInfo; -} - -QString UKMETIon::visibility(const QString& source) const -{ - return i18nc("visibility", m_weatherData[source].visibilityStr.toUtf8()); -} - -QMap UKMETIon::pressure(const QString& source) const -{ - QMap pressureInfo; - if (m_weatherData[source].pressure == "N/A") { - pressureInfo.insert("pressure", i18n("N/A")); - pressureInfo.insert("pressureUnit", QString::number(KUnitConversion::NoUnit)); - pressureInfo.insert("pressureTendency", i18n("N/A")); - return pressureInfo; - } - - pressureInfo.insert("pressure", QString(m_weatherData[source].pressure)); - pressureInfo.insert("pressureUnit", QString::number(KUnitConversion::Millibar)); - - pressureInfo.insert("pressureTendency", i18nc("pressure tendency", m_weatherData[source].pressureTendency.toUtf8())); - return pressureInfo; -} - -QVector UKMETIon::forecasts(const QString& source) -{ - QVector forecastData; - - for (int i = 0; i < m_weatherData[source].forecasts.size(); ++i) { - - if (m_weatherData[source].forecasts[i]->period.contains("Saturday")) { - m_weatherData[source].forecasts[i]->period.replace("Saturday", i18nc("Short for Saturday", "Sat")); - } - - if (m_weatherData[source].forecasts[i]->period.contains("Sunday")) { - m_weatherData[source].forecasts[i]->period.replace("Sunday", i18nc("Short for Sunday", "Sun")); - } - - if (m_weatherData[source].forecasts[i]->period.contains("Monday")) { - m_weatherData[source].forecasts[i]->period.replace("Monday", i18nc("Short for Monday", "Mon")); - } - - if (m_weatherData[source].forecasts[i]->period.contains("Tuesday")) { - m_weatherData[source].forecasts[i]->period.replace("Tuesday", i18nc("Short for Tuesday", "Tue")); - } - - if (m_weatherData[source].forecasts[i]->period.contains("Wednesday")) { - m_weatherData[source].forecasts[i]->period.replace("Wednesday", i18nc("Short for Wednesday", "Wed")); - } - - if (m_weatherData[source].forecasts[i]->period.contains("Thursday")) { - m_weatherData[source].forecasts[i]->period.replace("Thursday", i18nc("Short for Thursday", "Thu")); - } - if (m_weatherData[source].forecasts[i]->period.contains("Friday")) { - m_weatherData[source].forecasts[i]->period.replace("Friday", i18nc("Short for Friday", "Fri")); - } - - forecastData.append(QString("%1|%2|%3|%4|%5|%6") \ - .arg(m_weatherData[source].forecasts[i]->period) \ - .arg(m_weatherData[source].forecasts[i]->iconName) \ - .arg(m_weatherData[source].forecasts[i]->summary) \ - .arg(m_weatherData[source].forecasts[i]->tempHigh) \ - .arg(m_weatherData[source].forecasts[i]->tempLow) \ - .arg("N/U")); - //.arg(m_weatherData[source].forecasts[i]->windSpeed) - //arg(m_weatherData[source].forecasts[i]->windDirection)); - } - - return forecastData; -} - -#include "moc_ion_bbcukmet.cpp" diff --git a/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h b/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h deleted file mode 100644 index 11dce328..00000000 --- a/plasma/dataengines/weather/ions/bbcukmet/ion_bbcukmet.h +++ /dev/null @@ -1,178 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Shawn Starr * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -/* Ion for BBC Weather from UKMET Office */ - -#ifndef ION_BBCUKMET_H -#define ION_BBCUKMET_H - -#include -#include - -#include "../ion.h" -#include "../dataengineconsumer.h" - -class KJob; -namespace KIO -{ - class Job; - class TransferJob; -} - -class WeatherData -{ - -public: - QString place; - QString stationName; - // Current observation information. - QString obsTime; - int iconPeriodHour; - int iconPeriodMinute; - double longitude; - double latitude; - - QString condition; - QString conditionIcon; - QString temperature_C; - QString windDirection; - QString windSpeed_miles; - QString humidity; - QString pressure; - QString pressureTendency; - QString visibilityStr; - - // Five day forecast - struct ForecastInfo { - QString period; - QString iconName; - QString summary; - int tempHigh; - int tempLow; - int windSpeed; - QString windDirection; - }; - - // 5 day Forecast - QVector forecasts; -}; - -class KDE_EXPORT UKMETIon : public IonInterface, public Plasma::DataEngineConsumer -{ - Q_OBJECT - -public: - UKMETIon(QObject *parent, const QVariantList &args); - ~UKMETIon(); - void init(); // Setup the city location, fetching the correct URL name. - bool updateIonSource(const QString& source); - void updateWeather(const QString& source); - - QString place(const QString& source) const; - QString station(const QString& source) const; - QString observationTime(const QString& source) const; - //bool night(const QString& source) const; - int periodHour(const QString& source) const; - int periodMinute(const QString& source) const; - double periodLatitude(const QString& source) const; - double periodLongitude(const QString& source) const; - QString condition(const QString& source) const; - QMap temperature(const QString& source) const; - QMap wind(const QString& source) const; - QMap humidity(const QString& source) const; - QString visibility(const QString& source) const; - QMap pressure(const QString& source) const; - QVector forecasts(const QString& source); - -public Q_SLOTS: - virtual void reset(); - -protected Q_SLOTS: - void setup_slotDataArrived(KIO::Job *, const QByteArray &); - void setup_slotJobFinished(KJob *); - //void setup_slotRedirected(KIO::Job *, const KUrl &url); - void observation_slotDataArrived(KIO::Job *, const QByteArray &); - void observation_slotJobFinished(KJob *); - void forecast_slotDataArrived(KIO::Job *, const QByteArray &); - void forecast_slotJobFinished(KJob *); - -private: - /* UKMET Methods - Internal for Ion */ - - QMap setupDayIconMappings(void) const; - QMap setupNightIconMappings(void) const; - - QMap const& nightIcons(void) const; - QMap const& dayIcons(void) const; - - // Load and Parse the place search XML listings - void findPlace(const QString& place, const QString& source); - void validate(const QString& source); // Sync data source with Applet - void getFiveDayForecast(const QString& source); - void getXMLData(const QString& source); - void readSearchHTMLData(const QString& source, const QByteArray& html); - bool readFiveDayForecastXMLData(const QString& source, QXmlStreamReader& xml); - void parseSearchLocations(const QString& source, QXmlStreamReader& xml); - - // Observation parsing methods - bool readObservationXMLData(const QString& source, QXmlStreamReader& xml); - void parsePlaceObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml); - void parseWeatherChannel(const QString& source, WeatherData& data, QXmlStreamReader& xml); - void parseWeatherObservation(const QString& source, WeatherData& data, QXmlStreamReader& xml); - void parseFiveDayForecast(const QString& source, QXmlStreamReader& xml); - void parsePlaceForecast(const QString& source, QXmlStreamReader& xml); - void parseWeatherForecast(const QString& source, QXmlStreamReader& xml); - void parseUnknownElement(QXmlStreamReader& xml) const; - - void deleteForecasts(); - - struct XMLMapInfo { - QString place; - QString XMLurl; - QString forecastHTMLUrl; - QString XMLforecastURL; - }; - - // Key dicts - QHash m_place; - QVector m_locations; - - // Weather information - QHash m_weatherData; - - // Store KIO jobs - Search list - QMap m_jobHtml; - QMap m_jobList; - - QMap m_obsJobXml; - QMap m_obsJobList; - - QMap m_forecastJobXml; - QMap m_forecastJobList; - - KIO::TransferJob *m_job; - Plasma::DataEngine *m_timeEngine; - - QDateTime m_dateFormat; - QStringList m_sourcesToReset; -}; - -K_EXPORT_PLASMA_DATAENGINE(bbcukmet, UKMETIon) - -#endif diff --git a/plasma/dataengines/weather/ions/envcan/CMakeLists.txt b/plasma/dataengines/weather/ions/envcan/CMakeLists.txt deleted file mode 100644 index b2a7bf29..00000000 --- a/plasma/dataengines/weather/ions/envcan/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -SET (ion_envcan_SRCS ion_envcan.cpp) -kde4_add_plugin(ion_envcan ${ion_envcan_SRCS}) -target_link_libraries (ion_envcan ${KDE4_SOLID_LIBS} weather_ion) - -INSTALL (FILES ion-envcan.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) - -INSTALL (TARGETS ion_envcan DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) - diff --git a/plasma/dataengines/weather/ions/envcan/ion-envcan.desktop b/plasma/dataengines/weather/ions/envcan/ion-envcan.desktop deleted file mode 100644 index 9c94bba0..00000000 --- a/plasma/dataengines/weather/ions/envcan/ion-envcan.desktop +++ /dev/null @@ -1,153 +0,0 @@ -[Desktop Entry] -Name=Environment Canada -Name[ar]=وزارة البيئة الكندية -Name[ast]=Medioambiente de Canadá -Name[be@latin]=Environment Canada -Name[bg]=Environment Canada -Name[bs]=Prirodna sredina Kanada -Name[ca]=Medi ambient del Canadà -Name[ca@valencia]=Medi ambient del Canadà -Name[cs]=Meteorologický úřad Kanady (EC) -Name[da]=Environment Canada -Name[de]=Environment Canada -Name[el]=Περιβάλλον Καναδά -Name[en_GB]=Environment Canada -Name[eo]=Environment Canada -Name[es]=Medio ambiente de Canada -Name[et]=Environment Canada -Name[eu]=Kanadako Ingurumen Ministerioa -Name[fi]=Environment Canada -palvelu -Name[fr]=Météorologie du Canada -Name[fy]=Omjouwing Kanada -Name[ga]=Environment Canada -Name[gl]=Environment Canada -Name[gu]=એન્વાર્યમેન્ટ કેનેડા -Name[he]=Environment Canada -Name[hi]=एनवायरनमेंट कनाडा -Name[hne]=कनाडा मौसम -Name[hr]=Okoliš Kanade -Name[hu]=Environment Canada -Name[ia]=Environment Canada -Name[id]=Environment Canada -Name[is]=Environment Canada -Name[it]=Environment Canada -Name[ja]=Environment Canada -Name[kk]=Environment Canada -Name[km]=បរិស្ថាន​ប្រទេស​កាណាដា -Name[kn]=ಎನ್ವಯರನ್ಮೆಂಟ್ ಕೆನಡಾ -Name[ko]=캐나다 환경부 -Name[lt]=Environment Canada -Name[lv]=Environment Canada -Name[mk]=Environment Canada -Name[ml]=കാനഡയുടെ പരിസ്ഥിതി -Name[mr]=हवामान कॅनडा -Name[nb]=Environment Canada -Name[nds]=Ümwelt Kanada -Name[ne]=वातावरण क्यानाडा -Name[nl]=Environment Canada -Name[nn]=Environment Canada -Name[pa]=ਇੰਨਵਾਇਰਮੈਂਟ ਕੇਨੈਡਾ -Name[pl]=Environment Canada -Name[pt]=Environment Canada -Name[pt_BR]=Environment Canada -Name[ro]=Environment Canada -Name[ru]=Environment Canada -Name[se]=Environment Canada -Name[si]=කැනඩා පාරිසරිකය -Name[sk]=Počasie - Environment Canada -Name[sl]=Environment Canada -Name[sr]=Природна средина Канада -Name[sr@ijekavian]=Природна средина Канада -Name[sr@ijekavianlatin]=Prirodna sredina Kanada -Name[sr@latin]=Prirodna sredina Kanada -Name[sv]=Environment Canada -Name[ta]=Environment Canada -Name[te]=కెనడా వాతావరణం -Name[tg]=Environment Canada -Name[th]=Environment Canada -Name[tr]=Environment Canada -Name[ug]=كانادا مۇھىتى -Name[uk]=Погода в Канаді -Name[wa]=Evironmint Canada -Name[x-test]=xxEnvironment Canadaxx -Name[zh_CN]=加拿大环境 -Name[zh_TW]=Environment Canada -Comment=XML Data from Environment Canada -Comment[ar]=بيانات XML من وزارة البيئة الكندية -Comment[ast]=Datos XML de Medioambiente de Canadá -Comment[be@latin]=Źviestki ŭ farmacie „XML” ad „Environment Canada” -Comment[bg]=XML данни от Environment Canada -Comment[bs]=IksML podaci Prirodne sredine Kanada -Comment[ca]=Dades XML des de Medi ambient del Canadà -Comment[ca@valencia]=Dades XML des de Medi ambient del Canadà -Comment[cs]=XML data z meteorologického úřadu Kanady (EC) -Comment[da]=XML-data fra Environment Canada -Comment[de]=XML-Daten von Environment Canada -Comment[el]=Δεδομένα XML για το περιβάλλον του Καναδά -Comment[en_GB]=XML Data from Environment Canada -Comment[eo]=XML-datumoj el Environment Canada -Comment[es]=Datos XML de medio ambiente de Canada -Comment[et]=Environment Canada XML-andmed -Comment[eu]=XML datuak Kanadako Ingurumen Ministeriotik -Comment[fi]=XML-tietoa Environment Canada -palvelusta -Comment[fr]=Données au format XML de la météorologie du Canada -Comment[fy]=XML Data fan omjouwing Kanada -Comment[ga]=Sonraí XML ó Environment Canada -Comment[gl]=Datos XML de Environment Canada -Comment[gu]=એન્વાર્યમેન્ટ કેનેડા તરફથી XML માહિતી -Comment[he]=מידע ב־XML מ־Environment Canada -Comment[hi]=एनवायरनमेंट कनाडा से एक्सएमएल डाटा -Comment[hne]=कनाडा मौसम से एक्सएमएल डाटा -Comment[hr]=XML podaci iz Okoliša Kanade -Comment[hu]=XML-adatok az Environment Canada szervezettől -Comment[ia]=Datos XML ex Environment Canada -Comment[id]=Data XML dari Environment Canada -Comment[is]=XML gögn frá Umhverfisstofnun Kanada -Comment[it]=Dati XML da Environment Canada -Comment[ja]=Environment Canada の XML データ -Comment[kk]=Environment Canada-ның XML дерегі -Comment[km]=ទិន្នន័យ XML ពី​បរិស្ថាន​ប្រទេស​កាណាដា -Comment[kn]=ಎನ್ವಯರನ್ಮೆಂಟ್ ಕೆನಡಾ ದಿಂದ XML ದತ್ತ -Comment[ko]=캐나다 환경부의 XML 데이터 -Comment[lt]=XML duomenys iš Environment Canada -Comment[lv]=XML dati no Environment Canada -Comment[mk]=XML-податоци од „Environment Canada“ -Comment[ml]=കാനഡയുടെ പരിസ്ഥിതിയില്‍ നിന്നുമുള്ള എക്സ്എംഎല്‍ ഡേറ്റാ -Comment[mr]=हवामान कॅनडा पासून XML माहिती -Comment[nb]=XML-data fra Environment Canada -Comment[nds]=XML-Daten vun Ümwelt Kanada -Comment[ne]=वातावरण क्यानाडाबाट एक्सएमएल डेटा -Comment[nl]=XML-gegevens van Environment Canada -Comment[nn]=XML-data frå Environment Canada -Comment[pa]=ਇੰਨਵਾਇਰਨਮੈਂਟ ਕੇਨੈਡਾ ਤੋਂ XML ਡਾਟਾ -Comment[pl]=Dane XML z Environment Canada -Comment[pt]=Dados em XML do Environment Canada -Comment[pt_BR]=Dados em XML do Environment Canada -Comment[ro]=Date XML de la Environment Canada -Comment[ru]=Данные в формате XML от Environment Canada -Comment[se]=XML-dáhtat Environment Canadas -Comment[si]=කැනඩා පාරිසරිකය වෙතින් XML දත්ත -Comment[sk]=XML dáta z Environment Canada -Comment[sl]=Podatki XML od Environment Canada -Comment[sr]=ИксМЛ подаци Природне средине Канада -Comment[sr@ijekavian]=ИксМЛ подаци Природне средине Канада -Comment[sr@ijekavianlatin]=XML podaci Prirodne sredine Kanada -Comment[sr@latin]=XML podaci Prirodne sredine Kanada -Comment[sv]=XML-data från Environment Canada -Comment[ta]=XML Data from Environment Canada -Comment[te]=కెనడా వాతావరణం నుండి XML డాటా -Comment[tg]=Маълумоти XML аз Environment Canada -Comment[th]=ข้อมูล XML จาก Environment Canada -Comment[tr]=Environment Canada'dan XML Verisi -Comment[ug]=كانادا مۇھىتى تەمىنلىگەن XML سانلىق-مەلۇماتى -Comment[uk]=Дані XML з метеорологічного відділу Канади -Comment[wa]=Dinêyes XML da Evironmint Canada -Comment[x-test]=xxXML Data from Environment Canadaxx -Comment[zh_CN]=加拿大环境提供的 XML 数据 -Comment[zh_TW]=從 Environment Canada 來的 XML 資料 -X-KDE-ServiceTypes=Plasma/DataEngine -X-KDE-ParentApp=weatherengine -Type=Service -Icon=noneyet -X-KDE-Library=ion_envcan -X-KDE-PluginInfo-Name=envcan diff --git a/plasma/dataengines/weather/ions/envcan/ion_envcan.cpp b/plasma/dataengines/weather/ions/envcan/ion_envcan.cpp deleted file mode 100644 index 02bccc7e..00000000 --- a/plasma/dataengines/weather/ions/envcan/ion_envcan.cpp +++ /dev/null @@ -1,1922 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2011 by Shawn Starr * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -/* Ion for Environment Canada XML data */ - -#include "ion_envcan.h" - -#include -#include -#include -#include - - -// ctor, dtor -EnvCanadaIon::EnvCanadaIon(QObject *parent, const QVariantList &args) - : IonInterface(parent, args) -{ -} - -void EnvCanadaIon::deleteForecasts() -{ - QMutableHashIterator it(m_weatherData); - while (it.hasNext()) { - it.next(); - WeatherData &item = it.value(); - qDeleteAll(item.warnings); - item.warnings.clear(); - - qDeleteAll(item.watches); - item.watches.clear(); - - qDeleteAll(item.forecasts); - item.forecasts.clear(); - } -} - -void EnvCanadaIon::reset() -{ - deleteForecasts(); - emitWhenSetup = true; - m_sourcesToReset = sources(); - getXMLSetup(); -} - -EnvCanadaIon::~EnvCanadaIon() -{ - // Destroy each watch/warning stored in a QVector - deleteForecasts(); -} - -// Get the master list of locations to be parsed -void EnvCanadaIon::init() -{ - // Get the real city XML URL so we can parse this - getXMLSetup(); - m_timeEngine = dataEngine("time"); -} - -QMap EnvCanadaIon::setupConditionIconMappings(void) const -{ - QMap conditionList; - - // Explicit periods - conditionList["mainly sunny"] = FewCloudsDay; - conditionList["mainly clear"] = FewCloudsNight; - conditionList["sunny"] = ClearDay; - conditionList["clear"] = ClearNight; - - // Available conditions - conditionList["blowing snow"] = Snow; - conditionList["cloudy"] = Overcast; - conditionList["distant precipitation"] = LightRain; - conditionList["drifting snow"] = Flurries; - conditionList["drizzle"] = LightRain; - conditionList["dust"] = NotAvailable; - conditionList["dust devils"] = NotAvailable; - conditionList["fog"] = Mist; - conditionList["fog bank near station"] = Mist; - conditionList["fog depositing ice"] = Mist; - conditionList["fog patches"] = Mist; - conditionList["freezing drizzle"] = FreezingDrizzle; - conditionList["freezing rain"] = FreezingRain; - conditionList["funnel cloud"] = NotAvailable; - conditionList["hail"] = Hail; - conditionList["haze"] = Haze; - conditionList["heavy blowing snow"] = Snow; - conditionList["heavy drifting snow"] = Snow; - conditionList["heavy drizzle"] = LightRain; - conditionList["heavy hail"] = Hail; - conditionList["heavy mixed rain and drizzle"] = LightRain; - conditionList["heavy mixed rain and snow shower"] = RainSnow; - conditionList["heavy rain"] = Rain; - conditionList["heavy rain and snow"] = RainSnow; - conditionList["heavy rainshower"] = Rain; - conditionList["heavy snow"] = Snow; - conditionList["heavy snow pellets"] = Snow; - conditionList["heavy snowshower"] = Snow; - conditionList["heavy thunderstorm with hail"] = Thunderstorm; - conditionList["heavy thunderstorm with rain"] = Thunderstorm; - conditionList["ice crystals"] = Flurries; - conditionList["ice pellets"] = Hail; - conditionList["increasing cloud"] = Overcast; - conditionList["light drizzle"] = LightRain; - conditionList["light freezing drizzle"] = FreezingRain; - conditionList["light freezing rain"] = FreezingRain; - conditionList["light rain"] = LightRain; - conditionList["light rainshower"] = LightRain; - conditionList["light snow"] = LightSnow; - conditionList["light snow pellets"] = LightSnow; - conditionList["light snowshower"] = Flurries; - conditionList["lightning visible"] = Thunderstorm; - conditionList["mist"] = Mist; - conditionList["mixed rain and drizzle"] = LightRain; - conditionList["mixed rain and snow shower"] = RainSnow; - conditionList["not reported"] = NotAvailable; - conditionList["rain"] = Rain; - conditionList["rain and snow"] = RainSnow; - conditionList["rainshower"] = LightRain; - conditionList["recent drizzle"] = LightRain; - conditionList["recent dust or sand storm"] = NotAvailable; - conditionList["recent fog"] = Mist; - conditionList["recent freezing precipitation"] = FreezingDrizzle; - conditionList["recent hail"] = Hail; - conditionList["recent rain"] = Rain; - conditionList["recent rain and snow"] = RainSnow; - conditionList["recent rainshower"] = Rain; - conditionList["recent snow"] = Snow; - conditionList["recent snowshower"] = Flurries; - conditionList["recent thunderstorm"] = Thunderstorm; - conditionList["recent thunderstorm with hail"] = Thunderstorm; - conditionList["recent thunderstorm with heavy hail"] = Thunderstorm; - conditionList["recent thunderstorm with heavy rain"] = Thunderstorm; - conditionList["recent thunderstorm with rain"] = Thunderstorm; - conditionList["sand or dust storm"] = NotAvailable; - conditionList["severe sand or dust storm"] = NotAvailable; - conditionList["shallow fog"] = Mist; - conditionList["smoke"] = NotAvailable; - conditionList["snow"] = Snow; - conditionList["snow crystals"] = Flurries; - conditionList["snow grains"] = Flurries; - conditionList["squalls"] = Snow; - conditionList["thunderstorm with hail"] = Thunderstorm; - conditionList["thunderstorm with rain"] = Thunderstorm; - conditionList["thunderstorm with sand or dust storm"] = Thunderstorm; - conditionList["thunderstorm without precipitation"] = Thunderstorm; - conditionList["tornado"] = NotAvailable; - return conditionList; -} - - -QMap EnvCanadaIon::setupForecastIconMappings(void) const -{ - QMap forecastList; - - // Abbreviated forecast descriptions - forecastList["a few flurries"] = Flurries; - forecastList["a few flurries mixed with ice pellets"] = RainSnow; - forecastList["a few flurries or rain showers"] = RainSnow; - forecastList["a few flurries or thundershowers"] = RainSnow; - forecastList["a few rain showers or flurries"] = RainSnow; - forecastList["a few rain showers or wet flurries"] = RainSnow; - forecastList["a few showers"] = LightRain; - forecastList["a few showers or drizzle"] = LightRain; - forecastList["a few showers or thundershowers"] = Thunderstorm; - forecastList["a few showers or thunderstorms"] = Thunderstorm; - forecastList["a few thundershowers"] = Thunderstorm; - forecastList["a few thunderstorms"] = Thunderstorm; - forecastList["a few wet flurries"] = RainSnow; - forecastList["a few wet flurries or rain showers"] = RainSnow; - forecastList["a mix of sun and cloud"] = PartlyCloudyDay; - forecastList["cloudy with sunny periods"] = PartlyCloudyDay; - forecastList["partly cloudy"] = PartlyCloudyDay; - forecastList["mainly sunny"] = FewCloudsDay; - forecastList["sunny"] = ClearDay; - forecastList["blizzard"] = Snow; - forecastList["clear"] = ClearNight; - forecastList["cloudy"] = Overcast; - forecastList["drizzle"] = LightRain; - forecastList["drizzle mixed with freezing drizzle"] = FreezingDrizzle; - forecastList["drizzle mixed with rain"] = LightRain; - forecastList["drizzle or freezing drizzle"] = LightRain; - forecastList["drizzle or rain"] = LightRain; - forecastList["flurries"] = Flurries; - forecastList["flurries at times heavy"] = Flurries; - forecastList["flurries at times heavy or rain snowers"] = RainSnow; - forecastList["flurries mixed with ice pellets"] = FreezingRain; - forecastList["flurries or ice pellets"] = FreezingRain; - forecastList["flurries or rain showers"] = RainSnow; - forecastList["flurries or thundershowers"] = Flurries; - forecastList["fog"] = Mist; - forecastList["fog developing"] = Mist; - forecastList["fog dissipating"] = Mist; - forecastList["fog patches"] = Mist; - forecastList["freezing drizzle"] = FreezingDrizzle; - forecastList["freezing rain"] = FreezingRain; - forecastList["freezing rain mixed with rain"] = FreezingRain; - forecastList["freezing rain mixed with snow"] = FreezingRain; - forecastList["freezing rain or ice pellets"] = FreezingRain; - forecastList["freezing rain or rain"] = FreezingRain; - forecastList["freezing rain or snow"] = FreezingRain; - forecastList["ice fog"] = Mist; - forecastList["ice fog developing"] = Mist; - forecastList["ice fog dissipating"] = Mist; - forecastList["ice pellet"] = Hail; - forecastList["ice pellet mixed with freezing rain"] = Hail; - forecastList["ice pellet mixed with snow"] = Hail; - forecastList["ice pellet or snow"] = RainSnow; - forecastList["light snow"] = LightSnow; - forecastList["light snow and blizzard"] = LightSnow; - forecastList["light snow and blizzard and blowing snow"] = Snow; - forecastList["light snow and blowing snow"] = LightSnow; - forecastList["light snow mixed with freezing drizzle"] = FreezingDrizzle; - forecastList["light snow mixed with freezing rain"] = FreezingRain; - forecastList["light snow or ice pellets"] = LightSnow; - forecastList["light snow or rain"] = RainSnow; - forecastList["light wet snow"] = RainSnow; - forecastList["light wet snow or rain"] = RainSnow; - forecastList["local snow squalls"] = Snow; - forecastList["near blizzard"] = Snow; - forecastList["overcast"] = Overcast; - forecastList["increasing cloudiness"] = Overcast; - forecastList["increasing clouds"] = Overcast; - forecastList["periods of drizzle"] = LightRain; - forecastList["periods of drizzle mixed with freezing drizzle"] = FreezingDrizzle; - forecastList["periods of drizzle mixed with rain"] = LightRain; - forecastList["periods of drizzle or freezing drizzle"] = FreezingDrizzle; - forecastList["periods of drizzle or rain"] = LightRain; - forecastList["periods of freezing drizzle"] = FreezingDrizzle; - forecastList["periods of freezing drizzle or drizzle"] = FreezingDrizzle; - forecastList["periods of freezing drizzle or rain"] = FreezingDrizzle; - forecastList["periods of freezing rain"] = FreezingRain; - forecastList["periods of freezing rain mixed with ice pellets"] = FreezingRain; - forecastList["periods of freezing rain mixed with rain"] = FreezingRain; - forecastList["periods of freezing rain mixed with snow"] = FreezingRain; - forecastList["periods of freezing rain mixed with freezing drizzle"] = FreezingRain; - forecastList["periods of freezing rain or ice pellets"] = FreezingRain; - forecastList["periods of freezing rain or rain"] = FreezingRain; - forecastList["periods of freezing rain or snow"] = FreezingRain; - forecastList["periods of ice pellet"] = Hail; - forecastList["periods of ice pellet mixed with freezing rain"] = Hail; - forecastList["periods of ice pellet mixed with snow"] = Hail; - forecastList["periods of ice pellet or freezing rain"] = Hail; - forecastList["periods of ice pellet or snow"] = Hail; - forecastList["periods of light snow"] = LightSnow; - forecastList["periods of light snow and blizzard"] = Snow; - forecastList["periods of light snow and blizzard and blowing snow"] = Snow; - forecastList["periods of light snow and blowing snow"] = LightSnow; - forecastList["periods of light snow mixed with freezing drizzle"] = RainSnow; - forecastList["periods of light snow mixed with freezing rain"] = RainSnow; - forecastList["periods of light snow mixed with ice pelletS"] = LightSnow; - forecastList["periods of light snow mixed with rain"] = RainSnow; - forecastList["periods of light snow or freezing drizzle"] = RainSnow; - forecastList["periods of light snow or freezing rain"] = RainSnow; - forecastList["periods of light snow or ice pellets"] = LightSnow; - forecastList["periods of light snow or rain"] = RainSnow; - forecastList["periods of light wet snow"] = LightSnow; - forecastList["periods of light wet snow mixed with rain"] = RainSnow; - forecastList["periods of light wet snow or rain"] = RainSnow; - forecastList["periods of rain"] = Rain; - forecastList["periods of rain mixed with freezing rain"] = Rain; - forecastList["periods of rain mixed with snow"] = RainSnow; - forecastList["periods of rain or drizzle"] = Rain; - forecastList["periods of rain or freezing rain"] = Rain; - forecastList["periods of rain or thundershowers"] = Showers; - forecastList["periods of rain or thunderstorms"] = Thunderstorm; - forecastList["periods of rain or snow"] = RainSnow; - forecastList["periods of snow"] = Snow; - forecastList["periods of snow and blizzard"] = Snow; - forecastList["periods of snow and blizzard and blowing snow"] = Snow; - forecastList["periods of snow and blowing snow"] = Snow; - forecastList["periods of snow mixed with freezing drizzle"] = RainSnow; - forecastList["periods of snow mixed with freezing rain"] = RainSnow; - forecastList["periods of snow mixed with ice pellets"] = Snow; - forecastList["periods of snow mixed with rain"] = RainSnow; - forecastList["periods of snow or freezing drizzle"] = RainSnow; - forecastList["periods of snow or freezing rain"] = RainSnow; - forecastList["periods of snow or ice pellets"] = Snow; - forecastList["periods of snow or rain"] = RainSnow; - forecastList["periods of rain or snow"] = RainSnow; - forecastList["periods of wet snow"] = Snow; - forecastList["periods of wet snow mixed with rain"] = RainSnow; - forecastList["periods of wet snow or rain"] = RainSnow; - forecastList["rain"] = Rain; - forecastList["rain at times heavy"] = Rain; - forecastList["rain at times heavy mixed with freezing rain"] = FreezingRain; - forecastList["rain at times heavy mixed with snow"] = RainSnow; - forecastList["rain at times heavy or drizzle"] = Rain; - forecastList["rain at times heavy or freezing rain"] = Rain; - forecastList["rain at times heavy or snow"] = RainSnow; - forecastList["rain at times heavy or thundershowers"] = Showers; - forecastList["rain at times heavy or thunderstorms"] = Thunderstorm; - forecastList["rain mixed with freezing rain"] = FreezingRain; - forecastList["rain mixed with snow"] = RainSnow; - forecastList["rain or drizzle"] = Rain; - forecastList["rain or freezing rain"] = Rain; - forecastList["rain or snow"] = RainSnow; - forecastList["rain or thundershowers"] = Showers; - forecastList["rain or thunderstorms"] = Thunderstorm; - forecastList["rain showers or flurries"] = RainSnow; - forecastList["rain showers or wet flurries"] = RainSnow; - forecastList["showers"] = Showers; - forecastList["showers at times heavy"] = Showers; - forecastList["showers at times heavy or thundershowers"] = Showers; - forecastList["showers at times heavy or thunderstorms"] = Thunderstorm; - forecastList["showers or drizzle"] = Showers; - forecastList["showers or thundershowers"] = Thunderstorm; - forecastList["showers or thunderstorms"] = Thunderstorm; - forecastList["smoke"] = NotAvailable; - forecastList["snow"] = Snow; - forecastList["snow and blizzard"] = Snow; - forecastList["snow and blizzard and blowing snow"] = Snow; - forecastList["snow and blowing snow"] = Snow; - forecastList["snow at times heavy"] = Snow; - forecastList["snow at times heavy and blizzard"] = Snow; - forecastList["snow at times heavy and blowing snow"] = Snow; - forecastList["snow at times heavy mixed with freezing drizzle"] = RainSnow; - forecastList["snow at times heavy mixed with freezing rain"] = RainSnow; - forecastList["snow at times heavy mixed with ice pellets"] = Snow; - forecastList["snow at times heavy mixed with rain"] = RainSnow; - forecastList["snow at times heavy or freezing rain"] = RainSnow; - forecastList["snow at times heavy or ice pellets"] = Snow; - forecastList["snow at times heavy or rain"] = RainSnow; - forecastList["snow mixed with freezing drizzle"] = RainSnow; - forecastList["snow mixed with freezing rain"] = RainSnow; - forecastList["snow mixed with ice pellets"] = Snow; - forecastList["snow mixed with rain"] = RainSnow; - forecastList["snow or freezing drizzle"] = RainSnow; - forecastList["snow or freezing rain"] = RainSnow; - forecastList["snow or ice pellets"] = Snow; - forecastList["snow or rain"] = RainSnow; - forecastList["snow squalls"] = Snow; - forecastList["sunny"] = ClearDay; - forecastList["sunny with cloudy periods"] = PartlyCloudyDay; - forecastList["thunderstorms"] = Thunderstorm; - forecastList["thunderstorms and possible hail"] = Thunderstorm; - forecastList["wet flurries"] = Flurries; - forecastList["wet flurries at times heavy"] = Flurries; - forecastList["wet flurries at times heavy or rain snowers"] = RainSnow; - forecastList["wet flurries or rain showers"] = RainSnow; - forecastList["wet snow"] = Snow; - forecastList["wet snow at times heavy"] = Snow; - forecastList["wet snow at times heavy mixed with rain"] = RainSnow; - forecastList["wet snow mixed with rain"] = RainSnow; - forecastList["wet snow or rain"] = RainSnow; - forecastList["windy"] = NotAvailable; - - forecastList["chance of drizzle mixed with freezing drizzle"] = LightRain; - forecastList["chance of flurries mixed with ice pellets"] = Flurries; - forecastList["chance of flurries or ice pellets"] = Flurries; - forecastList["chance of flurries or rain showers"] = RainSnow; - forecastList["chance of flurries or thundershowers"] = RainSnow; - forecastList["chance of freezing drizzle"] = FreezingDrizzle; - forecastList["chance of freezing rain"] = FreezingRain; - forecastList["chance of freezing rain mixed with snow"] = RainSnow; - forecastList["chance of freezing rain or rain"] = FreezingRain; - forecastList["chance of freezing rain or snow"] = RainSnow; - forecastList["chance of light snow and blowing snow"] = LightSnow; - forecastList["chance of light snow mixed with freezing drizzle"] = LightSnow; - forecastList["chance of light snow mixed with ice pellets"] = LightSnow; - forecastList["chance of light snow mixed with rain"] = RainSnow; - forecastList["chance of light snow or freezing rain"] = RainSnow; - forecastList["chance of light snow or ice pellets"] = LightSnow; - forecastList["chance of light snow or rain"] = RainSnow; - forecastList["chance of light wet snow"] = Snow; - forecastList["chance of rain"] = Rain; - forecastList["chance of rain at times heavy"] = Rain; - forecastList["chance of rain mixed with snow"] = RainSnow; - forecastList["chance of rain or drizzle"] = Rain; - forecastList["chance of rain or freezing rain"] = Rain; - forecastList["chance of rain or snow"] = RainSnow; - forecastList["chance of rain showers or flurries"] = RainSnow; - forecastList["chance of rain showers or wet flurries"] = RainSnow; - forecastList["chance of severe thunderstorms"] = Thunderstorm; - forecastList["chance of showers at times heavy"] = Rain; - forecastList["chance of showers at times heavy or thundershowers"] = Thunderstorm; - forecastList["chance of showers at times heavy or thunderstorms"] = Thunderstorm; - forecastList["chance of showers or thundershowers"] = Thunderstorm; - forecastList["chance of showers or thunderstorms"] = Thunderstorm; - forecastList["chance of snow"] = Snow; - forecastList["chance of snow and blizzard"] = Snow; - forecastList["chance of snow mixed with freezing drizzle"] = Snow; - forecastList["chance of snow mixed with freezing rain"] = RainSnow; - forecastList["chance of snow mixed with rain"] = RainSnow; - forecastList["chance of snow or rain"] = RainSnow; - forecastList["chance of snow squalls"] = Snow; - forecastList["chance of thundershowers"] = Showers; - forecastList["chance of thunderstorms"] = Thunderstorm; - forecastList["chance of thunderstorms and possible hail"] = Thunderstorm; - forecastList["chance of wet flurries"] = Flurries; - forecastList["chance of wet flurries at times heavy"] = Flurries; - forecastList["chance of wet flurries or rain showers"] = RainSnow; - forecastList["chance of wet snow"] = Snow; - forecastList["chance of wet snow mixed with rain"] = RainSnow; - forecastList["chance of wet snow or rain"] = RainSnow; - - return forecastList; -} - -QMap const& EnvCanadaIon::conditionIcons(void) const -{ - static QMap const condval = setupConditionIconMappings(); - return condval; -} - -QMap const& EnvCanadaIon::forecastIcons(void) const -{ - static QMap const foreval = setupForecastIconMappings(); - return foreval; -} - -QStringList EnvCanadaIon::validate(const QString& source) const -{ - QStringList placeList; - QString sourceNormalized = source.toUpper(); - QHash::const_iterator it = m_places.constBegin(); - while (it != m_places.constEnd()) { - if (it.key().toUpper().contains(sourceNormalized)) { - placeList.append(QString("place|").append(it.key())); - } - ++it; - } - - // Check if placeList is empty if so, return nothing. - if (placeList.isEmpty()) { - return QStringList(); - } - placeList.sort(); - return placeList; -} - -// Get a specific Ion's data -bool EnvCanadaIon::updateIonSource(const QString& source) -{ - //kDebug() << "updateIonSource()" << source; - - // We expect the applet to send the source in the following tokenization: - // ionname|validate|place_name - Triggers validation of place - // ionname|weather|place_name - Triggers receiving weather of place - - QStringList sourceAction = source.split('|'); - - // Guard: if the size of array is not 2 then we have bad data, return an error - if (sourceAction.size() < 2) { - setData(source, "validate", "envcan|malformed"); - return true; - } - - if (sourceAction[1] == "validate" && sourceAction.size() > 2) { - QStringList result = validate(sourceAction[2]); - - if (result.size() == 1) { - setData(source, "validate", QString("envcan|valid|single|").append(result.join("|"))); - return true; - } else if (result.size() > 1) { - setData(source, "validate", QString("envcan|valid|multiple|").append(result.join("|"))); - return true; - } else if (result.size() == 0) { - setData(source, "validate", QString("envcan|invalid|single|").append(sourceAction[2])); - return true; - } - - } else if (sourceAction[1] == "weather" && sourceAction.size() > 2) { - getXMLData(source); - return true; - } else { - setData(source, "validate", "envcan|malformed"); - return true; - } - return false; -} - -// Parses city list and gets the correct city based on ID number -void EnvCanadaIon::getXMLSetup() -{ - //kDebug() << "getXMLSetup()"; - - // If network is down, we need to spin and wait - - KIO::TransferJob *job = KIO::get(KUrl("http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/siteList.xml"), KIO::NoReload, KIO::HideProgressInfo); - - m_xmlSetup.clear(); - connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, - SLOT(setup_slotDataArrived(KIO::Job*,QByteArray))); - connect(job, SIGNAL(result(KJob*)), this, SLOT(setup_slotJobFinished(KJob*))); -} - -// Gets specific city XML data -void EnvCanadaIon::getXMLData(const QString& source) -{ - foreach (const QString &fetching, m_jobList) { - if (fetching == source) { - // already getting this source and awaiting the data - return; - } - } - - //kDebug() << source; - - // Demunge source name for key only. - QString dataKey = source; - dataKey.remove("envcan|weather|"); - - KUrl url = QString("http://dd.weatheroffice.ec.gc.ca/citypage_weather/xml/" + m_places[dataKey].territoryName + "/" + m_places[dataKey].cityCode + "_e.xml"); - //url="file:///home/spstarr/Desktop/s0000649_e.xml"; - //kDebug() << "Will Try URL: " << url; - - if (m_places[dataKey].territoryName.isEmpty() && m_places[dataKey].cityCode.isEmpty()) { - setData(source, "validate", QString("envcan|malformed")); - return; - } - - KIO::TransferJob* const newJob = KIO::get(url.url(), KIO::Reload, KIO::HideProgressInfo); - - m_jobXml.insert(newJob, new QXmlStreamReader); - m_jobList.insert(newJob, source); - - connect(newJob, SIGNAL(data(KIO::Job*,QByteArray)), this, - SLOT(slotDataArrived(KIO::Job*,QByteArray))); - connect(newJob, SIGNAL(result(KJob*)), this, SLOT(slotJobFinished(KJob*))); -} - -void EnvCanadaIon::setup_slotDataArrived(KIO::Job *job, const QByteArray &data) -{ - Q_UNUSED(job) - - if (data.isEmpty()) { - //kDebug() << "done!"; - return; - } - - // Send to xml. - //kDebug() << data; - m_xmlSetup.addData(data); -} - -void EnvCanadaIon::slotDataArrived(KIO::Job *job, const QByteArray &data) -{ - - if (data.isEmpty() || !m_jobXml.contains(job)) { - return; - } - - // Send to xml. - m_jobXml[job]->addData(data); -} - -void EnvCanadaIon::slotJobFinished(KJob *job) -{ - // Dual use method, if we're fetching location data to parse we need to do this first - const QString source = m_jobList.value(job); - //kDebug() << source << m_sourcesToReset.contains(source); - setData(source, Data()); - QXmlStreamReader *reader = m_jobXml.value(job); - if (reader) { - readXMLData(m_jobList[job], *reader); - } - - m_jobList.remove(job); - delete m_jobXml[job]; - m_jobXml.remove(job); - - if (m_sourcesToReset.contains(source)) { - m_sourcesToReset.removeAll(source); - - // so the weather engine updates it's data - forceImmediateUpdateOfAllVisualizations(); - - // update the clients of our engine - emit forceUpdate(this, source); - } -} - -void EnvCanadaIon::setup_slotJobFinished(KJob *job) -{ - Q_UNUSED(job) - const bool success = readXMLSetup(); - m_xmlSetup.clear(); - //kDebug() << success << m_sourcesToReset; - setInitialized(success); -} - -// Parse the city list and store into a QMap -bool EnvCanadaIon::readXMLSetup() -{ - bool success = false; - QString territory; - QString code; - QString cityName; - - //kDebug() << "readXMLSetup()"; - - while (!m_xmlSetup.atEnd()) { - m_xmlSetup.readNext(); - - if (m_xmlSetup.isStartElement()) { - - // XML ID code to match filename - if (m_xmlSetup.name() == "site") { - code = m_xmlSetup.attributes().value("code").toString(); - } - - if (m_xmlSetup.name() == "nameEn") { - cityName = m_xmlSetup.readElementText(); // Name of cities - } - - if (m_xmlSetup.name() == "provinceCode") { - territory = m_xmlSetup.readElementText(); // Provinces/Territory list - } - } - - if (m_xmlSetup.isEndElement() && m_xmlSetup.name() == "site") { - EnvCanadaIon::XMLMapInfo info; - QString tmp = cityName + ", " + territory; // Build the key name. - - // Set the mappings - info.cityCode = code; - info.territoryName = territory; - info.cityName = cityName; - - // Set the string list, we will use for the applet to display the available cities. - m_places[tmp] = info; - success = true; - } - - } - - return (success && !m_xmlSetup.error()); -} - -void EnvCanadaIon::parseWeatherSite(WeatherData& data, QXmlStreamReader& xml) -{ - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isStartElement()) { - if (xml.name() == "license") { - xml.readElementText(); - } else if (xml.name() == "location") { - parseLocations(data, xml); - } else if (xml.name() == "warnings") { - // Cleanup warning list on update - data.warnings.clear(); - data.watches.clear(); - parseWarnings(data, xml); - } else if (xml.name() == "currentConditions") { - parseConditions(data, xml); - } else if (xml.name() == "forecastGroup") { - // Clean up forecast list on update - data.forecasts.clear(); - parseWeatherForecast(data, xml); - } else if (xml.name() == "yesterdayConditions") { - parseYesterdayWeather(data, xml); - } else if (xml.name() == "riseSet") { - parseAstronomicals(data, xml); - } else if (xml.name() == "almanac") { - parseWeatherRecords(data, xml); - } else { - parseUnknownElement(xml); - } - } - } -} - -// Parse Weather data main loop, from here we have to decend into each tag pair -bool EnvCanadaIon::readXMLData(const QString& source, QXmlStreamReader& xml) -{ - WeatherData data; - data.comforttemp = i18n("N/A"); - data.recordHigh = 0.0; - data.recordLow = 0.0; - - //kDebug() << "readXMLData()"; - - QString dataKey = source; - dataKey.remove("envcan|weather|"); - data.shortTerritoryName = m_places[dataKey].territoryName; - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "siteData") { - parseWeatherSite(data, xml); - } else { - parseUnknownElement(xml); - } - } - } - - m_weatherData[source] = data; - updateWeather(source); - return !xml.error(); -} - -void EnvCanadaIon::parseDateTime(WeatherData& data, QXmlStreamReader& xml, WeatherData::WeatherEvent *event) -{ - - Q_ASSERT(xml.isStartElement() && xml.name() == "dateTime"); - - // What kind of date info is this? - QString dateType = xml.attributes().value("name").toString(); - QString dateZone = xml.attributes().value("zone").toString(); - - QString selectTimeStamp; - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (dateType == "xmlCreation") { - return; - } - if (dateZone == "UTC") { - return; - } - if (xml.name() == "year") { - xml.readElementText(); - } else if (xml.name() == "month") { - xml.readElementText(); - } else if (xml.name() == "day") { - xml.readElementText(); - } else if (xml.name() == "hour") - xml.readElementText(); - else if (xml.name() == "minute") - xml.readElementText(); - else if (xml.name() == "timeStamp") - selectTimeStamp = xml.readElementText(); - else if (xml.name() == "textSummary") { - if (dateType == "eventIssue") { - if (event) { - event->timestamp = xml.readElementText(); - } - } else if (dateType == "observation") { - xml.readElementText(); - m_dateFormat = QDateTime::fromString(selectTimeStamp, "yyyyMMddHHmmss"); - data.obsTimestamp = m_dateFormat.toString("dd.MM.yyyy @ hh:mm"); - data.iconPeriodHour = m_dateFormat.toString("hh").toInt(); - data.iconPeriodMinute = m_dateFormat.toString("mm").toInt(); - } else if (dateType == "forecastIssue") { - data.forecastTimestamp = xml.readElementText(); - } else if (dateType == "sunrise") { - data.sunriseTimestamp = xml.readElementText(); - } else if (dateType == "sunset") { - data.sunsetTimestamp = xml.readElementText(); - } else if (dateType == "moonrise") { - data.moonriseTimestamp = xml.readElementText(); - } else if (dateType == "moonset") { - data.moonsetTimestamp = xml.readElementText(); - } - } - } - } -} - -void EnvCanadaIon::parseLocations(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "location"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "country") { - data.countryName = xml.readElementText(); - } else if (xml.name() == "province" || xml.name() == "territory") { - data.longTerritoryName = xml.readElementText(); - } else if (xml.name() == "name") { - data.cityName = xml.readElementText(); - } else if (xml.name() == "region") { - data.regionName = xml.readElementText(); - } else { - parseUnknownElement(xml); - } - } - } -} - -void EnvCanadaIon::parseWindInfo(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "wind"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "speed") { - data.windSpeed = xml.readElementText(); - } else if (xml.name() == "gust") { - data.windGust = xml.readElementText(); - } else if (xml.name() == "direction") { - data.windDirection = xml.readElementText(); - } else if (xml.name() == "bearing") { - data.windDegrees = xml.attributes().value("degrees").toString(); - } else { - parseUnknownElement(xml); - } - } - } -} - -void EnvCanadaIon::parseConditions(WeatherData& data, QXmlStreamReader& xml) -{ - - Q_ASSERT(xml.isStartElement() && xml.name() == "currentConditions"); - data.temperature = i18n("N/A"); - data.dewpoint = i18n("N/A"); - data.condition = i18n("N/A"); - data.comforttemp = i18n("N/A"); - data.stationID = i18n("N/A"); - data.stationLat = i18n("N/A"); - data.stationLon = i18n("N/A"); - data.pressure = 0.0; - data.pressureTendency = i18n("N/A"); - data.visibility = 0; - data.humidity = i18n("N/A"); - data.windSpeed = i18n("N/A"); - data.windGust = i18n("N/A"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "currentConditions") - break; - - if (xml.isStartElement()) { - if (xml.name() == "station") { - data.stationID = xml.attributes().value("code").toString(); - data.stationLat = xml.attributes().value("lat").toString(); - data.stationLon = xml.attributes().value("lon").toString(); - } else if (xml.name() == "dateTime") { - parseDateTime(data, xml); - } else if (xml.name() == "condition") { - data.condition = xml.readElementText(); - } else if (xml.name() == "temperature") { - data.temperature = xml.readElementText(); - } else if (xml.name() == "dewpoint") { - data.dewpoint = xml.readElementText(); - } else if (xml.name() == "humidex" || xml.name() == "windChill") { - data.comforttemp = xml.readElementText(); - } else if (xml.name() == "pressure") { - data.pressureTendency = xml.attributes().value("tendency").toString(); - if (data.pressureTendency.isEmpty()) { - data.pressureTendency = "steady"; - } - data.pressure = xml.readElementText().toFloat(); - } else if (xml.name() == "visibility") { - data.visibility = xml.readElementText().toFloat(); - } else if (xml.name() == "relativeHumidity") { - data.humidity = xml.readElementText(); - } else if (xml.name() == "wind") { - parseWindInfo(data, xml); - } - //} else { - // parseUnknownElement(xml); - //} - } - } - if (data.temperature.isEmpty()) { - data.temperature = i18n("N/A"); - } -} - -void EnvCanadaIon::parseWarnings(WeatherData &data, QXmlStreamReader& xml) -{ - WeatherData::WeatherEvent *watch = new WeatherData::WeatherEvent; - WeatherData::WeatherEvent *warning = new WeatherData::WeatherEvent; - - Q_ASSERT(xml.isStartElement() && xml.name() == "warnings"); - QString eventURL = xml.attributes().value("url").toString(); - int flag = 0; - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "warnings") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "dateTime") { - if (flag == 1) { - parseDateTime(data, xml, watch); - } - if (flag == 2) { - parseDateTime(data, xml, warning); - } - - if (!warning->timestamp.isEmpty() && !warning->url.isEmpty()) { - data.warnings.append(warning); - warning = new WeatherData::WeatherEvent; - } - if (!watch->timestamp.isEmpty() && !watch->url.isEmpty()) { - data.watches.append(watch); - watch = new WeatherData::WeatherEvent; - } - - } else if (xml.name() == "event") { - // Append new event to list. - QString eventType = xml.attributes().value("type").toString(); - if (eventType == "watch") { - watch->url = eventURL; - watch->type = eventType; - watch->priority = xml.attributes().value("priority").toString(); - watch->description = xml.attributes().value("description").toString(); - flag = 1; - } - - if (eventType == "warning") { - warning->url = eventURL; - warning->type = eventType; - warning->priority = xml.attributes().value("priority").toString(); - warning->description = xml.attributes().value("description").toString(); - flag = 2; - } - } else { - if (xml.name() != "dateTime") { - parseUnknownElement(xml); - } - } - } - } - delete watch; - delete warning; -} - - -void EnvCanadaIon::parseWeatherForecast(WeatherData& data, QXmlStreamReader& xml) -{ - WeatherData::ForecastInfo* forecast = new WeatherData::ForecastInfo; - Q_ASSERT(xml.isStartElement() && xml.name() == "forecastGroup"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "forecastGroup") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "dateTime") { - parseDateTime(data, xml); - } else if (xml.name() == "regionalNormals") { - parseRegionalNormals(data, xml); - } else if (xml.name() == "forecast") { - parseForecast(data, xml, forecast); - forecast = new WeatherData::ForecastInfo; - } else { - parseUnknownElement(xml); - } - } - } - delete forecast; -} - -void EnvCanadaIon::parseRegionalNormals(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "regionalNormals"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "textSummary") { - xml.readElementText(); - } else if (xml.name() == "temperature" && xml.attributes().value("class") == "high") { - data.normalHigh = xml.readElementText(); - } else if (xml.name() == "temperature" && xml.attributes().value("class") == "low") { - data.normalLow = xml.readElementText(); - } - } - } -} - -void EnvCanadaIon::parseForecast(WeatherData& data, QXmlStreamReader& xml, WeatherData::ForecastInfo *forecast) -{ - - Q_ASSERT(xml.isStartElement() && xml.name() == "forecast"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "forecast") { - data.forecasts.append(forecast); - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "period") { - forecast->forecastPeriod = xml.attributes().value("textForecastName").toString(); - } else if (xml.name() == "textSummary") { - forecast->forecastSummary = xml.readElementText(); - } else if (xml.name() == "abbreviatedForecast") { - parseShortForecast(forecast, xml); - } else if (xml.name() == "temperatures") { - parseForecastTemperatures(forecast, xml); - } else if (xml.name() == "winds") { - parseWindForecast(forecast, xml); - } else if (xml.name() == "precipitation") { - parsePrecipitationForecast(forecast, xml); - } else if (xml.name() == "uv") { - data.UVRating = xml.attributes().value("category").toString(); - parseUVIndex(data, xml); - // else if (xml.name() == "frost") { FIXME: Wait until winter to see what this looks like. - // parseFrost(xml, forecast); - } else { - if (xml.name() != "forecast") { - parseUnknownElement(xml); - } - } - } - } -} - -void EnvCanadaIon::parseShortForecast(WeatherData::ForecastInfo *forecast, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "abbreviatedForecast"); - - QString shortText; - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "abbreviatedForecast") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "pop") { - forecast->popPrecent = xml.readElementText(); - } - if (xml.name() == "textSummary") { - shortText = xml.readElementText(); - QMap forecastList; - forecastList = forecastIcons(); - if ((forecast->forecastPeriod == "tonight") || (forecast->forecastPeriod.contains("night"))) { - forecastList["a few clouds"] = FewCloudsNight; - forecastList["cloudy periods"] = PartlyCloudyNight; - forecastList["chance of drizzle mixed with rain"] = ChanceShowersNight; - forecastList["chance of drizzle"] = ChanceShowersNight; - forecastList["chance of drizzle or rain"] = ChanceShowersNight; - forecastList["chance of flurries"] = ChanceSnowNight; - forecastList["chance of light snow"] = ChanceSnowNight; - forecastList["chance of flurries at times heavy"] = ChanceSnowNight; - forecastList["chance of showers or drizzle"] = ChanceShowersNight; - forecastList["chance of showers"] = ChanceShowersNight; - forecastList["clearing"] = ClearNight; - } else { - forecastList["a few clouds"] = FewCloudsDay; - forecastList["cloudy periods"] = PartlyCloudyDay; - forecastList["chance of drizzle mixed with rain"] = ChanceShowersDay; - forecastList["chance of drizzle"] = ChanceShowersDay; - forecastList["chance of drizzle or rain"] = ChanceShowersDay; - forecastList["chance of flurries"] = ChanceSnowDay; - forecastList["chance of light snow"] = ChanceSnowDay; - forecastList["chance of flurries at times heavy"] = ChanceSnowDay; - forecastList["chance of showers or drizzle"] = ChanceShowersDay; - forecastList["chance of showers"] = ChanceShowersDay; - forecastList["clearing"] = ClearDay; - } - forecast->shortForecast = shortText; - forecast->iconName = getWeatherIcon(forecastList, shortText.toLower()); - } - } - } -} - -void EnvCanadaIon::parseUVIndex(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "uv"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "uv") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "index") { - data.UVIndex = xml.readElementText(); - } - if (xml.name() == "textSummary") { - xml.readElementText(); - } - } - } -} - -void EnvCanadaIon::parseForecastTemperatures(WeatherData::ForecastInfo *forecast, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "temperatures"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "temperatures") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "temperature" && xml.attributes().value("class") == "low") { - forecast->forecastTempLow = xml.readElementText(); - } else if (xml.name() == "temperature" && xml.attributes().value("class") == "high") { - forecast->forecastTempHigh = xml.readElementText(); - } else if (xml.name() == "textSummary") { - xml.readElementText(); - } - } - } -} - -void EnvCanadaIon::parsePrecipitationForecast(WeatherData::ForecastInfo *forecast, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "precipitation"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "precipitation") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "textSummary") { - forecast->precipForecast = xml.readElementText(); - } else if (xml.name() == "precipType") { - forecast->precipType = xml.readElementText(); - } else if (xml.name() == "accumulation") { - parsePrecipTotals(forecast, xml); - } - } - } -} - -void EnvCanadaIon::parsePrecipTotals(WeatherData::ForecastInfo *forecast, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "accumulation"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "accumulation") { - break; - } - - if (xml.name() == "name") { - xml.readElementText(); - } else if (xml.name() == "amount") { - forecast->precipTotalExpected = xml.readElementText(); - } - } -} - -void EnvCanadaIon::parseWindForecast(WeatherData::ForecastInfo *forecast, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "winds"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "winds") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "textSummary") { - forecast->windForecast = xml.readElementText(); - } else { - if (xml.name() != "winds") { - parseUnknownElement(xml); - } - } - } - } -} - -void EnvCanadaIon::parseYesterdayWeather(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "yesterdayConditions"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "temperature" && xml.attributes().value("class") == "high") { - data.prevHigh = xml.readElementText(); - } else if (xml.name() == "temperature" && xml.attributes().value("class") == "low") { - data.prevLow = xml.readElementText(); - } else if (xml.name() == "precip") { - data.prevPrecipType = xml.attributes().value("units").toString(); - if (data.prevPrecipType.isEmpty()) { - data.prevPrecipType = QString::number(KUnitConversion::NoUnit); - } - data.prevPrecipTotal = xml.readElementText(); - } - } - } -} - -void EnvCanadaIon::parseWeatherRecords(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "almanac"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "almanac") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "temperature" && xml.attributes().value("class") == "extremeMax") { - data.recordHigh = xml.readElementText().toFloat(); - } else if (xml.name() == "temperature" && xml.attributes().value("class") == "extremeMin") { - data.recordLow = xml.readElementText().toFloat(); - } else if (xml.name() == "precipitation" && xml.attributes().value("class") == "extremeRainfall") { - data.recordRain = xml.readElementText().toFloat(); - } else if (xml.name() == "precipitation" && xml.attributes().value("class") == "extremeSnowfall") { - data.recordSnow = xml.readElementText().toFloat(); - } - } - } -} - -void EnvCanadaIon::parseAstronomicals(WeatherData& data, QXmlStreamReader& xml) -{ - Q_ASSERT(xml.isStartElement() && xml.name() == "riseSet"); - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement() && xml.name() == "riseSet") { - break; - } - - if (xml.isStartElement()) { - if (xml.name() == "disclaimer") { - xml.readElementText(); - } else if (xml.name() == "dateTime") { - parseDateTime(data, xml); - } - } - } -} - -// handle when no XML tag is found -void EnvCanadaIon::parseUnknownElement(QXmlStreamReader& xml) const -{ - - while (!xml.atEnd()) { - xml.readNext(); - - if (xml.isEndElement()) { - break; - } - - if (xml.isStartElement()) { - parseUnknownElement(xml); - } - } -} - -void EnvCanadaIon::updateWeather(const QString& source) -{ - //kDebug() << "updateWeather()"; - - QMap dataFields; - Plasma::DataEngine::Data data; - QStringList fieldList; - QVector forecastList; - int i = 0; - - data.insert("Country", country(source)); - data.insert("Place", QString("%1, %2").arg(city(source)).arg(territory(source))); - data.insert("Region", region(source)); - data.insert("Station", station(source)); - - data.insert("Latitude", latitude(source)); - data.insert("Longitude", longitude(source)); - - // Real weather - Current conditions - data.insert("Observation Period", observationTime(source)); - data.insert("Current Conditions", i18nc("weather condition", condition(source).toUtf8())); - //kDebug() << "i18n condition string: " << qPrintable(condition(source)); - - // Tell applet which icon to use for conditions and provide mapping for condition type to the icons to display - QMap conditionList; - conditionList = conditionIcons(); - - const double lati = latitude(source).replace(QRegExp("[^0-9.]"), QString()).toDouble(); - const double longi = longitude(source).replace(QRegExp("[^0-9.]"), QString()).toDouble(); - const Plasma::DataEngine::Data timeData = m_timeEngine->query( - QString("Local|Solar|Latitude=%1|Longitude=%2") - .arg(lati).arg(-1 * longi)); - - if (timeData["Corrected Elevation"].toDouble() < 0.0) { - conditionList["decreasing cloud"] = FewCloudsNight; - conditionList["mostly cloudy"] = PartlyCloudyNight; - conditionList["partly cloudy"] = PartlyCloudyNight; - conditionList["fair"] = FewCloudsNight; - //kDebug() << "Before sunrise/After sunset - using night icons\n"; - } else { - conditionList["decreasing cloud"] = FewCloudsDay; - conditionList["mostly cloudy"] = PartlyCloudyDay; - conditionList["partly cloudy"] = PartlyCloudyDay; - conditionList["fair"] = FewCloudsDay; - //kDebug() << "Using daytime icons\n"; - } - - data.insert("Condition Icon", getWeatherIcon(conditionList, condition(source))); - - dataFields = temperature(source); - data.insert("Temperature", dataFields["temperature"]); - - // Do we have a comfort temperature? if so display it - if (dataFields["comfortTemperature"] != "N/A" && !dataFields["comfortTemperature"].isEmpty()) { - if (dataFields["comfortTemperature"].toFloat() <= 0) { - data.insert("Windchill", QString("%1").arg(dataFields["comfortTemperature"])); - data.insert("Humidex", i18n("N/A")); - } else { - data.insert("Humidex", QString("%1").arg(dataFields["comfortTemperature"])); - data.insert("Windchill", i18n("N/A")); - } - } else { - data.insert("Windchill", i18n("N/A")); - data.insert("Humidex", i18n("N/A")); - } - - // Used for all temperatures - data.insert("Temperature Unit", dataFields["temperatureUnit"]); - - data.insert("Dewpoint", dewpoint(source)); - - dataFields = pressure(source); - data.insert("Pressure", dataFields["pressure"]); - data.insert("Pressure Unit", dataFields["pressureUnit"]); - data.insert("Pressure Tendency", dataFields["pressureTendency"]); - - dataFields = visibility(source); - data.insert("Visibility", dataFields["visibility"]); - data.insert("Visibility Unit", dataFields["visibilityUnit"]); - - dataFields = humidity(source); - data.insert("Humidity", dataFields["humidity"]); - data.insert("Humidity Unit", dataFields["humidityUnit"]); - - dataFields = wind(source); - data.insert("Wind Speed", dataFields["windSpeed"]); - data.insert("Wind Speed Unit", dataFields["windUnit"]); - - data.insert("Wind Gust", dataFields["windGust"]); - data.insert("Wind Direction", dataFields["windDirection"]); - data.insert("Wind Degrees", dataFields["windDegrees"]); - data.insert("Wind Gust Unit", dataFields["windGustUnit"]); - - dataFields = regionalTemperatures(source); - data.insert("Normal High", dataFields["normalHigh"]); - data.insert("Normal Low", dataFields["normalLow"]); - - // Check if UV index is available for the location - dataFields = uvIndex(source); - data.insert("UV Index", dataFields["uvIndex"]); - data.insert("UV Rating", dataFields["uvRating"]); - - dataFields = watches(source); - - // Set number of forecasts per day/night supported - data.insert("Total Watches Issued", m_weatherData[source].watches.size()); - - // Check if we have warnings or watches - for (int i = 0; i < m_weatherData[source].watches.size(); i++) { - fieldList = dataFields[QString("watch %1").arg(i)].split('|'); - data.insert(QString("Watch Priority %1").arg(i), fieldList[0]); - data.insert(QString("Watch Description %1").arg(i), fieldList[1]); - data.insert(QString("Watch Info %1").arg(i), fieldList[2]); - data.insert(QString("Watch Timestamp %1").arg(i), fieldList[3]); - } - - dataFields = warnings(source); - - data.insert("Total Warnings Issued", m_weatherData[source].warnings.size()); - - for (int k = 0; k < m_weatherData[source].warnings.size(); k++) { - fieldList = dataFields[QString("warning %1").arg(k)].split('|'); - data.insert(QString("Warning Priority %1").arg(k), fieldList[0]); - data.insert(QString("Warning Description %1").arg(k), fieldList[1]); - data.insert(QString("Warning Info %1").arg(k), fieldList[2]); - data.insert(QString("Warning Timestamp %1").arg(k), fieldList[3]); - } - - forecastList = forecasts(source); - - // Set number of forecasts per day/night supported - data.insert("Total Weather Days", m_weatherData[source].forecasts.size()); - - foreach(const QString &forecastItem, forecastList) { - fieldList = forecastItem.split('|'); - - data.insert(QString("Short Forecast Day %1").arg(i), QString("%1|%2|%3|%4|%5|%6") \ - .arg(fieldList[0]).arg(fieldList[1]).arg(fieldList[2]).arg(fieldList[3]).arg(fieldList[4]).arg(fieldList[5])); - - /* - data.insert(QString("Long Forecast Day %1").arg(i), QString("%1|%2|%3|%4|%5|%6|%7|%8") \ - .arg(fieldList[0]).arg(fieldList[2]).arg(fieldList[3]).arg(fieldList[4]).arg(fieldList[6]) \ - .arg(fieldList[7]).arg(fieldList[8]).arg(fieldList[9])); - */ - i++; - } - - dataFields = yesterdayWeather(source); - data.insert("Yesterday High", dataFields["prevHigh"]); - data.insert("Yesterday Low", dataFields["prevLow"]); - - data.insert("Yesterday Precip Total", dataFields["prevPrecip"]); - data.insert("Yesterday Precip Unit", dataFields["prevPrecipUnit"]); - - dataFields = sunriseSet(source); - data.insert("Sunrise At", dataFields["sunrise"]); - data.insert("Sunset At", dataFields["sunset"]); - - dataFields = moonriseSet(source); - data.insert("Moonrise At", dataFields["moonrise"]); - data.insert("Moonset At", dataFields["moonset"]); - - dataFields = weatherRecords(source); - data.insert("Record High Temperature", dataFields["recordHigh"]); - data.insert("Record Low Temperature", dataFields["recordLow"]); - - data.insert("Record Rainfall", dataFields["recordRain"]); - data.insert("Record Rainfall Unit", dataFields["recordRainUnit"]); - data.insert("Record Snowfall", dataFields["recordSnow"]); - data.insert("Record Snowfall Unit", dataFields["recordSnowUnit"]); - - data.insert("Credit", i18n("Meteorological data is provided by Environment Canada")); - setData(source, data); -} - -QString const EnvCanadaIon::country(const QString& source) const -{ - // This will always return Canada - return m_weatherData[source].countryName; -} - -QString EnvCanadaIon::territory(const QString& source) const -{ - return m_weatherData[source].shortTerritoryName; -} - -QString EnvCanadaIon::city(const QString& source) const -{ - return m_weatherData[source].cityName; -} - -QString EnvCanadaIon::region(const QString& source) const -{ - return m_weatherData[source].regionName; -} - -QString EnvCanadaIon::station(const QString& source) const -{ - if (!m_weatherData[source].stationID.isEmpty()) { - return m_weatherData[source].stationID.toUpper(); - } - - return i18n("N/A"); -} - -QString EnvCanadaIon::latitude(const QString& source) const -{ - return m_weatherData[source].stationLat; -} - -QString EnvCanadaIon::longitude(const QString& source) const -{ - return m_weatherData[source].stationLon; -} - -QString EnvCanadaIon::observationTime(const QString& source) const -{ - return m_weatherData[source].obsTimestamp; -} - -int EnvCanadaIon::periodHour(const QString& source) const -{ - return m_weatherData[source].iconPeriodHour; -} - -int EnvCanadaIon::periodMinute(const QString& source) const -{ - return m_weatherData[source].iconPeriodMinute; -} - -QString EnvCanadaIon::condition(const QString& source) -{ - if (m_weatherData[source].condition.isEmpty()) { - m_weatherData[source].condition = i18n("N/A"); - } - return (m_weatherData[source].condition.toUtf8()); -} - -QString EnvCanadaIon::dewpoint(const QString& source) const -{ - if (!m_weatherData[source].dewpoint.isEmpty()) { - return (QString::number(m_weatherData[source].dewpoint.toFloat(), 'f', 1)); - } - return i18n("N/A"); -} - -QMap EnvCanadaIon::humidity(const QString& source) const -{ - QMap humidityInfo; - if (!m_weatherData[source].humidity.isEmpty()) { - humidityInfo.insert("humidity", m_weatherData[source].humidity); - humidityInfo.insert("humidityUnit", QString::number(KUnitConversion::Percent)); - } else { - humidityInfo.insert("humidity", i18n("N/A")); - humidityInfo.insert("humidityUnit", QString::number(KUnitConversion::NoUnit)); - } - return humidityInfo; -} - -QMap EnvCanadaIon::visibility(const QString& source) const -{ - QMap visibilityInfo; - - if (m_weatherData[source].visibility != 0) { - visibilityInfo.insert("visibility", QString::number(m_weatherData[source].visibility, 'f', 1)); - visibilityInfo.insert("visibilityUnit", QString::number(KUnitConversion::Kilometer)); - } else { - visibilityInfo.insert("visibility", i18n("N/A")); - visibilityInfo.insert("visibilityUnit", QString::number(KUnitConversion::NoUnit)); - } - return visibilityInfo; -} - -QMap EnvCanadaIon::temperature(const QString& source) const -{ - QMap temperatureInfo; - if (!m_weatherData[source].temperature.isEmpty()) { - temperatureInfo.insert("temperature", QString::number(m_weatherData[source].temperature.toFloat(), 'f', 1)); - } - - if (m_weatherData[source].temperature == i18n("N/A")) { - temperatureInfo.insert("temperature", i18n("N/A")); - } - - temperatureInfo.insert("comfortTemperature", i18n("N/A")); - - if (m_weatherData[source].comforttemp != i18n("N/A")) { - temperatureInfo.insert("comfortTemperature", m_weatherData[source].comforttemp); - } - - // This is used for not just current temperature but also 8 days. Cannot be NoUnit. - temperatureInfo.insert("temperatureUnit", QString::number(KUnitConversion::Celsius)); - return temperatureInfo; -} - -QMap EnvCanadaIon::watches(const QString& source) const -{ - QMap watchData; - QString watchType; - for (int i = 0; i < m_weatherData[source].watches.size(); ++i) { - watchType = QString("watch %1").arg(i); - watchData[watchType] = QString("%1|%2|%3|%4").arg(m_weatherData[source].watches[i]->priority) \ - .arg(m_weatherData[source].watches[i]->description) \ - .arg(m_weatherData[source].watches[i]->url) \ - .arg(m_weatherData[source].watches[i]->timestamp); - } - return watchData; -} - -QMap EnvCanadaIon::warnings(const QString& source) const -{ - QMap warningData; - QString warnType; - for (int i = 0; i < m_weatherData[source].warnings.size(); ++i) { - warnType = QString("warning %1").arg(i); - warningData[warnType] = QString("%1|%2|%3|%4").arg(m_weatherData[source].warnings[i]->priority) \ - .arg(m_weatherData[source].warnings[i]->description) \ - .arg(m_weatherData[source].warnings[i]->url) \ - .arg(m_weatherData[source].warnings[i]->timestamp); - } - return warningData; -} - -QVector EnvCanadaIon::forecasts(const QString& source) -{ - QVector forecastData; - - // Do some checks for empty data - for (int i = 0; i < m_weatherData[source].forecasts.size(); ++i) { - if (m_weatherData[source].forecasts[i]->forecastPeriod.isEmpty()) { - m_weatherData[source].forecasts[i]->forecastPeriod = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->shortForecast.isEmpty()) { - m_weatherData[source].forecasts[i]->shortForecast = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->iconName.isEmpty()) { - m_weatherData[source].forecasts[i]->iconName = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->forecastSummary.isEmpty()) { - m_weatherData[source].forecasts[i]->forecastSummary = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->forecastTempHigh.isEmpty()) { - m_weatherData[source].forecasts[i]->forecastTempHigh = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->forecastTempLow.isEmpty()) { - m_weatherData[source].forecasts[i]->forecastTempLow = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->popPrecent.isEmpty()) { - m_weatherData[source].forecasts[i]->popPrecent = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->windForecast.isEmpty()) { - m_weatherData[source].forecasts[i]->windForecast = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->precipForecast.isEmpty()) { - m_weatherData[source].forecasts[i]->precipForecast = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->precipType.isEmpty()) { - m_weatherData[source].forecasts[i]->precipType = i18n("N/A"); - } - if (m_weatherData[source].forecasts[i]->precipTotalExpected.isEmpty()) { - m_weatherData[source].forecasts[i]->precipTotalExpected = i18n("N/A"); - } - } - - for (int i = 0; i < m_weatherData[source].forecasts.size(); ++i) { - // We need to shortform the day/night strings. - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Today")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Today", i18n("day")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Tonight")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Tonight", i18nc("Short for tonight", "nite")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("night")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("night", i18nc("Short for night, appended to the end of the weekday", "nt")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Saturday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Saturday", i18nc("Short for Saturday", "Sat")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Sunday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Sunday", i18nc("Short for Sunday", "Sun")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Monday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Monday", i18nc("Short for Monday", "Mon")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Tuesday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Tuesday", i18nc("Short for Tuesday", "Tue")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Wednesday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Wednesday", i18nc("Short for Wednesday", "Wed")); - } - - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Thursday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Thursday", i18nc("Short for Thursday", "Thu")); - } - if (m_weatherData[source].forecasts[i]->forecastPeriod.contains("Friday")) { - m_weatherData[source].forecasts[i]->forecastPeriod.replace("Friday", i18nc("Short for Friday", "Fri")); - } - - forecastData.append(QString("%1|%2|%3|%4|%5|%6") \ - .arg(m_weatherData[source].forecasts[i]->forecastPeriod) \ - .arg(m_weatherData[source].forecasts[i]->iconName) \ - .arg(i18nc("weather forecast", m_weatherData[source].forecasts[i]->shortForecast.toUtf8())) \ - .arg(m_weatherData[source].forecasts[i]->forecastTempHigh) \ - .arg(m_weatherData[source].forecasts[i]->forecastTempLow) \ - .arg(m_weatherData[source].forecasts[i]->popPrecent)); - //kDebug() << "i18n summary string: " << qPrintable(i18n(m_weatherData[source].forecasts[i]->shortForecast.toUtf8())); - } - return forecastData; -} - -QMap EnvCanadaIon::pressure(const QString& source) const -{ - QMap pressureInfo; - - if (m_weatherData[source].pressure == 0) { - pressureInfo.insert("pressure", i18n("N/A")); - pressureInfo.insert("pressureUnit", QString::number(KUnitConversion::NoUnit)); - pressureInfo.insert("pressureTendency", "N/A"); - } else { - pressureInfo.insert("pressure", QString::number(m_weatherData[source].pressure, 'f', 1)); - pressureInfo.insert("pressureUnit", QString::number(KUnitConversion::Kilopascal)); - pressureInfo.insert("pressureTendency", i18nc("pressure tendency", m_weatherData[source].pressureTendency.toUtf8())); - } - return pressureInfo; -} - -QMap EnvCanadaIon::wind(const QString& source) const -{ - QMap windInfo; - - // May not have any winds - if (m_weatherData[source].windSpeed.isEmpty()) { - windInfo.insert("windSpeed", i18n("N/A")); - windInfo.insert("windUnit", QString::number(KUnitConversion::NoUnit)); - } else if (m_weatherData[source].windSpeed.toInt() == 0) { - windInfo.insert("windSpeed", i18nc("wind speed", "Calm")); - windInfo.insert("windUnit", QString::number(KUnitConversion::NoUnit)); - } else { - windInfo.insert("windSpeed", QString::number(m_weatherData[source].windSpeed.toInt())); - windInfo.insert("windUnit", QString::number(KUnitConversion::KilometerPerHour)); - } - - // May not always have gusty winds - if (m_weatherData[source].windGust.isEmpty() || m_weatherData[source].windGust == 0) { - windInfo.insert("windGust", i18n("N/A")); - windInfo.insert("windGustUnit", QString::number(KUnitConversion::NoUnit)); - } else { - windInfo.insert("windGust", QString::number(m_weatherData[source].windGust.toInt())); - windInfo.insert("windGustUnit", QString::number(KUnitConversion::KilometerPerHour)); - } - - if (m_weatherData[source].windDirection.isEmpty() && m_weatherData[source].windSpeed.isEmpty()) { - windInfo.insert("windDirection", i18n("N/A")); - windInfo.insert("windDegrees", i18n("N/A")); - } else if (m_weatherData[source].windSpeed.toInt() == 0) { - windInfo.insert("windDirection", i18nc("wind direction - wind speed is too low to measure", "VR")); // Variable/calm - } else { - windInfo.insert("windDirection", i18nc("wind direction", m_weatherData[source].windDirection.toUtf8())); - windInfo.insert("windDegrees", m_weatherData[source].windDegrees); - } - return windInfo; -} - -QMap EnvCanadaIon::uvIndex(const QString& source) const -{ - QMap uvInfo; - - if (m_weatherData[source].UVRating.isEmpty()) { - uvInfo.insert("uvRating", i18n("N/A")); - } else { - uvInfo.insert("uvRating", m_weatherData[source].UVRating); - } - - if (m_weatherData[source].UVIndex.isEmpty()) { - uvInfo.insert("uvIndex", i18n("N/A")); - } else { - uvInfo.insert("uvIndex", m_weatherData[source].UVIndex); - } - - return uvInfo; -} - -QMap EnvCanadaIon::regionalTemperatures(const QString& source) const -{ - QMap regionalTempInfo; - - if (m_weatherData[source].normalHigh.isEmpty()) { - regionalTempInfo.insert("normalHigh", i18n("N/A")); - } else { - regionalTempInfo.insert("normalHigh", m_weatherData[source].normalHigh); - } - - if (m_weatherData[source].normalLow.isEmpty()) { - regionalTempInfo.insert("normalLow", i18n("N/A")); - } else { - regionalTempInfo.insert("normalLow", m_weatherData[source].normalLow); - } - - return regionalTempInfo; -} - -QMap EnvCanadaIon::yesterdayWeather(const QString& source) const -{ - QMap yesterdayInfo; - - if (m_weatherData[source].prevHigh.isEmpty()) { - yesterdayInfo.insert("prevHigh", i18n("N/A")); - } else { - yesterdayInfo.insert("prevHigh", m_weatherData[source].prevHigh); - } - - if (m_weatherData[source].prevLow.isEmpty()) { - yesterdayInfo.insert("prevLow", i18n("N/A")); - } else { - yesterdayInfo.insert("prevLow", m_weatherData[source].prevLow); - } - - if (m_weatherData[source].prevPrecipTotal == "Trace") { - yesterdayInfo.insert("prevPrecip", i18nc("precipitation total, very little", "Trace")); - return yesterdayInfo; - } - - if (m_weatherData[source].prevPrecipTotal.isEmpty()) { - yesterdayInfo.insert("prevPrecip", i18n("N/A")); - yesterdayInfo.insert("prevPrecipUnit", QString::number(KUnitConversion::NoUnit)); - } else { - yesterdayInfo.insert("prevPrecipTotal", m_weatherData[source].prevPrecipTotal); - if (m_weatherData[source].prevPrecipType == "mm") { - yesterdayInfo.insert("prevPrecipUnit", QString::number(KUnitConversion::Millimeter)); - } else if (m_weatherData[source].prevPrecipType == "cm") { - yesterdayInfo.insert("prevPrecipUnit", QString::number(KUnitConversion::Centimeter)); - } else { - yesterdayInfo.insert("prevPrecipUnit", QString::number(KUnitConversion::NoUnit)); - } - } - - return yesterdayInfo; -} - -QMap EnvCanadaIon::sunriseSet(const QString& source) const -{ - QMap sunInfo; - - if (m_weatherData[source].sunriseTimestamp.isEmpty()) { - sunInfo.insert("sunrise", i18n("N/A")); - } else { - sunInfo.insert("sunrise", m_weatherData[source].sunriseTimestamp); - } - - if (m_weatherData[source].sunsetTimestamp.isEmpty()) { - sunInfo.insert("sunset", i18n("N/A")); - } else { - sunInfo.insert("sunset", m_weatherData[source].sunsetTimestamp); - } - - return sunInfo; -} - -QMap EnvCanadaIon::moonriseSet(const QString& source) const -{ - QMap moonInfo; - - if (m_weatherData[source].moonriseTimestamp.isEmpty()) { - moonInfo.insert("moonrise", i18n("N/A")); - } else { - moonInfo.insert("moonrise", m_weatherData[source].moonriseTimestamp); - } - - if (m_weatherData[source].moonsetTimestamp.isEmpty()) { - moonInfo.insert("moonset", i18n("N/A")); - } else { - moonInfo.insert("moonset", m_weatherData[source].moonsetTimestamp); - } - - return moonInfo; -} - -QMap EnvCanadaIon::weatherRecords(const QString& source) const -{ - QMap recordInfo; - - if (m_weatherData[source].recordHigh == 0) { - recordInfo.insert("recordHigh", i18n("N/A")); - } else { - recordInfo.insert("recordHigh", QString("%1").arg(m_weatherData[source].recordHigh)); - } - - if (m_weatherData[source].recordLow == 0) { - recordInfo.insert("recordLow", i18n("N/A")); - } else { - recordInfo.insert("recordLow", QString("%1").arg(m_weatherData[source].recordLow)); - } - - if (m_weatherData[source].recordRain == 0) { - recordInfo.insert("recordRain", i18n("N/A")); - recordInfo.insert("recordRainUnit", QString::number(KUnitConversion::NoUnit)); - } else { - recordInfo.insert("recordRain", QString("%1").arg(m_weatherData[source].recordRain)); - recordInfo.insert("recordRainUnit", QString::number(KUnitConversion::Millimeter)); - } - - if (m_weatherData[source].recordSnow == 0) { - recordInfo.insert("recordSnow", i18n("N/A")); - recordInfo.insert("recordSnowUnit", QString::number(KUnitConversion::NoUnit)); - } else { - recordInfo.insert("recordSnow", QString("%1").arg(m_weatherData[source].recordSnow)); - recordInfo.insert("recordSnowUnit", QString::number(KUnitConversion::Centimeter)); - } - - return recordInfo; -} - -#include "moc_ion_envcan.cpp" diff --git a/plasma/dataengines/weather/ions/envcan/ion_envcan.h b/plasma/dataengines/weather/ions/envcan/ion_envcan.h deleted file mode 100644 index 3e17d60c..00000000 --- a/plasma/dataengines/weather/ions/envcan/ion_envcan.h +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2009 by Shawn Starr * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - ***************************************************************************/ - -/* Ion for Environment Canada XML data */ - -#ifndef ION_ENVCAN_H -#define ION_ENVCAN_H - -#include -#include - -#include -#include - -#include "../ion.h" -#include "../dataengineconsumer.h" - -class KJob; -namespace KIO -{ - class Job; -} // namespace KIO - -class WeatherData -{ - -public: - // WeatherEvent can have more than one, especially in Canada, eh? :) - struct WeatherEvent { - QString url; - QString type; - QString priority; - QString description; - QString timestamp; - }; - - // Five day forecast - struct ForecastInfo { - QString forecastPeriod; - QString forecastSummary; - QString iconName; - QString shortForecast; - - QString forecastTempHigh; - QString forecastTempLow; - QString popPrecent; - QString windForecast; - - QString precipForecast; - QString precipType; - QString precipTotalExpected; - int forecastHumidity; - }; - - QString countryName; - QString longTerritoryName; - QString shortTerritoryName; - QString cityName; - QString regionName; - QString stationID; - QString stationLat; - QString stationLon; - - // Current observation information. - QString obsTimestamp; - - // Icon info to aproximate periods - int iconPeriodHour; - int iconPeriodMinute; - - QString condition; - QString temperature; - QString dewpoint; - - // In winter windchill, in summer, humidex - QString comforttemp; - - float pressure; - QString pressureTendency; - - float visibility; - QString humidity; - - QString windSpeed; - QString windGust; - QString windDirection; - QString windDegrees; - - QVector watches; - QVector warnings; - - QString normalHigh; - QString normalLow; - - QString forecastTimestamp; - - QString UVIndex; - QString UVRating; - - // 5 day Forecast - QVector forecasts; - - // Historical data from previous day. - QString prevHigh; - QString prevLow; - QString prevPrecipType; - QString prevPrecipTotal; - - // Almanac info - QString sunriseTimestamp; - QString sunsetTimestamp; - QString moonriseTimestamp; - QString moonsetTimestamp; - - // Historical Records - float recordHigh; - float recordLow; - float recordRain; - float recordSnow; -}; - -class KDE_EXPORT EnvCanadaIon : public IonInterface, public Plasma::DataEngineConsumer -{ - Q_OBJECT - -public: - EnvCanadaIon(QObject *parent, const QVariantList &args); - ~EnvCanadaIon(); - bool updateIonSource(const QString& source); // Sync data source with Applet - void updateWeather(const QString& source); - -public Q_SLOTS: - virtual void reset(); - -protected: - void init(); // Setup the city location, fetching the correct URL name. - -protected Q_SLOTS: - void setup_slotDataArrived(KIO::Job *, const QByteArray &); - void setup_slotJobFinished(KJob *); - - void slotDataArrived(KIO::Job *, const QByteArray &); - void slotJobFinished(KJob *); - -private: - /* Environment Canada Methods - Internal for Ion */ - void deleteForecasts(); - - QMap setupConditionIconMappings(void) const; - QMap setupForecastIconMappings(void) const; - - QMap const& conditionIcons(void) const; - QMap const& forecastIcons(void) const; - - // Place information - QString const country(const QString& source) const; - QString territory(const QString& source) const; - QString city(const QString& source) const; - QString region(const QString& source) const; - QString station(const QString& source) const; - QString latitude(const QString& source) const; - QString longitude(const QString& source) const; - - // Current Conditions Weather info - QString observationTime(const QString& source) const; - int periodHour(const QString& source) const; - int periodMinute(const QString& source) const; - QMap watches(const QString& source) const; - QMap warnings(const QString& source) const; - QString condition(const QString& source); - QMap temperature(const QString& source) const; - QString dewpoint(const QString& source) const; - QMap humidity(const QString& source) const; - QMap visibility(const QString& source) const; - QMap pressure(const QString& source) const; - QMap wind(const QString& source) const; - QMap regionalTemperatures(const QString& source) const; - QMap uvIndex(const QString& source) const; - QVector forecasts(const QString& source); - QMap yesterdayWeather(const QString& source) const; - QMap sunriseSet(const QString& source) const; - QMap moonriseSet(const QString& source) const; - QMap weatherRecords(const QString& source) const; - - // Load and Parse the place XML listing - void getXMLSetup(void); - bool readXMLSetup(void); - - // Load and parse the specific place(s) - void getXMLData(const QString& source); - bool readXMLData(const QString& source, QXmlStreamReader& xml); - - // Check if place specified is valid or not - QStringList validate(const QString& source) const; - - // Catchall for unknown XML tags - void parseUnknownElement(QXmlStreamReader& xml) const; - - // Parse weather XML data - void parseWeatherSite(WeatherData& data, QXmlStreamReader& xml); - void parseDateTime(WeatherData& data, QXmlStreamReader& xml, WeatherData::WeatherEvent* event = NULL); - void parseLocations(WeatherData& data, QXmlStreamReader& xml); - void parseConditions(WeatherData& data, QXmlStreamReader& xml); - void parseWarnings(WeatherData& data, QXmlStreamReader& xml); - void parseWindInfo(WeatherData& data, QXmlStreamReader& xml); - void parseWeatherForecast(WeatherData& data, QXmlStreamReader& xml); - void parseRegionalNormals(WeatherData& data, QXmlStreamReader& xml); - void parseForecast(WeatherData& data, QXmlStreamReader& xml, WeatherData::ForecastInfo* forecast); - void parseShortForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml); - void parseForecastTemperatures(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml); - void parseWindForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml); - void parsePrecipitationForecast(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml); - void parsePrecipTotals(WeatherData::ForecastInfo* forecast, QXmlStreamReader& xml); - void parseUVIndex(WeatherData& data, QXmlStreamReader& xml); - void parseYesterdayWeather(WeatherData& data, QXmlStreamReader& xml); - void parseAstronomicals(WeatherData& data, QXmlStreamReader& xml); - void parseWeatherRecords(WeatherData& data, QXmlStreamReader& xml); - - struct XMLMapInfo { - QString cityName; - QString territoryName; - QString cityCode; - }; - - // Key dicts - QHash m_places; - - // Weather information - QHash m_weatherData; - - // Store KIO jobs - QHash m_jobXml; - QHash m_jobList; - QStringList m_sourcesToReset; - QXmlStreamReader m_xmlSetup; - Plasma::DataEngine *m_timeEngine; - - QDateTime m_dateFormat; - bool emitWhenSetup; - -}; - -K_EXPORT_PLASMA_DATAENGINE(envcan, EnvCanadaIon) - -#endif -- 2.11.0