From: <an...@us...> - 2007-10-02 15:03:21
|
Revision: 968 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=968&view=rev Author: and-81 Date: 2007-10-02 08:03:19 -0700 (Tue, 02 Oct 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/MCEReplacement/InputMapper/InputHandler.cs trunk/plugins/MCEReplacement/InputMapper/InputMappingForm.cs Modified: trunk/plugins/MCEReplacement/InputMapper/InputHandler.cs =================================================================== --- trunk/plugins/MCEReplacement/InputMapper/InputHandler.cs 2007-10-02 05:45:04 UTC (rev 967) +++ trunk/plugins/MCEReplacement/InputMapper/InputHandler.cs 2007-10-02 15:03:19 UTC (rev 968) @@ -131,7 +131,7 @@ /// <summary> /// Constructor: Initializes mappings from XML file /// </summary> - /// <param name="deviceXmlName">Input device name</param> + /// <param name="deviceXmlName">Input device name.</param> public InputHandler(string deviceXmlName) { @@ -146,7 +146,7 @@ /// <summary> /// Get version of XML mapping file /// </summary> - /// <param name="xmlPath">Path to XML file</param> + /// <param name="xmlPath">Path to XML file.</param> /// Possible exceptions: System.Xml.XmlException public int GetXmlVersion(string xmlPath) { @@ -159,7 +159,7 @@ /// <summary> /// Check if XML file exists and version is current /// </summary> - /// <param name="xmlPath">Path to XML file</param> + /// <param name="xmlPath">Path to XML file.</param> /// Possible exceptions: System.IO.FileNotFoundException /// System.Xml.XmlException /// ApplicationException("XML version mismatch") @@ -174,14 +174,14 @@ /// <summary> /// Get path to XML mmapping file for given device name /// </summary> - /// <param name="deviceXmlName">Input device name</param> - /// <returns>Path to XML file</returns> + /// <param name="deviceXmlName">Input device name.</param> + /// <returns>Path to XML file.</returns> /// Possible exceptions: System.IO.FileNotFoundException /// System.Xml.XmlException /// ApplicationException("XML version mismatch") public string GetXmlPath(string deviceXmlName) { - string path = string.Empty; + string path = String.Empty; string pathCustom = MCEReplacement.CustomInputDevice + deviceXmlName + ".xml"; string pathDefault = MCEReplacement.CustomInputDefault + deviceXmlName + ".xml"; @@ -202,10 +202,10 @@ /// <summary> /// Load mapping from XML file /// </summary> - /// <param name="xmlPath">Path to XML file</param> + /// <param name="xmlPath">Path to XML file.</param> public void LoadMapping(string xmlPath) { - if (xmlPath != string.Empty) + if (xmlPath != String.Empty) { _remote = new ArrayList(); XmlDocument doc = new XmlDocument(); @@ -231,7 +231,7 @@ cmdKeyChar = Convert.ToInt32(nodeAction.Attributes["cmdkeychar"].Value); cmdKeyCode = Convert.ToInt32(nodeAction.Attributes["cmdkeycode"].Value); } - string sound = string.Empty; + string sound = String.Empty; XmlAttribute soundAttribute = nodeAction.Attributes["sound"]; if (soundAttribute != null) sound = soundAttribute.Value; @@ -254,7 +254,7 @@ /// <summary> /// Evaluates the button number, gets its mapping and executes the action /// </summary> - /// <param name="btnCode">Button code (ref: XML file)</param> + /// <param name="btnCode">Button code (ref: XML file).</param> public bool MapAction(int btnCode) { return DoMapAction(btnCode.ToString(), -1); @@ -263,7 +263,7 @@ /// <summary> /// Evaluates the button number, gets its mapping and executes the action /// </summary> - /// <param name="btnCode">Button code (ref: XML file)</param> + /// <param name="btnCode">Button code (ref: XML file).</param> public bool MapAction(string btnCode) { return DoMapAction(btnCode, -1); @@ -273,8 +273,8 @@ /// <summary> /// Evaluates the button number, gets its mapping and executes the action with an optional paramter /// </summary> - /// <param name="btnCode">Button code (ref: XML file)</param> - /// <param name="processID">Process-ID for close/kill commands</param> + /// <param name="btnCode">Button code (ref: XML file).</param> + /// <param name="processID">Process-ID for close/kill commands.</param> public bool MapAction(int btnCode, int processID) { return DoMapAction(btnCode.ToString(), processID); @@ -284,8 +284,8 @@ /// <summary> /// Evaluates the button number, gets its mapping and executes the action with an optional paramter /// </summary> - /// <param name="btnCode">Button code (ref: XML file)</param> - /// <param name="processID">Process-ID for close/kill commands</param> + /// <param name="btnCode">Button code (ref: XML file).</param> + /// <param name="processID">Process-ID for close/kill commands.</param> public bool MapAction(string btnCode, int processID) { return DoMapAction(btnCode, processID); @@ -295,8 +295,8 @@ /// <summary> /// Evaluates the button number, gets its mapping and executes the action /// </summary> - /// <param name="btnCode">Button code (ref: XML file)</param> - /// <param name="processID">Process-ID for close/kill commands</param> + /// <param name="btnCode">Button code (ref: XML file).</param> + /// <param name="processID">Process-ID for close/kill commands.</param> bool DoMapAction(string btnCode, int processID) { if (!_isLoaded) // No mapping loaded @@ -312,7 +312,7 @@ Log.Info("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty); #endif Action action; - if (map.Sound != string.Empty) + if (map.Sound != String.Empty) MediaPortal.Util.Utils.PlaySound(map.Sound, false, true); if (map.Focus && !GUIGraphicsContext.HasFocus) { @@ -426,8 +426,8 @@ /// <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> + /// <param name="btnCode">Button code (ref: XML file).</param> + /// <returns>Mapping.</returns> public Mapping GetMapping(string btnCode) { RemoteMap button = null; Modified: trunk/plugins/MCEReplacement/InputMapper/InputMappingForm.cs =================================================================== --- trunk/plugins/MCEReplacement/InputMapper/InputMappingForm.cs 2007-10-02 05:45:04 UTC (rev 967) +++ trunk/plugins/MCEReplacement/InputMapper/InputMappingForm.cs 2007-10-02 15:03:19 UTC (rev 968) @@ -37,8 +37,8 @@ using MediaPortal.InputDevices; using MediaPortal.Configuration; +using IrssUtils.Forms; - namespace MediaPortal.Plugins { /// <summary> @@ -74,10 +74,10 @@ string inputClassName; bool changedSettings = false; - + class Data { string type; @@ -150,12 +150,12 @@ private MediaPortal.UserInterface.Controls.MPTextBox textBoxKeyCode; private MediaPortal.UserInterface.Controls.MPLabel labelExpand; private MediaPortal.UserInterface.Controls.MPCheckBox checkBoxGainFocus; - - #endregion private MediaPortal.UserInterface.Controls.MPRadioButton radioButtonBlast; private Button buttonRemoveReplacements; + #endregion + /// <summary> /// Required designer variable. /// </summary> @@ -237,7 +237,7 @@ components.Dispose(); } } - + base.Dispose(disposing); } @@ -824,7 +824,7 @@ string condition = nodeAction.Attributes["condition"].Value.ToUpper(); string conProperty = nodeAction.Attributes["conproperty"].Value.ToUpper(); string command = nodeAction.Attributes["command"].Value.ToUpper(); - string cmdProperty = nodeAction.Attributes["cmdproperty"].Value.ToUpper(); + string cmdProperty = nodeAction.Attributes["cmdproperty"].Value; // .ToUpper() string sound = String.Empty; XmlAttribute soundAttribute = nodeAction.Attributes["sound"]; if (soundAttribute != null) @@ -841,7 +841,7 @@ { case "WINDOW": { - try { conditionString = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(conProperty))); } + try { conditionString = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(conProperty))); } catch { conditionString = conProperty; } break; } @@ -872,7 +872,7 @@ break; case "WINDOW": { - try { commandString = "Window \"" + GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(cmdProperty))) + "\""; } + try { commandString = "Window \"" + GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(cmdProperty))) + "\""; } catch { commandString = "Window \"" + cmdProperty + "\""; } break; } @@ -886,7 +886,7 @@ commandString = processList[Array.IndexOf(nativeProcessList, cmdProperty)]; break; case "BLAST": - commandString = "Blast IR: \"" + cmdProperty + "\""; + commandString = cmdProperty; break; } @@ -962,107 +962,108 @@ //try #endif { - XmlTextWriter writer = new XmlTextWriter(Config.GetFile(Config.Dir.CustomInputDevice, xmlFile), System.Text.Encoding.UTF8); - writer.Formatting = Formatting.Indented; - writer.Indentation = 1; - writer.IndentChar = (char)9; - writer.WriteStartDocument(true); - writer.WriteStartElement("mappings"); // <mappings> - writer.WriteAttributeString("version", "3"); - if (treeMapping.Nodes.Count > 0) - foreach (TreeNode remoteNode in treeMapping.Nodes) - { - writer.WriteStartElement("remote"); // <remote> - writer.WriteAttributeString("family", (string)((Data)remoteNode.Tag).Value); - if (remoteNode.Nodes.Count > 0) - foreach (TreeNode buttonNode in remoteNode.Nodes) - { - writer.WriteStartElement("button"); // <button> - writer.WriteAttributeString("name", (string)((Data)buttonNode.Tag).Parameter); - writer.WriteAttributeString("code", (string)((Data)buttonNode.Tag).Value); + using (XmlTextWriter writer = new XmlTextWriter(Config.GetFile(Config.Dir.CustomInputDevice, xmlFile), System.Text.Encoding.UTF8)) + { + writer.Formatting = Formatting.Indented; + writer.Indentation = 1; + writer.IndentChar = (char)9; + writer.WriteStartDocument(true); + writer.WriteStartElement("mappings"); // <mappings> + writer.WriteAttributeString("version", "3"); + if (treeMapping.Nodes.Count > 0) + foreach (TreeNode remoteNode in treeMapping.Nodes) + { + writer.WriteStartElement("remote"); // <remote> + writer.WriteAttributeString("family", (string)((Data)remoteNode.Tag).Value); + if (remoteNode.Nodes.Count > 0) + foreach (TreeNode buttonNode in remoteNode.Nodes) + { + writer.WriteStartElement("button"); // <button> + writer.WriteAttributeString("name", (string)((Data)buttonNode.Tag).Parameter); + writer.WriteAttributeString("code", (string)((Data)buttonNode.Tag).Value); - if (buttonNode.Nodes.Count > 0) - foreach (TreeNode layerNode in buttonNode.Nodes) - { - foreach (TreeNode conditionNode in layerNode.Nodes) + if (buttonNode.Nodes.Count > 0) + foreach (TreeNode layerNode in buttonNode.Nodes) { - string layer; - string condition; - string conProperty; - string command = String.Empty; - string cmdProperty = String.Empty; - string cmdKeyChar = String.Empty; - string cmdKeyCode = String.Empty; - string sound = String.Empty; - bool focus = false; - foreach (TreeNode commandNode in conditionNode.Nodes) + foreach (TreeNode conditionNode in layerNode.Nodes) { - switch (((Data)commandNode.Tag).Type) + string layer; + string condition; + string conProperty; + string command = String.Empty; + string cmdProperty = String.Empty; + string cmdKeyChar = String.Empty; + string cmdKeyCode = String.Empty; + string sound = String.Empty; + bool focus = false; + foreach (TreeNode commandNode in conditionNode.Nodes) { - case "COMMAND": - { - command = (string)((Data)commandNode.Tag).Parameter; - focus = ((Data)commandNode.Tag).Focus; - if (command != "KEY") - cmdProperty = ((Data)commandNode.Tag).Value.ToString(); - else + switch (((Data)commandNode.Tag).Type) + { + case "COMMAND": { - command = "ACTION"; - Key key = (Key)((Data)commandNode.Tag).Value; - cmdProperty = "93"; - cmdKeyChar = key.KeyChar.ToString(); - cmdKeyCode = key.KeyCode.ToString(); + command = (string)((Data)commandNode.Tag).Parameter; + focus = ((Data)commandNode.Tag).Focus; + if (command != "KEY") + cmdProperty = ((Data)commandNode.Tag).Value.ToString(); + else + { + command = "ACTION"; + Key key = (Key)((Data)commandNode.Tag).Value; + cmdProperty = "93"; + cmdKeyChar = key.KeyChar.ToString(); + cmdKeyCode = key.KeyCode.ToString(); + } } - } - break; - case "SOUND": - sound = (string)((Data)commandNode.Tag).Value; - break; + break; + case "SOUND": + sound = (string)((Data)commandNode.Tag).Value; + break; + } } - } - condition = (string)((Data)conditionNode.Tag).Parameter; - conProperty = ((Data)conditionNode.Tag).Value.ToString(); - layer = Convert.ToString(((Data)layerNode.Tag).Value); - writer.WriteStartElement("action"); // <action> - writer.WriteAttributeString("layer", layer); - writer.WriteAttributeString("condition", condition); - writer.WriteAttributeString("conproperty", conProperty); - writer.WriteAttributeString("command", command); - writer.WriteAttributeString("cmdproperty", cmdProperty); - if (cmdProperty == Convert.ToInt32(Action.ActionType.ACTION_KEY_PRESSED).ToString()) - { - if (!String.IsNullOrEmpty(cmdKeyChar)) + condition = (string)((Data)conditionNode.Tag).Parameter; + conProperty = ((Data)conditionNode.Tag).Value.ToString(); + layer = Convert.ToString(((Data)layerNode.Tag).Value); + writer.WriteStartElement("action"); // <action> + writer.WriteAttributeString("layer", layer); + writer.WriteAttributeString("condition", condition); + writer.WriteAttributeString("conproperty", conProperty); + writer.WriteAttributeString("command", command); + writer.WriteAttributeString("cmdproperty", cmdProperty); + if (cmdProperty == Convert.ToInt32(Action.ActionType.ACTION_KEY_PRESSED).ToString()) { - writer.WriteAttributeString("cmdkeychar", cmdKeyChar); + if (!String.IsNullOrEmpty(cmdKeyChar)) + { + writer.WriteAttributeString("cmdkeychar", cmdKeyChar); + } + else + { + writer.WriteAttributeString("cmdkeychar", "0"); + } + if (!String.IsNullOrEmpty(cmdKeyCode)) + { + writer.WriteAttributeString("cmdkeycode", cmdKeyCode); + } + else + { + writer.WriteAttributeString("cmdkeychar", "0"); + } + } - else - { - writer.WriteAttributeString("cmdkeychar", "0"); - } - if (!String.IsNullOrEmpty(cmdKeyCode)) - { - writer.WriteAttributeString("cmdkeycode", cmdKeyCode); - } - else - { - writer.WriteAttributeString("cmdkeychar", "0"); - } - + if (!String.IsNullOrEmpty(sound)) + writer.WriteAttributeString("sound", sound); + if (focus) + writer.WriteAttributeString("focus", focus.ToString()); + writer.WriteEndElement(); // </action> } - if (!String.IsNullOrEmpty(sound)) - writer.WriteAttributeString("sound", sound); - if (focus) - writer.WriteAttributeString("focus", focus.ToString()); - writer.WriteEndElement(); // </action> } - } - writer.WriteEndElement(); // </button> - } - writer.WriteEndElement(); // </remote> - } - writer.WriteEndElement(); // </mapping> - writer.WriteEndDocument(); - writer.Close(); + writer.WriteEndElement(); // </button> + } + writer.WriteEndElement(); // </remote> + } + writer.WriteEndElement(); // </mapping> + writer.WriteEndDocument(); + } changedSettings = false; return true; } @@ -1214,9 +1215,9 @@ radioButtonWindow.Checked = true; comboBoxCondProperty.Enabled = true; - + string friendlyName; - try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } + try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } catch { friendlyName = Convert.ToInt32(data.Value).ToString(); } UpdateCombo(ref comboBoxCondProperty, windowsList, friendlyName); break; @@ -1288,9 +1289,9 @@ comboBoxCmdProperty.Enabled = true; textBoxKeyChar.Enabled = textBoxKeyCode.Enabled = false; textBoxKeyChar.Text = textBoxKeyCode.Text = String.Empty; - + string friendlyName; - try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } + try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } catch { friendlyName = Convert.ToInt32(data.Value).ToString(); } UpdateCombo(ref comboBoxCmdProperty, windowsListFiltered, friendlyName); break; @@ -1501,12 +1502,12 @@ TreeNode node = getNode("COMMAND"); Data data = new Data("COMMAND", "WINDOW", "0"); node.Tag = data; - + string friendlyName; - try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } + try { friendlyName = GetFriendlyName(Enum.GetName(typeof(GUIWindow.Window), Convert.ToInt32(data.Value))); } catch { friendlyName = Convert.ToInt32(data.Value).ToString(); } UpdateCombo(ref comboBoxCmdProperty, windowsListFiltered, friendlyName); - + node.Text = "Window \"" + comboBoxCmdProperty.Text + "\""; ((Data)node.Tag).Focus = checkBoxGainFocus.Checked; changedSettings = true; @@ -1819,9 +1820,9 @@ TreeNode node = getNode("COMMAND"); Data data = new Data("COMMAND", "BLAST", String.Empty); node.Tag = data; - node.Text = "Blast IR: \"\""; + node.Text = ""; ((Data)node.Tag).Focus = checkBoxGainFocus.Checked; - UpdateCombo(ref comboBoxCmdProperty, MCEReplacement.GetFileList(true), string.Empty); + UpdateCombo(ref comboBoxCmdProperty, MCEReplacement.GetFileList(true), String.Empty); changedSettings = true; } @@ -1843,13 +1844,13 @@ if (e.KeyCode == Keys.Enter && comboBoxCondProperty.DropDownStyle == ComboBoxStyle.DropDown) ConditionPropChanged(); } - + private void comboBoxCmdProperty_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && comboBoxCmdProperty.DropDownStyle == ComboBoxStyle.DropDown) CommandPropChanged(); } - + private void CommandPropChanged() { if ((string)comboBoxCmdProperty.SelectedItem == "Key Pressed") @@ -1898,9 +1899,30 @@ node.Text = (string)comboBoxCmdProperty.SelectedItem; break; case "BLAST": - node.Tag = new Data("COMMAND", "BLAST", (string)comboBoxCmdProperty.SelectedItem); - node.Text = "Blast IR: \"" + (string)comboBoxCmdProperty.SelectedItem + "\""; - break; + { + string text = (string)comboBoxCmdProperty.SelectedItem; + if (text.StartsWith(IrssUtils.Common.CmdPrefixBlast, StringComparison.InvariantCultureIgnoreCase)) + { + BlastCommand blastCommand = new BlastCommand( + new IrssUtils.BlastIrDelegate(MCEReplacement.BlastIR), + MCEReplacement.IRFolder, + Enum.GetNames(typeof(MicrosoftMceTransceiver.BlasterPort)), + text.Substring(IrssUtils.Common.CmdPrefixBlast.Length)); + + if (blastCommand.ShowDialog(this) == DialogResult.OK) + { + string command = IrssUtils.Common.CmdPrefixBlast + blastCommand.CommandString; + node.Tag = new Data("COMMAND", "BLAST", command); + node.Text = command; + } + } + else if (text.StartsWith(IrssUtils.Common.CmdPrefixMacro, StringComparison.InvariantCultureIgnoreCase)) + { + node.Tag = new Data("COMMAND", "BLAST", text); + node.Text = text; + } + break; + } } ((Data)node.Tag).Focus = checkBoxGainFocus.Checked; changedSettings = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |