add possibility to select multimode instead of pal/ntsc for TVs with support
[enigma2.git] / lib / actions / action.cpp
index 494c252d8aed244ae08f84b41f89894457732f29..56ad89a11dff572449d57b2f694174a32f8bd9f5 100644 (file)
@@ -54,12 +54,11 @@ void eActionMap::bindAction(const std::string &context, int priority, int id, eW
        
        bnd.m_context = context;
        bnd.m_widget = widget;
-       bnd.m_fnc = 0;
        bnd.m_id = id;
        m_bindings.insert(std::pair<int,eActionBinding>(priority, bnd));
 }
 
-void eActionMap::bindAction(const std::string &context, int priority, PyObject *function)
+void eActionMap::bindAction(const std::string &context, int priority, ePyObject function)
 {
        eActionBinding bnd;
        
@@ -80,7 +79,7 @@ void eActionMap::unbindAction(eWidget *widget, int id)
                }
 }
 
-void eActionMap::unbindAction(const std::string &context, PyObject *function)
+void eActionMap::unbindAction(const std::string &context, ePyObject function)
 {
        for (std::multimap<int, eActionBinding>::iterator i(m_bindings.begin()); i != m_bindings.end(); ++i)
        {
@@ -105,7 +104,7 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st
                {
                                // we found a native action.
                        eNativeKeyBinding bind;
-                       bind.m_device = 0;
+                       bind.m_device = device;
                        bind.m_key = key;
                        bind.m_flags = flags;
                        bind.m_action = actions[i].m_id;
@@ -117,16 +116,25 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st
                // we didn't find the action, so it must be a pythonAction
        ePythonKeyBinding bind;
 
-       bind.m_device = 0;
+       bind.m_device = device;
        bind.m_key = key;
        bind.m_flags = flags;
        bind.m_action = action;
        m_python_keys.insert(std::pair<std::string,ePythonKeyBinding>(context, bind));
 }
 
-void eActionMap::keyPressed(int device, int key, int flags)
+struct call_entry
 {
-       std::list<std::pair<PyObject*,PyObject*> > call_list;
+       ePyObject m_fnc, m_arg;
+       eWidget *m_widget;
+       void *m_widget_arg, *m_widget_arg2;
+       call_entry(ePyObject fnc, ePyObject arg): m_fnc(fnc), m_arg(arg), m_widget(0), m_widget_arg(0) { }
+       call_entry(eWidget *widget, void *arg, void *arg2): m_widget(widget), m_widget_arg(arg), m_widget_arg2(arg2) { }
+};
+
+void eActionMap::keyPressed(const std::string &device, int key, int flags)
+{
+       std::list<call_entry> call_list;
        
                /* iterate active contexts. */
        for (std::multimap<int,eActionBinding>::const_iterator c(m_bindings.begin()); c != m_bindings.end();)
@@ -146,13 +154,11 @@ void eActionMap::keyPressed(int device, int key, int flags)
                                for (; k != e; ++k)
                                {
                                        if (
-                                               // (k->second.m_device == m_device) &&
-                                               (k->second.m_key == key) &&
-                                               (k->second.m_flags & (1<<flags)))
-                                       {
-                                               if (i->second.m_widget->event(eWidget::evtAction, 0, (void*)k->second.m_action))
-                                                       return;
-                                       }
+                                                       (k->second.m_key == key) &&
+                                                       (k->second.m_flags & (1<<flags)) &&
+                                                 ((k->second.m_device == device) || (k->second.m_device == "generic"))
+                                                 )
+                                               call_list.push_back(call_entry(i->second.m_widget, (void*)i->second.m_id, (void*)k->second.m_action));
                                }
                        } else
                        {
@@ -171,35 +177,47 @@ void eActionMap::keyPressed(int device, int key, int flags)
                                for (; k != e;)
                                {
                                        if (
-                                               // (k->second.m_device == m_device) &&
                                                (k->second.m_key == key) &&
-                                               (k->second.m_flags & (1<<flags)))
+                                               (k->second.m_flags & (1<<flags)) &&
+                                               ((k->second.m_device == device) || (k->second.m_device == "generic"))
+                                               )
                                        {
-                                               PyObject *pArgs = PyTuple_New(2);
-                                               PyTuple_SetItem(pArgs, 0, PyString_FromString(k->first.c_str()));
-                                               PyTuple_SetItem(pArgs, 1, PyString_FromString(k->second.m_action.c_str()));
+                                               ePyObject pArgs = PyTuple_New(2);
+                                               PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(k->first.c_str()));
+                                               PyTuple_SET_ITEM(pArgs, 1, PyString_FromString(k->second.m_action.c_str()));
                                                ++k;
                                                Py_INCREF(i->second.m_fnc);
-                                               call_list.push_back(std::pair<PyObject*,PyObject*>(i->second.m_fnc, pArgs));
+                                               call_list.push_back(call_entry(i->second.m_fnc, pArgs));
                                        } else
                                                ++k;
                                }
                        } else
                        {
-                               PyObject *pArgs = PyTuple_New(2);
-                               PyTuple_SetItem(pArgs, 0, PyInt_FromLong(key));
-                               PyTuple_SetItem(pArgs, 1, PyInt_FromLong(flags));
+                               eDebug("wildcard.");
+                               ePyObject pArgs = PyTuple_New(2);
+                               PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(key));
+                               PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(flags));
                                Py_INCREF(i->second.m_fnc);
-                               call_list.push_back(std::pair<PyObject*,PyObject*>(i->second.m_fnc, pArgs));
+                               call_list.push_back(call_entry(i->second.m_fnc, pArgs));
                        }
                }
        }
 
-       for (std::list<std::pair<PyObject*,PyObject*> >::iterator i(call_list.begin()); i != call_list.end(); ++i)
+       int res = 0;
+                       /* we need to iterate over all to not loose a reference */
+       for (std::list<call_entry>::iterator i(call_list.begin()); i != call_list.end(); ++i)
        {
-               ePython::call(i->first, i->second);
-               Py_DECREF(i->first);
-               Py_DECREF(i->second);
+               if (i->m_fnc)
+               {
+                       if (!res)
+                               res = ePython::call(i->m_fnc, i->m_arg);
+                       Py_DECREF(i->m_fnc);
+                       Py_DECREF(i->m_arg);
+               } else if (i->m_widget)
+               {
+                       if (!res)
+                               res = i->m_widget->event(eWidget::evtAction, (void*)i->m_widget_arg, (void*)i->m_widget_arg2 );
+               }
        }
 }