Merge branch 'bug_619_ask_for_scan_when_no_default_servicelists_are_avail'
[enigma2.git] / lib / actions / action.cpp
index 56ad89a11dff572449d57b2f694174a32f8bd9f5..a2d85ffdbf2eab49e0a7a3faf5f8d4738d0b7a6e 100644 (file)
@@ -2,6 +2,7 @@
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
 #include <lib/actions/actionids.h>
 #include <lib/base/init.h>
 #include <lib/base/init_num.h>
 #include <lib/actions/actionids.h>
+#include <lib/driver/rc.h>
 
 /*
 
 
 /*
 
@@ -41,13 +42,6 @@ RESULT eActionMap::getInstance(ePtr<eActionMap> &ptr)
        return 0;
 }
 
        return 0;
 }
 
-#if 0
-void eActionMap::getInstance(eActionMap **ptr)
-{
-       *ptr = instance;
-}
-#endif
-
 void eActionMap::bindAction(const std::string &context, int priority, int id, eWidget *widget)
 {
        eActionBinding bnd;
 void eActionMap::bindAction(const std::string &context, int priority, int id, eWidget *widget)
 {
        eActionBinding bnd;
@@ -94,7 +88,7 @@ void eActionMap::unbindAction(const std::string &context, ePyObject function)
 }
 
 
 }
 
 
-void eActionMap::bindKey(const std::string &device, int key, int flags, const std::string &context, const std::string &action)
+void eActionMap::bindKey(const std::string &domain, const std::string &device, int key, int flags, const std::string &context, const std::string &action)
 {
                // first, search the actionlist table
        unsigned int i;
 {
                // first, search the actionlist table
        unsigned int i;
@@ -108,6 +102,7 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st
                        bind.m_key = key;
                        bind.m_flags = flags;
                        bind.m_action = actions[i].m_id;
                        bind.m_key = key;
                        bind.m_flags = flags;
                        bind.m_action = actions[i].m_id;
+                       bind.m_domain = domain;
                        m_native_keys.insert(std::pair<std::string,eNativeKeyBinding>(context, bind));
                        return;
                }
                        m_native_keys.insert(std::pair<std::string,eNativeKeyBinding>(context, bind));
                        return;
                }
@@ -120,9 +115,27 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st
        bind.m_key = key;
        bind.m_flags = flags;
        bind.m_action = action;
        bind.m_key = key;
        bind.m_flags = flags;
        bind.m_action = action;
+       bind.m_domain = domain;
        m_python_keys.insert(std::pair<std::string,ePythonKeyBinding>(context, bind));
 }
 
        m_python_keys.insert(std::pair<std::string,ePythonKeyBinding>(context, bind));
 }
 
+void eActionMap::unbindKeyDomain(const std::string &domain)
+{
+       for (std::multimap<std::string, eNativeKeyBinding>::iterator i(m_native_keys.begin()); i != m_native_keys.end(); ++i)
+               if (i->second.m_domain == domain)
+               {
+                       m_native_keys.erase(i);
+                       i = m_native_keys.begin();
+               }
+
+       for (std::multimap<std::string, ePythonKeyBinding>::iterator i(m_python_keys.begin()); i != m_python_keys.end(); ++i)
+               if (i->second.m_domain == domain)
+               {
+                       m_python_keys.erase(i);
+                       i = m_python_keys.begin();
+               }
+}
+
 struct call_entry
 {
        ePyObject m_fnc, m_arg;
 struct call_entry
 {
        ePyObject m_fnc, m_arg;
@@ -137,20 +150,24 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
        std::list<call_entry> call_list;
        
                /* iterate active contexts. */
        std::list<call_entry> call_list;
        
                /* iterate active contexts. */
-       for (std::multimap<int,eActionBinding>::const_iterator c(m_bindings.begin()); c != m_bindings.end();)
+       for (std::multimap<int,eActionBinding>::iterator c(m_bindings.begin());
+               c != m_bindings.end(); ++c)
        {
        {
-               std::multimap<int,eActionBinding>::const_iterator i = c;
-               ++c;
+               if (flags == eRCKey::flagMake)
+                       c->second.m_prev_seen_make_key = key;
+               else if (c->second.m_prev_seen_make_key != key)  // ignore repeat or break when the make code for this key was not visible
+                       continue;
+
                        /* is this a native context? */
                        /* is this a native context? */
-               if (i->second.m_widget)
+               if (c->second.m_widget)
                {
                                /* is this a named context, i.e. not the wildcard? */
                {
                                /* is this a named context, i.e. not the wildcard? */
-                       if (i->second.m_context.size())
+                       if (c->second.m_context.size())
                        {
                                std::multimap<std::string,eNativeKeyBinding>::const_iterator
                        {
                                std::multimap<std::string,eNativeKeyBinding>::const_iterator
-                                       k = m_native_keys.lower_bound(i->second.m_context),
-                                       e = m_native_keys.upper_bound(i->second.m_context);
-                               
+                                       k = m_native_keys.lower_bound(c->second.m_context),
+                                       e = m_native_keys.upper_bound(c->second.m_context);
+
                                for (; k != e; ++k)
                                {
                                        if (
                                for (; k != e; ++k)
                                {
                                        if (
@@ -158,23 +175,23 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
                                                        (k->second.m_flags & (1<<flags)) &&
                                                  ((k->second.m_device == device) || (k->second.m_device == "generic"))
                                                  )
                                                        (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));
+                                               call_list.push_back(call_entry(c->second.m_widget, (void*)c->second.m_id, (void*)k->second.m_action));
                                }
                        } else
                        {
                                        /* wildcard - get any keys. */
                                }
                        } else
                        {
                                        /* wildcard - get any keys. */
-                               if (i->second.m_widget->event(eWidget::evtKey, (void*)key, (void*)flags))
+                               if (c->second.m_widget->event(eWidget::evtKey, (void*)key, (void*)flags))
                                        return;
                        }
                                        return;
                        }
-               } else if (i->second.m_fnc)
+               } else if (c->second.m_fnc)
                {
                {
-                       if (i->second.m_context.size())
+                       if (c->second.m_context.size())
                        {
                                std::multimap<std::string,ePythonKeyBinding>::const_iterator
                        {
                                std::multimap<std::string,ePythonKeyBinding>::const_iterator
-                                       k = m_python_keys.lower_bound(i->second.m_context),
-                                       e = m_python_keys.upper_bound(i->second.m_context);
-                               
-                               for (; k != e;)
+                                       k = m_python_keys.lower_bound(c->second.m_context),
+                                       e = m_python_keys.upper_bound(c->second.m_context);
+
+                               for (; k != e; ++k)
                                {
                                        if (
                                                (k->second.m_key == key) &&
                                {
                                        if (
                                                (k->second.m_key == key) &&
@@ -185,20 +202,18 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
                                                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()));
                                                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(call_entry(i->second.m_fnc, pArgs));
-                                       } else
-                                               ++k;
+                                               Py_INCREF(c->second.m_fnc);
+                                               call_list.push_back(call_entry(c->second.m_fnc, pArgs));
+                                       }
                                }
                        } else
                        {
                                }
                        } else
                        {
-                               eDebug("wildcard.");
+//                             eDebug("wildcard.");
                                ePyObject pArgs = PyTuple_New(2);
                                PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(key));
                                PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(flags));
                                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(call_entry(i->second.m_fnc, pArgs));
+                               Py_INCREF(c->second.m_fnc);
+                               call_list.push_back(call_entry(c->second.m_fnc, pArgs));
                        }
                }
        }
                        }
                }
        }
@@ -213,12 +228,16 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
                                res = ePython::call(i->m_fnc, i->m_arg);
                        Py_DECREF(i->m_fnc);
                        Py_DECREF(i->m_arg);
                                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 );
-               }
+               } else if (i->m_widget && !res)
+                       res = i->m_widget->event(eWidget::evtAction, (void*)i->m_widget_arg, (void*)i->m_widget_arg2 );
        }
 }
 
        }
 }
 
+ePtr<eActionMap> NewActionMapPtr(void)
+{
+       ePtr<eActionMap> ptr;
+       eActionMap::getInstance(ptr);
+       return ptr;
+}
+
 eAutoInitPtr<eActionMap> init_eActionMap(eAutoInitNumbers::actions, "eActionMap");
 eAutoInitPtr<eActionMap> init_eActionMap(eAutoInitNumbers::actions, "eActionMap");