actionmap: cosmetics/debugs
authorMirakels <mirakels@openpli.org>
Fri, 18 Dec 2015 09:59:36 +0000 (10:59 +0100)
committerMirakels <mirakels@openpli.org>
Fri, 18 Dec 2015 10:04:09 +0000 (11:04 +0100)
lib/actions/action.cpp

index 85dcfdb..b8c08ee 100644 (file)
@@ -46,6 +46,7 @@ void eActionMap::bindAction(const std::string &context, int priority, int id, eW
 {
        eActionBinding bnd;
 
+       //eDebug("[eActionMap] bind widget to %s: prio=%d id=%d", context.c_str(), priority, id);
        bnd.m_context = context;
        bnd.m_widget = widget;
        bnd.m_id = id;
@@ -56,6 +57,7 @@ void eActionMap::bindAction(const std::string &context, int priority, ePyObject
 {
        eActionBinding bnd;
 
+       //eDebug("[eActionMap] bind function to %s: prio=%d", context.c_str(), priority);
        bnd.m_context = context;
        bnd.m_widget = 0;
        Py_INCREF(function);
@@ -65,8 +67,9 @@ void eActionMap::bindAction(const std::string &context, int priority, ePyObject
 
 void eActionMap::unbindAction(eWidget *widget, int id)
 {
+       //eDebug("[eActionMap] unbind widget id=%d", id);
        for (std::multimap<int, eActionBinding>::iterator i(m_bindings.begin()); i != m_bindings.end(); ++i)
-               if ((i->second.m_widget == widget) && (i->second.m_id == id))
+               if (i->second.m_widget == widget && i->second.m_id == id)
                {
                        m_bindings.erase(i);
                        return;
@@ -75,28 +78,28 @@ void eActionMap::unbindAction(eWidget *widget, int id)
 
 void eActionMap::unbindAction(const std::string &context, ePyObject function)
 {
+       //eDebug("[eActionMap] unbind function from %s", context.c_str());
        for (std::multimap<int, eActionBinding>::iterator i(m_bindings.begin()); i != m_bindings.end(); ++i)
-       {
                if (i->second.m_fnc && (PyObject_Compare(i->second.m_fnc, function) == 0))
                {
                        Py_DECREF(i->second.m_fnc);
                        m_bindings.erase(i);
                        return;
                }
-       }
        eFatal("[eActionMap] unbindAction with illegal python reference");
 }
 
 
 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
+       // start searching the actionlist table
+       //eDebug("[eActionMap] bind key from %s to %s: domain=%s action=%s key=%d flags=%d", device.c_str(), context.c_str(), domain.c_str(), action.c_str(), key, flags);
        unsigned int i;
-       for (i=0; i<sizeof(actions)/sizeof(*actions); ++i)
+       for (i = 0; i < sizeof(actions)/sizeof(*actions); ++i)
        {
-               if ((actions[i].m_context == context) && (actions[i].m_action == action))
+               if (actions[i].m_context == context && actions[i].m_action == action)
                {
-                               // we found a native action.
+                       // found native action
                        eNativeKeyBinding bind;
                        bind.m_device = device;
                        bind.m_key = key;
@@ -108,7 +111,7 @@ void eActionMap::bindKey(const std::string &domain, const std::string &device, i
                }
        }
 
-               // we didn't find the action, so it must be a pythonAction
+       // no action, so it must be a pythonAction
        ePythonKeyBinding bind;
 
        bind.m_device = device;
@@ -121,6 +124,7 @@ void eActionMap::bindKey(const std::string &domain, const std::string &device, i
 
 void eActionMap::unbindKeyDomain(const std::string &domain)
 {
+       //eDebug("[eActionMap] unbindDomain %s", domain.c_str());
        for (std::multimap<std::string, eNativeKeyBinding>::iterator i(m_native_keys.begin()); i != m_native_keys.end(); ++i)
                if (i->second.m_domain == domain)
                {
@@ -147,57 +151,58 @@ struct call_entry
 
 void eActionMap::keyPressed(const std::string &device, int key, int flags)
 {
+       //eDebug("[eActionMap] key from %s: %d %d", device.c_str(), key, flags);
        std::list<call_entry> call_list;
 
-               /* iterate active contexts. */
-       for (std::multimap<int,eActionBinding>::iterator c(m_bindings.begin());
-               c != m_bindings.end(); ++c)
+       // iterate active contexts
+       for (std::multimap<int,eActionBinding>::iterator c(m_bindings.begin()); c != m_bindings.end(); ++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 (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 (c->second.m_context.size())
                        {
+                               //eDebug("[eActionMap]   native context %s", c->second.m_context.c_str());
                                std::multimap<std::string,eNativeKeyBinding>::const_iterator
                                        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 (
-                                                       (k->second.m_key == key) &&
-                                                       (k->second.m_flags & (1<<flags)) &&
-                                                 ((k->second.m_device == device) || (k->second.m_device == "generic"))
-                                                 )
+                                       if (    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(c->second.m_widget, (void*)c->second.m_id, (void*)k->second.m_action));
                                }
-                       } else
+                       }
+                       else
                        {
-                                       /* wildcard - get any keys. */
+                               // wildcard - get any keys.
+                               //eDebug("[eActionMap]    native wildcard");
                                if (c->second.m_widget->event(eWidget::evtKey, (void*)key, (void*)flags))
                                        return;
                        }
-               } else if (c->second.m_fnc)
+               }
+               else if (c->second.m_fnc)
                {
                        if (c->second.m_context.size())
                        {
+                               //eDebug("[eActionMap]   python context %s", c->second.m_context.c_str());
                                std::multimap<std::string,ePythonKeyBinding>::const_iterator
                                        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) &&
-                                               (k->second.m_flags & (1<<flags)) &&
-                                               ((k->second.m_device == device) || (k->second.m_device == "generic"))
-                                               )
+                                       if (    k->second.m_key == key &&
+                                               k->second.m_flags & (1<<flags) &&
+                                               (k->second.m_device == device || k->second.m_device == "generic") )
                                        {
                                                ePyObject pArgs = PyTuple_New(2);
                                                PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(k->first.c_str()));
@@ -206,9 +211,10 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
                                                call_list.push_back(call_entry(c->second.m_fnc, pArgs));
                                        }
                                }
-                       } else
+                       }
+                       else
                        {
-//                             eDebug("[eActionMap] wildcard.");
+                               //eDebug("[eActionMap]   python wildcard.");
                                ePyObject pArgs = PyTuple_New(2);
                                PyTuple_SET_ITEM(pArgs, 0, PyInt_FromLong(key));
                                PyTuple_SET_ITEM(pArgs, 1, PyInt_FromLong(flags));
@@ -219,7 +225,7 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
        }
 
        int res = 0;
-                       /* we need to iterate over all to not loose a reference */
+       // iterate over all to not loose a reference
        for (std::list<call_entry>::iterator i(call_list.begin()); i != call_list.end(); ++i)
        {
                if (i->m_fnc)
@@ -228,7 +234,8 @@ 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);
-               } else if (i->m_widget && !res)
+               }
+               else if (i->m_widget && !res)
                        res = i->m_widget->event(eWidget::evtAction, (void*)i->m_widget_arg, (void*)i->m_widget_arg2 );
        }
 }