Update of /cvsroot/freevo/kaa/xine/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24151

Modified Files:
        __init__.py utils.h xine.c 
Log Message:
Implement config API (or most of it, anyway)


Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/__init__.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** __init__.py 30 Jul 2005 20:55:15 -0000      1.17
--- __init__.py 31 Jul 2005 17:59:43 -0000      1.18
***************
*** 313,316 ****
--- 313,341 ----
          return types
  
+     def get_config_entries(self):
+         cfg = self._xine.config_get_first_entry()
+         yield cfg
+         while True:
+             cfg = self._xine.config_get_next_entry()
+             if not cfg:
+                 break
+             yield cfg
+ 
+     def get_config_value(self, key):
+         return self._xine.config_lookup_entry(key)
+ 
+     def set_config_value(self, key, value):
+         cfg = self.get_config_value(key)
+         if cfg == None:
+             raise XineError, "Config option '%s' doesn't exist" % key
+         if cfg["type"] == tuple and type(value) != int:
+             # Try to resolve value
+             if value not in cfg["enums"]:
+                 raise XineError, "Value '%s' is not in list of valid values" 
% value
+             value = cfg["enums"].index(value)
+         else:
+             assert(type(value) == cfg["type"])
+         return self._xine.config_update_entry(key, value)
+ 
  
  class VODriver(object):

Index: xine.c
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/xine.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** xine.c      30 Jul 2005 20:55:15 -0000      1.16
--- xine.c      31 Jul 2005 17:59:44 -0000      1.17
***************
*** 451,454 ****
--- 451,588 ----
  }
  
+ PyObject *
+ _xine_config_entry_to_pydict(xine_cfg_entry_t *cfg)
+ {
+     PyObject *dict = PyDict_New();
+     PyDict_SetItemString_STEAL(dict, "key", PyString_FromString(cfg->key));
+     switch(cfg->type) {
+         case XINE_CONFIG_TYPE_UNKNOWN:
+             PyDict_SetItemString(dict, "type", Py_None);
+             break;
+ 
+         case XINE_CONFIG_TYPE_RANGE:
+             PyDict_SetItemString(dict, "type", (PyObject *)&PyInt_Type);
+             PyDict_SetItemString_STEAL(dict, "min", 
PyInt_FromLong(cfg->range_min));
+             PyDict_SetItemString_STEAL(dict, "max", 
PyInt_FromLong(cfg->range_max));
+             PyDict_SetItemString_STEAL(dict, "value", 
PyInt_FromLong(cfg->num_value));
+             PyDict_SetItemString_STEAL(dict, "default", 
PyInt_FromLong(cfg->num_default));
+             break;
+ 
+         case XINE_CONFIG_TYPE_STRING:
+             PyDict_SetItemString(dict, "type", (PyObject *)&PyString_Type);
+             PyDict_SetItemString_STEAL(dict, "value", 
PyString_FromString(cfg->str_value));
+             PyDict_SetItemString_STEAL(dict, "default", 
PyString_FromString(cfg->str_default));
+             break;
+ 
+         case XINE_CONFIG_TYPE_ENUM:
+         {
+             int i;
+             PyObject *enums = PyList_New(0);
+             PyDict_SetItemString(dict, "type", (PyObject *)&PyTuple_Type);
+ 
+             for (i = 0; cfg->enum_values[i]; i++) {
+                 PyObject *val = PyString_FromString(cfg->enum_values[i]);
+                 PyList_Append_STEAL(enums, val);
+                 if (i == cfg->num_value)
+                     PyDict_SetItemString(dict, "value", val);
+                 if (i == cfg->num_default)
+                     PyDict_SetItemString(dict, "default", val);
+             }
+             PyDict_SetItemString_STEAL(dict, "enums", enums);
+             break;
+         }
+         case XINE_CONFIG_TYPE_NUM:
+             PyDict_SetItemString(dict, "type", (PyObject *)&PyInt_Type);
+             PyDict_SetItemString_STEAL(dict, "value", 
PyInt_FromLong(cfg->num_value));
+             PyDict_SetItemString_STEAL(dict, "default", 
PyInt_FromLong(cfg->num_default));
+             break;
+         case XINE_CONFIG_TYPE_BOOL:
+             PyDict_SetItemString(dict, "type", (PyObject *)&PyBool_Type);
+             PyDict_SetItemString_STEAL(dict, "value", 
PyBool_FromLong(cfg->num_value));
+             PyDict_SetItemString_STEAL(dict, "default", 
PyBool_FromLong(cfg->num_default));
+             break;
+     }
+     return dict;
+ }
+ 
+ PyObject *
+ Xine_PyObject_config_get_first_entry(Xine_PyObject *self, PyObject *args, 
PyObject *kwargs)
+ {
+     xine_cfg_entry_t cfg;
+ 
+     if (!xine_config_get_first_entry(self->xine, &cfg)) {
+         PyErr_Format(xine_error, "Failed to get first config entry");
+         return NULL;
+     }
+ 
+     return _xine_config_entry_to_pydict(&cfg);
+ }
+ 
+ PyObject *
+ Xine_PyObject_config_get_next_entry(Xine_PyObject *self, PyObject *args, 
PyObject *kwargs)
+ {
+     xine_cfg_entry_t cfg;
+ 
+     if (!xine_config_get_next_entry(self->xine, &cfg)) {
+         Py_INCREF(Py_None);
+         return Py_None;
+     }
+ 
+     return _xine_config_entry_to_pydict(&cfg);
+ }
+ 
+ PyObject *
+ Xine_PyObject_config_lookup_entry(Xine_PyObject *self, PyObject *args, 
PyObject *kwargs)
+ {
+     xine_cfg_entry_t cfg;
+     char *key;
+ 
+     if (!PyArg_ParseTuple(args, "s", &key))
+         return NULL;
+ 
+     if (!xine_config_lookup_entry(self->xine, key, &cfg)) {
+         Py_INCREF(Py_None);
+         return Py_None;
+     }
+     return _xine_config_entry_to_pydict(&cfg);
+ }
+ 
+ PyObject *
+ Xine_PyObject_config_update_entry(Xine_PyObject *self, PyObject *args, 
PyObject *kwargs)
+ {
+     xine_cfg_entry_t cfg;
+     char *key;
+     PyObject *value;
+ 
+     if (!PyArg_ParseTuple(args, "sO", &key, &value))
+         return NULL;
+ 
+     if (!xine_config_lookup_entry(self->xine, key, &cfg)) {
+         PyErr_Format(xine_error, "Unable to locate config entry '%s'", key);
+         return NULL;
+     }
+ 
+     switch(cfg.type) {
+         case XINE_CONFIG_TYPE_STRING:
+             if (cfg.str_value)
+                 free(cfg.str_value);
+             cfg.str_value = strdup(PyString_AsString(value));
+             break;
+         case XINE_CONFIG_TYPE_ENUM:
+         case XINE_CONFIG_TYPE_RANGE:
+         case XINE_CONFIG_TYPE_NUM:
+         case XINE_CONFIG_TYPE_BOOL:
+             cfg.num_value = PyLong_AsLong(value);
+             break;
+     }
+ 
+     xine_config_update_entry(self->xine, &cfg);
+     if (cfg.callback)
+         cfg.callback(cfg.callback_data, &cfg);
+ 
+     Py_INCREF(Py_None);
+     return Py_None;
+ }
+ 
  PyMethodDef Xine_PyObject_methods[] = {
      {"list_plugins", (PyCFunction) Xine_PyObject_list_plugins, METH_VARARGS },
***************
*** 466,469 ****
--- 600,608 ----
      {"get_file_extensions", (PyCFunction) Xine_PyObject_get_file_extensions, 
METH_VARARGS },
      {"get_mime_types", (PyCFunction) Xine_PyObject_get_mime_types, 
METH_VARARGS },
+ 
+     {"config_get_first_entry", (PyCFunction) 
Xine_PyObject_config_get_first_entry, METH_VARARGS },
+     {"config_get_next_entry", (PyCFunction) 
Xine_PyObject_config_get_next_entry, METH_VARARGS },
+     {"config_lookup_entry", (PyCFunction) Xine_PyObject_config_lookup_entry, 
METH_VARARGS },
+     {"config_update_entry", (PyCFunction) Xine_PyObject_config_update_entry, 
METH_VARARGS },
      {NULL, NULL}
  };

Index: utils.h
===================================================================
RCS file: /cvsroot/freevo/kaa/xine/src/utils.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** utils.h     23 Jul 2005 00:41:47 -0000      1.1
--- utils.h     31 Jul 2005 17:59:44 -0000      1.2
***************
*** 14,16 ****
--- 14,20 ----
   { PyObject *_tm=value; PyDict_SetItemString(dict, key, _tm); Py_DECREF(_tm); 
}
  
+ #define PyList_Append_STEAL(list, value) \
+  { PyObject *_tm=value; PyList_Append(list, _tm); Py_DECREF(_tm); }
+ 
+ 
  #endif



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to