From 295106877608238f7874040d21dc29e0b63d90e7 Mon Sep 17 00:00:00 2001 From: Thomas Amland Date: Tue, 17 Feb 2015 15:31:58 +0100 Subject: [PATCH] [python] add ContextItemAddonInvoker for running context item addons --- .../python/ContextItemAddonInvoker.cpp | 60 +++++++++++++++++++ .../python/ContextItemAddonInvoker.h | 41 +++++++++++++ xbmc/interfaces/python/Makefile.in | 1 + 3 files changed, 102 insertions(+) create mode 100644 xbmc/interfaces/python/ContextItemAddonInvoker.cpp create mode 100644 xbmc/interfaces/python/ContextItemAddonInvoker.h diff --git a/xbmc/interfaces/python/ContextItemAddonInvoker.cpp b/xbmc/interfaces/python/ContextItemAddonInvoker.cpp new file mode 100644 index 0000000000000..23d8d65996d11 --- /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 + * . + * + */ + +#if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS) + #include "config.h" +#endif + +// python.h should always be included first before any other includes +#include +#include + +#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 0000000000000..56eaf8a46ee84 --- /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 + * . + * + */ + +#include +#include "interfaces/python/PythonInvoker.h" +#include "interfaces/python/AddonPythonInvoker.h" + +class CFileItem; +typedef std::shared_ptr 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 e48c30ddf03da..92ddd25a6bcd7 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 \