Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #530 from cptspiff/weather

changed: always fetch weather using an add-on
  • Loading branch information...
commit ada86f4c96e5fbd35b9c4d35d87b0b37517f927f 2 parents 1f93655 + 569712f
Arne Morten Kvarving authored
View
2  addons/skin.confluence/720p/Home.xml
@@ -589,7 +589,7 @@
<onclick>ActivateWindow(Weather)</onclick>
<icon>special://skin/backgrounds/weather.jpg</icon>
<thumb>$INFO[Skin.String(Home_Custom_Back_Weather_Folder)]</thumb>
- <visible>!Skin.HasSetting(HomeMenuNoWeatherButton)</visible>
+ <visible>!Skin.HasSetting(HomeMenuNoWeatherButton)+!IsEmpty(Weather.Plugin)</visible>
</item>
<item id="4">
<label>1</label>
View
40 addons/weather.xbmc.builtin/addon.xml
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="weather.xbmc.builtin"
- name="Weather.com (standard)"
- version="1.0.0"
- provider-name="Team XBMC">
- <extension point="xbmc.python.weather" library=""/>
- <extension point="xbmc.addon.metadata">
- <summary lang="br">Condições meteorológicas atuais.</summary>
- <summary lang="ca">Condicions meteorològiques actuals.</summary>
- <summary lang="en">Current weather conditions.</summary>
- <summary lang="es">Condiciones meteorológicas actuales.</summary>
- <summary lang="de">Aktuelle Wetterbedingungen</summary>
- <summary lang="fr">Conditions météorologiques en cours.</summary>
- <summary lang="hu">A jelenlegi időjárás.</summary>
- <summary lang="ko">현재 날씨</summary>
- <summary lang="nl">Huidige weersomstandigheden.</summary>
- <summary lang="pl">Aktualne warunki pogodowe.</summary>
- <summary lang="pt">Condições meteorológicas actuais.</summary>
- <summary lang="ro">Condiții meteo curente.</summary>
- <summary lang="ru">Текущие погодные условия.</summary>
- <summary lang="se">Aktuella väderförhållanden.</summary>
- <summary lang="zh">当前天气状况</summary>
- <description lang="br">Esta é a origem padrão de informação meteorológicas.[CR][CR]Ela provê as condições atuais e previsão para quatro dias.</description>
- <description lang="ca">Aquesta és la font per defecte de la informació meteorològica.[CR][CR]Proporciona les condicions meteorològiques actuals i una predicció a 4 dies.</description>
- <description lang="en">This is the default weather source.[CR][CR]It provides current weather conditions and a four day outlook.</description>
- <description lang="es">Fuente para las condiciones meteorológicas.[CR][CR]Proporciona las condiciones meteorológicas actuales y una previsión para 4 días.</description>
- <description lang="de">Standardquelle für Wetterinformationen[CR][CR]Das aktuelle Wetter sowie eine 4 tägige Vorausschau werden angezeigt</description>
- <description lang="fr">C'est la source météo par défaut.[CR][CR]Fournit les conditions climatiques en cours et les prévisions sur 4 jours.</description>
- <description lang="hu">Ez az alapértelmezett időjárás információforrás.[CR][CR]Tájékoztat a jelenlegi időjárásról, valamint négynapos előrejelzést ad.</description>
- <description lang="ko">기본 날씨 정보입니다.[CR][CR] 현재날씨와 4일치 예보를 제공합니다.</description>
- <description lang="nl">Dit is de standaardbron voor weersinformatie.[CR][CR]Het toont de huidige weersomstandigheden en de voorspellingen voor de vier volgende dagen.</description>
- <description lang="pl">Jest to domyślne źródło pogody.[CR][CR]Dostarcza aktualną pogodę oraz prognozę na cztery dni.</description>
- <description lang="pt">Fonte padrão das condições meteorológicas.[CR][CR]Providencia as condições meteorológicas actuais e previsão para quatro dias.</description>
- <description lang="ro">Sursă implicită pentru informații meteorologice.[CR][CR]Furnizează condiții meteo curente plus prognoza pe 4 zile.</description>
- <description lang="ru">Это источник информации о погоде.[CR][CR]Он предоставляет текущие погодные условия и прогноза на четыре дня.</description>
- <description lang="se">Detta är standardkällan för väder.[CR][CR]Det tillhandahåller nuvarande väderförhållanden och en fyra dagars prognos.</description>
- <description lang="zh">这是默认的天气预报信息来源。[CR][CR]它提供了当前的天气状况和未来4天的天气预报。</description>
- <platform>all</platform>
- </extension>
-</addon>
View
2  xbmc/GUIInfoManager.cpp
@@ -1098,7 +1098,7 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow)
URIUtils::RemoveExtension(strLabel);
break;
case WEATHER_PLUGIN:
- strLabel = g_guiSettings.GetString("weather.script");
+ strLabel = g_guiSettings.GetString("weather.addon");
break;
case SYSTEM_DATE:
strLabel = GetDate();
View
3  xbmc/GUIUserMessages.h
@@ -127,3 +127,6 @@
// Sent to tell window to initiate a search dialog
#define GUI_MSG_SEARCH GUI_MSG_USER + 34
+
+// Sent to the AddonSetting dialogs from addons if they updated a setting
+#define GUI_MSG_SETTING_UPDATED GUI_MSG_USER + 35
View
14 xbmc/addons/AddonManager.cpp
@@ -81,11 +81,23 @@ AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
return AddonPtr(new CPluginSource(props));
case ADDON_SCRIPT_LIBRARY:
case ADDON_SCRIPT_LYRICS:
- case ADDON_SCRIPT_WEATHER:
case ADDON_SCRIPT_SUBTITLES:
case ADDON_SCRIPT_MODULE:
case ADDON_WEB_INTERFACE:
return AddonPtr(new CAddon(props));
+ case ADDON_SCRIPT_WEATHER:
+ {
+ // Eden (API v2.0) broke old weather add-ons
+ AddonPtr result(new CAddon(props));
+ AddonVersion ver1 = AddonVersion(GetXbmcApiVersionDependency(result));
+ AddonVersion ver2 = AddonVersion("2.0");
+ if (ver1 < ver2)
+ {
+ CLog::Log(LOGINFO,"%s: Weather add-ons for api < 2.0 unsupported (%s)",__FUNCTION__,result->ID().c_str());
+ return AddonPtr();
+ }
+ return result;
+ }
case ADDON_SERVICE:
return AddonPtr(new CService(props));
case ADDON_SCRAPER_ALBUMS:
View
19 xbmc/addons/GUIDialogAddonSettings.cpp
@@ -44,6 +44,7 @@
#include "FileItem.h"
#include "settings/Settings.h"
#include "GUIInfoManager.h"
+#include "GUIUserMessages.h"
#include "dialogs/GUIDialogSelect.h"
#include "GUIWindowAddonBrowser.h"
#include "utils/log.h"
@@ -126,6 +127,17 @@ bool CGUIDialogAddonSettings::OnMessage(CGUIMessage& message)
}
return true;
}
+ case GUI_MSG_SETTING_UPDATED:
+ {
+ CStdString id = message.GetStringParam(0);
+ CStdString value = message.GetStringParam(1);
+ m_settings[id] = value;
+ int iControl = GetFocusedControl()->GetID();
+ CreateControls();
+ CGUIMessage msg(GUI_MSG_SETFOCUS,GetID(),iControl);
+ OnMessage(msg);
+ return true;
+ }
}
return CGUIDialogBoxBase::OnMessage(message);
}
@@ -1133,3 +1145,10 @@ void CGUIDialogAddonSettings::DoProcess(unsigned int currentTime, CDirtyRegionLi
((CGUIButtonControl *)control)->SetSelected(false);
}
}
+
+CStdString CGUIDialogAddonSettings::GetCurrentID() const
+{
+ if (m_addon)
+ return m_addon->ID();
+ return "";
+}
View
1  xbmc/addons/GUIDialogAddonSettings.h
@@ -38,6 +38,7 @@ class CGUIDialogAddonSettings : public CGUIDialogBoxBase
static bool ShowAndGetInput(const ADDON::AddonPtr &addon, bool saveToDisk = true);
virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
+ CStdString GetCurrentID() const;
protected:
virtual void OnInitWindow();
View
25 xbmc/interfaces/python/xbmcmodule/PythonAddon.cpp
@@ -24,6 +24,8 @@
#include "pythreadstate.h"
#include "addons/AddonManager.h"
#include "addons/GUIDialogAddonSettings.h"
+#include "guilib/GUIWindowManager.h"
+#include "GUIUserMessages.h"
#include "utils/log.h"
namespace PYXBMC
@@ -245,8 +247,27 @@ namespace PYXBMC
AddonPtr addon(self->pAddon);
CPyThreadState pyState;
- addon->UpdateSetting(id, value);
- addon->SaveSettings();
+ bool save=true;
+ if (g_windowManager.IsWindowActive(WINDOW_DIALOG_ADDON_SETTINGS))
+ {
+ CGUIDialogAddonSettings* dialog = (CGUIDialogAddonSettings*)g_windowManager.GetWindow(WINDOW_DIALOG_ADDON_SETTINGS);
+ if (dialog->GetCurrentID() == addon->ID())
+ {
+ CGUIMessage message(GUI_MSG_SETTING_UPDATED,0,0);
+ std::vector<CStdString> params;
+ params.push_back(id);
+ params.push_back(value);
+ message.SetStringParams(params);
+ g_windowManager.SendThreadMessage(message,WINDOW_DIALOG_ADDON_SETTINGS);
+ save=false;
+ }
+ }
+ if (save)
+ {
+ addon->UpdateSetting(id, value);
+ addon->SaveSettings();
+ }
+
pyState.Restore();
Py_INCREF(Py_None);
View
8 xbmc/settings/GUISettings.cpp
@@ -259,12 +259,8 @@ void CGUISettings::Initialize()
AddGroup(2, 8);
CSettingsCategory* wea = AddCategory(2, "weather", 16000);
AddInt(NULL, "weather.currentlocation", 0, 1, 1, 1, 3, SPIN_CONTROL_INT_PLUS);
- AddString(wea, "weather.areacode1", 14019, "USNY0996 - New York, NY", BUTTON_CONTROL_STANDARD);
- AddString(wea, "weather.areacode2", 14020, "UKXX0085 - London, United Kingdom", BUTTON_CONTROL_STANDARD);
- AddString(wea, "weather.areacode3", 14021, "JAXX0085 - Tokyo, Japan", BUTTON_CONTROL_STANDARD);
- AddSeparator(wea, "weather.sep1");
- AddDefaultAddon(wea, "weather.script", 24027, DEFAULT_WEATHER_ADDON, ADDON_SCRIPT_WEATHER);
- AddString(wea, "weather.scriptsettings", 21417, "", BUTTON_CONTROL_STANDARD, true);
+ AddDefaultAddon(wea, "weather.addon", 24027, "", ADDON_SCRIPT_WEATHER);
+ AddString(wea, "weather.addonsettings", 21417, "", BUTTON_CONTROL_STANDARD, true);
// My Music Settings
AddGroup(3, 2);
View
33 xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -867,12 +867,6 @@ void CGUIWindowSettingsCategory::UpdateSettings()
if (strSetting.Equals("screensaver.usedimonpause") && g_guiSettings.GetString("screensaver.mode").Equals("screensaver.xbmc.builtin.dim"))
pControl->SetEnabled(false);
}
- else if (strSetting.Left(16).Equals("weather.areacode"))
- {
- CSettingString *pSetting = (CSettingString *)GetSetting(strSetting)->GetSetting();
- CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(GetSetting(strSetting)->GetID());
- pControl->SetLabel2(CWeather::GetAreaCity(pSetting->GetData()));
- }
else if (strSetting.Equals("musicfiles.trackformat"))
{
if (m_strOldTrackFormat != g_guiSettings.GetString("musicfiles.trackformat"))
@@ -937,10 +931,10 @@ void CGUIWindowSettingsCategory::UpdateSettings()
pControl->SetEnabled(enabled);
}
}
- else if (strSetting.Equals("weather.scriptsettings"))
+ else if (strSetting.Equals("weather.addonsettings"))
{
AddonPtr addon;
- if (CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.script"), addon, ADDON_SCRIPT_WEATHER))
+ if (CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.addon"), addon, ADDON_SCRIPT_WEATHER))
{
CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
if (pControl)
@@ -983,26 +977,9 @@ void CGUIWindowSettingsCategory::UpdateRealTimeSettings()
void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
{
CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
- if (strSetting.Left(16).Equals("weather.areacode"))
- {
- CStdString strSearch;
- if (CGUIDialogKeyboard::ShowAndGetInput(strSearch, g_localizeStrings.Get(14024), false))
- {
- strSearch.Replace(" ", "+");
- CStdString strResult = ((CSettingString *)pSettingControl->GetSetting())->GetData();
- if (g_weatherManager.GetSearchResults(strSearch, strResult))
- {
- ((CSettingString *)pSettingControl->GetSetting())->SetData(strResult);
- // Update the labels on the location spinner
- g_weatherManager.Reset();
- // Refresh the weather using the new location
- g_weatherManager.Refresh();
- }
- }
- }
- else if (strSetting.Equals("weather.scriptsettings"))
+ if (strSetting.Equals("weather.addonsettings"))
{
- CStdString name = g_guiSettings.GetString("weather.script");
+ CStdString name = g_guiSettings.GetString("weather.addon");
AddonPtr addon;
if (CAddonMgr::Get().GetAddon(name, addon, ADDON_SCRIPT_WEATHER))
{ // TODO: maybe have ShowAndGetInput return a bool if settings changed, then only reset weather if true.
@@ -1026,7 +1003,7 @@ void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
{ // prompt for the addon
CSettingAddon *setting = (CSettingAddon *)pSettingControl->GetSetting();
CStdString addonID = setting->GetData();
- if (CGUIWindowAddonBrowser::SelectAddonID(setting->m_type, addonID, setting->m_type == ADDON_SCREENSAVER || setting->m_type == ADDON_VIZ) == 1)
+ if (CGUIWindowAddonBrowser::SelectAddonID(setting->m_type, addonID, setting->m_type == ADDON_SCREENSAVER || setting->m_type == ADDON_VIZ || setting->m_type == ADDON_SCRIPT_WEATHER) == 1)
setting->SetData(addonID);
else
return;
View
1  xbmc/settings/Settings.h
@@ -29,7 +29,6 @@
#define DEFAULT_SKIN "skin.confluence"
#endif
#define DEFAULT_FANART_HEIGHT 0
-#define DEFAULT_WEATHER_ADDON "weather.xbmc.builtin"
#define DEFAULT_WEB_INTERFACE "webinterface.default"
#ifdef MID
#define DEFAULT_VSYNC VSYNC_DISABLED
View
478 xbmc/utils/Weather.cpp
@@ -22,66 +22,30 @@
#if (defined HAVE_CONFIG_H) && (!defined WIN32)
#include "config.h"
#endif
-#include "system.h"
#include "Weather.h"
#include "filesystem/ZipManager.h"
-#ifdef HAS_FILESYSTEM_RAR
-#include "filesystem/RarManager.h"
-#endif
-#include "filesystem/FileCurl.h"
#include "XMLUtils.h"
#include "Temperature.h"
#include "network/Network.h"
-#include "Util.h"
#include "Application.h"
#include "settings/GUISettings.h"
#include "settings/Settings.h"
#include "guilib/GUIWindowManager.h"
#include "GUIUserMessages.h"
-#include "dialogs/GUIDialogProgress.h"
-#include "dialogs/GUIDialogSelect.h"
#include "XBDateTime.h"
#include "LangInfo.h"
#include "guilib/LocalizeStrings.h"
#include "filesystem/Directory.h"
-#include "utils/TimeUtils.h"
#include "StringUtils.h"
+#include "URIUtils.h"
#include "log.h"
+#include "addons/AddonManager.h"
+#include "interfaces/python/XBPython.h"
using namespace std;
+using namespace ADDON;
using namespace XFILE;
-#define CONTROL_BTNREFRESH 2
-#define CONTROL_SELECTLOCATION 3
-#define CONTROL_LABELLOCATION 10
-#define CONTROL_LABELUPDATED 11
-#define CONTROL_IMAGELOGO 101
-
-#define CONTROL_IMAGENOWICON 21
-#define CONTROL_LABELNOWCOND 22
-#define CONTROL_LABELNOWTEMP 23
-#define CONTROL_LABELNOWFEEL 24
-#define CONTROL_LABELNOWUVID 25
-#define CONTROL_LABELNOWWIND 26
-#define CONTROL_LABELNOWDEWP 27
-#define CONTROL_LABELNOWHUMI 28
-
-#define CONTROL_STATICTEMP 223
-#define CONTROL_STATICFEEL 224
-#define CONTROL_STATICUVID 225
-#define CONTROL_STATICWIND 226
-#define CONTROL_STATICDEWP 227
-#define CONTROL_STATICHUMI 228
-
-#define CONTROL_LABELD0DAY 31
-#define CONTROL_LABELD0HI 32
-#define CONTROL_LABELD0LOW 33
-#define CONTROL_LABELD0GEN 34
-#define CONTROL_IMAGED0IMG 35
-
-#define PARTNER_ID "1004124588" //weather.com partner id
-#define PARTNER_KEY "079f24145f208494" //weather.com partner key
-
#define LOCALIZED_TOKEN_FIRSTID 370
#define LOCALIZED_TOKEN_LASTID 395
#define LOCALIZED_TOKEN_FIRSTID2 1396
@@ -94,26 +58,16 @@ using namespace XFILE;
/*
FIXME'S
>strings are not centered
->weather.com dev account is mine not a general xbmc one
*/
-// USE THESE FOR ZIP
#define WEATHER_BASE_PATH "special://temp/weather/"
-#define WEATHER_USE_ZIP 1
-#define WEATHER_USE_RAR 0
#define WEATHER_SOURCE_FILE "special://xbmc/media/weather.zip"
-// OR THESE FOR RAR
-//#define WEATHER_BASE_PATH "special://temp/weather/"
-//#define WEATHER_USE_ZIP 0
-//#define WEATHER_USE_RAR 1
-//#define WEATHER_SOURCE_FILE "special://xbmc/media/weather.rar"
-
bool CWeatherJob::m_imagesOkay = false;
-CWeatherJob::CWeatherJob(const CStdString &areaCode)
+CWeatherJob::CWeatherJob(int location)
{
- m_areaCode = areaCode;
+ m_location = location;
}
bool CWeatherJob::DoWork()
@@ -122,29 +76,38 @@ bool CWeatherJob::DoWork()
if (!g_application.getNetwork().IsAvailable(true))
return false;
+ AddonPtr addon;
+ if (!ADDON::CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.addon"), addon, ADDON_SCRIPT_WEATHER))
+ return false;
+
+ // initialize our sys.argv variables
+ std::vector<CStdString> argv;
+ argv.push_back(addon->LibPath());
+
+ CStdString strSetting;
+ strSetting.Format("%i", m_location);
+ argv.push_back(strSetting);
+
// Download our weather
CLog::Log(LOGINFO, "WEATHER: Downloading weather");
- XFILE::CFileCurl httpUtil;
- CStdString strURL;
-
- strURL.Format("http://xoap.weather.com/weather/local/%s?cc=*&unit=m&dayf=4&prod=xoap&link=xoap&par=%s&key=%s",
- m_areaCode.c_str(), PARTNER_ID, PARTNER_KEY);
- CStdString xml;
- if (httpUtil.Get(strURL, xml))
+ // call our script, passing the areacode
+ if (g_pythonParser.evalFile(argv[0], argv,addon))
{
- CLog::Log(LOGINFO, "WEATHER: Weather download successful");
+ while (true)
+ {
+ if (!g_pythonParser.isRunning(g_pythonParser.getScriptId(addon->LibPath().c_str())))
+ break;
+ Sleep(100);
+ }
if (!m_imagesOkay)
{
CDirectory::Create(WEATHER_BASE_PATH);
- if (WEATHER_USE_ZIP)
- g_ZipManager.ExtractArchive(WEATHER_SOURCE_FILE, WEATHER_BASE_PATH);
-#ifdef HAS_FILESYSTEM_RAR
- else if (WEATHER_USE_RAR)
- g_RarManager.ExtractArchive(WEATHER_SOURCE_FILE, WEATHER_BASE_PATH);
-#endif
+ g_ZipManager.ExtractArchive(WEATHER_SOURCE_FILE, WEATHER_BASE_PATH);
m_imagesOkay = true;
}
- LoadWeather(xml);
+
+ SetFromProperties();
+
// and send a message that we're done
CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_WEATHER_FETCHED);
g_windowManager.SendThreadMessage(msg);
@@ -160,26 +123,6 @@ const CWeatherInfo &CWeatherJob::GetInfo() const
return m_info;
}
-void CWeatherJob::GetString(const TiXmlElement* pRootElement, const CStdString& strTagName, CStdString &value, const CStdString& strDefaultValue)
-{
- value = "";
- const TiXmlNode *pChild = pRootElement->FirstChild(strTagName.c_str());
- if (pChild && pChild->FirstChild())
- {
- value = pChild->FirstChild()->Value();
- if (value == "-")
- value = "";
- }
- if (value.IsEmpty())
- value = strDefaultValue;
-}
-
-void CWeatherJob::GetInteger(const TiXmlElement* pRootElement, const CStdString& strTagName, int& iValue)
-{
- if (!XMLUtils::GetInt(pRootElement, strTagName.c_str(), iValue))
- iValue = 0;
-}
-
void CWeatherJob::LocalizeOverviewToken(CStdString &token)
{
// NOTE: This routine is case-sensitive. Reason is std::less<CStdString> uses a case-sensitive
@@ -283,159 +226,6 @@ void CWeatherJob::FormatTemperature(CStdString &text, int temp)
text.Format("%.0f", temperature.ToLocale());
}
-bool CWeatherJob::LoadWeather(const CStdString &weatherXML)
-{
- CStdString iTmpStr;
- SYSTEMTIME time;
-
- GetLocalTime(&time); //used when deciding what weather to grab for today
-
- // Load in our tokens if necessary
- if (!m_localizedTokens.size())
- LoadLocalizedToken();
-
- // load the xml file
- TiXmlDocument xmlDoc;
- if (!xmlDoc.Parse(weatherXML))
- {
- CLog::Log(LOGERROR, "WEATHER: Unable to get data - invalid XML");
- return false;
- }
-
- TiXmlElement *pRootElement = xmlDoc.RootElement();
- if (!pRootElement)
- {
- CLog::Log(LOGERROR, "WEATHER: Unable to get data - invalid XML");
- return false;
- }
-
- //if root element is 'error' display the error message
- if (strcmp(pRootElement->Value(), "error") == 0)
- {
- CStdString error;
- GetString(pRootElement, "err", error, "Unknown Error"); //grab the error string
- CLog::Log(LOGERROR, "WEATHER: Unable to get data: %s", error.c_str());
- return false;
- }
-
- // location
- TiXmlElement *pElement = pRootElement->FirstChildElement("loc");
- if (pElement)
- {
- GetString(pElement, "dnam", m_info.location, "");
- }
-
- //current weather
- pElement = pRootElement->FirstChildElement("cc");
- if (pElement)
- {
- // Use the local date/time the file is parsed...
- CDateTime time=CDateTime::GetCurrentDateTime();
- m_info.lastUpdateTime = time.GetAsLocalizedDateTime(false, false);
-
- // ...and not the date/time from weather.com
- //GetString(pElement, "lsup", m_szLastUpdateTime, "");
-
- GetString(pElement, "icon", iTmpStr, ""); //string cause i've seen it return N/A
- if (iTmpStr == "N/A")
- m_info.currentIcon.Format("%s128x128/na.png", WEATHER_BASE_PATH);
- else
- m_info.currentIcon.Format("%s128x128/%s.png", WEATHER_BASE_PATH, iTmpStr.c_str());
-
- GetString(pElement, "t", m_info.currentConditions, ""); //current condition
- LocalizeOverview(m_info.currentConditions);
-
- int iTmpInt;
- GetInteger(pElement, "tmp", iTmpInt); //current temp
- FormatTemperature(m_info.currentTemperature, iTmpInt);
- GetInteger(pElement, "flik", iTmpInt); //current 'Feels Like'
- FormatTemperature(m_info.currentFeelsLike, iTmpInt);
-
- TiXmlElement *pNestElement = pElement->FirstChildElement("wind"); //current wind
- if (pNestElement)
- {
- GetInteger(pNestElement, "s", iTmpInt); //current wind strength
- iTmpInt = ConvertSpeed(iTmpInt); //convert speed if needed
- GetString(pNestElement, "t", iTmpStr, "N"); //current wind direction
-
- CStdString szCalm = g_localizeStrings.Get(1410);
- if (iTmpStr == "CALM") {
- m_info.currentWind = szCalm;
- } else {
- LocalizeOverviewToken(iTmpStr);
- m_info.currentWind.Format(g_localizeStrings.Get(434).c_str(),
- iTmpStr, iTmpInt, g_langInfo.GetSpeedUnitString().c_str());
- }
- }
-
- GetInteger(pElement, "hmid", iTmpInt); //current humidity
- m_info.currentHumidity.Format("%i%%", iTmpInt);
-
- pNestElement = pElement->FirstChildElement("uv"); //current UV index
- if (pNestElement)
- {
- GetInteger(pNestElement, "i", iTmpInt);
- GetString(pNestElement, "t", iTmpStr, "");
- LocalizeOverviewToken(iTmpStr);
- m_info.currentUVIndex.Format("%i %s", iTmpInt, iTmpStr);
- }
-
- GetInteger(pElement, "dewp", iTmpInt); //current dew point
- FormatTemperature(m_info.currentDewPoint, iTmpInt);
- }
- //future forcast
- pElement = pRootElement->FirstChildElement("dayf");
- if (pElement)
- {
- TiXmlElement *pOneDayElement = pElement->FirstChildElement("day");;
- if (pOneDayElement)
- {
- for (int i = 0; i < NUM_DAYS; i++)
- {
- const char *attr = pOneDayElement->Attribute("t");
- if (attr)
- {
- m_info.forecast[i].m_day = attr;
- LocalizeOverviewToken(m_info.forecast[i].m_day);
- }
-
- GetString(pOneDayElement, "hi", iTmpStr, ""); //string cause i've seen it return N/A
- if (iTmpStr == "N/A")
- m_info.forecast[i].m_high = "";
- else
- FormatTemperature(m_info.forecast[i].m_high, atoi(iTmpStr));
-
- GetString(pOneDayElement, "low", iTmpStr, "");
- if (iTmpStr == "N/A")
- m_info.forecast[i].m_low = "";
- else
- FormatTemperature(m_info.forecast[i].m_low, atoi(iTmpStr));
-
- TiXmlElement *pDayTimeElement = pOneDayElement->FirstChildElement("part"); //grab the first day/night part (should be day)
- if (pDayTimeElement)
- {
- if (i == 0 && (time.wHour < 7 || time.wHour >= 19)) //weather.com works on a 7am to 7pm basis so grab night if its late in the day
- pDayTimeElement = pDayTimeElement->NextSiblingElement("part");
-
- GetString(pDayTimeElement, "icon", iTmpStr, ""); //string cause i've seen it return N/A
- if (iTmpStr == "N/A")
- m_info.forecast[i].m_icon.Format("%s128x128/na.png", WEATHER_BASE_PATH);
- else
- m_info.forecast[i].m_icon.Format("%s128x128/%s.png", WEATHER_BASE_PATH, iTmpStr);
-
- GetString(pDayTimeElement, "t", m_info.forecast[i].m_overview, "");
- LocalizeOverview(m_info.forecast[i].m_overview);
- }
-
- pOneDayElement = pOneDayElement->NextSiblingElement("day");
- if (!pOneDayElement)
- break; // No more days, break out
- }
- }
- }
- return true;
-}
-
void CWeatherJob::LoadLocalizedToken()
{
// We load the english strings in to get our tokens
@@ -485,131 +275,70 @@ void CWeatherJob::LoadLocalizedToken()
}
}
-
-CWeather::CWeather(void) : CInfoLoader(30 * 60 * 1000) // 30 minutes
+void CWeatherJob::SetFromProperties()
{
- Reset();
-}
-
-CWeather::~CWeather(void)
-{
-}
-
-bool CWeather::GetSearchResults(const CStdString &strSearch, CStdString &strResult)
-{
- // Check to see if the user entered a weather.com code
- if (strSearch.size() == 8)
- {
- strResult = "";
- int i = 0;
- for (i = 0; i < 4; ++i)
- {
- strResult += toupper(strSearch[i]);
- if (!isalpha(strSearch[i]))
- break;
- }
- if (i == 4)
- {
- for ( ; i < 8; ++i)
- {
- strResult += strSearch[i];
- if (!isdigit(strSearch[i]))
- break;
- }
- if (i == 8)
- {
- return true; // match
- }
- }
- // no match, wipe string
- strResult = "";
- }
-
- CGUIDialogSelect *pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
- CGUIDialogProgress *pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
-
- //do the download
- CStdString strURL;
- CStdString strXML;
- XFILE::CFileCurl httpUtil;
-
- if (pDlgProgress)
- {
- pDlgProgress->SetHeading(410); //"Accessing Weather.com"
- pDlgProgress->SetLine(0, 194); //"Searching"
- pDlgProgress->SetLine(1, strSearch);
- pDlgProgress->SetLine(2, "");
- pDlgProgress->StartModal();
- pDlgProgress->Progress();
- }
-
- strURL.Format("http://xoap.weather.com/search/search?where=%s", strSearch);
-
- if (!httpUtil.Get(strURL, strXML))
- {
- if (pDlgProgress)
- pDlgProgress->Close();
- return false;
- }
-
- //some select dialog init stuff
- if (!pDlgSelect)
- {
- if (pDlgProgress)
- pDlgProgress->Close();
- return false;
- }
-
- pDlgSelect->SetHeading(396); //"Select Location"
- pDlgSelect->Reset();
-
- ///////////////////////////////
- // load the xml file
- ///////////////////////////////
- TiXmlDocument xmlDoc;
- xmlDoc.Parse(strXML.c_str());
- if (xmlDoc.Error())
- return false;
+ // Load in our tokens if necessary
+ if (!m_localizedTokens.size())
+ LoadLocalizedToken();
- TiXmlElement *pRootElement = xmlDoc.RootElement();
- if (pRootElement)
+ CGUIWindow* window = g_windowManager.GetWindow(WINDOW_WEATHER);
+ CDateTime time=CDateTime::GetCurrentDateTime();
+ m_info.lastUpdateTime = time.GetAsLocalizedDateTime(false, false);
+ m_info.currentConditions = window->GetProperty("Current.Condition").asString();
+ m_info.currentIcon = URIUtils::AddFileToFolder(WEATHER_BASE_PATH,
+ "128x128/"+window->GetProperty("Current.OutlookIcon").asString());
+ LocalizeOverview(m_info.currentConditions);
+ FormatTemperature(m_info.currentTemperature,
+ strtol(window->GetProperty("Current.Temperature").asString().c_str(),0,10));
+ FormatTemperature(m_info.currentFeelsLike,
+ strtol(window->GetProperty("Current.FeelsLike").asString().c_str(),0,10));
+ m_info.currentUVIndex = window->GetProperty("Current.UVIndex").asString();
+ LocalizeOverview(m_info.currentUVIndex);
+ int speed = ConvertSpeed(strtol(window->GetProperty("Current.Wind").asString().c_str(),0,10));
+ CStdString direction = window->GetProperty("Current.WindDirection").asString();
+ if (direction == "CALM")
+ m_info.currentWind = g_localizeStrings.Get(1410);
+ else
{
- CStdString strItemTmp;
- TiXmlElement *pElement = pRootElement->FirstChildElement("loc");
- while (pElement)
- {
- if (!pElement->NoChildren())
- {
- strItemTmp.Format("%s - %s", pElement->Attribute("id"), pElement->FirstChild()->Value());
- pDlgSelect->Add(strItemTmp);
- }
- pElement = pElement->NextSiblingElement("loc");
- }
+ LocalizeOverviewToken(direction);
+ m_info.currentWind.Format(g_localizeStrings.Get(434).c_str(),
+ direction, speed, g_langInfo.GetSpeedUnitString().c_str());
}
-
- if (pDlgProgress)
- pDlgProgress->Close();
-
- pDlgSelect->EnableButton(true, 222); //'Cancel' button returns to weather settings
- pDlgSelect->DoModal();
-
- if (pDlgSelect->GetSelectedLabel() < 0)
+ FormatTemperature(m_info.currentDewPoint,
+ strtol(window->GetProperty("Current.DewPoint").asString().c_str(),0,10));
+ m_info.currentHumidity.Format("%s%%",window->GetProperty("Current.Humidity").asString().c_str());
+ m_info.location = window->GetProperty("Current.Location").asString();
+ for (int i=0;i<4;++i)
{
- if (pDlgSelect->IsButtonPressed())
- {
- pDlgSelect->Close(); //close the select dialog and return to weather settings
- return true;
- }
+ CStdString strDay;
+ strDay.Format("Day%i.Title",i);
+ m_info.forecast[i].m_day = window->GetProperty(strDay).asString();
+ LocalizeOverviewToken(m_info.forecast[i].m_day);
+ strDay.Format("Day%i.HighTemp",i);
+ FormatTemperature(m_info.forecast[i].m_high,
+ strtol(window->GetProperty(strDay).asString().c_str(),0,10));
+ strDay.Format("Day%i.LowTemp",i);
+ FormatTemperature(m_info.forecast[i].m_low,
+ strtol(window->GetProperty(strDay).asString().c_str(),0,10));
+ strDay.Format("Day%i.OutlookIcon",i);
+ if (window->GetProperty(strDay).asString() == "N/A")
+ m_info.forecast[i].m_icon = URIUtils::AddFileToFolder(WEATHER_BASE_PATH,"128x128/na.png");
+ else
+ m_info.forecast[i].m_icon = URIUtils::AddFileToFolder(WEATHER_BASE_PATH,
+ "128x128/"+window->GetProperty(strDay).asString());
+ strDay.Format("Day%i.Outlook",i);
+ m_info.forecast[i].m_overview = window->GetProperty(strDay).asString();
+ LocalizeOverview(m_info.forecast[i].m_overview);
}
+}
- //copy the selected code into the settings
- if (pDlgSelect->GetSelectedLabel() >= 0)
- strResult = pDlgSelect->GetSelectedLabelText();
-
- if (pDlgProgress)
- pDlgProgress->Close();
+CWeather::CWeather(void) : CInfoLoader(30 * 60 * 1000) // 30 minutes
+{
+ Reset();
+}
- return true;
+CWeather::~CWeather(void)
+{
}
CStdString CWeather::BusyInfo(int info) const
@@ -637,24 +366,6 @@ CStdString CWeather::TranslateInfo(int info) const
return "";
}
-CStdString CWeather::GetAreaCity(const CStdString &codeAndCity)
-{
- CStdString areaCode(codeAndCity);
- int pos = areaCode.Find(" - ");
- if (pos >= 0)
- areaCode = areaCode.Mid(pos + 3);
- return areaCode;
-}
-
-CStdString CWeather::GetAreaCode(const CStdString &codeAndCity)
-{
- CStdString areaCode(codeAndCity);
- int pos = areaCode.Find(" - ");
- if (pos >= 0)
- areaCode = areaCode.Left(pos);
- return areaCode;
-}
-
/*!
\brief Retrieve the city name for the specified location from the settings
\param iLocation the location index (can be in the range [1..MAXLOCATION])
@@ -662,20 +373,15 @@ CStdString CWeather::GetAreaCode(const CStdString &codeAndCity)
*/
CStdString CWeather::GetLocation(int iLocation)
{
- if (m_location[iLocation - 1].IsEmpty())
- {
- CStdString setting;
- setting.Format("weather.areacode%i", iLocation);
- m_location[iLocation - 1] = GetAreaCity(g_guiSettings.GetString(setting));
- }
- return m_location[iLocation - 1];
+ CGUIWindow* window = g_windowManager.GetWindow(WINDOW_WEATHER);
+ CStdString setting;
+ setting.Format("Location%i", iLocation);
+ return window->GetProperty(setting).asString();
}
void CWeather::Reset()
{
m_info.Reset();
- for (int i = 0; i < MAX_LOCATION; i++)
- m_location[i] = "";
}
bool CWeather::IsFetched()
@@ -712,9 +418,7 @@ int CWeather::GetArea() const
CJob *CWeather::GetJob() const
{
- CStdString strSetting;
- strSetting.Format("weather.areacode%i", GetArea());
- return new CWeatherJob(GetAreaCode(g_guiSettings.GetString(strSetting)));
+ return new CWeatherJob(GetArea());
}
void CWeather::OnJobComplete(unsigned int jobID, bool success, CJob *job)
View
17 xbmc/utils/Weather.h
@@ -39,8 +39,6 @@ class TiXmlElement;
#define WEATHER_LABEL_CURRENT_DEWP 27
#define WEATHER_LABEL_CURRENT_HUMI 28
-#define MAX_LOCATION 3
-
struct day_forecast
{
CStdString m_icon;
@@ -96,20 +94,19 @@ class CWeatherInfo
class CWeatherJob : public CJob
{
public:
- CWeatherJob(const CStdString &areaCode);
+ CWeatherJob(int location);
virtual bool DoWork();
const CWeatherInfo &GetInfo() const;
private:
- bool LoadWeather(const CStdString& strWeatherFile); //parse strWeatherFile
- void GetString(const TiXmlElement* pRootElement, const CStdString& strTagName, CStdString &value, const CStdString& strDefaultValue);
- void GetInteger(const TiXmlElement* pRootElement, const CStdString& strTagName, int& iValue);
void LocalizeOverview(CStdString &str);
void LocalizeOverviewToken(CStdString &str);
void LoadLocalizedToken();
int ConvertSpeed(int speed);
+ void SetFromProperties();
+
/*! \brief Formats a celcius temperature into a string based on the users locale
\param text the string to format
\param temp the temperature (in degrees celcius).
@@ -120,7 +117,7 @@ class CWeatherJob : public CJob
typedef std::map<CStdString, int>::const_iterator ilocalizedTokens;
CWeatherInfo m_info;
- CStdString m_areaCode;
+ int m_location;
static bool m_imagesOkay;
};
@@ -140,10 +137,6 @@ class CWeather : public CInfoLoader
void SetArea(int iLocation);
int GetArea() const;
-
- static CStdString GetAreaCode(const CStdString &codeAndCity);
- static CStdString GetAreaCity(const CStdString &codeAndCity);
-
protected:
virtual CJob *GetJob() const;
virtual CStdString TranslateInfo(int info) const;
@@ -152,8 +145,6 @@ class CWeather : public CInfoLoader
private:
- CStdString m_location[MAX_LOCATION];
-
CWeatherInfo m_info;
};
View
78 xbmc/windows/GUIWindowWeather.cpp
@@ -60,11 +60,9 @@ using namespace ADDON;
#define LOCALIZED_TOKEN_FIRSTID 370
#define LOCALIZED_TOKEN_LASTID 395
-unsigned int timeToCallScript = 1000;
/*
FIXME'S
>strings are not centered
->weather.com dev account is mine not a general xbmc one
*/
CGUIWindowWeather::CGUIWindowWeather(void)
@@ -88,10 +86,6 @@ bool CGUIWindowWeather::OnMessage(CGUIMessage& message)
}
else if (iControl == CONTROL_SELECTLOCATION)
{
- // stop the script timer here, so the user has a full second
- if (m_scriptTimer.IsRunning())
- m_scriptTimer.Stop();
-
CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_SELECTLOCATION);
g_windowManager.SendMessage(msg);
@@ -109,20 +103,6 @@ bool CGUIWindowWeather::OnMessage(CGUIMessage& message)
{
UpdateLocations();
SetProperties();
- if (g_windowManager.GetActiveWindow() == WINDOW_WEATHER)
- m_scriptTimer.StartZero();
- else
- CallScript();
- }
- break;
- case GUI_MSG_WINDOW_INIT:
- {
- if (!g_sysinfo.HasInternet())
- {
- CGUIDialogOK::ShowAndGetInput(8,21451,20022,20022);
- g_windowManager.PreviousWindow();
- return true;
- }
}
break;
case GUI_MSG_ITEM_SELECT:
@@ -138,9 +118,9 @@ bool CGUIWindowWeather::OnMessage(CGUIMessage& message)
{
if (message.GetSenderId() == 0) //handle only message from builtin
{
- // Clamp location between 1 and MAX_LOCATION
- int v = (g_weatherManager.GetArea() + message.GetParam1() - 1) % MAX_LOCATION + 1;
- if (v < 1) v += MAX_LOCATION;
+ // Clamp location between 1 and m_maxLocation
+ int v = (g_weatherManager.GetArea() + message.GetParam1() - 1) % m_maxLocation + 1;
+ if (v < 1) v += m_maxLocation;
SetLocation(v);
return true;
}
@@ -157,6 +137,7 @@ void CGUIWindowWeather::OnInitWindow()
{
// call UpdateButtons() so that we start with our initial stuff already present
UpdateButtons();
+ m_maxLocation = strtol(GetProperty("Locations").asString().c_str(),0,10);
UpdateLocations();
CGUIWindow::OnInitWindow();
}
@@ -171,7 +152,7 @@ void CGUIWindowWeather::UpdateLocations()
unsigned int iCurWeather = g_weatherManager.GetArea();
- for (unsigned int i = 1; i <= MAX_LOCATION; i++)
+ for (unsigned int i = 1; i <= m_maxLocation; i++)
{
CStdString strLabel = g_weatherManager.GetLocation(i);
if (strLabel.size() > 1) //got the location string yet?
@@ -245,13 +226,6 @@ void CGUIWindowWeather::FrameMove()
// update our controls
UpdateButtons();
- // call weather script
- if (m_scriptTimer.IsRunning() && m_scriptTimer.GetElapsedMilliseconds() > timeToCallScript)
- {
- m_scriptTimer.Stop();
- CallScript();
- }
-
CGUIWindow::FrameMove();
}
@@ -261,7 +235,7 @@ void CGUIWindowWeather::FrameMove()
*/
void CGUIWindowWeather::SetLocation(int loc)
{
- if (loc < 1 || loc > MAX_LOCATION)
+ if (loc < 1 || loc > (int)m_maxLocation)
return;
// Avoid a settings write if old location == new location
if (g_weatherManager.GetArea() != loc)
@@ -282,9 +256,6 @@ void CGUIWindowWeather::SetProperties()
int iCurWeather = g_weatherManager.GetArea();
SetProperty("Location", g_weatherManager.GetLocation(iCurWeather));
SetProperty("LocationIndex", iCurWeather);
- CStdString strSetting;
- strSetting.Format("weather.areacode%i", iCurWeather);
- SetProperty("AreaCode", CWeather::GetAreaCode(g_guiSettings.GetString(strSetting)));
SetProperty("Updated", g_weatherManager.GetLastUpdateTime());
SetProperty("Current.ConditionIcon", g_weatherManager.GetInfo(WEATHER_IMAGE_CURRENT_ICON));
SetProperty("Current.Condition", g_weatherManager.GetInfo(WEATHER_LABEL_CURRENT_COND));
@@ -314,40 +285,3 @@ void CGUIWindowWeather::SetProperties()
SetProperty(day + "FanartCode", fanartcode);
}
}
-
-void CGUIWindowWeather::CallScript()
-{
-#ifdef HAS_PYTHON
- if (!g_guiSettings.GetString("weather.script").Equals(DEFAULT_WEATHER_ADDON))
- {
- AddonPtr addon;
- if (!ADDON::CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.script"), addon, ADDON_SCRIPT_WEATHER))
- return;
-
- // initialize our sys.argv variables
- std::vector<CStdString> argv;
- argv.push_back(addon->LibPath());
-
- // if script is running we wait for another timeout only when in weather window
- if (g_windowManager.GetActiveWindow() == WINDOW_WEATHER)
- {
- int id = g_pythonParser.getScriptId(argv[0]);
- if (id != -1 && g_pythonParser.isRunning(id))
- {
- m_scriptTimer.StartZero();
- return;
- }
- }
-
- // get the current locations area code
- CStdString strSetting;
- strSetting.Format("weather.areacode%i", g_weatherManager.GetArea());
- argv.push_back(CWeather::GetAreaCode(g_guiSettings.GetString(strSetting)));
-
- // call our script, passing the areacode
- g_pythonParser.evalFile(argv[0], argv,addon);
-
- CLog::Log(LOGDEBUG, "%s - Weather script called: %s (%s)", __FUNCTION__, argv[0].c_str(), argv[1].c_str());
- }
-#endif
-}
View
3  xbmc/windows/GUIWindowWeather.h
@@ -38,8 +38,7 @@ class CGUIWindowWeather : public CGUIWindow
void UpdateButtons();
void UpdateLocations();
void SetProperties();
- void CallScript();
void SetLocation(int loc);
- CStopWatch m_scriptTimer;
+ unsigned int m_maxLocation;
};
Please sign in to comment.
Something went wrong with that request. Please try again.