Project

General

Profile

Bug #128 » xbmc4xbox-weather-2011-01-17.diff

nuka1195, 17/01/2011 05:10 AM

View differences:

scripts/.modules/script.module.weather/lib/xbmcweather/search.py (working copy)
html = self._fetch_source()
# get location name
result = self.regex_geo.search( html ).groups( 1 )
# raise an error if city not in database
if ( result[ 1 ].startswith( "-" ) ):
raise
# if ip has not changed return old values
if ( result[ 0 ] == self.Addon.getSetting( "ip_geo" ) ):
return self.Addon.getSetting( "id_geo" ), result[ 0 ]
......
return self.get_town( text=result[ 1 ] )[ 1 ], result[ 0 ]
except:
# use our fallback for any errors
return self.Addon.getSetting( "id_geo_fallback" ), ""
return self.Addon.getSetting( "id_geo_fallback" ), "None"
def get_town( self, text=None ):
try:
scripts/.modules/script.module.xbmcaddon/lib/xbmcaddon.py (working copy)
self._set_addon_info( cwd, id )
def _get_root_dir( self ):
print "****************************"
print sys.argv
print xbmc.translatePath( os.path.dirname( sys.argv[ 0 ] ) )
print "****************************"
print os.getcwd()
print "****************************"
# get current working directory
cwd = xbmc.translatePath( os.path.dirname( sys.argv[ 0 ] ) )#os.getcwd()
cwd = xbmc.translatePath( os.path.dirname( sys.argv[ 0 ] ) )
# check if we're at root folder of addon
if ( not os.path.isfile( os.path.join( cwd, "addon.xml" ) ) ):
# we're not at root, assume resources/lib/
cwd = os.path.dirname( os.path.dirname( cwd ) )#os.path.dirname( os.getcwd() ) )
cwd = os.path.dirname( os.path.dirname( os.path.dirname( cwd ) )
# return result
return cwd
skin/Confluence/720p/script.weather.com.plus/CommonValues.xml (working copy)
</include>
<include name="TWC.LoadingLabel">
<label>$LOCALIZE[410]</label>
<visible>!IsTrue(Window.Property(Weather.IsFetched)) + !StringCompare(Window.Property(Weather.IsFetched),error)</visible>
<visible>!Weather.IsFetched + !StringCompare(Window.Property(Weather.IsFetched),error)</visible>
<include>TWC.LoadingLabelCommon</include>
</include>
<include name="TWC.LoadingFailedLabel">
skin/Confluence/720p/script.weather.com.plus/Current.xml (working copy)
<!-- current weather -->
<control type="group">
<animation effect="fade" reversible="true" time="300">VisibleChange</animation>
<visible>IsTrue(Window.Property(Weather.IsFetched))</visible>
<visible>Weather.IsFetched</visible>
<control type="group">
<posx>-30</posx>
<posy>-20</posy>
......
<itemgap>0</itemgap>
<orientation>horizontal</orientation>
<animation effect="fade" reversible="true" time="300">VisibleChange</animation>
<visible>IsTrue(Window.Property(Weather.IsFetched))</visible>
<visible>Weather.IsFetched</visible>
<control type="group">
<width>168</width>
<control type="image">
xbmc/GUIWindowWeather.cpp (working copy)
#include "stdafx.h"
#include "GUIWindowWeather.h"
#include "GUIImage.h"
#include "utils/Weather.h"
#include "GUISettings.h"
#include "GUIWindowManager.h"
#include "Util.h"
#include "lib/libPython/XBPython.h"
#include "GUIDialogOK.h"
#include "xbox/network.h"
#define CONTROL_BTNREFRESH 2
#define CONTROL_SELECTLOCATION 3
#define CONTROL_LABELUPDATED 11
#define CONTROL_IMAGELOGO 101
#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 MAX_LOCATION 3
#define LOCALIZED_TOKEN_FIRSTID 370
#define LOCALIZED_TOKEN_LASTID 395
DWORD timeToCallPlugin = 1000;
float timeToCallPlugin = 1000;
bool forceRefresh = false;
/*
FIXME'S
>strings are not centered
>weather.com dev account is mine not a general xbmc one
*/
CGUIWindowWeather::CGUIWindowWeather(void)
: CGUIWindow(WINDOW_WEATHER, "MyWeather.xml")
{
m_iCurWeather = 0;
#ifdef _USE_ZIP_
#endif
}
CGUIWindowWeather::~CGUIWindowWeather(void)
......
if (iControl == CONTROL_BTNREFRESH)
{
forceRefresh = true;
CallPlugin();
Refresh();
}
else if (iControl == CONTROL_SELECTLOCATION)
{
......
if (m_pluginTimer.IsRunning())
m_pluginTimer.Stop();
CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_SELECTLOCATION);
CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_SELECTLOCATION);
g_windowManager.SendMessage(msg);
m_iCurWeather = msg.GetParam1();
CStdString strLabel=g_weatherManager.GetLocation(m_iCurWeather);
CStdString strLabel = g_weatherManager.GetLocation(m_iCurWeather);
int iPos = strLabel.ReverseFind(", ");
if (iPos)
{
......
{
UpdateLocations();
SetProperties();
if (IsActive())
if (IsActive() && !forceRefresh)
m_pluginTimer.StartZero();
else
CallPlugin();
......
{
if (!IsActive()) return;
CGUIMessage msg(GUI_MSG_LABEL_RESET,GetID(),CONTROL_SELECTLOCATION);
CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_SELECTLOCATION);
g_windowManager.SendMessage(msg);
CGUIMessage msg2(GUI_MSG_LABEL_ADD,GetID(),CONTROL_SELECTLOCATION);
CGUIMessage msg2(GUI_MSG_LABEL_ADD, GetID(), CONTROL_SELECTLOCATION);
unsigned int maxLocations = g_weatherManager.GetMaxLocations();
for (unsigned int i = 0; i < maxLocations; i++)
{
char *szLocation = g_weatherManager.GetLocation(i);
if (!szLocation) continue;
CStdString strLabel(szLocation);
if (strlen(szLocation) > 1) //got the location string yet?
CStdString strLabel = g_weatherManager.GetLocation(i);
if (strLabel.size() > 1) //got the location string yet?
{
int iPos = strLabel.ReverseFind(", ");
if (iPos)
......
else
{
strLabel.Format("AreaCode %i", i + 1);
msg2.SetLabel(strLabel);
msg2.SetParam1(i);
g_windowManager.SendMessage(msg2);
}
if (i==m_iCurWeather)
SET_CONTROL_LABEL(CONTROL_SELECTLOCATION,strLabel);
SET_CONTROL_LABEL(CONTROL_SELECTLOCATION, strLabel);
}
CONTROL_SELECT_ITEM(CONTROL_SELECTLOCATION, m_iCurWeather);
......
void CGUIWindowWeather::UpdateButtons()
{
CONTROL_ENABLE(CONTROL_BTNREFRESH);
SET_CONTROL_LABEL(CONTROL_BTNREFRESH, 184); //Refresh
}
......
argv[0] = (char*)plugin.c_str();
// if plugin is running we wait for another timeout only when in weather window
if (g_windowManager.GetActiveWindow() == WINDOW_WEATHER)
if (IsActive())
{
int id = g_pythonParser.getScriptId(argv[0]);
if (id != -1 && g_pythonParser.isRunning(id))
xbmc/utils/Weather.cpp (working copy)
return 15 * 60 * 1000;
}
char *CWeather::GetLocation(int iLocation)
CStdString CWeather::GetLocation(int iLocation)
{
if (strlen(m_szLocation[iLocation]) == 0)
if (m_szLocation[iLocation].IsEmpty())
{
CStdString cScriptPath = "special://home/plugins/weather/" + g_guiSettings.GetString("weather.plugin");
CScriptSettings* settings = new CScriptSettings();
......
settings->Load(cScriptPath);
CStdString setting;
setting.Format("town%i", iLocation + 1);
strcpy(m_szLocation[iLocation], settings->Get(setting).c_str());
m_szLocation[iLocation] = settings->Get(setting);
}
return m_szLocation[iLocation];
}
......
{
for (int i = 0; i < MAX_LOCATION; i++)
{
strcpy(m_szLocation[i], "");
m_szLocation[i] = "";
}
m_MaxLocations = -1;
}
xbmc/utils/Weather.h (working copy)
CWeather(void);
virtual ~CWeather(void);
char *GetLocation(int iLocation);
CStdString GetLocation(int iLocation);
bool IsFetched();
void Reset();
......
virtual CStdString TranslateInfo(int info) const;
virtual DWORD TimeToNextRefreshInMs();
char m_szLocation[10][100];
CStdString m_szLocation[10];
unsigned int m_iCurWeather;
int m_MaxLocations;
(10-10/13)