diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2012-09-10 20:41:22 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2012-09-10 20:41:22 -0400 |
commit | e5d85a1c881852cbf6a8bea4cb688d04ba64da21 (patch) | |
tree | 2fb8d7c8e28ac280676a14efb0e4cac647db98c4 | |
parent | 254e862dfcef916f95128d7fa01902d11e447c06 (diff) |
[fix] Undo ref-count of controls. Also add 'addItems' to ControlList.
-rw-r--r-- | xbmc/interfaces/legacy/Control.cpp | 15 | ||||
-rw-r--r-- | xbmc/interfaces/legacy/Control.h | 10 | ||||
-rw-r--r-- | xbmc/interfaces/swig/AddonModuleXbmcgui.i | 66 | ||||
-rw-r--r-- | xbmc/interfaces/swig/ControlListAddItemMethods.i | 160 |
4 files changed, 178 insertions, 73 deletions
diff --git a/xbmc/interfaces/legacy/Control.cpp b/xbmc/interfaces/legacy/Control.cpp index 92619665a8..fcd1c71abc 100644 --- a/xbmc/interfaces/legacy/Control.cpp +++ b/xbmc/interfaces/legacy/Control.cpp @@ -1181,12 +1181,12 @@ namespace XBMCAddon return pGUIControl; } - void ControlList::addItemStream(const String& fileOrUrl) throw(UnimplementedException,WindowException) + void ControlList::addItemStream(const String& fileOrUrl, bool sendMessage) throw(UnimplementedException,WindowException) { - addListItem(ListItem::fromString(fileOrUrl)); + addListItem(ListItem::fromString(fileOrUrl),sendMessage); } - void ControlList::addListItem(const XBMCAddon::xbmcgui::ListItem* pListItem) throw(UnimplementedException,WindowException) + void ControlList::addListItem(const XBMCAddon::xbmcgui::ListItem* pListItem, bool sendMessage) throw(UnimplementedException,WindowException) { if (pListItem == NULL) throw WindowException("NULL ListItem passed to ControlList::addListItem"); @@ -1194,9 +1194,16 @@ namespace XBMCAddon // add item to objects vector vecItems.push_back(pListItem); + // send all of the items ... this is what it did before. + if (sendMessage) + sendLabelBind(vecItems.size()); + } + + void ControlList::sendLabelBind(int tail) + { // construct a CFileItemList to pass 'em on to the list CGUIListItemPtr items(new CFileItemList()); - for (unsigned int i = 0; i < vecItems.size(); i++) + for (unsigned int i = vecItems.size() - tail; i < vecItems.size(); i++) ((CFileItemList*)items.get())->Add(vecItems[i]->item); CGUIMessage msg(GUI_MSG_LABEL_BIND, iParentId, iControlId, 0, 0, items); diff --git a/xbmc/interfaces/legacy/Control.h b/xbmc/interfaces/legacy/Control.h index db44ac9058..0a236efab2 100644 --- a/xbmc/interfaces/legacy/Control.h +++ b/xbmc/interfaces/legacy/Control.h @@ -134,8 +134,8 @@ namespace XBMCAddon // These need to be here for the stubbed out addItem // and addItems methods - virtual void addItemStream(const String& fileOrUrl) DECL_UNIMP2("Control",WindowException); - virtual void addListItem(const XBMCAddon::xbmcgui::ListItem* listitem) DECL_UNIMP2("Control",WindowException); + virtual void addItemStream(const String& fileOrUrl, bool sendMessage = true) DECL_UNIMP2("Control",WindowException); + virtual void addListItem(const XBMCAddon::xbmcgui::ListItem* listitem, bool sendMessage = true) DECL_UNIMP2("Control",WindowException); /** * getId() -- Returns the control's current id as an integer. @@ -635,8 +635,8 @@ namespace XBMCAddon * example: * - cList.addItem('Reboot XBMC') */ - virtual void addItemStream(const String& fileOrUrl) throw(UnimplementedException,WindowException); - virtual void addListItem(const XBMCAddon::xbmcgui::ListItem* listitem) throw(UnimplementedException,WindowException); + virtual void addItemStream(const String& fileOrUrl, bool sendMessage = true) throw(UnimplementedException,WindowException); + virtual void addListItem(const XBMCAddon::xbmcgui::ListItem* listitem, bool sendMessage = true) throw(UnimplementedException,WindowException); /** * selectItem(item) -- Select an item by index number. @@ -790,6 +790,8 @@ namespace XBMCAddon virtual void setStaticContent(const ListItemList* items) throw (UnimplementedException); #ifndef SWIG + void sendLabelBind(int tail); + SWIGHIDDENVIRTUAL bool canAcceptMessages(int actionId) { return ((actionId == ACTION_SELECT_ITEM) | (actionId == ACTION_MOUSE_LEFT_CLICK)); } diff --git a/xbmc/interfaces/swig/AddonModuleXbmcgui.i b/xbmc/interfaces/swig/AddonModuleXbmcgui.i index 4d33575424..03d7875a29 100644 --- a/xbmc/interfaces/swig/AddonModuleXbmcgui.i +++ b/xbmc/interfaces/swig/AddonModuleXbmcgui.i @@ -54,71 +54,7 @@ using namespace xbmcgui; %include "interfaces/legacy/ListItem.h" - -%feature("python:method:addItem") ControlList -{ - TRACE; - - static const char *keywords[] = { - "item", - NULL}; - - String item; - PyObject* pyitem = NULL; - if (!PyArg_ParseTupleAndKeywords( - args, - kwds, - (char*)"O", - (char**)keywords, - &pyitem - )) - return NULL; - - const char* callName = "addItem"; - try - { - XBMCAddon::xbmcgui::ControlList* apiobj = ((XBMCAddon::xbmcgui::ControlList*)retrieveApiInstance((PyObject*)self, - &PyXBMCAddon_xbmcgui_ControlList_Type,"addItem","XBMCAddon::xbmcgui::Control")); - - if (PyUnicode_Check(pyitem) || PyString_Check(pyitem)) - { - callName = "addItemStream"; - PyXBMCGetUnicodeString(item,pyitem,false,"item","addItem"); - apiobj->addItemStream(item); - } - else - { - callName = "addListItem"; - // assume it's a ListItem. retrieveApiInstance will throw an exception if it's not - XBMCAddon::xbmcgui::ListItem* listItem = ((XBMCAddon::xbmcgui::ListItem*)retrieveApiInstance((PyObject*)pyitem, - &PyXBMCAddon_xbmcgui_ListItem_Type,"addItem","XBMCAddon::xbmcgui::ListItem")); - apiobj->addListItem(listItem); - } - } - catch (const XbmcCommons::Exception& e) - { - CLog::Log(LOGERROR,"Leaving Python method 'XBMCAddon_xbmcgui_Control_addItemStream'. Exception from call to '%s' '%s' ... returning NULL", callName,e.GetMessage()); - PyErr_SetString(PyExc_RuntimeError, e.GetMessage()); - return NULL; - } - catch (...) - { - CLog::Log(LOGERROR,"Unknown exception thrown from the call '%s'",callName); - PyErr_SetString(PyExc_RuntimeError, "Unknown exception thrown from the call 'addItem'"); - return NULL; - } - - PyObject* result; - - // transform the result - Py_INCREF(Py_None); - result = Py_None; - - return result; - } - -%feature("ref") Control "${ths}->Acquire();" -%feature("unref") Control "${ths}->Release();" +%include "ControlListAddItemMethods.i" %feature("python:coerceToUnicode") XBMCAddon::xbmcgui::ControlButton::getLabel "true" %feature("python:coerceToUnicode") XBMCAddon::xbmcgui::ControlButton::getLabel2 "true" %include "interfaces/legacy/Control.h" diff --git a/xbmc/interfaces/swig/ControlListAddItemMethods.i b/xbmc/interfaces/swig/ControlListAddItemMethods.i new file mode 100644 index 0000000000..4a222ad1d7 --- /dev/null +++ b/xbmc/interfaces/swig/ControlListAddItemMethods.i @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.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, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +/** + * This file contains the two python methods, addItem and addItems for controls + */ +#pragma once + +%feature("python:method:addItem") ControlList +{ + TRACE; + + static const char *keywords[] = { + "item", + NULL}; + + String item; + PyObject* pyitem = NULL; + if (!PyArg_ParseTupleAndKeywords( + args, + kwds, + (char*)"O", + (char**)keywords, + &pyitem + )) + return NULL; + + const char* callName = "addItem"; + try + { + XBMCAddon::xbmcgui::ControlList* apiobj = ((XBMCAddon::xbmcgui::ControlList*)retrieveApiInstance((PyObject*)self, + &PyXBMCAddon_xbmcgui_ControlList_Type,"addItem","XBMCAddon::xbmcgui::Control")); + + if (PyUnicode_Check(pyitem) || PyString_Check(pyitem)) + { + callName = "addItemStream"; + PyXBMCGetUnicodeString(item,pyitem,false,"item","addItem"); + apiobj->addItemStream(item); + } + else + { + callName = "addListItem"; + // assume it's a ListItem. retrieveApiInstance will throw an exception if it's not + XBMCAddon::xbmcgui::ListItem* listItem = ((XBMCAddon::xbmcgui::ListItem*)retrieveApiInstance((PyObject*)pyitem, + &PyXBMCAddon_xbmcgui_ListItem_Type,"addItem","XBMCAddon::xbmcgui::ListItem")); + apiobj->addListItem(listItem); + } + } + catch (const XbmcCommons::Exception& e) + { + CLog::Log(LOGERROR,"Leaving Python method 'XBMCAddon_xbmcgui_Control_addItemStream'. Exception from call to '%s' '%s' ... returning NULL", callName,e.GetMessage()); + PyErr_SetString(PyExc_RuntimeError, e.GetMessage()); + return NULL; + } + catch (...) + { + CLog::Log(LOGERROR,"Unknown exception thrown from the call '%s'",callName); + PyErr_SetString(PyExc_RuntimeError, "Unknown exception thrown from the call 'addItem'"); + return NULL; + } + + PyObject* result; + + // transform the result + Py_INCREF(Py_None); + result = Py_None; + + return result; +} + +%feature("python:method:addItems") ControlList +{ + TRACE; + + static const char *keywords[] = { + "items", + NULL}; + + String items; + PyObject* pyitems = NULL; + if (!PyArg_ParseTupleAndKeywords( + args, + kwds, + (char*)"O", + (char**)keywords, + &pyitems + )) + return NULL; + + const char* callName = "addItems"; + try + { + XBMCAddon::xbmcgui::ControlList* apiobj = ((XBMCAddon::xbmcgui::ControlList*)retrieveApiInstance((PyObject*)self, + &PyXBMCAddon_xbmcgui_ControlList_Type,"addItem","XBMCAddon::xbmcgui::Control")); + + CGUIListItemPtr items(new CFileItemList()); + int listSize = PyList_Size(pyitems); + for (int index = 0; index < listSize; index++) + { + PyObject *pyitem = PyList_GetItem(pyitems, index); + + if (PyUnicode_Check(pyitem) || PyString_Check(pyitem)) + { + callName = "addItemStream"; + String item; + PyXBMCGetUnicodeString(item,pyitem,false,"item","addItem"); + apiobj->addItemStream(item,false); + } + else + { + callName = "addListItem"; + // assume it's a ListItem. retrieveApiInstance will throw an exception if it's not + XBMCAddon::xbmcgui::ListItem* listItem = ((XBMCAddon::xbmcgui::ListItem*)retrieveApiInstance((PyObject*)pyitem, + &PyXBMCAddon_xbmcgui_ListItem_Type,"addItem","XBMCAddon::xbmcgui::ListItem")); + apiobj->addListItem(listItem,false); + } + } + + apiobj->sendLabelBind(listSize); + } + catch (const XbmcCommons::Exception& e) + { + CLog::Log(LOGERROR,"Leaving Python method 'XBMCAddon_xbmcgui_Control_addItemStream'. Exception from call to '%s' '%s' ... returning NULL", callName,e.GetMessage()); + PyErr_SetString(PyExc_RuntimeError, e.GetMessage()); + return NULL; + } + catch (...) + { + CLog::Log(LOGERROR,"Unknown exception thrown from the call '%s'",callName); + PyErr_SetString(PyExc_RuntimeError, "Unknown exception thrown from the call 'addItem'"); + return NULL; + } + + PyObject* result; + + // transform the result + Py_INCREF(Py_None); + result = Py_None; + + return result; +} + |