/// <summary>
        /// Load mapping from XML file
        /// </summary>
        /// <param name="xmlPath">Path to XML file</param>
        public void LoadMapping(string xmlPath)
        {
            if (xmlPath != string.Empty)
            {
                _remoteMaps.Clear();
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlPath);
                XmlNodeList listButtons = doc.DocumentElement.SelectNodes("/mappings/remote/button");
                foreach (XmlNode nodeButton in listButtons)
                {
                    string name  = nodeButton.Attributes["name"].Value;
                    string value = nodeButton.Attributes["code"].Value;

                    List <Mapping> mappings    = new List <Mapping>();
                    XmlNodeList    listActions = nodeButton.SelectNodes("action");
                    foreach (XmlNode nodeAction in listActions)
                    {
                        int    cmdKeyChar  = 0;
                        int    cmdKeyCode  = 0;
                        string condition   = nodeAction.Attributes["condition"].Value.ToUpper();
                        string conProperty = nodeAction.Attributes["conproperty"].Value;
                        // conProperty of  PLUGIN is case sensitive, chefkoch
                        if (condition != "PLUGIN")
                        {
                            conProperty = conProperty.ToUpper();
                        }
                        string command     = nodeAction.Attributes["command"].Value.ToUpper();
                        string cmdProperty = nodeAction.Attributes["cmdproperty"].Value.ToUpper();
                        if ((command == "ACTION") && (cmdProperty == "93"))
                        {
                            cmdKeyChar = Convert.ToInt32(nodeAction.Attributes["cmdkeychar"].Value);
                            cmdKeyCode = Convert.ToInt32(nodeAction.Attributes["cmdkeycode"].Value);
                        }
                        string       sound          = string.Empty;
                        XmlAttribute soundAttribute = nodeAction.Attributes["sound"];
                        if (soundAttribute != null)
                        {
                            sound = soundAttribute.Value;
                        }
                        bool         focus          = false;
                        XmlAttribute focusAttribute = nodeAction.Attributes["focus"];
                        if (focusAttribute != null)
                        {
                            focus = Convert.ToBoolean(focusAttribute.Value);
                        }
                        int     layer        = Convert.ToInt32(nodeAction.Attributes["layer"].Value);
                        Mapping conditionMap = new Mapping(layer, condition, conProperty, command, cmdProperty, cmdKeyChar,
                                                           cmdKeyCode, sound, focus);
                        mappings.Add(conditionMap);
                    }
                    RemoteMap remoteMap = new RemoteMap(value, name, mappings);
                    _remoteMaps.Add(remoteMap);
                }
                _isLoaded = true;
            }
        }
    /// <summary>
    /// Load mapping from XML file
    /// </summary>
    /// <param name="xmlPath">Path to XML file</param>
    public void LoadMapping(string xmlPath)
    {
      if (xmlPath != string.Empty)
      {
        _remoteMaps.Clear();
        XmlDocument doc = new XmlDocument();
        doc.Load(xmlPath);
        XmlNodeList listButtons = doc.DocumentElement.SelectNodes("/mappings/remote/button");
        foreach (XmlNode nodeButton in listButtons)
        {
          string name = nodeButton.Attributes["name"].Value;
          string value = nodeButton.Attributes["code"].Value;

          List<Mapping> mappings = new List<Mapping>();
          XmlNodeList listActions = nodeButton.SelectNodes("action");
          foreach (XmlNode nodeAction in listActions)
          {
            int cmdKeyChar = 0;
            int cmdKeyCode = 0;
            string condition = nodeAction.Attributes["condition"].Value.ToUpper();
            string conProperty = nodeAction.Attributes["conproperty"].Value;
            // conProperty of  PLUGIN is case sensitive, chefkoch
            if (condition != "PLUGIN")
              conProperty = conProperty.ToUpper();
            string command = nodeAction.Attributes["command"].Value.ToUpper();
            string cmdProperty = nodeAction.Attributes["cmdproperty"].Value.ToUpper();
            if ((command == "ACTION") && (cmdProperty == "93"))
            {
              cmdKeyChar = Convert.ToInt32(nodeAction.Attributes["cmdkeychar"].Value);
              cmdKeyCode = Convert.ToInt32(nodeAction.Attributes["cmdkeycode"].Value);
            }
            string sound = string.Empty;
            XmlAttribute soundAttribute = nodeAction.Attributes["sound"];
            if (soundAttribute != null)
              sound = soundAttribute.Value;
            bool focus = false;
            XmlAttribute focusAttribute = nodeAction.Attributes["focus"];
            if (focusAttribute != null)
              focus = Convert.ToBoolean(focusAttribute.Value);
            int layer = Convert.ToInt32(nodeAction.Attributes["layer"].Value);
            Mapping conditionMap = new Mapping(layer, condition, conProperty, command, cmdProperty, cmdKeyChar,
                                               cmdKeyCode, sound, focus);
            mappings.Add(conditionMap);
          }
          RemoteMap remoteMap = new RemoteMap(value, name, mappings);
          _remoteMaps.Add(remoteMap);
        }
        _isLoaded = true;
      }
    }
        /// <summary>
        /// Get mappings for a given button code based on the current conditions
        /// </summary>
        /// <param name="btnCode">Button code (ref: XML file)</param>
        /// <returns>Mapping</returns>
        public Mapping GetMapping(string btnCode)
        {
            RemoteMap button = null;
            Mapping   found  = null;

            foreach (RemoteMap btn in _remote)
            {
                if (btnCode == btn.Code)
                {
                    button = btn;
                    break;
                }
            }
            if (button != null)
            {
                foreach (Mapping map in button.Mapping)
                {
                    if ((map.Layer == 0) || (map.Layer == _currentLayer))
                    {
                        switch (map.Condition)
                        {
                        case "*": // wildcard, no further condition
                            found = map;
                            break;

                        case "WINDOW": // Window-ID = x
                            if ((!GUIWindowManager.IsOsdVisible &&
                                 (GUIWindowManager.ActiveWindowEx == Convert.ToInt32(map.ConProperty))) ||
                                ((int)GUIWindowManager.VisibleOsd == Convert.ToInt32(map.ConProperty)))
                            {
                                found = map;
                            }
                            break;

                        case "FULLSCREEN": // Fullscreen = true/false
                            if ((GUIGraphicsContext.IsFullScreenVideo == Convert.ToBoolean(map.ConProperty)) &&
                                !GUIWindowManager.IsRouted && !GUIWindowManager.IsOsdVisible)
                            {
                                found = map;
                            }
                            break;

                        case "PLAYER": // Playing TV/DVD/general
                            if (!GUIWindowManager.IsRouted)
                            {
                                switch (map.ConProperty)
                                {
                                case "TV":
                                    if (g_Player.IsTimeShifting || g_Player.IsTV || g_Player.IsTVRecording)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "DVD":
                                    if (g_Player.IsDVD)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "MUSIC":
                                    if (g_Player.Playing && g_Player.IsMusic)
                                    {
                                        found = map;
                                    }
                                    break;

                                case "MEDIA":
                                    if (g_Player.Playing)
                                    {
                                        found = map;
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                        if (found != null)
                        {
                            return(found);
                        }
                    }
                }
            }
            return(null);
        }