Beispiel #1
0
  PyObject* ControlList_AddItems(ControlList *self, PyObject *args, PyObject *kwds)
  {
    PyObject *pList = NULL;
    static const char *keywords[] = { "items", NULL };

    if (!PyArg_ParseTupleAndKeywords(
      args,
      kwds,
      (char*)"O",
      (char**)keywords,
      &pList) || pList == NULL || !PyObject_TypeCheck(pList, &PyList_Type))
    {
      PyErr_SetString(PyExc_TypeError, "Object should be of type List");
      return NULL;
    }

    CFileItemList items;
    for (int item = 0; item < PyList_Size(pList); item++)
    {
      PyObject *pItem = PyList_GetItem(pList, item);

      ListItem* pListItem = NULL;
      if (ListItem_CheckExact(pItem))
      {
        // object is a listitem
        pListItem = (ListItem*)pItem;
        Py_INCREF(pListItem);
      }
      else
      {
        string strText;
        // object is probably a text item
        if (!PyGetUnicodeString(strText, pItem, 1)) return NULL;
        // object is a unicode string now, create a new ListItem
        pListItem = ListItem_FromString(strText);
      }

      // add item to objects vector
      self->vecItems.push_back(pListItem);
      items.Add(pListItem->item);
    }

    // create message
    CGUIMessage msg(GUI_MSG_LABEL_BIND, self->iParentId, self->iControlId, 0, 0, &items);

    // send message
    PyGUILock();
    if (self->pGUIControl) self->pGUIControl->OnMessage(msg);
    PyGUIUnlock();


    Py_INCREF(Py_None);
    return Py_None;
  }
  PyObject* ControlList_AddItem(ControlList *self, PyObject *args)
  {
    PyObject *pObject;
    if (!PyArg_ParseTuple(args, (char*)"O", &pObject))  return NULL;

    ListItem* pListItem = NULL;
    if (ListItem_CheckExact(pObject))
    {
      // object is a listitem
      pListItem = (ListItem*)pObject;
      Py_INCREF(pListItem);
    }
    else
    {
      string strText;
      // object is probably a text item
      if (!PyXBMCGetUnicodeString(strText, pObject, 1)) return NULL;
      // object is a unicode string now, create a new ListItem
      pListItem = ListItem_FromString(strText);
    }

    // add item to objects vector
    self->vecItems.push_back(pListItem);

    // construct a CFileItemList to pass 'em on to the list
    CGUIListItemPtr items(new CFileItemList());
    for (unsigned int i = 0; i < self->vecItems.size(); i++)
      ((CFileItemList*)items.get())->Add(self->vecItems[i]->item);

    CGUIMessage msg(GUI_MSG_LABEL_BIND, self->iParentId, self->iControlId, 0, 0, items);
    msg.SetPointer(items.get());
    g_windowManager.SendThreadMessage(msg, self->iParentId);

    Py_INCREF(Py_None);
    return Py_None;
  }