Skip to content

Commit

Permalink
[python] add ContextItemAddonInvoker for running context item addons
Browse files Browse the repository at this point in the history
  • Loading branch information
tamland committed Mar 1, 2015
1 parent ae8a02e commit 2951068
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
60 changes: 60 additions & 0 deletions xbmc/interfaces/python/ContextItemAddonInvoker.cpp
Original file line number Diff line number Diff line change
@@ -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
}
}
}
41 changes: 41 additions & 0 deletions xbmc/interfaces/python/ContextItemAddonInvoker.h
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions xbmc/interfaces/python/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include ../../../codegenerator.mk

SRCS = AddonPythonInvoker.cpp \
CallbackHandler.cpp \
ContextItemAddonInvoker.cpp \
LanguageHook.cpp \
PythonInvoker.cpp \
XBPython.cpp \
Expand Down

0 comments on commit 2951068

Please sign in to comment.