+++ /dev/null
-<?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>
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);
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"))
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.scriptsettings"))
{
CStdString name = g_guiSettings.GetString("weather.script");
AddonPtr addon;
#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
bool CWeatherJob::m_imagesOkay = false;
-CWeatherJob::CWeatherJob(const CStdString &areaCode)
+CWeatherJob::CWeatherJob(int location)
{
- m_areaCode = areaCode;
+ m_location = location;
}
bool CWeatherJob::DoWork()
if (!g_application.getNetwork().IsAvailable(true))
return false;
+ AddonPtr addon;
+ if (!ADDON::CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.script"), 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);
#endif
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);
}
}
+void CWeatherJob::SetFromProperties()
+{
+ // Load in our tokens if necessary
+ if (!m_localizedTokens.size())
+ LoadLocalizedToken();
+
+ 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
+ {
+ LocalizeOverviewToken(direction);
+ m_info.currentWind.Format(g_localizeStrings.Get(434).c_str(),
+ direction, speed, g_langInfo.GetSpeedUnitString().c_str());
+ }
+ 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)
+ {
+ 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);
+ }
+}
CWeather::CWeather(void) : CInfoLoader(30 * 60 * 1000) // 30 minutes
{
*/
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()
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)
#define WEATHER_LABEL_CURRENT_DEWP 27
#define WEATHER_LABEL_CURRENT_HUMI 28
-#define MAX_LOCATION 3
-
struct day_forecast
{
CStdString m_icon;
class CWeatherJob : public CJob
{
public:
- CWeatherJob(const CStdString &areaCode);
+ CWeatherJob(int location);
virtual bool DoWork();
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).
typedef std::map<CStdString, int>::const_iterator ilocalizedTokens;
CWeatherInfo m_info;
- CStdString m_areaCode;
+ int m_location;
static bool m_imagesOkay;
};
private:
- CStdString m_location[MAX_LOCATION];
-
CWeatherInfo m_info;
};
}
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);
{
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:
{
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;
}
{
// 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();
}
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?
// update our controls
UpdateButtons();
- // call weather script
- if (m_scriptTimer.IsRunning() && m_scriptTimer.GetElapsedMilliseconds() > timeToCallScript)
- {
- m_scriptTimer.Stop();
- CallScript();
- }
-
CGUIWindow::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)
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));
void SetLocation(int loc);
CStopWatch m_scriptTimer;
+ unsigned int m_maxLocation;
};