rendered paste body /*
* ControlList_AddItem
* (string label) / (ListItem)
* ListItem is added to vector
* For a string we create a new ListItem and add it to the vector
*/
PyDoc_STRVAR(addItem__doc__,
"addItem(item) -- Add a new item to this control list.\n"
"\n"
"item : string, unicode or ListItem - item to add.\n"
"\n"
"example:\n"
" - cList.addItem('Reboot XBMC')\n");
PyObject* ControlList_AddItem(ControlList *self, PyObject *args)
{
int itemPosition = INT_MAX;
PyObject *pObject;
string strText;
ListItem* pListItem = NULL;
if (!PyArg_ParseTuple(args, "O|i", &pObject, &itemPosition)) return NULL;
if (ListItem_CheckExact(pObject))
{
// object is a listitem
pListItem = (ListItem*)pObject;
Py_INCREF(pListItem);
}
else
{
// object is probably a text item
if (!PyGetUnicodeString(strText, pObject, 1)) return NULL;
// object is a unicode string now, create a new ListItem
pListItem = ListItem_FromString(strText);
}
// add item to objects vector
if (itemPosition == INT_MAX || (int)self->vecItems.size() < itemPosition)
{
self->vecItems.push_back(pListItem);
}
else if (itemPosition < -1 && !(itemPosition*-1 < (int)self->vecItems.size()))
{
self->vecItems.insert(self->vecItems.begin(), pListItem);
}
else
{
if (itemPosition >= 0)
{
vector<int>::iterator theIterator = self->vecItems.begin();
self->vecItems.insert(theIterator+itemPosition, pListItem);
}
else
{
self->vecItems.insert(self->vecItems.begin()+(self->vecItems.size()+itemPosition), pListItem);
}
}
// create message
CGUIMessage msg(GUI_MSG_LABEL_ADD, self->iParentId, self->iControlId);
msg.SetLPVOID(pListItem->item);
// send message
PyGUILock();
if (self->pGUIControl) self->pGUIControl->OnMessage(msg);
PyGUIUnlock();
Py_INCREF(Py_None);
return Py_None;
}