Skip to content
Browse files

added: ticket #5815 - Weather plugin via python script. thanks to nuk…

…a1195

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/branches/linuxport/XBMC@20734 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information...
1 parent 9b1ead7 commit accd65eb9254b6b36fd5bc6027af1ec5c11451cd spiff_ committed May 28, 2009
View
2 language/English/strings.xml
@@ -2077,6 +2077,8 @@
<string id="22042">white/blue</string>
<string id="22043">black/white</string>
+ <string id="23000">Weather plug-in</string>
+
<!-- strings 29800 thru 29998 reserved strings used only in the default Project Mayhem III skin and not c++ code -->
<string id="29800">Library Mode</string>
<string id="29801">QWERTY keyboard</string>
View
4 xbmc/Application.cpp
@@ -1027,6 +1027,7 @@ CProfile* CApplication::InitDirectoriesLinux()
CDirectory::Create("special://home/plugins/music");
CDirectory::Create("special://home/plugins/pictures");
CDirectory::Create("special://home/plugins/programs");
+ CDirectory::Create("special://home/plugins/weather");
CDirectory::Create("special://home/scripts");
CDirectory::Create("special://home/scripts/My Scripts"); // FIXME: both scripts should be in 1 directory
symlink( INSTALL_PATH "/scripts", _P("special://home/scripts/Common Scripts").c_str() );
@@ -1133,6 +1134,7 @@ CProfile* CApplication::InitDirectoriesOSX()
CDirectory::Create("special://home/plugins/music");
CDirectory::Create("special://home/plugins/pictures");
CDirectory::Create("special://home/plugins/programs");
+ CDirectory::Create("special://home/plugins/weather");
CDirectory::Create("special://home/scripts");
CDirectory::Create("special://home/scripts/My Scripts"); // FIXME: both scripts should be in 1 directory
#ifdef __APPLE__
@@ -1228,6 +1230,7 @@ CProfile* CApplication::InitDirectoriesWin32()
CDirectory::Create("special://home/plugins/music");
CDirectory::Create("special://home/plugins/pictures");
CDirectory::Create("special://home/plugins/programs");
+ CDirectory::Create("special://home/plugins/weather");
CDirectory::Create("special://home/scripts");
CDirectory::Create("special://masterprofile");
@@ -1318,6 +1321,7 @@ HRESULT CApplication::Initialize()
CDirectory::Create("special://xbmc/plugins/video");
CDirectory::Create("special://xbmc/plugins/pictures");
CDirectory::Create("special://xbmc/plugins/programs");
+ CDirectory::Create("special://xbmc/plugins/weather");
CDirectory::Create("special://xbmc/language");
CDirectory::Create("special://xbmc/visualisations");
CDirectory::Create("special://xbmc/sounds");
View
4 xbmc/GUISettings.cpp
@@ -226,7 +226,9 @@ void CGUISettings::Initialize()
AddString(2, "weather.areacode2", 14020, "UKXX0085 - London, United Kingdom", BUTTON_CONTROL_STANDARD);
AddString(3, "weather.areacode3", 14021, "JAXX0085 - Tokyo, Japan", BUTTON_CONTROL_STANDARD);
AddSeparator(4, "weather.sep1");
- AddString(5, "weather.jumptolocale", 20026, "", BUTTON_CONTROL_STANDARD);
+ AddString(5, "weather.plugin", 23000, "", SPIN_CONTROL_TEXT, true);
+ AddSeparator(6, "weather.sep2");
+ AddString(7, "weather.jumptolocale", 20026, "", BUTTON_CONTROL_STANDARD);
// My Music Settings
AddGroup(3, 2);
View
49 xbmc/GUIWindowSettingsCategory.cpp
@@ -85,6 +85,7 @@
#include "FileItem.h"
#include "GUIToggleButtonControl.h"
#include "FileSystem/SpecialProtocol.h"
+#include "File.h"
#include "Zeroconf.h"
#include "PowerManager.h"
@@ -891,6 +892,11 @@ void CGUIWindowSettingsCategory::CreateSettings()
pControl->AddLabel(g_localizeStrings.Get(13509), RESAMPLE_REALLYHIGH);
pControl->SetValue(pSettingInt->GetData());
}
+ else if (strSetting.Equals("weather.plugin"))
+ {
+ CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
+ FillInWeatherPlugins(pControl, g_guiSettings.GetString("weather.plugin", false));
+ }
}
if (m_vecSections[m_iSection]->m_strCategory == "network")
@@ -1287,6 +1293,11 @@ void CGUIWindowSettingsCategory::UpdateSettings()
CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(GetSetting(strSetting)->GetID());
pControl->SetLabel2(g_weatherManager.GetAreaCity(pSetting->GetData()));
}
+ else if (strSetting.Equals("weather.plugin"))
+ {
+ CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
+ g_guiSettings.SetString("weather.plugin", pControl->GetCurrentLabel());
+ }
else if (strSetting.Equals("system.leddisableonplayback"))
{
CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
@@ -1458,6 +1469,11 @@ void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
}
}
+ if (strSetting.Equals("weather.plugin"))
+ {
+ g_weatherManager.ResetTimer();
+ }
+
// if OnClick() returns false, the setting hasn't changed or doesn't
// require immediate update
if (!pSettingControl->OnClick())
@@ -3842,6 +3858,39 @@ void CGUIWindowSettingsCategory::FillInAudioDevices(CSetting* pSetting)
#endif
}
+void CGUIWindowSettingsCategory::FillInWeatherPlugins(CGUISpinControlEx *pControl, const CStdString& strSelected)
+{
+ int j=0;
+ int k=0;
+ pControl->Clear();
+ // add our disable option
+ pControl->AddLabel("weather.com", j++);
+
+ CFileItemList items;
+ if (CDirectory::GetDirectory("special://home/plugins/weather/", items, "/", false))
+ {
+ for (int i=0; i<items.Size(); ++i)
+ {
+ // create the full path to the plugin
+ CStdString plugin;
+ CStdString pluginPath = items[i]->m_strPath;
+ // remove slash at end so we can use the plugins folder as plugin name
+ CUtil::RemoveSlashAtEnd(pluginPath);
+ // add default.py to our plugin path to create the full path
+ CUtil::AddFileToFolder(pluginPath, "default.py", plugin);
+ if (XFILE::CFile::Exists(plugin))
+ {
+ // is this the users choice
+ if (CUtil::GetFileName(pluginPath).Equals(strSelected))
+ k = j;
+ // we want to use the plugins folder as name
+ pControl->AddLabel(CUtil::GetFileName(pluginPath), j++);
+ }
+ }
+ }
+ pControl->SetValue(k);
+}
+
void CGUIWindowSettingsCategory::NetworkInterfaceChanged(void)
{
if (!g_application.IsStandAlone())
View
1 xbmc/GUIWindowSettingsCategory.h
@@ -71,6 +71,7 @@ class CGUIWindowSettingsCategory :
void FillInScrapers(CGUISpinControlEx *pControl, const CStdString& strSelected, const CStdString& strContent);
void FillInAudioDevices(CSetting* pSetting);
+ void FillInWeatherPlugins(CGUISpinControlEx *pControl, const CStdString& strSelected);
virtual void SetupControls();
void CreateSettings();
View
54 xbmc/GUIWindowWeather.cpp
@@ -26,6 +26,7 @@
#include "GUISettings.h"
#include "GUIWindowManager.h"
#include "Util.h"
+#include "lib/libPython/XBPython.h"
#define CONTROL_BTNREFRESH 2
#define CONTROL_SELECTLOCATION 3
@@ -51,6 +52,8 @@
#define MAX_LOCATION 3
#define LOCALIZED_TOKEN_FIRSTID 370
#define LOCALIZED_TOKEN_LASTID 395
+
+DWORD timeToCallPlugin = 1000;
/*
FIXME'S
>strings are not centered
@@ -93,6 +96,10 @@ bool CGUIWindowWeather::OnMessage(CGUIMessage& message)
}
else if (iControl == CONTROL_SELECTLOCATION)
{
+ // stop the plugin timer here, so the user has a full second
+ if (m_pluginTimer.IsRunning())
+ m_pluginTimer.Stop();
+
CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_SELECTLOCATION);
m_gWindowManager.SendMessage(msg);
m_iCurWeather = msg.GetParam1();
@@ -120,6 +127,10 @@ bool CGUIWindowWeather::OnMessage(CGUIMessage& message)
{
UpdateLocations();
SetProperties();
+ if (m_gWindowManager.GetActiveWindow() == WINDOW_WEATHER)
+ m_pluginTimer.StartZero();
+ else
+ CallPlugin();
}
break;
}
@@ -227,6 +238,13 @@ void CGUIWindowWeather::Render()
// update our controls
UpdateButtons();
+ // call weather plugin
+ if (m_pluginTimer.IsRunning() && m_pluginTimer.GetElapsedMilliseconds() > timeToCallPlugin)
+ {
+ m_pluginTimer.Stop();
+ CallPlugin();
+ }
+
CGUIWindow::Render();
}
@@ -277,3 +295,39 @@ void CGUIWindowWeather::SetProperties()
SetProperty(day + "FanartCode", fanartcode);
}
}
+
+void CGUIWindowWeather::CallPlugin()
+{
+ if (!g_guiSettings.GetString("weather.plugin", false).empty() && !g_guiSettings.GetString("weather.plugin", false).Equals(g_localizeStrings.Get(23001)))
+ {
+ // create the full path to the plugin
+ CStdString plugin = "special://home/plugins/weather/" + g_guiSettings.GetString("weather.plugin", false) + "/default.py";
+
+ // initialize our sys.argv variables
+ unsigned int argc = 2;
+ char ** argv = new char*[argc];
+ argv[0] = (char*)plugin.c_str();
+
+ // if plugin is running we wait for another timeout only when in weather window
+ if (m_gWindowManager.GetActiveWindow() == WINDOW_WEATHER)
+ {
+ int id = g_pythonParser.getScriptId(argv[0]);
+ if (id != -1 && g_pythonParser.isRunning(id))
+ {
+ m_pluginTimer.StartZero();
+ return;
+ }
+ }
+
+ // get the current locations area code
+ CStdString strSetting;
+ strSetting.Format("weather.areacode%i", m_iCurWeather + 1);
+ const CStdString &areacode = g_weatherManager.GetAreaCode(g_guiSettings.GetString(strSetting)).c_str();
+ argv[1] = (char*)areacode.c_str();
+
+ // call our plugin, passing the areacode
+ g_pythonParser.evalFile(argv[0], argc, (const char**)argv);
+
+ CLog::Log(LOGDEBUG, "%s - Weather plugin called: %s (%s)", __FUNCTION__, argv[0], argv[1]);
+ }
+}
View
3 xbmc/GUIWindowWeather.h
@@ -22,6 +22,7 @@
*/
#include "GUIWindow.h"
+#include "utils/Stopwatch.h"
class CGUIWindowWeather : public CGUIWindow
{
@@ -38,8 +39,10 @@ class CGUIWindowWeather : public CGUIWindow
void UpdateButtons();
void UpdateLocations();
void SetProperties();
+ void CallPlugin();
void Refresh();
unsigned int m_iCurWeather;
+ CStopWatch m_pluginTimer;
};

0 comments on commit accd65e

Please sign in to comment.
Something went wrong with that request. Please try again.