forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] add ContextItemAddonInvoker for running context item addons
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters