diff options
author | Thomas Amland <thomas.amland@gmail.com> | 2015-02-17 15:31:58 +0100 |
---|---|---|
committer | Thomas Amland <thomas.amland@gmail.com> | 2015-03-01 15:54:21 +0100 |
commit | 295106877608238f7874040d21dc29e0b63d90e7 (patch) | |
tree | aa51f0d560199cbb446959dd332032e101534513 | |
parent | ae8a02ee4de0afb53356de51aeac0d02bdf785c6 (diff) |
[python] add ContextItemAddonInvoker for running context item addons
-rw-r--r-- | xbmc/interfaces/python/ContextItemAddonInvoker.cpp | 60 | ||||
-rw-r--r-- | xbmc/interfaces/python/ContextItemAddonInvoker.h | 41 | ||||
-rw-r--r-- | xbmc/interfaces/python/Makefile.in | 1 |
3 files changed, 102 insertions, 0 deletions
diff --git a/xbmc/interfaces/python/ContextItemAddonInvoker.cpp b/xbmc/interfaces/python/ContextItemAddonInvoker.cpp new file mode 100644 index 0000000000..23d8d65996 --- /dev/null +++ b/xbmc/interfaces/python/ContextItemAddonInvoker.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 Team XBMC + * http://xbmc.org + * + * 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, 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 XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS) + #include "config.h" +#endif + +// python.h should always be included first before any other includes +#include <Python.h> +#include <osdefs.h> + +#include "system.h" +#include "ContextItemAddonInvoker.h" +#include "addons/AddonVersion.h" +#include "utils/log.h" +#include "interfaces/python/swig.h" + + +CContextItemAddonInvoker::CContextItemAddonInvoker( + ILanguageInvocationHandler *invocationHandler, + const CFileItemPtr& item) + : CAddonPythonInvoker(invocationHandler), m_item(CFileItemPtr(new CFileItem(*item.get()))) +{ +} + +CContextItemAddonInvoker::~CContextItemAddonInvoker() +{ +} + +void CContextItemAddonInvoker::onPythonModuleInitialization(void* moduleDict) +{ + CAddonPythonInvoker::onPythonModuleInitialization(moduleDict); + if (m_item) + { + XBMCAddon::xbmcgui::ListItem* arg = new XBMCAddon::xbmcgui::ListItem(m_item); + PyObject* pyItem = PythonBindings::makePythonInstance(arg, true); + if (pyItem == Py_None || PySys_SetObject((char*)"listitem", pyItem) == -1) + { + CLog::Log(LOGERROR, "CPythonInvoker(%d, %s): Failed to set sys parameter", GetId(), m_sourceFile.c_str()); + //FIXME: we should really abort execution + } + } +} diff --git a/xbmc/interfaces/python/ContextItemAddonInvoker.h b/xbmc/interfaces/python/ContextItemAddonInvoker.h new file mode 100644 index 0000000000..56eaf8a46e --- /dev/null +++ b/xbmc/interfaces/python/ContextItemAddonInvoker.h @@ -0,0 +1,41 @@ +#pragma once +/* + * Copyright (C) 2015 Team XBMC + * http://xbmc.org + * + * 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, 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 XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include <memory> +#include "interfaces/python/PythonInvoker.h" +#include "interfaces/python/AddonPythonInvoker.h" + +class CFileItem; +typedef std::shared_ptr<CFileItem> CFileItemPtr; + +class CContextItemAddonInvoker : public CAddonPythonInvoker +{ +public: + explicit CContextItemAddonInvoker(ILanguageInvocationHandler *invocationHandler, + const CFileItemPtr& item); + virtual ~CContextItemAddonInvoker(); + +protected: + virtual void onPythonModuleInitialization(void* moduleDict); + +private: + const CFileItemPtr m_item; +}; diff --git a/xbmc/interfaces/python/Makefile.in b/xbmc/interfaces/python/Makefile.in index e48c30ddf0..92ddd25a6b 100644 --- a/xbmc/interfaces/python/Makefile.in +++ b/xbmc/interfaces/python/Makefile.in @@ -13,6 +13,7 @@ include ../../../codegenerator.mk SRCS = AddonPythonInvoker.cpp \ CallbackHandler.cpp \ + ContextItemAddonInvoker.cpp \ LanguageHook.cpp \ PythonInvoker.cpp \ XBPython.cpp \ |